DBRaven
Failure Mode · sharding

Hot Shard (Unbalanced Write Distribution)

critical

Summary

A sharded database where a small number of shards absorb disproportionately more writes than the rest, because the shard key does not distribute uniformly under the real workload. The hot shard hits its own write ceiling while its siblings sit idle, so the cluster's aggregate write throughput never rises to meet demand. Sharding added operational surface without adding write capacity for that workload.

Description

Sharding divides write load across N independent databases by a shard key. It only delivers 1/N write load per shard if the shard key distributes writes uniformly, and shard-key choice is the whole story here; hot_partition covers the general mapping problem across partitioned systems, this entity is specifically about what shard-key choice does to write throughput in a sharded database.

The dominant cause is a monotonically increasing shard key: an auto-increment id or a timestamp under range-based sharding. Every new row's key is greater than every existing key, so every write lands on the single highest-range shard while every other shard goes read-only cold. This is not a corner case, it is the default outcome of sharding a sequential key by range, and it is the primary reason to shard write-heavy tables by hash or by a well-distributed business key instead.

A second cause is a high-cardinality key with a skewed real-world distribution: a marketplace seller with orders of magnitude more orders than the median, a shared resource many users write through. The key hashes fine in principle, but in practice one hash value carries far more than 1/N of the traffic.

A third cause is a low-cardinality key: a shard key with only a few dozen distinct values sharded across a thousand shards leaves most shards empty and concentrates all traffic on the handful of shards that own the popular values.

What the hot shard suffers, specifically. Write throughput on the hot shard hits the same ceiling a non-sharded system would hit; for that workload, sharding bought nothing. Because the shard also carries disproportionate write volume, its WAL (or binlog) generation rate rises with it, and if replica apply falls behind the shard's own WAL throughput, its replicas lag more than the cluster average, so reads routed to those replicas return staler data than reads against a cold shard's replicas. Sustained high write volume on one shard also increases buffer-cache churn there (recently written pages compete with the working set for cache), which can raise read latency on that shard even for queries that do not touch the hot rows. And because more writes route through the same small key range or set of hot rows, the hot shard is also the shard most likely to show lock_contention.

Characteristics

Propagationisolated
Time to detectPer-shard write-rate metrics reveal the imbalance immediately once instrumented. Without per-shard monitoring, the symptom looks like feature-specific latency for whichever users or entities happen to hash to the hot shard, which can take hours to trace back to shard distribution.
Blast radiusWrites routed to the hot shard slow down and may error under load; writes to other shards are unaffected. If the hot shard's replicas fall behind, reads served from those replicas return staler data than reads against any other shard's replicas, and this staleness gap widens with sustained write pressure. Recovery operations (failover, backup, resharding) on the hot shard take longer because it holds more data and a higher ongoing write rate than its siblings.

Triggers

  • ·Sequential or timestamp-based shard key chosen for a write-heavy table
  • ·A viral or high-activity entity (a seller, a shared resource) generating outsized write volume on one shard
  • ·A low-cardinality shard key that cannot produce uniform hash distribution across the configured shard count
  • ·Range-based sharding of a key that is effectively append-only

Detection Signals

alert

Mitigation Strategies

Hash-based sharding with a random or UUID shard keypreventscomplexity: medium

Replace a sequential shard key with a UUID v4 or an application-generated random id. Hash distribution of random values is uniform across shards, which removes the monotonic-key hotspot entirely. The cost is a shard-key migration, and any code that relied on key ordering for range queries loses that property.

Shard key padding for known high-activity entitiespreventscomplexity: high

For an entity expected to generate outsized write volume, append a suffix to spread its writes across N virtual shards: shard_key = f"{entity_id}_{random.randint(0, N)}". Writes for that entity spread across N shards instead of one. The cost lands on reads, which must fan out across all N virtual shards and merge to reconstruct the entity's full write history.

Monitor per-shard write rate and alert on imbalancecomplexity: low

Track write rate per shard as a first-class metric and alert when any shard exceeds roughly 2x the cluster mean. This does not fix skew, but it turns a silent throughput ceiling into a visible signal early enough to rebalance before the hot shard becomes the binding constraint.

Recovery Steps

  1. 1.Measure per-shard write rate to confirm which shard (or shards) are hot
  2. 2.Identify the cause: is the shard key sequential, or is one entity dominating?
  3. 3.For a sequential key: plan a migration to hash-based sharding (significant effort)
  4. 4.For a single hot entity: apply virtual shard padding for that entity specifically
  5. 5.Check replica lag on the hot shard and confirm it has recovered after remediation

Estimated recovery time: Shard-key migration for an existing large dataset is a multi-week to multi-month project. Virtual shard padding for a specific hot entity can ship in days. Vertically scaling the hot shard buys time while the structural fix is built, but does not resolve the imbalance.

Affected Systems

Patterns

shardingconsistent hashing

Technologies

postgresqlmysqlcassandradynamodbmongodb

Basis

Hot shard from a monotonic key is documented in DynamoDB, Cassandra, and MySQL sharding guidance; the write-ceiling, replica-lag amplification, and buffer-cache pressure effects follow directly from standard replication and MVCC storage mechanics; mitigation strategies match Amazon DynamoDB best practices and Cassandra data modeling guides.

Related Architecture Knowledge

Inbound: affects this entity

Vulnerable ToTechnology
dynamodb
Grounded

DynamoDB partitions data by partition key hash; sequential or low-cardinality partition keys cause hot partitions that exceed per-partition throughput limits and receive 400 ProvisionedThroughputExceededException responses.

Full relationship →
Vulnerable ToWorkload
high throughput oltp
Grounded

High-throughput OLTP workloads are vulnerable to hot shard problems when the shard key is a sequential ID or timestamp, concentrating all new writes on the highest-range shard.

Full relationship →
Introduces RiskPattern
sharding
Grounded

Sharding is only effective when the shard key distribution is uniform; monotonic or low-cardinality keys produce hot shards that eliminate the write throughput benefit of sharding.

Full relationship →