Sharded Counters for High-Write Systems
A single counter row can only absorb so many concurrent increments before it becomes the bottleneck. Splitting it into shards fixes that.
Advanced
UPDATE restaurants SET order_count = order_count + 1 forces every one of those concurrent writers to serialize on the same database row β the row itself becomes a bottleneck, sometimes called a hot key, no matter how well the rest of the system is sharded.
order_count_shard_0 = 4213
order_count_shard_1 = 4198
order_count_shard_2 = 4256
...
order_count_shard_9 = 4177
total = sum(all shards) # computed at read time, or periodically cached
| Use a sharded counter when⦠| A plain counter is fine when⦠|
|---|---|
| The counter is incremented by many concurrent writers (likes, views, trending items) | Updates are infrequent or naturally serialized (a single restaurant's own inventory count) |
| Write contention on one row is a measured, real bottleneck | There's no evidence of contention β this is a targeted fix, not a default |