Other

cobalt

Key-value store in Zig

An embedded LSM key-value store written in Zig: a small database that ships inside a program as a library. It writes fast, protects data in a crash and reclaims disk space by itself.

cobalt

About the project

cobalt is an embedded key-value store in Zig: a database that runs inside a program and keeps data as pairs of a key and a value. It has an LSM (log-structured merge) design: fresh writes go to a skiplist (a sorted in-memory structure) backed by a WAL (a write-ahead log that protects data in a crash). They are then flushed to disk as immutable SSTable files, and the space left by old data is reclaimed by leveled compaction, which merges files level by level.

The challenge

An LSM store has to reconcile fast writes with reclaiming disk space. The hardest part was not losing data on the way between memory and disk: a write has to survive a crash before it reaches an SSTable file.

What we did

  1. 01

    An embedded LSM key-value store in Zig

  2. 02

    An in-memory skiplist for fresh writes

  3. 03

    A WAL: every write goes to a log on disk first

  4. 04

    Flushing data from memory to immutable SSTable files

  5. 05

    Space reclaimed by leveled compaction

Related projects

Describe your project.

A free quote comes back within an hour during working hours.

Tell us what you want to build.

A free quote comes back within an hour during working hours. You talk to the person who writes the code.