Challenge 4: G-Counter (Eventually Consistent Counter)

desccode

Built a distributed counter that survives network partitions using node-local counters and eventual consistency. No fancy CRDTs needed - just good old divide and conquer.

How it Works

Local First, Global Later

Implementation Bits

Why This Works

  1. Partition Friendly: Nodes keep working even when isolated

  2. Eventually Consistent: Global reads converge once network heals

  3. Fast Writes: No coordination needed for increments

  4. Clean Code: ~150 lines tells the whole story

Trade-offs

Pros:

Cons:

Could've gone full CRDT, but letting each node count its own stuff just works. Plus, Go's goroutines make those concurrent reads feel like cheating.