A lightweight, concurrent key-value database built from scratch in C.
Implements low-level file persistence, interprocess communication, multithreading, and networked client access using Unix domain sockets and POSIX system calls.
- Concurrent Request Handling — spawns worker threads per connection using
pthreadfor parallel client servicing. - Interprocess Communication — utilizes Unix domain sockets for local multi-client connectivity.
- Persistent Storage — appends key-value pairs to a data file with atomic writes and locking (
flock). - Compaction via Signals — triggers on
SIGUSR1to reclaim unused disk space. - Custom Commands
set <key> <value>— insert or overwrite a keyget <key>— retrieve a valuesize— return file size using a forkedwcprocesscompact— operates behind scenes with signaling, optimizes datastore file size on reassignment.quit— close client connection
Core Components
kvstore.c— data operations (set,get,size,compact)kvstore_server.c— network listener, connection handler, signal setupkvstore_client.c— interactive user interface and command sender
gcc kvstore.c -c
gcc kvstore_server.c -pthread kvstore.o -o kvstore_server
gcc kvstore_client.c -o kvstore_clientCopy code
./kvstore_server./kvstore_client
MIT License