Skip to main content
← PROBLEMS / ARCHITECTURE
An end-to-end domain learning journey

Design a Linearizable Metadata & Config Store
with Raft Lease Reads & Watchers.

Pair a 5-node Raft cluster with MVCC B+Tree storage (global monotonic revision), Batched ReadIndex / Follower offload for 100K RPS reads, and multiplexed gRPC Watch streams.
Start the journey5 stages· Last modified Nov 27, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When designing an etcd-scale metadata store, back Watchers with MVCC revision catch-up, protect locks with fencing tokens, and offload reads via ReadIndex.

TL;DR30-second simplified summary
▾

MVCC revisions enable seamless Watch catch-up and monotonic fencing tokens, while Batched ReadIndex + Follower offload serves 100K RPS reads without touching the WAL.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Raft ReadIndex & Lease Reads
Know how Batched ReadIndex and Monotonic Lease Reads serve linearizable reads without WAL writes.
MVCC Revisions & Fencing Tokens
Understand monotonic global revision numbers for Watchers and why distributed locks need monotonic fencing tokens.
Full walkthrough · 5 stages
01
L4 · FUNDAMENTALS

R & E · Requirements, Revision Math & Watch Fanout Sizing.

5K CAS writes/sec x 2 KB = 10 MB/s of Raft log replication across 5 nodes—easily handled by NVMe WALs (<5 ms quorum fsync).

Illustrative Sizing: 100K reads/sec x 4 KB = 400 MB/s (3.2 Gbps) egress. A single Leader's 10 Gbps NIC can serve it, or offloading 80% to the 4 Followers via Follower ReadIndex drops per-node egress to 80 MB/s! For 50,000 Watchers receiving 100 config updates/sec, multiplexing 100 Watchers per gRPC HTTP/2 connection cuts TCP sockets from 50,000 to 500.

Control Plane Scaling

Polling + Unbounded History vs. MVCC Revisions + Multiplexed Watch

Before · Naive Polling + 50K Sockets
  • 50K clients polling every 1s
  • Missed updates during reconnects
  • Leader NIC saturated on reads
After · MVCC + ReadIndex + gRPC Mux
  • Zero missed events via revision
  • Batched ReadIndex + Follower offload
  • 500 muxed HTTP/2 Watch streams
02
L4 · FUNDAMENTALS

S · Storage: MVCC B+Tree Keyed by Monotonic Revision.

Instead of overwriting keys in place, every Raft-committed PUT or DELETE writes a new MVCC tuple keyed by (main_rev, sub_rev).

An in-memory TreeIndex maps user_key -> [rev_1, rev_2, ...] while BoltDB/B+Tree stores rev -> {key, value, create_rev, mod_rev, version, lease_id}. Watchers that disconnect at rev = 10,400 reconnect with watch(start_rev=10,401) and catch up seamlessly from the B+Tree.

MVCC Storage Layout

In-Memory TreeIndex (Key -> Revs) + BoltDB B+Tree (Rev -> Value)

03
L5 · APPLIED DESIGN

H & A · 5-Node Raft + Follower ReadIndex + Watch Multiplexer.

All writes (PUT, CAS, LeaseGrant) route to the Raft Leader, replicate to a 3/5 majority, and commit.

On commit, the state machine updates TreeIndex + BoltDB and immediately pushes {key, rev, value} into the local Watch Event Multiplexer, which fans out to all matching Watchers. Reads hit either Leader Lease/Batched ReadIndex or Follower ReadIndex (Follower -> Leader.ReadIndex() -> local apply >= readIndex).

CAS + Watch Flow

Writer CAS -> Raft Quorum Commit -> MVCC Apply -> Watch Push

Writer ClientRaft LeaderFollowers (3/5)Watchers1. CAS(key, expected_mod_rev=42)2. Replicate Raft entry (rev=43)3. Commit & return fencing rev=434. Mux push event(rev=43)
04
L5 · APPLIED DESIGN

D · Detailed Design: Leases, Fencing Tokens & Watch Catch-Up.

Clients acquire distributed locks by attaching a TTL Lease (LeaseGrant(ttl=10s)) to a lock key via CAS(create_rev == 0).

The store returns the lock key's mod_revision (e.g., 104) as a Fencing Token. Downstream storage servers reject any write carrying token < max_seen_token, blocking a paused zombie lock holder even if its lease expired! If the client fails to send LeaseKeepAlive within 10s, the Leader proposes LeaseRevoke through Raft, deleting all attached keys and notifying Watchers.

Watcher Stream State

Synced (Live Mux) -> Slow Buffer Full (Unsynced) -> MVCC Catch-Up -> Compacted

gRPC buffer fullcaught up to headrev < compact_revSynced (Live Push)Unsynced (B+TreeScan)Compacted ->List+Watch
Engineering Decision Framework
Problem
How to scale Watchers and linearizable reads on a Raft metadata store without OOMing or stalling writes.
Naive Solution
Buffer all Watch events per client in unbounded RAM and run all reads through the Raft WAL.
Why It Fails
Slow Watch clients OOM the server; WAL reads cap cluster read QPS at disk fsync throughput.
Alternatives
Unbounded per-Watcher RAM queues vs. MVCC B+Tree Catch-Up + Bounded Buffers + ReadIndex.
Engineering Decision
Back Watchers with an MVCC B+Tree (unsynced fallback on slow consumers), multiplex over HTTP/2, and serve reads via Batched ReadIndex + Follower offload.
Trade-Offs
Requires periodic MVCC compaction (forcing very stale Watchers to List + Watch) in exchange for bounded RAM and 100K RPS reads.
Decision Exercise · Make the Call

A Watch client pauses for 20 minutes while MVCC compaction runs every 5 minutes. When it reconnects with start_revision = 5,000 (already compacted), what must the metadata store return?

05
L6 · SCALE & TRADE-OFFS

E & D · Evaluation, Assumptions, Limitations & Glossary.

Raft metadata stores are designed for small, critical control-plane state (<=8–16 GB), not bulk blob or event storage.

Assumptions & Limitations: Sizing assumes <=16 GB live MVCC state, <=10 ms intra-region RTT across 5 voting nodes, and periodic 5-minute MVCC compaction. Storing multi-GB payloads or millions of keys per second in Raft saturates BoltDB write transactions and heartbeat timers, risking spurious leader elections.

Control Plane Architecture

5-Node Raft -> MVCC BoltDB -> Batched ReadIndex + gRPC Watch Mux

5-Node Raft QuorumingressMVCC BoltDB +TreeIndexstorageReadIndex +Follower OffloadcomputegRPC WatchMultiplexercontrolcommit rev100K RPS reads50K Watchers
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

How does an etcd-style metadata store let a disconnected Watch client resume without missing any config updates?

Recommended Learning Flow