A comprehensive, high-performance in-memory database system with ACID transactions, persistence, and RESTful API.
- Key-Value Store: Store and retrieve data with O(1) average complexity
- Multiple Data Types: Support for strings, integers, floats, booleans, and complex objects
- TTL Support: Automatic expiration of keys with configurable time-to-live
- Memory Management: Configurable memory limits with LRU eviction policies
- Write-Ahead Logging (WAL): Every write operation is logged before execution
- Snapshots: Periodic point-in-time snapshots of the entire database
- Crash Recovery: Automatic recovery from WAL and snapshots on startup
- Backup & Restore: Manual backup and restore capabilities
- Thread-Safe Operations: Concurrent access using optimized locking
- ACID Transactions: Atomic, consistent, isolated, durable transactions
- Multiple Clients: Support for thousands of concurrent connections
- Deadlock Prevention: Ordered locking to prevent deadlocks
- In-Memory Storage: All data stored in RAM for maximum speed
- Optimized Data Structures: Concurrent hash maps and LRU caches
- Minimal Overhead: Efficient serialization and compression
- High Throughput: Designed for high-performance workloads
- RESTful API: Complete HTTP REST API for all operations
- JSON Protocol: Human-readable request/response format
- Error Handling: Comprehensive error codes and messages
- Health Monitoring: Built-in health checks and metrics
# Clone the repository
git clone mukhostho-db.git
cd mukhostho-db
# Build the application
go build -o mukhostho cmd/mukhostho/main.go
# Run with default settings
./mukhostho# Run with custom configuration
./mukhostho -config config.json -port 9090 -memory-limit 4096
# Available flags:
# -config: Path to JSON configuration file
# -data-dir: Data directory (default: ./data)
# -port: Server port (default: 8080)
# -host: Server host (default: localhost)
# -memory-limit: Memory limit in MB (default: 1024)
# -log-level: Log level (debug, info, warn, error)curl -X PUT http://localhost:8080/api/v1/keys/mykey \
-H "Content-Type: application/json" \
-d '{"value": "Hello World", "ttl": 3600}'curl http://localhost:8080/api/v1/keys/mykeycurl -X DELETE http://localhost:8080/api/v1/keys/mykeycurl http://localhost:8080/api/v1/keyscurl http://localhost:8080/api/v1/itemscurl -X POST http://localhost:8080/api/v1/transactions
# Returns: {"transaction_id": "txn-1234567890-1"}# Set operation
curl -X PUT http://localhost:8080/api/v1/transactions/txn-1234567890-1/set \
-H "Content-Type: application/json" \
-d '{"key": "key1", "value": "value1"}'
# Delete operation
curl -X DELETE http://localhost:8080/api/v1/transactions/txn-1234567890-1/delete \
-H "Content-Type: application/json" \
-d '{"key": "key2"}'curl -X POST http://localhost:8080/api/v1/transactions/txn-1234567890-1/commitcurl -X POST http://localhost:8080/api/v1/transactions/txn-1234567890-1/rollbackcurl -X POST http://localhost:8080/api/v1/admin/snapshot \
-H "Content-Type: application/json" \
-d '{"description": "Manual backup"}'curl http://localhost:8080/api/v1/admin/statscurl http://localhost:8080/api/v1/admin/memorycurl http://localhost:8080/api/v1/admin/health{
"server": {
"host": "localhost",
"port": 8080,
"read_timeout": "30s",
"write_timeout": "30s",
"max_clients": 1000
},
"memory": {
"max_memory_mb": 2048,
"eviction_policy": "lru",
"ttl_cleanup_delay": "1m",
"gc_interval": "5m"
},
"persistence": {
"data_dir": "./data",
"wal_dir": "./data/wal",
"snapshot_dir": "./data/snapshots",
"backup_dir": "./data/backups",
"snapshot_interval": "10m",
"wal_sync_policy": "always",
"compression_type": "gzip"
},
"logging": {
"level": "info",
"format": "json",
"output": "stdout"
}
}host: Server bind addressport: Server port numberread_timeout: HTTP read timeoutwrite_timeout: HTTP write timeoutmax_clients: Maximum concurrent connections
max_memory_mb: Maximum memory usage in megabyteseviction_policy: Eviction policy (lru, lfu, random)ttl_cleanup_delay: Interval for cleaning expired keysgc_interval: Garbage collection interval
data_dir: Base data directorywal_dir: Write-ahead log directorysnapshot_dir: Snapshot storage directorybackup_dir: Backup storage directorysnapshot_interval: Automatic snapshot intervalwal_sync_policy: WAL sync policy (always, periodic, never)compression_type: Compression for snapshots (none, gzip, lz4)
- GET operations: < 100μs average
- SET operations: < 200μs average (including WAL)
- DELETE operations: < 150μs average
- Transaction commit: < 1ms for small transactions
- Read operations: 1M+ ops/sec (concurrent)
- Write operations: 500K+ ops/sec (with WAL)
- Mixed workload: 750K+ ops/sec
- Key overhead: ~64 bytes per key
- Value overhead: ~32 bytes + value size
- Metadata overhead: ~48 bytes per key
┌─────────────────────────────────────────────────────────────┐
│ API Layer │
│ (HTTP REST, JSON Protocol) │
├─────────────────────────────────────────────────────────────┤
│ Transaction Manager │
│ (ACID Properties, Locking, Isolation) │
├─────────────────────────────────────────────────────────────┤
│ Core Engine │
│ (CRUD Operations, Concurrency Control) │
├─────────────────────────────────────────────────────────────┤
│ Memory Manager │
│ (LRU Eviction, TTL, Garbage Collection) │
├─────────────────────────────────────────────────────────────┤
│ Data Layer │
│ (Concurrent HashMap + LRU Cache) │
├─────────────────────────────────────────────────────────────┤
│ Persistence Layer │
│ (WAL Manager + Snapshot Manager) │
└─────────────────────────────────────────────────────────────┘
- Concurrent Data Structures: Uses Go's
sync.Mapfor lock-free reads - Ordered Locking: Prevents deadlocks in transactions
- WAL-First Design: Ensures durability without blocking operations
- Pluggable Eviction: Configurable eviction policies
- Compression: Optional compression for snapshots
go test ./...go test -bench=. ./test/# Install hey (HTTP load testing tool)
go install github.com/rakyll/hey@latest
# Test SET operations
hey -n 10000 -c 100 -m PUT -H "Content-Type: application/json" \
-d '{"value":"test"}' http://localhost:8080/api/v1/keys/testkey
# Test GET operations
hey -n 10000 -c 100 http://localhost:8080/api/v1/keys/testkey- Memory: 4GB+ RAM recommended
- Storage: SSD recommended for WAL/snapshots
- CPU: Multi-core CPU for optimal performance
- OS: Linux, macOS, or Windows
- Monitor memory usage via
/api/v1/admin/memory - Track operation latencies via logs
- Set up alerts for memory pressure
- Monitor WAL disk usage
- Configure automatic snapshots
- Regularly backup snapshot and WAL directories
- Test restore procedures
- Consider replication for high availability
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
MIT License - see LICENSE file for details.
- GitHub Issues: Report bugs and feature requests
- Documentation: See
/docsdirectory for detailed documentation - Examples: See
/examplesdirectory for usage examples