Hot Partitions And Rebalancing
Purpose
Repair a distribution that is correct on paper and broken in production. A suitable hash
can make non-adversarial key placement approximately uniform; it says nothing about traffic,
value size or work per request. Every shard can hold close to the mean key count while one
is at 100% CPU because a single key receives a large share of requests. Rehashing, more
virtual nodes or more shards can repair placement variance, but cannot divide an indivisible
hot key; they usually move that bottleneck to a different owner.
The failure this prevents is diagnosing the wrong thing. A hot partition and an overloaded
fleet look identical on an aggregate dashboard — elevated p99, elevated error rate — and
require different investigation paths. Per-shard evidence distinguishes skew from fleet-wide
pressure; logs, traces or store statistics may supply it when metric labels are missing.
Without that evidence, keep the diagnosis conditional and capture a bounded incident sample.
Inspect the store, driver and topology versions before recommending an online split or
ownership protocol. The Java examples are partial Java 17-compatible sketches, not a storage
implementation; inspect the project's toolchain and APIs without assuming upgrade permission.
Workflow
- Measure distribution, normalized by each shard's capacity, for accepted and offered
request rate, errors, queueing, latency, CPU/IO, storage and replication lag. Use top-share,
max/median and a heat map; max/mean is only a screening signal. A ratio near 1 can still
hide a uniformly saturated fleet, rejected work or heterogeneous instances.
- Classify the skew as read-hot, write-hot, storage-hot or mixed from which ratio is
elevated. They have different repairs, and a cache fixes exactly one of them. The
signature table is
references/detecting-skew.md.
- Name the key. A shard-level metric proves skew exists; it does not say what to fix.
Sample requests on the hot shard and count by key, or read the store's own top-key
facility. Cheap sampling techniques are in
references/detecting-skew.md.
- Decide whether the key is intrinsically hot or the key choice is wrong. One celebrity
key on an otherwise even distribution is a key-level repair. A shard key whose design
concentrates traffic — a timestamp, an enum, a tenant id in a power-law fleet — is a key
problem, and the repair is a migration (
sharding-and-partitioning).
- Apply the narrowest repair that fits the classification, and price it before shipping:
salting costs read fan-out, a dedicated shard costs an operational special case, a cache
costs staleness.
references/repairs-and-rebalancing.md has each with its condition.
- If the repair is a move, treat the move as a distributed protocol. Version the shard
map, define the double-ownership window, throttle the copy, and make a stale client unable
to write to the former owner.
- Prove steady state and recovery. Replay the observed power-law key distribution,
measure tail amplification and catch-up time, inject stale clients and abort midway.
Then add bounded-cardinality per-shard detection and alerts on skew plus saturation.
Decision block
Salt (split) the key across S sub-partitions when:
- one write-hot key exceeds a single shard's write capacity, and reads for that key are rare
enough, or aggregate in nature, that fanning them out to S is acceptable; operations can
be partitioned with a valid merge without violating required atomicity or ordering
Give the tenant a dedicated shard when:
- one known, named tenant is persistently large or hot, the set of such tenants is small and
changes slowly, and per-tenant isolation is independently valuable
Put a cache in front of the key when:
- the key is READ-hot, the value tolerates the staleness a TTL implies, and the value is
small enough to cache — a cache does nothing for write skew (caching-strategies)
Coalesce concurrent requests for the key when:
- many identical in-flight reads for one key arrive together; this removes duplicate work
when identity, authorization, consistency level and response semantics are part of the
coalescing key; define cancellation and failure sharing explicitly
Split the partition when:
- the store supports online split, the hot range is contiguous, and the skew is a range
boundary rather than a single key
Investigate fleet capacity or common-mode failure when:
- normalized load is similar across shards and saturation, queueing or rejection is elevated;
a ratio near 1 alone does not establish overload or justify adding capacity
Change the shard key when:
- the concentration is structural rather than incidental — the key design guarantees it
recurs. Accept that this is a full migration (sharding-and-partitioning)
Rules
- Skew is easily hidden by an aggregate. With N equal shards and one saturated, the fleet
mean's excess is diluted by roughly N. Report a normalized distribution: maximum or high
quantile, median, top-shard share and capacity utilization.
max/mean is useful but highly
sensitive to one outlier and says nothing about two clusters or heterogeneous capacity.
- Add bounded shard identity before incidents to preserve history. Instrumenting during an
incident still provides current evidence; record that the historical baseline is missing.
- Read-hot, write-hot and storage-hot are three problems. A cache removes read load and does
nothing for writes; salting spreads writes and makes reads more expensive; a dedicated
shard isolates the tenant but only relieves its bottleneck if available capacity is sufficient.
Name the class first; ordinary read caching does not remove write throughput requirements.
- Rehashing is not a repair for a hot key. The key still has one owner under every
placement function in
consistent-hashing; the hash decides which node melts, not
whether one does.
- Salt only when independent operations have a valid merge and the required atomicity and
ordering survive the split; write heat alone is insufficient evidence.
- Salting is
key#i for i in [0, S): writers route by a deliberate sub-key (random,
round-robin or an entity identifier), readers query the required buckets and merge. The
cost includes read fan-out, loss of single-key atomicity/global order, retries and future
resharding. Choose S from measured per-partition capacity with headroom; random assignment
can still burst and a deterministic secondary key is preferable when semantics allow it.
- Do not salt every key. Salt the identified hot keys from a list you can update without a
deploy; otherwise every read in the system pays the fan-out to fix one key.
- A move creates overlapping copies, not two unconstrained authorities. Name the sole
write authority for every phase. Publish a monotonic ownership epoch, require it on every
mutation, and enforce it at the state transition that commits the write. Rejecting stale
routing only in a client or proxy is insufficient: paused clients and old owners survive
cutover. The general fencing mechanism is
distributed-locks-and-leases.
- Throttle the migration copy explicitly, in bytes or rows per second, and treat it as
production load. An unthrottled rebalance to relieve a hot shard is a second, larger
incident caused by the fix.
- Automatic rebalancing without hysteresis oscillates: it moves a partition off a hot node,
the target becomes hot, and it moves back. Require the threshold to be exceeded for a
sustained window, cap concurrent moves, and impose a per-partition cool-down.
- A shard-map read must not depend on the data plane it describes. If clients discover
ownership by querying the shards, the hot shard's saturation makes the map unavailable
precisely when a rebalance needs it.
- Latency figures from the hot shard are still latency figures: do not average p99 across
shards to decide whether the fleet is healthy — that is the error
latency-statistics
exists to prevent, and the per-shard decomposition is tail-latency-analysis.
- Protecting the hot shard by rejecting the excess is legitimate and often the fastest
mitigation, but it is a per-key limit, not a global one —
rate-limiting-and-load-shedding
owns the mechanism.
Operational invariants
- At most one ownership epoch may commit writes for a partition.
- Every acknowledged pre-cutover write is present at the target before target activation.
- Every accepted post-cutover write is routed to or forwarded into the target epoch.
- Map publication is monotonic, cacheable only with bounded staleness, and observable by
version; rollback uses a new epoch rather than resurrecting an old one.
- Replica safety is preserved throughout: moving data must not remove enough healthy copies
to violate the store's durability/quorum rule.
- Source deletion starts only after a retention window, reconciliation and a tested restore
point. Retention alone is not rollback unless post-cutover writes are reverse-replicated or
replayable.
Return the observed distribution and missing evidence, the hypothesis and its falsifier,
the chosen repair's semantic costs, and the before/after SLO and recovery checks. Keep
unmeasured benefits conditional.
Anti-patterns
| Anti-pattern |
Symptom |
Better alternative |
| Average-only dashboard |
fleet looks healthy while one shard rejects work |
normalized per-shard heat maps and top-share |
| Key as metric label |
telemetry cardinality becomes the outage |
bounded sketches; protected top-K logs with redaction |
| Add shards for one hot key |
bottleneck changes owner but not capacity |
split/coalesce/cache/isolate the logical key |
| Blind salting |
reads fan out, ordering and uniqueness silently break |
derive bucket and merge semantics before migration |
| Reactive auto-balancer |
partitions ping-pong and copy traffic amplifies load |
prediction, hysteresis, move budget and kill switch |
| Copy then flip |
writes disappear across snapshot/cutover |
snapshot position, change catch-up, epoch fence and reconciliation |
References
- Detecting skew and finding the key — the per-shard metric
set and the max/mean ratio, the query shapes that expose skew, cheap top-K sampling to name
the offending key, and the signatures separating read-hot, write-hot, storage-hot and a
uniformly overloaded fleet. Read at the start of an incident where one shard looks
different, or when instrumenting a sharded system.
- Repairs and rebalancing — each mitigation with the
condition that selects it, the salting scheme with its read fan-out cost, the live-migration
sequence with the double-ownership and shard-map-version rules, and rebalance throttling and
hysteresis. Read once the hot key is identified, or before moving a partition under load.
1---2name: hot-partitions-and-rebalancing3description: Repairing a partitioned system whose distribution has failed in production: a hash distributes keys uniformly and says nothing about traffic, so one celebrity key or one large tenant saturates a shard while the map is correct. Covers detection — per-shard rate, latency and storage, and the max-to-mean ratio, because an aggregate dashboard hides skew; naming the key by top-K sampling; the read-hot, write-hot, storage-hot and overloaded-fleet signatures; the repairs and their prices; and the rebalance, with its double-ownership window and versioned map. Use when one shard runs far above the others while the fleet average looks fine, when a shard is hot before and after a rehash, when one tenant dominates a shard, or when a rebalance is planned or is itself the incident. Not the mapping function (consistent-hashing), the key choice (sharding-and-partitioning), caching (caching-strategies), capping the caller (rate-limiting-and-load-shedding), the tail (tail-latency-analysis), or the numbers (latency-statistics).4---56# Hot Partitions And Rebalancing78## Purpose910Repair a distribution that is correct on paper and broken in production. **A suitable hash11can make non-adversarial key placement approximately uniform; it says nothing about traffic,12value size or work per request.** Every shard can hold close to the mean key count while one13is at 100% CPU because a single key receives a large share of requests. Rehashing, more14virtual nodes or more shards can repair placement variance, but cannot divide an indivisible15hot key; they usually move that bottleneck to a different owner.1617The failure this prevents is diagnosing the wrong thing. A hot partition and an overloaded18fleet look identical on an aggregate dashboard — elevated p99, elevated error rate — and19require different investigation paths. Per-shard evidence distinguishes skew from fleet-wide20pressure; logs, traces or store statistics may supply it when metric labels are missing.21Without that evidence, keep the diagnosis conditional and capture a bounded incident sample.2223Inspect the store, driver and topology versions before recommending an online split or24ownership protocol. The Java examples are partial Java 17-compatible sketches, not a storage25implementation; inspect the project's toolchain and APIs without assuming upgrade permission.2627## Workflow28291. **Measure distribution, normalized by each shard's capacity**, for accepted and offered30 request rate, errors, queueing, latency, CPU/IO, storage and replication lag. Use top-share,31 max/median and a heat map; max/mean is only a screening signal. A ratio near 1 can still32 hide a uniformly saturated fleet, rejected work or heterogeneous instances.332. **Classify the skew** as read-hot, write-hot, storage-hot or mixed from which ratio is34 elevated. They have different repairs, and a cache fixes exactly one of them. The35 signature table is `references/detecting-skew.md`.363. **Name the key.** A shard-level metric proves skew exists; it does not say what to fix.37 Sample requests on the hot shard and count by key, or read the store's own top-key38 facility. Cheap sampling techniques are in `references/detecting-skew.md`.394. **Decide whether the key is intrinsically hot or the key choice is wrong.** One celebrity40 key on an otherwise even distribution is a key-level repair. A shard key whose design41 concentrates traffic — a timestamp, an enum, a tenant id in a power-law fleet — is a key42 problem, and the repair is a migration (`sharding-and-partitioning`).435. **Apply the narrowest repair that fits the classification**, and price it before shipping:44 salting costs read fan-out, a dedicated shard costs an operational special case, a cache45 costs staleness. `references/repairs-and-rebalancing.md` has each with its condition.466. **If the repair is a move, treat the move as a distributed protocol.** Version the shard47 map, define the double-ownership window, throttle the copy, and make a stale client unable48 to write to the former owner.497. **Prove steady state and recovery.** Replay the observed power-law key distribution,50 measure tail amplification and catch-up time, inject stale clients and abort midway.51 Then add bounded-cardinality per-shard detection and alerts on skew plus saturation.5253## Decision block5455```text56Salt (split) the key across S sub-partitions when:57- one write-hot key exceeds a single shard's write capacity, and reads for that key are rare58 enough, or aggregate in nature, that fanning them out to S is acceptable; operations can59 be partitioned with a valid merge without violating required atomicity or ordering60Give the tenant a dedicated shard when:61- one known, named tenant is persistently large or hot, the set of such tenants is small and62 changes slowly, and per-tenant isolation is independently valuable63Put a cache in front of the key when:64- the key is READ-hot, the value tolerates the staleness a TTL implies, and the value is65 small enough to cache — a cache does nothing for write skew (caching-strategies)66Coalesce concurrent requests for the key when:67- many identical in-flight reads for one key arrive together; this removes duplicate work68 when identity, authorization, consistency level and response semantics are part of the69 coalescing key; define cancellation and failure sharing explicitly70Split the partition when:71- the store supports online split, the hot range is contiguous, and the skew is a range72 boundary rather than a single key73Investigate fleet capacity or common-mode failure when:74- normalized load is similar across shards and saturation, queueing or rejection is elevated;75 a ratio near 1 alone does not establish overload or justify adding capacity76Change the shard key when:77- the concentration is structural rather than incidental — the key design guarantees it78 recurs. Accept that this is a full migration (sharding-and-partitioning)79```8081## Rules8283- **Skew is easily hidden by an aggregate.** With N equal shards and one saturated, the fleet84 mean's excess is diluted by roughly N. Report a normalized distribution: maximum or high85 quantile, median, top-shard share and capacity utilization. `max/mean` is useful but highly86 sensitive to one outlier and says nothing about two clusters or heterogeneous capacity.87- Add bounded shard identity before incidents to preserve history. Instrumenting during an88 incident still provides current evidence; record that the historical baseline is missing.89- Read-hot, write-hot and storage-hot are three problems. A cache removes read load and does90 nothing for writes; salting spreads writes and makes reads more expensive; a dedicated91 shard isolates the tenant but only relieves its bottleneck if available capacity is sufficient.92 Name the class first; ordinary read caching does not remove write throughput requirements.93- **Rehashing is not a repair for a hot key.** The key still has one owner under every94 placement function in `consistent-hashing`; the hash decides _which_ node melts, not95 whether one does.96- Salt only when independent operations have a valid merge and the required atomicity and97 ordering survive the split; write heat alone is insufficient evidence.98- Salting is `key#i` for `i` in `[0, S)`: writers route by a deliberate sub-key (random,99 round-robin or an entity identifier), readers query the required buckets and merge. The100 cost includes read fan-out, loss of single-key atomicity/global order, retries and future101 resharding. Choose S from measured per-partition capacity with headroom; random assignment102 can still burst and a deterministic secondary key is preferable when semantics allow it.103- Do not salt every key. Salt the identified hot keys from a list you can update without a104 deploy; otherwise every read in the system pays the fan-out to fix one key.105- **A move creates overlapping copies, not two unconstrained authorities.** Name the sole106 write authority for every phase. Publish a monotonic ownership epoch, require it on every107 mutation, and enforce it at the state transition that commits the write. Rejecting stale108 routing only in a client or proxy is insufficient: paused clients and old owners survive109 cutover. The general fencing mechanism is `distributed-locks-and-leases`.110- Throttle the migration copy explicitly, in bytes or rows per second, and treat it as111 production load. An unthrottled rebalance to relieve a hot shard is a second, larger112 incident caused by the fix.113- Automatic rebalancing without hysteresis oscillates: it moves a partition off a hot node,114 the target becomes hot, and it moves back. Require the threshold to be exceeded for a115 sustained window, cap concurrent moves, and impose a per-partition cool-down.116- A shard-map read must not depend on the data plane it describes. If clients discover117 ownership by querying the shards, the hot shard's saturation makes the map unavailable118 precisely when a rebalance needs it.119- Latency figures from the hot shard are still latency figures: do not average p99 across120 shards to decide whether the fleet is healthy — that is the error `latency-statistics`121 exists to prevent, and the per-shard decomposition is `tail-latency-analysis`.122- Protecting the hot shard by rejecting the excess is legitimate and often the fastest123 mitigation, but it is a per-key limit, not a global one — `rate-limiting-and-load-shedding`124 owns the mechanism.125126## Operational invariants127128- At most one ownership epoch may commit writes for a partition.129- Every acknowledged pre-cutover write is present at the target before target activation.130- Every accepted post-cutover write is routed to or forwarded into the target epoch.131- Map publication is monotonic, cacheable only with bounded staleness, and observable by132 version; rollback uses a new epoch rather than resurrecting an old one.133- Replica safety is preserved throughout: moving data must not remove enough healthy copies134 to violate the store's durability/quorum rule.135- Source deletion starts only after a retention window, reconciliation and a tested restore136 point. Retention alone is not rollback unless post-cutover writes are reverse-replicated or137 replayable.138139Return the observed distribution and missing evidence, the hypothesis and its falsifier,140the chosen repair's semantic costs, and the before/after SLO and recovery checks. Keep141unmeasured benefits conditional.142143## Anti-patterns144145| Anti-pattern | Symptom | Better alternative |146| -------------------------- | ----------------------------------------------------- | ------------------------------------------------------------------ |147| Average-only dashboard | fleet looks healthy while one shard rejects work | normalized per-shard heat maps and top-share |148| Key as metric label | telemetry cardinality becomes the outage | bounded sketches; protected top-K logs with redaction |149| Add shards for one hot key | bottleneck changes owner but not capacity | split/coalesce/cache/isolate the logical key |150| Blind salting | reads fan out, ordering and uniqueness silently break | derive bucket and merge semantics before migration |151| Reactive auto-balancer | partitions ping-pong and copy traffic amplifies load | prediction, hysteresis, move budget and kill switch |152| Copy then flip | writes disappear across snapshot/cutover | snapshot position, change catch-up, epoch fence and reconciliation |153154## References155156- [Detecting skew and finding the key](references/detecting-skew.md) — the per-shard metric157 set and the max/mean ratio, the query shapes that expose skew, cheap top-K sampling to name158 the offending key, and the signatures separating read-hot, write-hot, storage-hot and a159 uniformly overloaded fleet. Read at the start of an incident where one shard looks160 different, or when instrumenting a sharded system.161- [Repairs and rebalancing](references/repairs-and-rebalancing.md) — each mitigation with the162 condition that selects it, the salting scheme with its read fan-out cost, the live-migration163 sequence with the double-ownership and shard-map-version rules, and rebalance throttling and164 hysteresis. Read once the hot key is identified, or before moving a partition under load.