← Building blocks

Fix a hot shard

Scaling & loadsenior

One partition takes most of the traffic (a celebrity, a popular tenant, a time-ordered key).

Say it like this

The celebrity partition is taking most of the writes, so I salt the key into sub-partitions and read them back together, trading a wider read for an even write load.

Basic solution

Choose a key with better spread, add a random or hashed prefix to spread sequential keys, or split the hot partition.

salted keyscompound partition keysrange splitting

Salting a hot key across buckets

Writes to the hot key are spread across bucketed partitions by appending a salt. A read fetches every bucket and merges, so the pattern suits write-hot, read-cached keys.

How it works

  1. Detect the skew: per-partition metrics (requests per second and latency for each partition) show one partition carrying a multiple of the average load while the others sit idle.
  2. Identify why. Either a single hot entity (a celebrity account, a large tenant) owns the partition, or a sequential key (a timestamp, an auto-increment id) sends every new write to the last range in the key space.
  3. Spread the writes: append a salt to the key, so post_id#0 through post_id#15 become sixteen physical partitions for one logical key. Each write picks a salt at random and lands on one of the sixteen, so the write load divides by sixteen.
  4. Spread the reads: a read of the logical key fans out to all sixteen salts, fetches each bucket, and merges the results in memory. Cache the merged result, because hot keys are read far more often than they are written and the cache absorbs the repeat reads.
  5. For a sequential key, reverse or hash the leading part of the key so new writes land across the whole key space instead of piling onto the end.
  6. If one entity is big enough on its own, give it a dedicated partition or shard and route it there explicitly through a directory entry.

Why not just add nodes

  • Adding nodes spreads keys across more machines, not a single key. A hot key still hashes to one partition on one node however many nodes you add, so only splitting or replicating that key changes where its traffic goes.

Worked example

News feed fan-out for a celebrity

  • A user with 50M followers posts. Push fan-out would write 50M timeline entries: at 100K writes/s that is 8 minutes of writing, and if timelines are keyed by author one partition takes all of it.
  • Hybrid rule: above 10K followers the post is not pushed into follower timelines at all. Readers pull the celebrity author's recent posts at read time and merge them into their timeline, so the 50M writes never happen.
  • The celebrity's posts_by_author partition is still hot on read: ~50M followers × 5 feed loads/day ≈ 2,900 reads/s landing on one partition, more than one partition serves comfortably.
  • Fix: cache the last 50 post ids per celebrity in Redis (one key per author, replicated under 8 suffixes so reads spread across 8 cache nodes). Each cache copy serves ~360 reads/s; the partition itself sees only cache refreshes, a few per minute.

Variants and when each wins

Salted (bucketed) keys

  • The logical key gets a bucket number appended so writes spread across several physical partitions, and reads fetch every bucket and merge. It wins for write-hot counters and append-only lists that are read rarely or through a cache.

Dedicated partition or shard for the hot entity

  • The few hottest tenants are routed to their own hardware by a directory entry, so their load cannot affect anyone else. It wins when a handful of entities are predictably large; it needs the directory and a way to detect and promote new hot entities.

Caching in front

  • If the key is read-hot rather than write-hot, you replicate it in a cache (suffixed copies across nodes, plus an in-process cache in each app server) so the partition only sees refreshes. It wins whenever the hot traffic is reads of a value that changes slowly.

Key redesign

  • Reverse the timestamp, hash the leading column, or use a compound key such as (tenant_id, random) so new writes do not pile onto one range. It wins for sequential keys, where the skew is a property of the key itself rather than of one entity.

Fix write-hot keys with salting or a dedicated shard; fix read-hot keys with caching; fix sequential keys by redesigning the key.

Failure modes

Salting breaks range scans

  • A "latest 20 posts" query that used to be one read now needs 16 reads and a merge. It happens because each bucket is sorted independently, so no single bucket holds the overall latest 20. Fix it by reading all buckets with a small limit each and merging in memory, and cap the bucket count at what one request can fan out to without hurting latency.

Salt count fixed too low

  • The skew comes back as the entity grows. It happens because 4 buckets spread the load 4× and no further; once the entity's traffic grows past four partitions' worth, the hot spot returns. Fix it by choosing the bucket count per entity from its size and storing that count alongside the key, so readers know how many buckets to fetch.

Hot entity promoted too late

  • An account goes viral and takes its partition down before anyone reacts. It happens because moving an entity onto the hot path is a manual decision. Fix it with automatic detection on per-key request rate, with a threshold that switches the entity to the hot path without a human in the loop.

Cache stampede on the hot key

  • The hot key's cache entry expires and the partition is flattened by every reader missing at once. It happens because the cache was the only thing between the readers and the partition. Fix it with refresh-ahead for hot keys, so the entry is renewed before it expires, and single-flight refresh so only one request fetches.

Timestamp-leading keys

  • Write throughput never rises no matter how many nodes you add. It happens because every insert goes to the newest range, which lives on one node. Fix it with a hash prefix on the key or a compound key of (shard_id, timestamp) so inserts spread across nodes.

Interviewer follow-ups

Answer out loud before you open each one.

How do you detect a hot partition before it becomes an incident?

Per-partition throughput and latency metrics with an alert on the ratio of the hottest partition to the median. Many stores expose this directly, such as CloudWatch contributor insights for DynamoDB. Alert at 5× the median, which is well before saturation.

Why does adding more nodes not fix a hot key?

A key maps to exactly one partition, so it lands on one node regardless of how many exist. More nodes reduce the average load, not the maximum per key. Only splitting the key itself, or replicating it, changes where its traffic goes.

What is the cost of salting a key into 16 buckets?

Reads of that key become 16 reads plus a merge, roughly 16× read cost and some extra tail latency. That is why salting fits write-hot keys that are read rarely or read through a cache, not keys read on every request.

How would you handle a celebrity in a push-based feed?

Do not push. Set a follower threshold, mark accounts above it, and have the feed service pull their recent posts at read time and merge with the pushed timeline. Cache those recent posts heavily because every follower reads the same list.

Connections

In study paths
Splitting the data · Feeds and fan-out
Built on
Consistent hash ring
Pairs with
Partition the data · Spread a hot key · Precompute on write, read cheaply · Protect against a cache stampede
Pulls against
Page results with a cursor
Used in
News Feed (Twitter / X timeline) · Ride Matching (Uber / Lyft)

The same parts on other clouds

The diagrams above name AWS services as one concrete example. Every part has a close equivalent elsewhere. In an interview, name the role first, such as “a managed Redis cache”, then the product you would pick.

AWSUsed here asGoogle CloudMicrosoft AzureOpen source and others
Amazon EC2 Auto ScalingWriter, ReaderCompute Engine managed instance groupsVirtual Machine Scale SetsKubernetes Deployment with a HorizontalPodAutoscaler, Nomad
Amazon ElastiCacheMerged result cacheMemorystoreAzure Managed RedisRedis, Valkey, Memcached