Scalability & Performance Scalability

Hot Partition Mitigation

Avoiding write and read hotspots in partitioned and sharded systems; write amplification via scatter, key salting, time-bucketed partitions, read hotspots via caching, DynamoDB adaptive capacity, and Cassandra token ring balancing.

⏱ 11 min read

What it is

A hot partition (or hot shard) occurs when a disproportionate fraction of read or write traffic is directed at a single partition, shard, or node in a distributed data system. While the rest of the cluster sits largely idle, the hot partition becomes a bottleneck that caps the system's total throughput, inflates latency, and may cause failures such as throttling, OOM errors, or request timeouts. Hot partitions negate the scaling benefits of sharding and partitioning entirely.

Hot partitions arise from poor partition key selection, inherently skewed data distribution (e.g., celebrity users, trending hashtags), or temporal access patterns (all writes going to the current-time partition). Mitigation requires a combination of key design (salting, composite keys), read amplification (fan-out queries), caching hot items, and leveraging platform-level adaptive features like DynamoDB Adaptive Capacity or Cassandra's virtual nodes.

Why it exists

Real-world data is never uniformly distributed. In a social network, a celebrity user may have 100 million followers and generate posts that fan out to enormous write load on a single user partition. In a time-series database, all new sensor readings go to the "current hour" partition. In an e-commerce system, a flash sale on a single product floods one product partition with reads. These patterns cannot always be eliminated through partition key selection alone — some business entities are genuinely more popular than others.

The problem is compounded in cloud-managed services with per-partition throughput limits. DynamoDB, for example, enforces per-partition limits of 3,000 RCU and 1,000 WCU. Cassandra's consistent hashing is only as even as the token assignment. When hot partitions cause throttling, the entire application may experience elevated error rates even though aggregate cluster capacity is far from exhausted.

When to use

  • You observe that one or a few partitions/shards consistently receive far more traffic than others in monitoring dashboards.
  • Your partition key is a timestamp or monotonically increasing value, guaranteeing all writes go to the latest partition.
  • Your data contains inherently "famous" or high-traffic entities (celebrities, trending topics, popular products).
  • You are using DynamoDB or Cassandra and experiencing ProvisionedThroughputExceededException or TimeoutException on specific partition keys.
  • You are designing a new sharded system and want to proactively prevent hot partitions from forming.

When not to use

  • Traffic is already uniformly distributed across partitions — mitigation strategies add unnecessary complexity.
  • The "hot" partition is hot because of a genuine, temporary event (e.g., a major product launch) that will naturally subside; caching alone is sufficient.
  • The key salting strategy would require significant query-side fan-out that exceeds the cost of the hot partition problem itself.
  • Platform-level solutions (DynamoDB Adaptive Capacity, auto-sharding) already handle the imbalance transparently without application changes.

Typical architecture


  Write Hotspot — Timestamp Key Problem:
  ┌───────────────────────────────────┐
  │ All writes → partition "2025-05"  │ ← 100% write load
  │ Old partitions: idle              │ ← 0% write load
  └───────────────────────────────────┘

  Fix 1: Key Salting (write scatter)
  Original key: "2025-05"
  Salted key:   "2025-05#0" through "2025-05#N"
  Write → randomly pick salt suffix
  Read  → query ALL N suffixes and merge results

  Fix 2: Composite Partition Key (DynamoDB)
  Before: PK = "USER#celeb123"
  After:  PK = "USER#celeb123#" + random(0,9)
          → 10x more partitions for one hot user
  Read:   fan out 10 queries, merge results

  Fix 3: Read Hotspot — Cache Popular Items
  ┌───────────┐    miss    ┌────────────┐
  │  Request  │──────────►│  DB Shard  │ ← hot
  │           │◄──────────│            │
  └───────────┘           └────────────┘
        │
        ▼ (after first read)
  ┌───────────┐    hit     ┌────────────┐
  │  Request  │──────────►│  Redis     │ ← serves hot reads
  │           │◄──────────│  Cache     │
  └───────────┘           └────────────┘

  DynamoDB Adaptive Capacity:
  Partition A: 500 WCU  (provisioned)
  Partition B: 500 WCU  (provisioned)
  Actual load: A = 900 WCU, B = 100 WCU
  Adaptive: borrows unused B capacity → A gets ~900 WCU
          

