Skip to content

Driftless

Raft consensus in Go, checked by a deterministic simulator that tries to break it.

Role
Designer & engineer, M.S. project
Timeline
2022
The Driftless replay viewer: the DRIFTLESS wordmark on orange, and 2,000 seeded runs with 43,410 injected crashes and partitions and zero broken invariants.
The Driftless replay viewer: the DRIFTLESS wordmark on orange, and 2,000 seeded runs with 43,410 injected crashes and partitions and zero broken invariants.

The problem

Distributed databases keep copies of data on several machines that must agree, even when networks split, machines crash and messages are lost. The bugs that break agreement are rare and depend on timing, so ordinary tests almost never see them, and when they do, they cannot reproduce them.

And a test suite that has never caught anything proves nothing.

What I did

I implemented Raft consensus in Go as a pure state machine, with no clocks, sockets or disks, so the same code runs in a real cluster and in a simulator.

A seeded simulator drives a five-node cluster through partitions, crashes, restarts and lost, duplicated or reordered messages while clients read and write, and every run replays exactly from its seed. A linearizability checker I wrote from scratch, with safety invariants, decides whether anything went wrong.

To prove the checks work, I planted three well-known Raft bugs that can be switched on.

Driftless replays: the correct build and three planted bugs, with a message-by-message timeline of a five-node cluster under partitions and crashes.

The outcome

Across 2,000 seeded runs of the correct build (27.6 million messages, 43,410 injected faults, 16,540 elections), no invariant broke and every history was linearizable.

Every planted bug was caught: stale reads in 291 of 2,000 runs, a forgotten vote in 20, and the Raft paper’s Figure 8 scenario in 40. CI fails if the simulator ever stops catching one.

Driftless bug hunts: 2,000 seeded runs per build, with how many runs failed, the first failing seed and which check caught each planted bug.

Next project

Hark

Live captions that run on your device and learn your voice from your corrections.