ARCHIVED from builddistributedsystem.com on 2026-04-28 — URL: https://builddistributedsystem.com/tracks/gossiper/tasks/task-3-4-5-gossip-kv-bench
TASK

Implementation

Benchmark your gossip KV store to measure real-world performance characteristics:

  1. Convergence time: How long until all replicas have the same value?
  2. Message overhead: How many gossip messages per write operation?
  3. Consistency violations: How often does a read return stale data?

Implement a bench_write that tracks timing:

Request:  {"type": "bench_write", "msg_id": 1, "key": "x", "value": "v1"}
Response: {"type": "bench_write_ok", "in_reply_to": 1, "write_id": 1}

And a bench_report endpoint:

Request:  {"type": "bench_report", "msg_id": 2}
Response: {"type": "bench_report_ok", "in_reply_to": 2,
           "total_writes": 10, "total_gossip_msgs": 45,
           "msgs_per_write": 4.5, "keys_stored": 5}

Sample Test Cases

Bench write returns write_idTimeout: 5000ms
Input
{"src":"c0","dest":"n1","body":{"type":"init","msg_id":1,"node_id":"n1","node_ids":["n1"]}}
{"src":"c1","dest":"n1","body":{"type":"bench_write","msg_id":2,"key":"x","value":"v1"}}
Expected Output
{"src": "n1", "dest": "c0", "body": {"type": "init_ok", "in_reply_to": 1, "msg_id": 0}}
{"src": "n1", "dest": "c1", "body": {"type": "bench_write_ok", "write_id": 1, "in_reply_to": 2, "msg_id": 1}}
Bench report with zero writesTimeout: 5000ms
Input
{"src":"c0","dest":"n1","body":{"type":"init","msg_id":1,"node_id":"n1","node_ids":["n1"]}}
{"src":"c1","dest":"n1","body":{"type":"bench_report","msg_id":2}}
Expected Output
{"src": "n1", "dest": "c0", "body": {"type": "init_ok", "in_reply_to": 1, "msg_id": 0}}
{"src": "n1", "dest": "c1", "body": {"type": "bench_report_ok", "total_writes": 0, "total_gossip_msgs": 0, "msgs_per_write": 0, "keys_stored": 0, "in_reply_to": 2, "msg_id": 1}}

Hints

Hint 1
Track total messages exchanged for gossip sync
Hint 2
Measure time from write to full convergence (all replicas agree)
Hint 3
Count consistency violations: reads that return stale data
Hint 4
Compare metrics under normal vs partition conditions
Hint 5
Expose metrics via a bench_stats endpoint
OVERVIEW

Theoretical Hub

Concept overview coming soon

Key Concepts

benchmarkingconvergence timemessage overheadconsistency
main.py
python
Benchmark Gossip KV Store Performance - The Gossiper | Build Distributed Systems