---
title: "cobalt: Key-value store in Zig | VulCode"
description: "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."
url: "https://vulcode.com/en/portfolio/other/cobalt"
lang: "en"
---

[Other](https://vulcode.com/en/portfolio/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.

## 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

- An embedded LSM key-value store in Zig

- An in-memory skiplist for fresh writes

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

- Flushing data from memory to immutable SSTable files

- Space reclaimed by leveled compaction

## Related projects

- [**excache** A cache written in Elixir on the OTP actor model, for applications where many processes read and write data at once. One failing process does not stop the others.](https://vulcode.com/en/portfolio/other/excache)

- [**fluxswap** A set of smart contracts for a decentralised exchange (DEX), written in Solidity and built with Foundry. It covers liquidity pools, a router, staking and a timelock.](https://vulcode.com/en/portfolio/other/fluxswap)

- [**gambit** A chess engine written in Scala 3 and built with the scala-cli tool. It generates moves, evaluates positions and picks the move to play on its own.](https://vulcode.com/en/portfolio/other/gambit)

## Describe your project.

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

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)

## 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.

[Free quote](https://vulcode.com/en/quote) [Free consultation](https://vulcode.com/en/consultation)

- [hello@vulcode.com](mailto:hello@vulcode.com)

- [+48 576 043 920](tel:+48576043920)

- [discord.gg/vulcode](https://discord.gg/vulcode)
