Kafka-inspired · Pure Go · No dependencies

A distributed commit log
built from scratch

Segmented storage, sparse indexing, ISR replication, epoch-fenced leader election, and group commit batching: sustaining 245k records/sec at P99 < 20ms.

View on GitHub See the numbers
245krec/s
peak throughput · group commit
18.4ms
P99 write latency
10k
fault scenarios validated
Architecture

How it works

Eight phases, each building on the last. Every layer is independently tested and documented.

📦
Producer
Idempotent sends
Group Commit
Batch fsync
📂
Segment Log
CRC + sparse index
🔁
ISR Replication
High-watermark
🗳️
Leader Election
Epoch fencing
🧪
Fault Sim
Seeded RNG

Results

By the numbers

01

Throughput & latency

Group commit amortises fsync cost across concurrent writers: one sync covers hundreds of records instead of one. Batch size is emergent: more concurrent producers means larger batches, which means fewer fsyncs per record.

183k–245k
rec/s · P99 18.4ms
02

Replication & failover

ISR-based replication with high-watermark consistency ensures consumers never read un-replicated records. Epoch-fenced leader election prevents stale leaders from writing after a new leader has been elected: zero split-brain, zero acknowledged-record loss.

0 lost
records · <3s failover
03

Fault injection

Deterministic simulator with seeded RNG: same seed → same fault schedule every run. Crashed leaders, network partitions, message delays and reorderings: all reproducible. Found 7 correctness bugs invisible to unit tests.

10,000
scenarios · 7 bugs found

Implementation

8 phases, ~40 source files

Built incrementally: each phase has its own PDF writeup, test suite, and can be read in isolation.

01

Segmented Commit Log

CRC-stamped records, 8-byte sparse index entries, segment rolling, crash recovery. 7 tests including property test and torn-write simulation.

record.go index.go segment.go recovery.go 7 tests
02

Wire Protocol & TCP Server

Length-prefixed binary framing, semaphore-based backpressure, graceful SIGTERM shutdown, linger-timer producer batching. Fuzz-tested decoder.

frame.go codec.go server.go 17 tests
03

Topics, Partitions & Ordering

Per-partition append-only logs, key-hashed routing, sticky producer assignment. Per-partition ordering guarantee.

topic.go partition.go tests passing
04

Consumer Groups & Sticky Rebalance

Group coordinator, sticky partition assignment to minimise rebalance churn, durable offset commits to an internal log.

coordinator.go rebalance.go tests passing
05

ISR Replication

Leader–follower log replication, high-watermark tracking, follower fetch loop, ISR shrink and expand on lag detection.

replication.go isr.go tests passing
06

Leader Election & Epoch Fencing

Durable monotonic EpochStore, controller polling loop, NeedsElection / Elect pure functions, Fence() rejects stale epochs. 5 tests including split-brain scenario.

epoch.go election.go controller.go 5 tests
07

Fault Injection Simulator

SimClock (zero wall-clock cost), seeded Network with drop/delay, invariant checker (CheckAllOwned, CheckMonotonic, CheckNoRegression), Reproduce() for replay. 10 tests, race-clean.

sim/clock.go sim/network.go sim/simulator.go 10 tests
08

Idempotent Producer & Group Commit

SequenceTracker dedup, EncodeKey wire format, appendNoSync + batch sync(), MaxBatchSize / MaxBatchWait config, CI perf gate with 10% regression threshold.

sequence.go groupcommit.go eval/metrics.go 9 tests 245k rec/s

Stack

Technology

Pure Go: no external runtime dependencies in the broker binary.

Language
Go 1.25
Storage
os.File + fsync
Network
Raw TCP
Serialisation
encoding/binary
Runtime
Alpine Docker
Tests
go test -race
$ go run ./cmd/metrics/ -workers 500 -duration 5s
measuring: 500 workers, 5s window...

Bullet 1: throughput & latency
  Group commit: 183,682–244,909 rec/s   P50: 9.2ms   P99: 18.4ms

Bullet 2: replication & failover
  Acknowledged lost records: 0   Failover: 1200ms–2400ms

Bullet 3: fault injection
  Scenarios: 10,000   Seeds: 100   Violations found: 7