# Hot keys and hot shards

> When one key or one shard takes a large share of the traffic, adding servers does not help, so spread that key or change the shard key.

A hot key or a hot shard saturates one machine while the rest of the fleet idles, so more machines buy nothing.

## Use it when

- One shard or one cache node runs red while the others sit near idle.
- A single item, such as a celebrity profile or a flash-sale product, draws a large share of reads.
- New rows always land on the same shard, because the key grows with time.

## How it works

Hashing spreads keys evenly, but it cannot spread one key. Two repairs exist. Pick a shard key that matches how the traffic is spread, and for a key that is hot anyway, split it: store copies under suffixed keys (`item:7#0` to `item:7#9`) and read a random one. A cache in front absorbs read-heavy keys too.

A range key such as an auto-increment ID sends every new user to the last shard. A hash of the ID does not. A hot key that takes writes is harder. A counter can be split into suffixed parts that a read adds up, but a value that must stay in step cannot.

## What it costs

Splitting a read-heavy key makes writes touch every copy, and splitting a counter makes a read sum every part. You also have to know which keys are hot, usually from metrics, and the hot set changes. A tenant key keeps a tenant together, which is good for queries and bad when one tenant is huge.

## In Quorum



The range key piles new users onto one shard, so one box takes the writes. Against the hash Design on [Sharding](https://wiki.playquorum.dev/patterns/sharding.md), the same shards, Users and sizes give a lower Apdex and a longer p99.





Both Boards run a Hot key incident on the Cache. Read the Load row on each card: without splitting, the Cache's capacity falls while the hot key runs, and with it the capacity stays whole. Nothing fails at this load, so the capacity figure is the evidence. On a [Cache](https://wiki.playquorum.dev/components/cache.md), turn on key splitting so a hot key spreads over the cache's shards. It needs [Hybrid fan-out](https://wiki.playquorum.dev/research/hybrid-fanout.md). A [Wide-column Store](https://wiki.playquorum.dev/components/wide.md) has the same switch.

The [Hot key](https://wiki.playquorum.dev/incidents/hot-key.md) incident sends a large share of reads to one key, and [Hot shard](https://wiki.playquorum.dev/incidents/hot-shard.md) lands the biggest tenant on one shard. The glossary defines the [hot key](https://wiki.playquorum.dev/glossary/hot-key.md).

Source: https://wiki.playquorum.dev/patterns/hot-keys-and-hot-shards
