AlgoViz

Sharded counters in detail

hard 28 min

What a sharded counter needs in production: a cached total, write buffering with a known loss, a clear consistency promise, changing the number of shards live, replicas and failover, retries that do not count twice, and monitoring.

Where it shows up

The same pattern appears across everyday software.

  • Redis with append-only file

    With fsync every second, the documentation says about one second of writes can be lost in a disaster. The same kind of number as a write buffer.

  • Redis Cluster failover

    The specification describes small windows in which acknowledged writes can be lost, because replication is asynchronous.

  • DynamoDB atomic counters

    The developer guide states that these updates are not idempotent: a retry can overcount. It suggests conditional updates where that is not acceptable.

  • DynamoDB adaptive capacity

    The service reacts to uneven access by itself, but a single partition has a documented maximum of 1,000 write units a second.

  • Java LongAdder

    Grows its set of cells under contention and documents that the sum is not an atomic snapshot while updates run.

  • Prometheus counters

    Each process exposes its own counter that only increases or resets to zero on restart; queries add them up. Shards by process, aggregated outside.