ARCHIVED from builddistributedsystem.com on 2026-04-28 — URL: https://builddistributedsystem.com/tracks/store/tasks/task-8-2-3-follower-reads
TASK

Implementation

Implement follower reads with bounded staleness. Clients can opt to read from any follower if they accept data up to T seconds stale. This scales read throughput linearly with cluster size.

Request:  {"type": "follower_read", "msg_id": 1, "key": "x", "max_staleness_ms": 5000}
Response: {"type": "follower_read_ok", "in_reply_to": 1, "value": "42", "actual_staleness_ms": 200, "served_by": "n2", "linearizable": false}

Request:  {"type": "follower_read", "msg_id": 2, "key": "x", "max_staleness_ms": 0}
Response: {"type": "follower_read_ok", "in_reply_to": 2, "value": "42", "served_by": "n1", "linearizable": true, "reason": "redirected_to_leader"}

Sample Test Cases

Follower read within staleness boundTimeout: 5000ms
Input
{"src":"c0","dest":"n1","body":{"type":"init","msg_id":1,"node_id":"n1","node_ids":["n1","n2","n3"]}}
{"src":"c1","dest":"n1","body":{"type":"follower_read","msg_id":2,"key":"x","max_staleness_ms":5000}}
Expected Output
{"src": "n1", "dest": "c0", "body": {"type": "init_ok", "in_reply_to": 1, "msg_id": 0}}
Zero staleness redirects to leaderTimeout: 5000ms
Input
{"src":"c0","dest":"n1","body":{"type":"init","msg_id":1,"node_id":"n1","node_ids":["n1","n2","n3"]}}
{"src":"c1","dest":"n1","body":{"type":"follower_read","msg_id":2,"key":"x","max_staleness_ms":0}}
Expected Output
{"src": "n1", "dest": "c0", "body": {"type": "init_ok", "in_reply_to": 1, "msg_id": 0}}

Hints

Hint 1
Clients opt in to reading from followers if they accept data up to T seconds stale
Hint 2
Followers track their applied index; reads are served if the data is fresh enough
Hint 3
This distributes read load across all replicas, not just the leader
Hint 4
The staleness bound is configurable per-request
Hint 5
Compare latency: follower reads avoid the leader bottleneck
OVERVIEW

Theoretical Hub

Concept overview coming soon

Key Concepts

follower readsbounded stalenessread scalabilityconsistency tradeoff
main.py
python
Add Follower Reads with Bounded Staleness - The Store | Build Distributed Systems