ARCHIVED from builddistributedsystem.com on 2026-04-28 — URL: https://builddistributedsystem.com/tracks/gossiper/tasks/task-3-2-5-tuning
TASK

Implementation

The Maelstrom broadcast workload requires messages-per-op < 30 under network partitions. Your task is to implement configurable gossip parameters and track message efficiency.

Implement a configure handler to set gossip parameters:

Request:  {"type": "configure", "msg_id": 1, "fanout": 3, "gossip_interval_ms": 200}
Response: {"type": "configure_ok", "in_reply_to": 1}

And a gossip_stats handler to report efficiency:

Request:  {"type": "gossip_stats", "msg_id": 2}
Response: {"type": "gossip_stats_ok", "in_reply_to": 2, 
           "broadcasts_received": 10, "gossip_messages_sent": 45,
           "messages_per_op": 4.5, "unique_messages": 10}

Sample Test Cases

Configure updates fanoutTimeout: 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":"configure","msg_id":2,"fanout":3,"gossip_interval_ms":100}}
Expected Output
{"src": "n1", "dest": "c0", "body": {"type": "init_ok", "in_reply_to": 1, "msg_id": 0}}
{"src": "n1", "dest": "c1", "body": {"type": "configure_ok", "in_reply_to": 2, "msg_id": 1}}
Stats with zero broadcastsTimeout: 5000ms
Input
{"src":"c0","dest":"n1","body":{"type":"init","msg_id":1,"node_id":"n1","node_ids":["n1"]}}
{"src":"c1","dest":"n1","body":{"type":"gossip_stats","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": "gossip_stats_ok", "broadcasts_received": 0, "gossip_messages_sent": 0, "messages_per_op": 0, "unique_messages": 0, "in_reply_to": 2, "msg_id": 1}}

Hints

Hint 1
messages-per-op = total messages sent / total broadcast operations
Hint 2
Lower fanout = fewer messages but slower convergence
Hint 3
Higher gossip interval = fewer rounds but more latency
Hint 4
The sweet spot balances message overhead vs delivery reliability
Hint 5
Track both metrics and expose them via a stats endpoint
OVERVIEW

Theoretical Hub

Concept overview coming soon

Key Concepts

parameter tuningmessages-per-oplatency tradeoffgossip optimization
main.py
python
Tune Gossip Parameters for Maelstrom Broadcast - The Gossiper | Build Distributed Systems