Scrivio Interview library
InternalsFoundations6 min read · updated 13 November 2026

Range-partitioned stores, such as HBase, Bigtable-style systems and several distributed SQL databases, keep rows sorted by key and cut the key space into contiguous ranges that are spread across servers and split automatically as they grow.

How does such a store decide where a key lives, how does a range split happen, and how does a client find the right server after a split has moved data?

A range-partitioned store keeps keys sorted and cuts them into contiguous ranges [start, end), and a metadata table, often range-partitioned itself, maps each range to the server holding it. When a range grows past a size (and in some systems a load) threshold, it splits at a middle key, which is a metadata change, and one half can then move to another server. Clients cache range locations; a request with a stale location is rejected with a not-serving style error, and the client refreshes that entry and retries.

Why this question is asked

Range partitioning is the design behind HBase, Bigtable and distributed SQL databases such as CockroachDB and TiDB. Its big advantage over hashing is that neighbouring keys stay together, so scans by key prefix are cheap. Interviewers ask how it works inside because the same mechanics explain both its strengths and its classic failure, the hot last range. In this answer, we will recap what a range is, follow a key lookup through the metadata, watch a split and a move happen, see how a client with an old cache finds its way, and finish with key design and pre-splitting.

1A Quick Recap: Ranges of a Sorted Key Space

Picture every row of a table sorted by its key, like the entries of a dictionary. A range partitioned store cuts this sorted list into contiguous pieces. Each piece covers an interval written [start, end): it includes every key greater than or equal to start and less than end. HBase calls these pieces regions, Bigtable calls them tablets, and CockroachDB calls them ranges. The pieces are spread across servers, and every key belongs to exactly one piece.

Ranges of a users table
RangeInterval [start, end)Server
r1["", "user_2000")server A
r2["user_2000", "user_5000")server B
r3["user_5000", "user_8000")server C
r4["user_8000", end of table)server A
Keys compare as strings or bytes, so the boundaries are byte sequences, not numbers.

2Finding Where a Key Lives

To find a key, the system needs the mapping from ranges to servers. That mapping is stored in a metadata table whose rows are keyed by the end (or start) of each range, so finding the right row is itself a range lookup. Because a large cluster can have millions of ranges, the metadata table is often range partitioned as well. HBase stores it in a table called hbase:meta, whose own location is published in a well-known place; CockroachDB uses meta ranges at two levels. A client looking up user_4711 asks the metadata for the row covering that key, learns that range r2 on server B holds it, and sends the request to server B.

Doing this lookup for every request would overload the metadata servers, so clients cache what they learn. After the first lookup, the client knows r2 covers [user_2000, user_5000) on server B, and every later request for a key in that interval goes straight to server B.

3How a Split Happens

Ranges are kept to a manageable size so they can move and recover quickly. HBase splits regions at several gigabytes by default, and CockroachDB keeps ranges around 512 MB; check the defaults in your version. When a range grows past the threshold, the server picks a split key near the middle of its data, for example user_3500 in r2, and creates two ranges: [user_2000, user_3500) and [user_3500, user_5000).

Notice that no data has to be copied for the split itself. The rows are already on server B, sorted, so a split only changes metadata: the old entry is replaced by two new ones. Moving data is a separate step. After the split, a balancer may move one of the halves to a less loaded server, which does copy data. Some systems also split on load, not only on size: if a range receives far more queries than others, it is split so the two halves can be served by different servers, which spreads a hot spot that lives in a small amount of data.

Step throughA split followed by a move
  1. r2 grows past the size thresholdor its load passes a load threshold
  2. Choose a split key near the middleuser_3500
  3. Update metadata: r2a and r2bno data copied yet
  4. Balancer: is server B busier than others?
    YesMove r2b to server DNoKeep both halves on B
  5. Metadata updated again after the moveclients still holding old entries are now stale

5 steps in order. Play them, or step through them one at a time.

4How a Client With a Stale Cache Finds the Right Server

