Each server is slow (over one second) one time in 100. A user request must wait for all 100 such servers. About what share of user requests take more than one second?
1%
10%
63%
99%
06-763 · L21
Latency, the tail at scale, fan-out
A Google service: p99 of 10 ms for one random request, 140 ms for all of them
Hedged requests sent after 10 ms: p99.9 from 1,800 ms to 74 ms, for 2% more requests
Little's law says that in steady state the average number of requests in a system equals their arrival rate times the average time each one spends there, .
Holds for any queue in steady state, whatever the distributions
A check on any load test: concurrency ÷ throughput should equal mean latency
Closed loop: each client sends a request, waits for the answer, sends the next
A canary release sends a change to a small, time-limited share of traffic and compares it with the current version before deciding whether to roll it out further.
SRE workbook: "a partial and time-limited deployment of a change in a service and its evaluation"
Staged rollout: widening rings, a check at each step
Rollback: return to the previous version if the check fails
L1 promised a "staged rollout so a bad model does not reach everyone at once, and the ability to roll back"
Fit L14's ensemble, save it with a manifest; the endpoints in process, including the 422
uvicorn in the background under load: p50, p95, Little's law; one request against a batch
The async def stall; an L15-style loop counting its calls; Docker cells only where Docker exists
06-763 · L21
Recap
Where: in process, service, serverless, batch, browser; the course has used each
Contract: bounds that 422 the impossible, a domain flag, an interval, a version
Load once, check the hash and versions; each worker holds its own copy
Package from the lockfile, CPU-only, non-root, no secrets in any layer
Report percentiles at a stated concurrency; check load tests with
Batch for throughput; retry at one point, with backoff and jitter
Release in stages, verify what is running, restore your backups
06-763 · L21
Standings
Nicknames only. Everyone who skipped one still counted in every bar you saw.
06-763 · L21
Before next time
No assignment for this optional session
Practice module for this session: on the course site
Run the worked example; the Docker cells are optional
Read: FastAPI's lifespan and concurrency pages, Kubernetes probes, one of the postmortems
Notes: lectures/l21/notes.md
Why 5, where 12, contract 15, packaging 15, latency 15, cost 8, releasing 12, limits 5, demo
and recap 3. About 90 minutes, then the notebook and questions. Three clicker questions:
readiness (packaging), fan-out and Little's law (latency). Open the vote page before class.
One worked example all the way through: Lecture 14's five-network ensemble on the L9
concrete strength data, served with FastAPI from service/app.py. Every measured number
comes from figures/make_figures.py on an Apple M4 Pro laptop.
5 min
Two minutes. Nothing here is a modelling error. The code that was meant to run was
correct. The failure was getting it onto every machine, checking it arrived, and knowing
what the fallback would do.
Same failure as Knight, at the scale of a course website. We come back to the fix,
build-info.json, in the releasing section.
This session collects those answers, applies them to a model, and measures what they cost.
12 min
Walk left to right. DuckDB and the FAISS index in process; PostgreSQL and the MQTT broker
as long-running services; the clicker serverless; pipeline stages as batch; the notes
chat and the practice game in the browser.
Both databases answer SQL. They differ in where the work happens, who keeps it running,
and what the caller must install. In process is fine when the caller is your own
pipeline; a problem when it is a colleague's MATLAB script.
The practice game is the other browser example: no "runtime network call of any kind"
(CLAUDE.md).
Most decisions live in the second row, which is why the rest of the session builds it.
15 min
So the service answers an unusual request and says it is out of domain. The manifest
stores the min and max of each feature over the training mixes.
The ensemble's members agree with each other off the data as readily as on it. The model
version lets a caller who logs it find out later which model produced a number. FastAPI
also validates the response: wrong shape is a server error, not incorrect data.
The docs use this exact case: "loading the model can take quite some time ... So you
don't want to do it for every request." For a large model the load dominates.
A plain def endpoint "is run in an external threadpool that is then awaited". The docs
frame blocking as I/O; a CPU-bound predict blocks the loop the same way. def is not free,
the threads share the GIL, but the server keeps answering.
A whole pickled PyTorch model is "bound to the specific classes and the exact directory
structure used when the model is saved". Older code that loaded whole models now fails
until someone opts into the unsafe path, which is the intended effect.
The recipe was saved and it did not reproduce the model. Final weights depend on
floating-point details that a library build can move. The manifest lets you show the
tested file and the served file are the same.
L1 named the commonest form: "a feature computed one way in training and another way in
serving." The course chat embeds index and query with the same runtime for this reason.
15 min
uv binary pinned, because tags can be moved. uv sync --locked fails the build if uv.lock
has fallen out of step with pyproject.toml: L2's lockfile discipline inside the image.
Shell form runs under /bin/sh, which does not pass on the stop signal. A .dockerignore
keeps the local .venv out of the build context.
The measuring machine runs Docker without BuildKit, so make_figures.py built an
equivalent image with plain COPY in place of the mounts; the final stage is the same.
Red bars measured here, grey bars cited. These numbers change with every release.
L11: "A GPU is a throughput device with a large fixed cost per kernel launch." Many
engineering surrogates, this one included, are that size.
The history line was |1 API_KEY=demo-not-a-real-key-7f3a /bin/sh -c rm /app/key.txt.
This is the course's first treatment of secrets.
GitHub: removing a secret from history "is time-intensive and often unnecessary if you've
already revoked the credential".
A liveness check that calls the model or a database fails when that dependency is slow;
restarting every instance at once turns a slow dependency into an outage.
C is the cascading failure the docs warn about, which is what happens when the database
check is put in liveness instead.
15 min
Ask before showing the curve.
Engineering pipelines fan out too. L18's pipeline runs a search, a re-ranker that cost "a
thousand times the cost of the search itself", then a language model: as slow as the sum
of its stages, and as unlucky as its unluckiest one.
D is 1,799 / 8, the most common slip: dividing the wrong way.
Same laptop for client and server, so latency is a floor; a real network adds to every
point. Little's law: throughput fixed, so latency doubles with the clients.
Say this: the first load test drove every client from one Python process, and its
throughput fell from about 1,570 to 321 requests/s between 8 and 32 clients, p95 327 ms.
Four server workers did not change it (319 requests/s), which put the limit in the load generator. L5: "A
benchmark measures one workload on one machine"; a load test also measures the machine
that sends the load. One process per client gave this figure.
T = 1/(mu - lambda), eq. 3.26. Variability in service time makes it worse
(Pollaczek-Khinchine, same chapter). Harchol-Balter's corollary is the counterintuitive
one: when the arrival rate doubles, keeping the same mean response time takes a server
that is "Less than double" as fast.
A thousand-mix batch is a hundred times cheaper per prediction: almost all of a single
request's cost was overhead, not the five small networks.
L17: "Cost and time are counted in tokens." Inter-token latency per NVIDIA NIM is "the
average time between consecutive tokens".
For a surrogate in a design loop the target is arithmetic you can do: calls the optimizer
makes times latency per call, against how long the engineer will wait. Same habit as L1's
"10% of the code" figure.
8 min
Nine dollars per thousand answers. Batch API: "a 50 percent discount on both input and
output tokens". Cache write 1.25x base input, pays "after one cache read for the 5-minute
duration". Prices change: record the date with the estimate.
A prediction endpoint is idempotent by nature; one that writes a result, places an order or
starts an experiment is not unless you make it so. The clicker budgets "a 40-person class
near 24k requests a session against a 100k/day budget"; 160 students would come within a
few percent of it in one session.
12 min
Postmortem, SRE book: "a written record of an incident, its impact, the actions taken...",
written "without indicting any individual or team". Test the interface between new content
and consuming code with real values; make the consumer reject malformed input, as the
manifest check does.
CLAUDE.md: "The run is green. That does not tell you the site updated." and "The page
returns 200. That does not tell you it rendered." A deploy is complete when you have
confirmed on every instance that the tested artifact is the one running.
L3 described PostgreSQL as a server you must "back up". "Five of five backup methods
failed" is not in the postmortem; it comes from posts made on the day. The pg_dump
mismatch is the same failure as the service's scikit-learn check: two components that
must agree on a version, and nothing checking.
Model analogues: a deploy script that refuses to take the last ready instance out of
service; monitoring that does not run on the system it monitors; a shadow deployment costs
what the model costs, on the machines serving real traffic. Cloudflare: "The SOP allowed a
non-emergency rule change to go globally into production without a staged rollout."
5 min
CPU-bound Python shares one interpreter lock per process, so throughput scales with
processes, and each process holds its own copy of the model. A managed container platform
or one VM serves many engineering workloads at a fraction of the operating cost.
Runs in Colab or locally, no cloud account, no Docker required.