Learn
Lesson · Scaling Laws and Cost · What bytes cost

Move the Data or the Compute

Either the data goes to the job or the job goes to the data. Both plans divide by the same link, so the bandwidth cancels and the comparison is code + result against the whole dataset. Since results are almost always far smaller than inputs, one side of that wins by orders of magnitude.

move the data D/bw = 2 TB ÷ 125 MB/s = 16 000 s = 4.44 h move the compute (code + result)/bw = 5.2 MB ÷ 125 MB/s = 41.6 ms 384 615× apart, and bw divides both sides: the comparison is code + result against D result/input = 5 MB / 2 TB = 1/400 000 the two plans tie at 2 TB of result, which is the whole dataset
Two placements, and a comparison with no link in it

Core ideas

What this lesson establishes

One ratio decides this, and the reason the answer is usually so lopsided is that the ratio is usually tiny.

1

Both plans cross the same link, so it cancels

D/bw against (code + result)/bw. The bandwidth divides both sides, so the comparison reduces to code + result against D — bytes against bytes. A faster link changes how long both plans take and nothing at all about which of them is quicker, which makes this the most portable decision on the course.

2

The result-to-input ratio is the whole question

The plans tie when code + result = D, and since code is negligible that is when the result is the size of the dataset. Here the result is 5 MB against 2 TB, a ratio of 1/400 000, so moving the compute wins by 384 615×. Aggregations, filters and counts all produce ratios in that region, which is why the answer is so consistent.

3

This is why query languages exist

Sending SELECT count(*) … instead of the table is exactly this arithmetic, and so is a stored procedure, a map-reduce job, an edge function and a pushdown predicate. Each is a mechanism for shipping a small amount of code to where a large amount of data already is, and each is worth precisely the ratio above.

The material

Two placements, the cancellation, and the ratio that decides

Where each time comes from, why the link drops out, and the cases in which the usual answer is the wrong one.

Definition · The two placements

For a computation over a dataset of D bytes that emits result bytes, with code bytes of program, across a link of bw bytes a second:

move the data takes D/bw;

move the compute takes (code + result)/bw.

The processing itself is assumed to take the same time wherever it runs, so it appears on both sides and cancels with the bandwidth.

D = 2 TB = 2 000 000 MB result = 5 MB code = 200 kB bw = 1 000 Mbit/s = 125 MB/s move the data 2 000 000 ÷ 125 = 16 000 s = 4.44 h move the compute 5.2 ÷ 125 = 0.0416 s = 41.6 ms ratio of the two 16 000/0.0416 = 384 615.4× result/input 5 MB / 2 TB = 1/400 000 the tie code + result = D ⟹ result ≈ 2 TB

4.44 hours against 41.6 milliseconds is not a close call, and the gap is not a property of this link. Put both plans on a connection a hundred times faster and they become 160 seconds and 0.42 milliseconds — the same factor of 384 615, because both numerators were divided by the same thing.

The cancellation, written out

It is worth doing explicitly, because the conclusion that a faster network does not change the decision is counter-intuitive enough to need the algebra rather than the assertion.

move the compute is faster when (code + result)/bw < D/bw multiply both sides by bw > 0: code + result < D no bandwidth anywhere: the decision is bytes against bytes, and the link only sets how long the winner takes.
Example · A count over two terabytes

The dataset is 2 TB; the job is a few hundred kilobytes of code; the answer is a single number. Moving the data takes 4.44 hours and moving the compute takes 41.6 milliseconds, and the ratio 1/400 000 is generous — a count returns a few bytes, so the true ratio is nearer 10⁻¹². Every database that pushes a predicate down to the storage layer is making this comparison implicitly.

When the usual answer is wrong

The comparison inverts exactly when the result is not small. A job that decompresses, joins or enriches can emit more than it reads, and then code + result > D and the data should come to the compute — or, better, the job should be split so that the reducing part runs next to the data and only its output travels.

There are also constraints that are not about time at all. The data may not be allowed to leave its jurisdiction, in which case the compute moves regardless of sizes; or the code may not be allowed to run next to the data, in which case it cannot move whatever the arithmetic says. Both are constraints applied before this calculation, not terms inside it.

The third case is repetition. One transfer of 2 TB followed by a thousand local queries is a different plan from a thousand remote queries, and the comparison to make is D against 1 000 × (code + result). That is still bytes against bytes, with the same cancellation; only the counts changed.

