Learn
Lesson · Partitioning and Load Balancing · Crossing shards

Rebalancing Cost

Moving a fraction m of a D-byte dataset at a throttled bandwidth B takes m·D/B, which at the lab's defaults is sixteen hours and forty minutes. That is not idle time: the copy is holding a share of each node's transfer budget, so the node serves fewer requests and its utilisation rises for the whole window — and the wait at the higher utilisation is three times the wait at the lower one. Turning the throttle up shortens the window and makes the utilisation worse, and past a point it puts it above one.

duration = m · D / B 0.25 × 48 TB = 12.00 TB at 200 MB/s = 60 000 s = 16 h 40 min the copy holds B/budget of the node: 200/800 = 1/4 so the node serves 6 000/s instead of 8 000/s ρ goes 62.50% → 83.33% M/M/1 wait 0.333 ms → 1.000 ms, a factor of 3.00 at 400 MB/s the window halves and ρ passes 1
A duration, and the utilisation it is bought at

Core ideas

What this lesson establishes

One division for the duration and one subtraction for the capacity, and the two are joined by a dial that moves them in opposite directions.

1

The duration is bytes over bandwidth, and nothing is hidden in it

m · D is the bytes that must move and B is the rate they move at, so the window is their quotient. At m = 25% of 48 TB that is 12.00 TB, and at 200 MB/s it is 60 000 seconds — sixteen hours and forty minutes. A terabyte here is 10¹² bytes and a MB/s is 10⁶ bytes a second, which is how both a disk and a throttle are sold.

2

The copy is capacity the node is no longer serving with

A node has a finite transfer budget, and whatever the rebalance takes from it is not available for serving. At 200 MB/s out of 800 MB/s the copy holds a quarter, so a node that served 8 000 /s now serves 6 000 /s. The arrival rate did not change, so utilisation goes from 62.50% to 83.33% and stays there until the copy finishes.

3

The throttle moves the two costs in opposite directions

Turn it up and the window shortens and the utilisation worsens; turn it down and the reverse. At 50 MB/s the move takes two days and eighteen hours and forty minutes at ρ = 66.67%; at 200 MB/s it takes sixteen hours and forty minutes at 83.33%; at 400 MB/s it takes eight hours and twenty minutes and the node can no longer serve the arriving load at all. There is no setting that is cheap on both axes.

The material

How long it takes, and what it costs while it runs

The duration, the capacity the copy steals, what that does to the wait, and the setting at which shortening the window stops being an option.

Definition · Rebalance

A rebalance moves a fraction m of the stored data between nodes, because the shard count changed, because a node was added or lost, or because the placement became uneven. The throttle B is the bandwidth the copy is allowed to use, and it is a deliberate limit rather than a property of the hardware: the whole reason to set one is that the node has other work to do.

Where m comes from is the earlier lesson. Under mod N assignment a growth step moves N/(N+1) of the keys — at seven shards going to eight, 87.50% of the dataset — and on a ring it moves 1/(N+1), or 12.50%. The 25% in the lab's defaults is a middling figure that could come from either a ring on a small fleet or a deliberate re-spread; what this lesson does is turn any such fraction into hours and a utilisation.

m = 25%, D = 48 TB, B = 200 MB/s, node budget 800 MB/s λ at the node = 5 000 /s, service rate μ = 8 000 /s bytes to move = 0.25 × 48 TB = 12.00 TB duration = 12 × 10¹² / (200 × 10⁶) = 60 000 s = 16 h 40 min capacity taken = 200/800 = 1/4 = 25.00% service during = 8 000 × (1 − 1/4) = 6 000 /s ρ before = 5 000/8 000 = 62.50% ρ during = 5 000/6 000 = 83.33% M/M/1 wait W = 1/(μ − λ) before = 1/(8 000 − 5 000) = 0.333 ms during = 1/(6 000 − 5 000) = 1.000 ms 3.00×

The wait figures are not new arithmetic. They are “The M/M/1 Queue” evaluated at two utilisations, and the reason a 21-point rise in ρ triples the wait is the knee that “The Knee: Response Time vs Utilisation” describes: the response time rises without bound as ρ approaches 1, so equal steps in utilisation are not equal steps in latency. A rebalance is a decision to sit further up that curve for a measured number of hours.

Turning the throttle

the same move, at six throttles throttle duration capacity taken ρ during wait 50 MB/s 2 d 18 h 40 min 6.3% 66.67% 0.400 ms 100 MB/s 1 d 9 h 20 min 12.5% 71.43% 0.500 ms 200 MB/s 16 h 40 min 25.0% 83.33% 1.000 ms 400 MB/s 8 h 20 min 50.0% past capacity 800 MB/s 4 h 10 min 100.0% past capacity

The fourth row is the one to look at. Halving the window from sixteen hours to eight takes half the node's transfer budget, which leaves it serving 4 000 /s against an arrival rate of 5 000 /s. That is not a slower system; it is a queue that grows without bound for as long as the copy runs, and “Transient Overload and Draining the Backlog” is what happens afterwards. The throttle has a hard ceiling and it is reached well before the hardware's.

Example · The same rebalance, priced two ways

“Moving 12 TB takes about seventeen hours” is the version that gets said in a planning meeting. The version that describes what will actually happen is “for sixteen hours and forty minutes, every node's utilisation is 83.33% instead of 62.50% and the queueing wait is three times normal” — and if there is a latency objective, that is the sentence it has to be checked against. The duration is the easy half of the cost and it is the half that gets reported.

What this makes cheaper elsewhere

