Search⌘ K
AI Features

High-Level Design of Sharded Counters

High-level solution sketch

Handling millions of likes on a single tweet can create contention on a shared counter. If each like generates a write request to the same counter, the updates are serialized at that resource. This serialization increases write latency and limits overall throughput.

Real-time applications require low latency. To achieve this, we must eliminate the bottleneck caused by concurrent writes to a single data point.

The following illustration demonstrates this problem:

Celebrity vs. common people tweet
Celebrity vs. common people tweet

A single counter cannot handle millions of concurrent writes. The solution is a sharded counter (or distributed counter). This approach splits the counter into multiple shards, each running in parallel on a different node. By balancing write requests across these shards, we reduce contention and improve performance.

When a user likes a tweet, ...