Skip to content
Tutorials Center
My learning

Topics

Lesson 20 of 36 ยท Schema Design

Hotspotting, Salting and Hashing

Understand why sequential HBase row keys overload one region server, and how salting, hashing, reversing and pre-splitting spread writes evenly.

HBase scales by splitting a table into regions, each a contiguous range of row keys served by one region server. That design works only if traffic is spread across regions. When most reads or writes hit the same small key range, one server is saturated while the rest of the cluster idles. This is called hotspotting.

The classic cause is a row key that starts with something that always increases: a timestamp, an auto-increment id, a date. Every new row sorts after all existing rows, so every write goes to the last region. This lesson shows how to see the problem, and the standard fixes. Row key basics are in Row Key Design.

HBase itself cannot run in the editors here. The blocks below are stand-ins: a tiny Java model that assigns keys to regions by key range and counts writes per region. The real client code is shown read-only.

Seeing a hotspot

Imagine a table pre-split into four regions by the first character of the key. If your keys are timestamps like 20260101-..., all of them start with 2, so they all land in one region.

Java Sequential keys hit one region (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

The sequential keys all fall into region 0; the random hex keys spread across regions, though the exact counts depend on the generator (here the seed is fixed so the run is repeatable).

Fix 1: salting

Salting prepends a small, deterministic prefix, the salt, to the key. The salt is usually hash(key) % N where N is the number of buckets, often the number of regions or a small multiple of it. Writes now go to N different key ranges even though the underlying keys are sequential.

TEXT
originalKey = 20260101-sensor7
salt        = hash(originalKey) % 4   ->  2
saltedKey   = 2|20260101-sensor7

The cost is on reads. A range scan over the original key order must now be issued as N scans, one per salt, and merged on the client. Gets are still cheap: compute the salt from the key and read one row.

Java Salting and fan-out scans (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

The merge step is the price of salting: the client issues four scans and sorts the results. Many teams accept that for write-heavy tables, such as event streams, where reads mostly use a known id.

Fix 2: hashing the key

If you only ever do point reads, use a hash of the natural key as the prefix, or as the whole key. An MD5 prefix of a few bytes is common. The hash is deterministic, so you can recompute it for a Get, but you lose meaningful range scans. A middle road keeps the readable key after the hash, as with salting but with more buckets.

Fix 3: reversing and field swapping

Sometimes the problem is a skewed first field rather than a monotonically increasing one. Two lighter fixes:

  • Reverse the key: store "moc.elpmaxe" instead of "example.com" to spread domains that share a common suffix. Scans over a whole domain tree still work if you reverse consistently, and reversed domains also group subdomains.
  • Swap fields: put a high-cardinality field (user id) ahead of the low-cardinality, always-increasing one (date).
flowchart TB
  A["Sequential key<br/>2026-01-01, 2026-01-02, ..."] --> B{"Strategy"}
  B -->|"Prefix with hash mod N"| C["Salting: N scans on reads"]
  B -->|"Hash whole key"| D["Hashing: point reads only"]
  B -->|"Reverse / swap fields"| E["Spread by a skewed field"]
  B -->|"Pre-split table"| F["Many regions from day one"]

Pick the fix by the read pattern, not by habit.

Pre-splitting: do not start with one region

A new table starts as one region. All the first writes land on its single server until HBase splits it, and splitting under load is slow. With salted or hashed keys you know the key distribution in advance, so create the table pre-split into regions that match.

Read-only example with the Admin API (HBase 2.x):

Java
byte[][] splitKeys = {
    Bytes.toBytes("1"), Bytes.toBytes("2"), Bytes.toBytes("3")   // 4 regions for 4 salts
};
TableDescriptor desc = TableDescriptorBuilder.newBuilder(TableName.valueOf("events"))
    .setColumnFamily(ColumnFamilyDescriptorBuilder.of("d"))
    .build();
admin.createTable(desc, splitKeys);

In the shell the equivalent is create 'events', 'd', SPLITS => ['1','2','3'], or NUMREGIONS => 16, SPLITALGO => 'HexStringSplit' for hex-prefixed keys.

Reads can be hot too

Hotspots also come from reads: a "celebrity" row read by millions of clients, or a hot configuration row. Remedies are caching in the client or an application cache, and the HBase block cache with in-memory column families. Salting does not help a single hot row, because it is still one row on one server.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does an increasing timestamp prefix cause hotspotting?

    Sequential keys all fall at the end of the key space, so one region (and one server) takes all the writes.
  2. 2. What is the main read-side cost of salting?

    Rows of one original range are spread over N prefixes, so the client must run N scans and merge them.
  3. 3. When is hashing the entire key acceptable?

    A full hash destroys key order, so it only fits access by exact key.
  4. 4. Why pre-split a table that uses salted keys?

    A new table has one region; pre-splitting creates regions that match the salt buckets from the start.

Summary

  • Hotspots come from sequential or skewed key prefixes.
  • Salting spreads writes but turns a range scan into N scans.
  • Hashing is for point reads; reversing and field swapping fix skew cheaply.
  • Pre-split tables to match the expected key distribution.
  • A single hot row cannot be fixed by key design.

Next: Column Families and Versions