The cloud bill for a 120 MB phone video, broken down line by line, and the TypeScript that moves the job into the browser.
A studio ships a feature that turns phone reels into shareable clips. Four months later the cloud invoice has a line nobody can explain: data transfer out, four figures a month, growing faster than the user count. The engineering answer is already in the room and nobody says it, because it sounds like a joke: the file is on the user's phone, the phone has four cores, and the browser tab runs JavaScript that the engine compiles to machine code. The server is there because a decade of tutorials put it there, not because the job needs it.
The job behind the line is one 120 MB video from a phone, and the server does three small things with it: it makes a thumbnail (a small preview image), reads the duration, and computes a checksum (a fingerprint of the file, used to detect changes). In the book's priced example, 79.3% of what that job costs is egress — the invoice line called data transfer out: every byte the server sends over the network, which cloud providers bill by the gigabyte. The same three things run on the device, where the file already is, and 120,000,000 bytes never leave it.
This article takes the invoice apart with one TypeScript program you can run. It shows the four lines a provider charges, the one that decides the bill, and the measured client row beside it. Every number below is printed by the code, not typed from memory.
Repo: github.com/edgarmilvus/zero-backend · GitHub: @edgarmilvus · Ebook: Zero Backend
The job is small; the file is not
The workload is deliberately boring: one reel, one thumbnail, one duration, one checksum. It is the kind of job a media product runs millions of times, and it is where the invoice becomes interesting.
The file is 120 MB. That number matters more than the work: a checksum is arithmetic on bytes, a thumbnail is one decoded frame, and the duration is a header read. None of the three needs the file to travel. On the server path the file is uploaded, processed, and sent back; on the client path it is already there.
The book calls the difference egress. Every provider charges for the bytes that leave its network, and a media product pays that line on every job. Compute gets cheaper every year. Egress does not.
The tariff is data, not a formula
The first program does not contain prices. It imports a tariff: four unit prices, a currency, a source URL and the day the list was read. The tariff is a TypeScript object, so a reader can put it beside the provider's pricing page and check it line by line. A new price list is a data change, not a code change.
That matters for an article about a number: the number can be traced. The program below prints the tariff id and the date before it prints a single dollar.
Run the bill
Chapter 1 needs no package: a clone and Node 24 are enough for this program.
git clone https://github.com/edgarmilvus/zero-backend.git
cd zero-backend
node chapters/chapter01/files/01_price_one_job.ts
/**
* Example 1 - price one job on the server path.
*
* Before comparing anything, the bill has to be taken apart. Four line items,
* one total, and the share each of them holds. On a media pipeline the answer is
* almost always the same, and it is almost never the one people guess.
*
* node chapters/chapter01/files/01_price_one_job.ts
*/
import { formatRow, priceServer, serverRow, usd } from "./ledger.ts";
import { REEL } from "./reel.ts";
import { TARIFF_2026_11 } from "./tariff.ts";
const percent = (part: number, whole: number): string =>
whole === 0 ? "0%" : `${((part / whole) * 100).toFixed(1)}%`;
export function main(): number {
const tariff = TARIFF_2026_11;
const breakdown = priceServer(REEL, tariff);
console.log(`tariff ${tariff.id}`);
console.log(`read on ${tariff.source.readOn}`);
console.log(`workload ${REEL.id}`);
console.log(` ${REEL.label}`);
console.log("");
console.log(`requests ${usd(breakdown.requestsUsd).padStart(10)} ${percent(breakdown.requestsUsd, breakdown.totalUsd)}`);
console.log(`compute ${usd(breakdown.computeUsd).padStart(10)} ${percent(breakdown.computeUsd, breakdown.totalUsd)}`);
console.log(`egress ${usd(breakdown.egressUsd).padStart(10)} ${percent(breakdown.egressUsd, breakdown.totalUsd)}`);
console.log(`storage ${usd(breakdown.storageUsd).padStart(10)} ${percent(breakdown.storageUsd, breakdown.totalUsd)}`);
console.log(`-----------------------------------------`);
console.log(`per job ${usd(breakdown.totalUsd).padStart(10)}`);
console.log(`per 1,000 ${usd(breakdown.totalUsd * 1000).padStart(10)}`);
console.log("");
console.log(formatRow(serverRow(REEL, tariff)));
return 0;
}
if (import.meta.main) {
process.exit(main());
}
tariff aws-us-east-1-2026-11
read on 2026-11-20
workload reel-120mb
one 120 MB phone reel: thumbnail, duration, checksum
requests <$0.000001 0.0%
compute $0.000067 0.5%
egress $0.0108 79.3%
storage $0.002760 20.3%
-----------------------------------------
per job $0.0136
per 1,000 $13.63
server $13.63 62.1 s 120.0 MB | 4 GB address space per worker; single-threaded decode on iOS below 17; no ffmpeg filters that need a second pass
Reading the four lines
Requests are effectively free at this volume: a fraction of a cent per million, printed as < $0.000001. Compute is half a percent. Storage is a fifth of the bill, because the file sits somewhere for a while.
Egress is 79.3%. The line that decides the architecture is the one nobody puts on the slide.
The per-job total is $0.0136. A fraction of a cent is hard to argue about in a meeting, so the program also prints per 1,000 jobs: $13.63. Multiply by your volume and the invoice line has a shape. The server row adds what the price does not say: 62.1 seconds for the job on the server path, 120 MB of traffic, a 4 GB address-space ceiling per worker, and two losses the provider does not bill — single-threaded decode on older iOS, and no ffmpeg filters that need a second pass.
The same job, on the device
The repository ships a second program that puts both rows together. It reads the measured client record and prints the five columns the book uses: server cost per thousand, client cost, latency, bytes leaving the device, and what each path loses.
node chapters/chapter01/files/02_compare_paths.ts
| $13.63 | $0.00 | 62.1 s -> 247 ms | 120.0 MB -> 0 B | 4 GB address space per worker; single-threaded decode on iOS below 17; no ffmpeg filters that need a second pass |
server per job $0.0136
client source measured (runs/chapter01/reel-120mb/record.json)
bytes avoided 120000000 bytes never leave the device
The client row is not an estimate. It comes from runs/chapter01/reel-120mb/record.json, the record a real Chrome run wrote: the page read the file from disk, hashed it in a worker, and the digest matched the node run. The 247 ms is the click-to-result time on the measured machine; the 0 B is the only number that matters for the invoice.
The client is not free, and the fifth column says so. It costs battery, memory and one repaint; a phone is not a data centre. The argument is not that the device is faster at everything. It is that this job — read a file that is already there, do arithmetic on it — does not need to travel.
What this does not prove
A 6 GB file in one piece does not fit this approach, and the book refuses it. Two people editing the same sentence cannot be merged by the last-writer-wins rule the book builds. A format another application has to read needs a writer that format's owner accepts. Every chapter has a section on what its approach cannot do, and the last chapter checks all twenty claims against their records.
That last part is the reason to trust the first: the book ships a program that reads the twenty claims and compares each one with the file that proves it. If a record moves, the row goes red.
Run the whole book
The bill in this article is one of twenty. The book repeats the same move on nineteen more jobs, and each one ships with the program that produced its number and the record that holds it. A few, to show the range:
- Video (chapter 4). A two-second clip re-encoded in the page in 122–240 ms by FFmpeg compiled to WebAssembly, with a 32 MB engine loaded in 149 ms. No per-minute transcode service.
- Photos (chapter 6). An iPhone HEIC decoded and converted in 14.5 ms warm, 68.9 ms cold; 6,190 bytes become 4,436, and the camera, date and location written into the photo are stripped. No upload of personal photos.
- A gigabyte (chapter 8). Hashed in 64 MB slices: 76 MB of memory instead of 1,023, 92.6% less, with the same fingerprint. Serverless memory is billed by the GB-second.
- A database (chapter 9). A thousand notes in PostgreSQL inside the page: first open in 1,647 ms, a search in 16.2 ms, and the rows survive the tab closing. No instance running all month.
- A million rows (chapter 10). Grouped in the page and written as Parquet: 2.4 MB against 23.3 MB as CSV, 89.6% fewer bytes to scan and ship.
- Search by meaning (chapter 11). Forty notes: 70% of the right subject in the top five against 37.5% for keywords, with 15 KB of vectors instead of 61.
- A permission (chapter 14). A 358-character token in a URL fragment, verified in 2.68 ms with no request to an auth service. A forged token that widens the scope is refused.
- The whole app (chapter 16). Notes, storage and merge in one HTML file of 14,376 bytes, 14% of a 100 KB budget.
Why run all of it? Because one example proves one line, and a single line can be a coincidence. The book's claim is that the method repeats: measure the job, save the record, ship the program. The gate runs every chapter's harness and its five exercises offline, with no key and no network. The last chapter then reads the twenty records and checks the twenty claims against them.
cd zero-backend
npm ci
./run_offline.sh
node chapters/chapter20/files/01_ledger.ts
chapters 20
with a claim 20
verified 20
missing none
failed 0
If a record moves, the row goes red. That is the check working — and the reason the numbers in the article are worth believing.
Repo: github.com/edgarmilvus/zero-backend — MIT, twenty chapters, every claim checked against a record
GitHub: @edgarmilvus — the other books and repositories
Ebook: Zero Backend — the prose around the code
Top comments (0)