After r2b moves to server D, clients that cached r2 on server B are wrong for keys from user_3500 up. The system does not try to notify every client. Instead, each server checks every request against the ranges it currently serves. When a client sends a request for user_4711 to server B, B replies with an error saying it does not serve that key: in HBase this shows up as a NotServingRegionException, and other systems use a range-not-found or not-leaseholder style error.

The client treats that error as a signal to refresh, not as a failure. It drops the stale cache entry, reads the metadata for user_4711 again, learns that r2b is on server D, and retries there. The application sees at most a few extra milliseconds. This lazy approach scales because only clients that actually touch a moved range pay for the update.

Step throughA request with a stale location
ClientServer BMetadataServer D
get user_4711 (cache: r2 on B)
not serving this key
which range holds user_4711?
r2b [user_3500, user_5000) on D
get user_4711
row

6 messages in order. Play them, or step through them one at a time.

5Key Design and Pre-Splitting

Keeping neighbouring keys together is a gift for scans: reading all orders of customer 42 with keys customer_42#... touches one or two ranges. But it is a trap for sequential keys. If the key is a timestamp or an increasing id, every new row is larger than all existing ones, so every insert goes to the last range. One server takes all the writes while the rest idle, and splits do not help, because the new last range is again the only one receiving writes.

The fix is in the key. Prefixing the key with a hash of something, or with a small bucket number such as hash(id) mod 16, spreads writes across 16 ranges, at the price that a scan over a time window must now read 16 places. Starting with an entity id instead of a time, for example sensor_id then timestamp, spreads writes across sensors while keeping each sensor's readings together.

A brand-new table starts as a single range. Until it grows enough to split, every write lands on one server. If we know the key distribution, we pre-split the table at creation, for example into 16 ranges at the bucket boundaries, so writes spread from the first minute.

6Follow-up questions

Why do some systems split ranges by load as well as by size?

Because load and size are not the same. A range of 50 MB might hold a few very popular keys and receive half of all requests, while a 500 MB range is barely read. Splitting only by size would leave the hot range on one server forever. Splitting by load creates two ranges that can live on different servers, so the hot spot is shared. It cannot help a single hot key, which can only be fixed in the application or with caching.

What happens if the metadata server is down?

Clients with cached locations keep working for ranges that have not moved, but any cache miss or stale entry cannot be resolved, so new lookups fail. That is why metadata is replicated and partitioned like any other data.

Can ranges merge?

Yes, many systems merge small adjacent ranges, for example after a large delete, to keep the number of ranges and the metadata small. Like a split, a merge is mostly a metadata change once both halves are on the same servers.

7Conclusion

In this answer, we saw that a range-partitioned store cuts its sorted key space into [start, end) intervals and keeps a metadata table, often range partitioned itself, that maps ranges to servers. Splits happen at a middle key when a range passes a size or load threshold and only change metadata; moving a half to another server is a separate step. Clients cache locations and refresh lazily when a server answers with a not-serving error. Neighbouring keys stay together, which helps scans but makes sequential keys hit the last range, so key design and pre-splitting decide whether writes spread.

What to say in the interviewAbout 90 seconds aloud

Open with

In a range-partitioned store the rows are sorted by key, and the key space is cut into contiguous ranges, each covering an interval from a start key inclusive to an end key exclusive.

Then, if they want more

A metadata table maps each range to the server holding it; in HBase that is hbase:meta, and in large systems the metadata is itself range partitioned. To find a key, the client looks up the range covering it, sends the request to that server, and caches the location.

When a range grows past a size threshold, and in some systems a load threshold, it splits at a middle key. The split itself is just a metadata change, because the data is already sorted on that server; afterwards the balancer may move one half to another server, which copies data. Clients are not notified.

If a client sends a request with a stale location, the server rejects it with a not-serving or range-not-found error, and the client refreshes that entry from the metadata and retries. The upside of ranges is efficient scans, since neighbours stay together.

The downside is that sequential keys, like timestamps, send every write to the last range, so the key design, with a hashed or bucketed prefix, decides whether writes spread, and pre-splitting a new table avoids one server taking everything at the start.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How does such a store decide where a key lives, how does a range split happen, and how...": https://scrivio-interview-library.netlify.app/architecture/partitioning-and-replication/73e06365d8/