Pros and cons

Pros

  • Eliminates the single bottleneck that caps aggregate system throughput.
  • Prevents cascading failures where one hot partition causes throttling errors that degrade user-facing APIs.
  • Key salting is a well-understood, low-risk technique applicable to most distributed databases.
  • Caching hot partitions delivers read performance improvements far exceeding any database tuning.
  • DynamoDB Adaptive Capacity provides automatic mitigation without application changes.

Cons

  • Key salting introduces write amplification: reads must fan out to all salt suffixes and merge results.
  • Composite key scatter increases the complexity of aggregation queries and SDK code.
  • Caching hot reads introduces cache invalidation complexity, especially for frequently updated hot entities.
  • Adaptive platform features have limits and may not fully absorb extreme hotspot ratios.
  • Detecting hot partitions proactively requires per-partition metrics, which are not always exposed by managed database services.

Implementation notes

Key salting for writes: Add a random suffix to the partition key (e.g., append a random integer from 0 to N-1). Writes are distributed across N logical partitions. For reads, you must query all N partitions and merge results in the application. Choose N based on the expected write hotspot ratio. If a single item receives 10× the average write rate, N=10 is sufficient. Keep N as a power of 2 for simpler bitmasking. Be aware that salting breaks key-based ordering within a "logical" entity's partitions.

Time-based partition hotspots: For time-series data, prefix the timestamp with a shard suffix: shard_N + "_" + YYYYMMDD_HH. Cycle through N shards round-robin per write. Reads for a given time window query all N shards. In DynamoDB, consider using a GSI on a time attribute with a composite key that includes a bucket number. For Cassandra, ensure your token ring has sufficient vnodes (256 is the default) and that the partition key itself has high enough cardinality to prevent token range collisions on hot values.

Common failure modes

  • Misidentifying the hot key: Salting a key that is not actually hot adds read fan-out cost with no benefit. Always instrument per-partition access rates before applying mitigations.
  • Insufficient salt range: Choosing N=2 when one entity generates 50× the average load — the hotspot is reduced but not eliminated.
  • Cache stampede on hot partition removal: When a cache entry for a very popular item expires, all concurrent requests miss the cache simultaneously and hammer the partition. Use probabilistic early re-computation (jitter on TTL) to prevent simultaneous expiration.
  • DynamoDB Adaptive Capacity exhaustion: Adaptive Capacity can borrow from under-utilized partitions but cannot exceed the total table provisioned throughput. If the entire table is underprovisioned, adaptive capacity offers no relief.
  • Cassandra tombstone accumulation on hot partitions: Frequently deleted or overwritten data on a hot Cassandra partition accumulates tombstones, degrading read performance. Use TTL and compaction strategies appropriately.

Decision checklist

  • Per-partition access rate metrics are being collected and alerted on to detect hotspots as they form.
  • The partition key design has been evaluated for monotonically increasing (e.g., timestamp) or skewed-distribution values that predictably create hotspots.
  • For write hotspots: a salting or scatter strategy with the appropriate N factor has been designed and tested.
  • For read hotspots: a caching layer with appropriate TTL and stampede-prevention is in place for known high-traffic entities.
  • The fan-out read cost of any scatter strategy has been benchmarked and accepted.
  • Platform-level adaptive features (DynamoDB Adaptive Capacity, auto-sharding) are enabled where available.

Example use cases

  • Social media celebrity posts: A post-like counter for a celebrity with 100M followers is stored with a salted key (10 suffixes), distributing 100K likes/second across 10 DynamoDB partitions, each receiving ~10K writes/second (within limits).
  • IoT sensor time-series: A Cassandra cluster receiving 1M events/second for current-second time buckets uses composite keys with a shard number prefix, distributing writes across 16 token ranges for the same timestamp.
  • E-commerce product hotspot: During a flash sale, a Redis cache fronts the product detail shard for the featured SKU, absorbing 99% of read traffic and preventing the DynamoDB partition from throttling.

Further reading