Why does a timestamp row key send all writes to one server in the wide-column store HBase, and what key fixes it?
Rows sort by row key and each region owns a contiguous key range, so a timestamp-led key sends every new write to the last region. Lead with a hashed prefix or a high-cardinality field such as device_id; a time-range scan then reads every prefix.
- Thinking HBase hashes row keys across servers the way Cassandra hashes partition keys
- Believing a reversed timestamp at the front of the key spreads writes, when it only flips which end of the key space is hot
- Salting the key without planning that every time-range extract must now run one scan per salt value
- How would a nightly Spark job extract one day of events from a table salted into 16 buckets?
- Where does Google's managed wide-column service Bigtable put the timestamp in a row key, and why?
Why one server. In HBase (and Bigtable) a table is a list sorted by row key and cut into regions by key range. A key like 20261109T101500|evt-… grows monotonically, so every new row lands at the end of the last region. The region splits, but its right half again takes every write: the hotspot just moves.
Key options.
| Key | Writes | Extract for a period |
|---|---|---|
ts | one region | one contiguous scan |
device_id ‖ ts | spread by device | a scan per device, or a full scan with a filter |
hash(device_id) % 16 ‖ ts ‖ device_id | 16 buckets | 16 parallel scans, one per bucket |
| random salt | even | 16 scans, and a point Get has to try all 16 salt values |
A deterministic hash beats a random salt: from device_id and the time the row key is rebuilt and read with one Get. A reversed timestamp (Long.MAX_VALUE - ts) goes at the end of the key so a device's latest events come first — never at the front, where it is just as hot.
The data-engineering takeaway. The key is chosen together with the extract: a nightly job for one day over a 16-bucket table builds 16 ranges [b ‖ day_start, b ‖ day_end) and reads them in parallel — often faster than one scan. For Bigtable, Google advises putting a high-cardinality field before the timestamp and never starting the key with it. Cassandra and DynamoDB hash the partition key themselves, so there the same problem shows up as a hot partition rather than a hot range.
import hashlib
def row_key(device_id: str, ts_ms: int, buckets: int = 16) -> bytes:
b = int(hashlib.md5(device_id.encode()).hexdigest(), 16) % buckets
return f"{b:02d}|{ts_ms:013d}|{device_id}".encode()