Run the arithmetic on the two fractions from “Rehashing When N Changes” and the argument for consistent hashing stops being theoretical. Growing a seven-shard fleet under mod N moves 7/8 of 48 TB — 42 TB, which at 200 MB/s is 2 d 10 h 20 min at ρ = 83.33% throughout. The same growth step on a ring moves 1/8, or 6 TB, which is eight hours and twenty minutes. The identity 7/8 + 1/8 = 1 is, in the end, a statement about how many days of elevated latency a growth step costs.

It also prices the choice of V from “Virtual Nodes” and the decision to reshard from “Hot Keys and Salting”. A rebalance is the operation that every structural change on this course eventually has to pay for, which is why it is worth computing before the change rather than after it — the duration and the utilisation are both available from numbers you already have.

Interactive

Rebalancing cost

m·D/B of wall clock, and the utilisation the copy holds it at

Rebalancing is neither instant nor freem·D/B of wall clock, at a utilisation the copy raised while it ran
servingthe copythe wait it causes

Method

Planning a rebalance

Compute the duration, then the utilisation, then check the second one against whatever latency objective exists. The order matters because the first number is the one that tempts you to stop.

1

Get m from the change you are making, not from a guess

Under mod N assignment a growth step moves N/(N+1); on a ring it moves about 1/(N+1); a deliberate re-spread moves whatever you choose. The fraction is the largest single lever in this calculation and it is decided by a design choice made much earlier.

2

Divide bytes by the throttle for the window

m · D / B, in consistent units — a TB is 10¹² bytes and a MB/s is 10⁶ bytes a second. 12 TB at 200 MB/s is 60 000 seconds. Report it in hours, because that is the unit the decision is made in.

3

Compute the service rate and the utilisation during the move

The copy takes B/budget of the node's transfer capacity, so the effective service rate is μ(1 − B/budget) and ρ during the move is λ over that. If the result is at or above 1, the throttle is too high and nothing else in the plan matters.

4

Check the wait at that ρ against the latency objective

W = 1/(μ − λ) at the reduced service rate. Here it triples, from 0.333 ms to 1.000 ms, and it stays tripled for sixteen hours and forty minutes. That is the sentence the plan needs, and it is the one that decides whether the rebalance happens at this throttle or a lower one.

Windows, throttles and utilisation

Score 0 / 0

A quarter of 48 TB, throttled to 200 MB/s

The window first, then what the node looks like while it is open, then what happens if you try to close it faster.

m = 25% D = 48 TB B = 200 MB/s budget = 800 MB/s λ = 5 000 /s μ = 8 000 /s the window bytes = 0.25 × 48 × 10¹² = 12 × 10¹² = 12.00 TB duration = 12 × 10¹² / (200 × 10⁶) = 60 000 s = 16 h 40 min the node while it is open capacity taken = 200/800 = 1/4 service rate = 8 000 × 3/4 = 6 000 /s ρ before = 5 000/8 000 = 62.50% ρ during = 5 000/6 000 = 83.33% W before = 1/(8 000 − 5 000) = 0.333 ms W during = 1/(6 000 − 5 000) = 1.000 ms 3.00× trying to halve the window B = 400 MB/s duration = 8 h 20 min capacity taken = 1/2, service rate = 4 000 /s λ = 5 000 /s > 4 000 /s, so ρ ≥ 1 and the queue grows

The last block is where the plan is actually decided. Halving the window is arithmetically available and operationally impossible, because the node cannot serve 5 000 /s on 4 000 /s of remaining capacity. The throttle's ceiling is set by the workload, not by the network.

For a faded rehearsal, keep every other number and take the dataset to 96 TB. The supplied first move is the bytes to move, 24.00 TB. Produce the duration at 200 MB/s, then say what happens to ρ during the move and why, then find the throttle at which the window would be back to sixteen hours and forty minutes — and say whether that throttle is usable at this arrival rate.

Common mistakes

1
Reporting the duration and not the utilisation“About seventeen hours” sounds like scheduled maintenance. “Sixteen hours and forty minutes at ρ = 83.33% with three times the queueing wait” is what will happen, and it is the version that can be checked against a latency objective. The duration is the half of the cost that is easy to compute, which is why it is the half that gets quoted.
2
Raising the throttle to shorten the window without checking ρThe copy and the request path share one transfer budget. At 400 MB/s of an 800 MB/s budget the node serves 4 000 /s against 5 000 /s of arrivals, and the queue grows for the whole window. The throttle's ceiling is the arrival rate's, and it is well below the hardware's.
3
Taking the moved fraction as 1/N out of habitIt is N/(N+1) under mod N assignment and about 1/(N+1) on a ring, and those differ by a factor of N. At seven shards on a 48 TB dataset that is 42 TB against 6 TB — the difference between 2 d 10 h 20 min of elevated latency and 8 h 20 min of it.

Check your understanding

✓
Finish when a rebalance plan you read makes you ask what ρ will be while it runs.

You should be able to turn a moved fraction, a dataset size and a throttle into a window, compute the service rate and utilisation the copy leaves, evaluate the wait at both utilisations, and find the throttle at which the node stops keeping up.

Note: That closes the course. Every structural decision on it — the shard count, the partitioning function, the token count, the salt, the index design — is eventually paid for in the currency of this last lesson: bytes moved, hours of wall clock, and a utilisation held above normal while they move. The cheapest rebalance is the one a partitioning choice made years earlier does not require.

Kept in this browser only, for you. Nothing is sent anywhere and nothing checks it. Carry it to another device.

Feedback and recommendations

Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.

No recommendations yet for this lesson.