Case study 01 / Software Engineering
A database, from storage to consensus.
A Go key-value database that connects an embedded LSM storage engine to a Raft-replicated cluster.
The problem
What does a database need to keep a write correct when processes crash, leaders change, or a follower falls behind?
What I built
Built an embedded LSM engine with a write-ahead log, immutable SSTables, Bloom filters, sparse indexes, range scans, and size-tiered compaction. A separate replica mode uses that engine as the state machine for a three-node Raft cluster that can grow to five nodes through joint consensus.
How it works
The replicated path persists and orders commands through Raft before applying them to the LSM engine. A write succeeds only after a majority has persisted and committed it. Durable snapshots bound the retained log and are streamed in chunks to followers that fall behind. The embedded mode keeps its own WAL-based recovery path.
- gRPC client
- Raft quorum
- Committed log
- LSM state
Engineering decisions
One ordering authority
Replica mode uses the Raft log index as the LSM sequence number. This keeps replicated ordering and recovery under one authority.
Correctness through failure
Tests cover pre-vote, elections and partitions, conflicting logs, quorum-loss stepdown, durable-log corruption recovery, snapshot streaming, and membership changes. Reads confirm a current-term quorum before serving. No linearizability checker has been run, so read correctness rests on those tests.
Measure each fix on its own
Interleaved benchmark arms on one VM type isolate each change. A duplicate-acknowledgement loop was sending up to 166 AppendEntries per committed entry. Fixing it and a per-append log copy, then adding leader batching and follower coalescing, took 16-client throughput from 27.9 to 1,531.7 ops/s.
Results & evidence
Write throughput by engine version
- 1 client
- 4 clients
- 16 clients
View data table
| 1 client | 4 clients | 16 clients | |
|---|---|---|---|
| Before fixes (bfa2a77) | 40.6 ops/s [39.5, 43.3] | 23.6 ops/s [22.0, 27.7] | 27.9 ops/s [27.4, 28.6] |
| Ack fix, no log copy (18369e8) | 233.1 ops/s [231.5, 245.3] | 437.5 ops/s [411.5, 461.5] | 419.4 ops/s [410.0, 442.4] |
| Hardening, in-flight limit (53b5d70) | 241.2 ops/s [212.9, 247.7] | 504.5 ops/s [453.8, 536.4] | 526.3 ops/s [507.5, 546.3] |
| Leader batching, follower coalescing (a76f182) | 234.6 ops/s [220.2, 238.5] | 559.3 ops/s [526.5, 593.7] | 1,531.7 ops/s [1,477.1, 1,575.7] |
16-client write throughput
1,531.7 ops/s
Median of 5 runs (range 1,477–1,576) on a GCE e2-standard-4 VM with pd-ssd; three Raft nodes in one process, 128-byte writes, 30 s window. 27.9 ops/s before the Raft fixes.
Single-client p99 latency
5.82 ms
Same setup and final engine; 562.88 ms before the duplicate-acknowledgement fix.
Results are documented in the linked project artifacts. They have not been independently reproduced for this portfolio.
Limits & lessons
One VM type, three nodes in one process, and a write-only load; another disk or a multi-machine cluster would give different numbers. At 16 clients the final engine’s p99.9 latency (363 ms) is about twice the earlier arm’s, and the cause is unknown. No failover measurement exists for the current engine.
A throughput number is only useful alongside its durability settings, its hardware, and the change that produced it.