Skip to content

Hogwarts-coder10/kedis-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

35 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Kedis-Python

A Redis-inspired in-memory datastore built in pure Python to explore storage engines, networking, persistence, caching, and systems architecture.

Built to understand systems, not just use them.


πŸ“– Overview

Kedis-Python is a Redis-inspired in-memory datastore implemented from scratch in Python.

The project was created to explore how modern in-memory databases work internally by implementing core components such as:

  • storage engines
  • command routing
  • networking
  • persistence
  • memory management
  • transactions
  • data structures

Rather than focusing on Redis compatibility, Kedis focuses on understanding the architectural and engineering principles behind high-performance backend systems.


✨ Features

πŸ”‘ Core Key-Value Operations

  • SET
  • GET
  • DEL
  • EXISTS

πŸ“¦ Multiple Data Structures

Strings

SET user karthik
GET user

Lists

LPUSH tasks coding
RPUSH tasks testing
LPOP tasks

Sets

SADD skills python
SADD skills systems
SMEMBERS skills

Hashes

HSET user name karthik
HGET user name

Sorted Sets (Skip Lists)

ZADD leaderboard 100 karthik
ZRANGE leaderboard

Implemented using a custom Skip List inspired by Redis sorted set internals.


⏳ Expiration Support

EXPIRE session 60
TTL session

Supports automatic key expiration.


πŸ’Ύ Persistence

Append-Only File (AOF) persistence:

  • durable write logging
  • automatic recovery on startup
  • AOF compaction support

🧠 Memory Management

LRU-based eviction support:

  • tracks key usage
  • evicts least recently used entries when limits are reached

πŸ”„ Transactions

Supports transactional execution:

MULTI
SET a 1
SET b 2
EXEC

🌐 Networking

TCP server implementation supporting:

  • multiple client connections
  • command execution over sockets
  • standalone local mode fallback

πŸ“Š Observability

Built-in INFO command exposing:

  • key counts
  • data type statistics
  • persistence information
  • expiration information
  • runtime metadata

πŸ“΄ Offline / Standalone Mode

When the server becomes unavailable:

  • users can switch to standalone mode
  • local operations continue
  • users are warned about possible state divergence
  • reconnection remains user-controlled

This feature was added to explore failure handling and graceful degradation.


πŸ—οΈ Architecture

Client
   β”‚
   β–Ό
TCP Server
   β”‚
   β–Ό
Command Parser
   β”‚
   β–Ό
Command Router
   β”‚
   β–Ό
Storage Engine
   β”œβ”€β”€ Strings
   β”œβ”€β”€ Lists
   β”œβ”€β”€ Sets
   β”œβ”€β”€ Hashes
   └── Sorted Sets (Skip Lists)
   β”‚
   β–Ό
Persistence Layer (AOF)

The architecture is intentionally modular to make experimentation and future rewrites easier.


⚑ Benchmark

Current benchmark results:

~5300 requests/sec

Environment:

  • Python 3.x
  • TCP networking enabled
  • Concurrent client workload
  • Mixed GET / SET operations
  • AOF persistence enabled

Benchmarking is ongoing as persistence and networking layers continue to evolve.


πŸ§ͺ Testing

The project includes automated tests covering:

  • command execution
  • data structures
  • persistence recovery
  • expiration behavior

Additional coverage is actively being expanded as the project evolves.


🎯 Design Goals

Kedis was created to explore:

  • storage engine design
  • command-driven architectures
  • networking fundamentals
  • persistence strategies
  • memory management
  • data structure implementation
  • systems engineering tradeoffs

πŸ€” Why Skip Lists?

Sorted Sets are implemented using Skip Lists.

Reasons:

  • expected O(log N) insertion
  • expected O(log N) lookup
  • natural ordered traversal
  • simpler implementation than self-balancing trees

This mirrors the design approach used by Redis for sorted sets.


⚠ Known Limitations

Kedis is an educational systems project and is not intended for production use.

Current limitations include:

  • custom text protocol (RESP not implemented)
  • thread-based concurrency model
  • simplified memory accounting
  • limited fault tolerance compared to production databases

These limitations are intentional learning opportunities and areas of active development.


πŸ›£οΈ Roadmap

Planned improvements:

  • Buffered AOF persistence
  • RESP protocol support
  • Async networking
  • Improved observability
  • Memory-based eviction
  • Enhanced benchmark tooling
  • Additional persistence optimizations

πŸ“š Learning Outcomes

This project explores concepts commonly found in modern backend systems:

  • Redis-style architecture
  • command dispatch systems
  • persistence mechanisms
  • cache eviction policies
  • TCP networking
  • transaction processing
  • skip lists
  • systems performance analysis

πŸš€ Future Direction

Kedis serves as an architecture and systems-design exploration platform before moving toward lower-level implementations and more advanced storage engine designs.

The long-term goal is to understand how production systems are engineered, optimized, and maintained.


🀝 Contributing

Suggestions, issues, and discussions are welcome.

This project is primarily a learning and exploration platform, but contributions are appreciated.


πŸ‘¨β€πŸ’» Author

V SS Karthik

AI/ML Student β€’ Systems Enthusiast β€’ Builder of developer tools and infrastructure projects

"Built to understand systems, not just use them."

About

In-memory data store built from scratch to explore system design, concurrency, and real-world backend architecture.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages