High-Level Design of Sharded Counters 00:00:01 A view counter attracts every writer to one row A small video receives twenty views per second. Then it reaches twenty-seven hundred seventy-eight per second while the one counter row can apply only two hundred increments per second. 20 increments a second use a tenth of the row. 180 a second: waiting begins. 2,778 a second arrive, 200 are served. The queue grows without end. The key still has one owner. Adding machines changes nothing here. With constant rates, backlog grows by twenty-five hundred seventy-eight increments each second. Adding unrelated machines does not move any work while the one key still has a single write owner. 00:00:46 Send each increment to one of five buckets Create five independently updatable counter shards at zero. For each new view choose exactly one shard and increment it atomically. Follow three simultaneous arrivals across different keys. The service creates five shards at zero. The random choice is 2. Shards 0, 2 and 4 each take one, in parallel. The shards are nearly equal. Random selection spreads work in expectation, not in perfectly equal short runs. Retries need an event identity or another deduplication policy when the count must avoid duplicate views. 00:01:26 The missing fifth reply is not a zero Five shard totals are ready. Ask every shard, add the replies, then remove one result and predict whether the four-shard sum can still be shown as the complete count. One request fans out to five. 12,345 plus 12,344 plus 12,345 plus 12,346 plus 12,344. The sum of four would be 49,378. That is not the count. Show 61,724 and its age. The complete values sum to sixty-one thousand seven hundred twenty-four. A partial sum can be labeled as partial, or the interface can show a known complete cached total with its age. 00:02:15 Size the shard count from a measured rate Try three write loads against three measured per-shard capacities. Divide offered increments per second by sustainable increments per shard per second and round up before adding operating headroom. 1,000 a second at 100 each. 10,000 a second at 200 each. 100,000 a second at 1,000 each. Capacity calculations assume the shards disperse across real resources and traffic spreads reasonably. A higher shard count costs more on reads, metadata, coordination and recovery. 00:02:51 Add three buckets before sending views to them Five shards approach their capacity limit. Add three empty shards, update readers to include all eight, then let writers choose from the expanded range. Why does this order matter? All are busy. Three empty keys count as zero. Writes now spread over eight. If writers go first, shards 5 to 7 are missing from the sum. New empty shards contribute zero, so old data need not move. Publish the configuration safely and keep old readers from silently reporting totals that omit new shards.