DEV Community

ashfromsky
ashfromsky

Posted on

Building a Type-Safe In-Memory DB

Hi everyone! ๐Ÿ‘‹ Iโ€™d like to share a backend engineering project that Iโ€™ve been working on:

YaraDB โ€” a lightweight, document-oriented in-memory database built entirely with Python and FastAPI, designed to work natively with Pydantic models.

๐Ÿ‘‰ Repo: Repo

Key Technical Features:

  • โšก Hybrid Storage Engine: Organize data into Tables that support both Strict Mode (rigid schema enforcement) for critical data and Free Mode (schema-less) for rapid prototyping.
  • ๐Ÿ” Advanced Indexing: Don't just scanโ€”search. Includes built-in Hash Indexes for O(1) lookups and B-Tree Indexes for fast range queries and sorting (O(log n)).
  • ๐Ÿ›ก๏ธ Optimistic Concurrency Control (OCC): Built-in protection against race conditions using document versioning (returns 409 Conflict on mismatches).
  • ๐Ÿ’พ Persistence: Implements WAL (Write-Ahead Logging) and Snapshots, so you don't lose data if the server restarts or crashes.
  • ๐Ÿ”Œ HTTP-Native: No drivers needed โ€” it runs on FastAPI, so you can interact with it via standard REST calls or the built-in Swagger UI.

๐ŸŒฑ Why I Built It

I love Redis, but for many Python microservices, I found myself writing the same validation logic over and over again to ensure the JSON I got back wasn't broken.

My goals were:

  • To create a storage solution where Data Integrity is a first-class citizen (Schema-first approach).
  • To dive deep into database internalsโ€”implementing my own WAL, Indexing engine, and Concurrency Control logic in Python was a huge learning experience.
  • To make a tool perfect for AI Agents and LLMs that need structured short-term memory without the complexity of setting up a heavy SQL server.
  • It's currently in the Alpha/MVP stage. Itโ€™s not a "Redis killer" (C is faster, obviously), but itโ€™s a robust, developer-friendly alternative for Python-heavy stacks.

๐Ÿค Contributing

I am actively looking for feedback on the architecture, especially regarding the WAL implementation and performance optimizations.

If you are interested in backend engineering, database internals, or just want a lightweight DB for your next pet project, check it out!

Feedback and โญ stars are highly appreciated!

Top comments (0)