Built on our single-node code, now we're actually spreading messages across multiple nodes! Kept it super simple but effective - just tell everyone about new messages.
Instead of getting fancy with topology or complicated gossip protocols, went with the most straightforward solution:
When a node gets a new message, tell literally everyone else
Skip the node that sent us the message (no echo chambers!)
Skip ourselves (we already know the message)
Fire-and-forget sends for speed
Each new message gets blasted out to all other nodes (except the sender). Using goroutines to send messages concurrently keeps things snappy.
Using a map for O(1) duplicate detection
Empty struct value saves memory (0 bytes!)
Clean lock handling to prevent races
Full Connectivity: Every node knows about every other node
Direct Communication: No need to route through intermediaries
Fast Propagation: New messages spread in one hop
Duplicate Prevention: Map-based deduplication keeps us efficient
Pros:
Dead simple implementation
fast message propagation (one hop)
No topology management needed
Easy to reason about
Cons:
Not network efficient (O(n) messages per broadcast)
More network traffic than necessary
Might not scale well to huge clusters
But for our needs here ig, simple is better than complex. This does the job reliably and the code is clear. We'll optimize if we need to in 3d and 3e!