Stackbook Logo
scalingestablished · medium operational burden

Hot Key Mitigation

Also known as: hot-partition-mitigation, hot-shard-handling

Intent

Prevent a single disproportionately popular key from overloading one cache node or partition.

Problem

Key-based routing sends all traffic for one key to one node. When a single item goes viral, that node saturates while the rest of the cluster sits idle, and adding nodes does not help.

Forces

  • •Access popularity follows a heavy-tailed distribution
  • •Routing is deterministic by key
  • •Replicating everything wastes memory
  • •Hot keys appear suddenly and unpredictably

Solution

Overview

A hot key is one key whose traffic exceeds what a single node can serve. Consistent hashing and partitioning balance the number of keys, not the number of requests, so a single popular key defeats them.

How it works

Read-side replication:

write(k, v):   for i in 0..N-1: cache.set(k + "#" + i, v)
read(k):       i = random(N); return cache.get(k + "#" + i)

Each suffixed key hashes to a different node, so reads divide roughly by N. Updates must touch all copies, so use this for data that changes rarely.

Write-side splitting for counters:

increment(k):  shard = random(16); incr(k + ":" + shard)
total(k):      sum(get(k + ":" + s) for s in 0..15)

A local cache with a one to five second TTL in each application instance is often the cheapest fix: with 200 instances, a node sees at most 200 requests per TTL for that key instead of millions.

Detect hot keys with sampled counters in the proxy or client library, then promote only those keys to replication. Many stores, such as DynamoDB with adaptive capacity, also offer automatic isolation of hot partitions, but only up to per-partition limits.

Pitfalls

  • Replicating all keys instead of only the hot ones.
  • Forgetting to invalidate every replica on update.
  • Splitting a key that requires transactional reads or exact ordering.
  • Using a fixed list of hot keys. Popularity moves, so detection must be continuous.
  • Rate limits and counters on a single key in front of a global resource.

Key takeaways

  • Load skew, not key count, is the problem; more nodes alone will not fix it.
  • Layer a short-TTL local cache first, then replicate or split.
  • Detect hot keys automatically and apply mitigations selectively.
  • Accept brief inconsistency for replicated read copies.

✓ When to Use

  • •Viral content, flash-sale products and popular configuration keys
  • •Counters or rate-limit buckets with extreme write rates
  • •Partitioned stores where one partition shows disproportionate load

✗ When Not to Use

  • •Uniform access patterns where load is already balanced
  • •Keys that need strict single-writer ordering
  • •Clusters small enough that one node can serve the peak

Pros

  • +Removes single-node bottlenecks
  • +Scales reads for the hottest data
  • +Keeps cluster utilization even

Cons

  • −Replicated copies can be briefly inconsistent
  • −Read-time aggregation of split counters costs more
  • −Detection and promotion logic add moving parts

Cost Profile

Infrastructure

Extra memory for replicas and local caches

Operational

Medium: monitoring and tuning

Cognitive

Medium: key splitting semantics

Failure Modes

  • Hot key detected too late and the node already failed

  • Replicated copies serve stale data after an update

  • Split counter aggregation reads become expensive and slow

Real-World Examples

Alternatives

    Related Patterns

    • consistent-hashing
    • partitioning
    • caching

    Competency Domains

    reliability opsdata state