Imagine the final of a band contest in a city park. The audience votes by phone, the big screen shows a live total, and thousands of votes per second pour in, most of them for one favourite band. The table runs in on-demand mode, so it "should scale automatically". Instead, the logs fill up with ThrottlingException.

I wrote a full hands-on guide on DynamoDB write sharding with a working voting API. This post sums up the ideas behind it.

One key, one partition, one hard ceiling

DynamoDB spreads data across physical partitions by partition key. According to the AWS documentation, a single partition delivers at most 1,000 write units and 3,000 read units per second, no matter how big the table is or which capacity mode you use. On-demand scales the table as a whole, not a single key.

Adaptive capacity helps with uneven load and can even isolate a very popular item on its own partition. That item still never gets more than 1,000 write units per second. For one counter that everybody increments, that is a physical limit.

Two tools help you confirm the diagnosis. The ThrottlingReasons field in the error tells you whether one key range or the whole table hit its limit, for example TableWriteKeyRangeThroughputExceeded. And CloudWatch Contributor Insights in THROTTLED_KEYS mode names the hot key, while only costing money when throttling actually happens. I would turn that on for important tables even before there is a problem.

Spread the writes, add them up on read

The idea is almost boringly simple. Instead of one key for the favourite band, you use twenty keys with a numeric suffix. Each write picks one of them, DynamoDB hashes them to different partitions, and one bottleneck becomes twenty small streams.

export const counterKey = (contest: string, band: string, shards: number) => `VOTES#${contest}#${band}#${Math.floor(Math.random() * shards)}`; export const allCounterKeys = (contest: string, band: string, shards: number) => Array.from({ length: shards }, (_, i) => `VOTES#${contest}#${band}#${i}`); 

A random suffix fits counters, where only the sum matters. If you need to find a single item again, a calculated suffix such as a hash of the order number keeps it reachable with a plain GetItem.

The price is paid on reads: the total means fetching every shard and summing them. For the sizing I use napkin math with a 50 percent safety margin. With up to 5,000 votes per second and a transaction costing 2 write units per item, the article ends up at 20 shards. Also keep the adjustable table-level default of 40,000 write units per second for on-demand tables in mind.

The rollout mistake that silently drops votes

The nastiest trap shows up later. Say the event grows and you double the number of shards for writing. If the read path still only knows the old number, about half of the new votes land on shards nobody reads. Every vote is stored correctly, yet the total grows at half speed.

That is why the example keeps two separate settings for reading and writing. Raise the read side first and deploy, then raise the write side. Empty shards simply count as zero. Never lower the read value below the highest write value you have ever used.

Shard the hot key, not the whole table

The most common mistake I see is sharding everything. Most access patterns spread out on their own, and every suffix makes reads more complicated. Shard only the key that Contributor Insights or your load calculation points to. Watch out for global secondary indexes with few distinct values, and do not add tight retry loops on top of the SDK's own backoff, which only makes a hot partition hotter.

Before reaching for suffixes, I also ask myself whether the counter really needs to be exact to the second. Sometimes an aggregated total every minute is enough, and sharding becomes unnecessary.

What the full article covers

  • A complete voting API with Lambda, TypeScript and the Serverless Framework, using a transaction to prevent double votes
  • The read path with BatchGetItem, retries for unprocessed keys and a short cache
  • Shard sizing in a table, growing and shrinking shards safely, and an aggregator for very hot reads
  • Tests that run without AWS, IAM details, costs and security notes

Read it here: DynamoDB write sharding: avoid hot partitions

📖 This is the condensed version. The full article on sascha-ms.de goes deeper – with all code samples, diagrams and a short knowledge check.

👉 Next step: Not sure which AWS service fits your use case? My AWS service finder asks a few questions and points you to the right one.

📬 Stay updated: New articles on serverless, AI and leading tech teams via RSS, browser push or the weekly newsletter (in German).

Originally published on sascha-ms.de. More articles on serverless, AI in everyday development and leading tech teams: sascha-ms.de/en