The assumption that the processing takes the same time in both places is the one this model leans on, and it is the one to check. If the data’s home is a storage tier with little processor beside it, moving the compute there may be slower in total even though it moves almost no bytes — and then the right answer is the one the measurement gives rather than the one the ratio suggests.

Interactive

Move the data or the compute

A comparison the link speed drops out of entirely

Move the data or the computethe link cancels; the result-to-input ratio decides
the datasetthe codethe result

Method

Placing a computation

Three sizes and a comparison. The link is needed only to turn the answer into a duration.

1

Write down the three byte counts

The dataset, the result and the code. Do not start with the link: it cancels, and reaching for it first is what makes people believe a network upgrade could change the answer.

2

Compare code + result with D

That is the decision, in bytes. Here 5.2 MB against 2 TB, which is not close, and the verdict is stable against anything the network does.

3

Report the result-to-input ratio

result/D, as a fraction. 1/400 000 here. It is the number that says how safe the verdict is: a ratio near one is a case worth re-examining, and a ratio of 10⁻⁶ is not.

4

Divide by the link only to state the durations

4.44 h and 41.6 ms. These are what a reader remembers, and they are downstream of a decision that was already made, so present them in that order.

5

Check the constraints and the repetition count

Jurisdiction and where code is allowed to run override the arithmetic. Repetition changes which side is multiplied: one big transfer against n small ones is the same comparison with a count in it.

Placements, ratios and the link that cancels

Score 0 / 0

An aggregation over a 2 TB table, returning 5 MB

The job is 200 kB of code, the link is a gigabit, and the processing time is taken to be the same wherever it runs.

D = 2 TB = 2 000 000 MB result = 5 MB code = 200 kB = 0.2 MB bw = 1 000 Mbit/s = 125 MB/s decide first, in bytes: code + result = 5.2 MB against D = 2 000 000 MB ⟹ move the compute, by a factor of 384 615 then state the durations: move the data 2 000 000 ÷ 125 = 16 000 s = 4.44 h move the compute 5.2 ÷ 125 = 0.0416 s = 41.6 ms result-to-input 5 MB / 2 TB = 1/400 000 (the panel shows this rounded, as 0.0003%) the tie code + result = D ⟹ result = 2 TB − 200 kB ≈ 2 TB of result a 100× faster link: 160 s against 0.42 ms still 384 615× apart

The order of the two blocks is the method. The decision is taken in bytes, where the link does not appear; the durations are then computed from it, and they are the only place the link is used at all.

The last block is the claim worth defending. A hundredfold faster network divided both numerators by a hundred and left the ratio exactly where it was. Bandwidth buys you a faster winner, never a different one.

For a faded attempt, keep the 2 TB table and make the job emit 1.5 TB — a decompressing scan rather than an aggregation. Predict from code + result against D which side wins before timing anything, compute both durations, and say what result size would have made it a tie.

Common mistakes

1
Pulling everything to the clientIt is the default because it is the easiest thing to write, and on this example it is 4.44 hours instead of 41.6 milliseconds. The error is about the result-to-input ratio rather than about bandwidth: it is wrong exactly when the result is smaller than the input, which is nearly always.
2
Believing a faster link will fix itbw divides both plans, so it cancels out of the comparison completely. A hundredfold upgrade turns 4.44 h into 160 s and leaves the other plan 384 615 times quicker still. Buying bandwidth to avoid moving a computation is paying to lose the same argument faster.
3
Forgetting the processing time is assumed equalThe model cancels the computation itself because it assumes it costs the same in both places. A storage tier with little processor beside it breaks that assumption, and there the plan that moves almost no bytes can still be slower overall. The ratio says where the bytes should go, not where the work will be fast.

Check your understanding

✓
Finish when a placement decision is made in bytes and the link is used only to report durations.

You should be able to compare code + result with D, show the bandwidth cancelling from the inequality, report the result-to-input ratio as a fraction, and name the result size at which the two plans would tie.

Note: That closes the course: what another machine buys, what a shape costs, the three ways capacity is paid for, and the break-evens about moving bytes. Every one of them was an equality located exactly rather than a rule of thumb, and the one figure that had to be rounded — the square root in the Universal Scalability Law’s peak — was printed beside the integer it glosses. “Measuring Systems” asks the question all of this has been deferring: how would you know any of these numbers from a system that is actually running?

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.