Library/ML system design/Inference and compute

A batch inference service: failures and overload

125 min7 partsAdvancedFast-moving topicChecked Nov 2026
Start the lessonShort steps, each with something to do
What you'll learn
  • What a batch API promises (a 24-hour window, half the price, one outcome for each request), with Anthropic's and OpenAI's current limits
  • The parts of a batch service from submit to results file, and why workers pull work instead of having it pushed at them
  • How many GPUs finish a day of batch work inside the window, worked step by step from an assumed tokens-per-second rate
  • Batch as filler in the gaps of interactive traffic, evicted when people need the GPU, with fair shares so one huge batch can't starve the rest
  • Failure handling that holds up in a deep dive, from leases and writes that are safe to repeat to a worker dying at token 3,000 and a model version change mid-batch
  • Overload protection from the front door down, and the numbers to graph and page on, starting with the age of the oldest queued request
Part 1 of 7about 19 min
The batch API

Review a design doc for a batch sampling service

Some design rounds hand you a finished design instead of a blank page. The interviewer shares a doc and says:

A teammate wrote this design for our batch sampling service and wants a review before it goes to architecture review. Read it, then give me your review: what's wrong, how bad each problem is, and what you'd change. We have about 45 minutes.

The doc opens like this:

Batch Sampling Service: design doc, draft v0.3

Customers upload a file of sampling requests and get results within 24 hours at half the interactive price. Batch work runs on the same GPU pools as interactive traffic, so it costs us almost nothing extra.

It goes on for a page: the API, two tables, seven steps from submit to completion, failure handling, deploys, capacity and monitoring. Every part of it works on the happy path.

You don't review it yet. First you build a model of a batch service good enough to notice what's missing: what a batch API promises, the pieces from submit to results, how many GPUs it takes, how it shares GPUs with people, and how it handles failure and overload. The lesson ends on a mock interview with follow-ups, asked in the order a 45-minute review runs.

The round: review a design and find where it breaks

One Staff candidate's system design phone round at Anthropic was a design doc review of a batch sampling service (1 report). The candidate wrote that "it asked me to review an existing design doc and give feedback." (1 report)

The review then turned into "a typical deep dive session on failure handling, overload protection." (1 report)

That's a single report, so treat it as a strong hint rather than a pattern.

A review tests something different from a blank-page design. The happy path is already drawn. Your job is to find where it breaks, say how badly, and fix it with the smallest change that works.

That takes a model of the system good enough to notice what's missing. The estimates and queues come from the design round lesson, and why decoding waits on memory comes from the KV cache lesson.

In the editor, pieces lists the parts of a typical batch service in the order a request meets them, from the submit API that takes the customer's file to the delivery service that hands back the results. Each one gets its own step later. Write review_questions(pieces): for each piece, What if the {piece} dies? and then What if the {piece} slows down?

A batch API trades speed for half the price

Start with what a batch API promises its customers, because the design follows from that promise.

Work that can wait gets a 24-hour window

One batch's window
the first hourmost of it is done
hours 1 to 24slack, for interactive peaks, retries and a bad deploy
hour 24what's left expires

Interactive inference answers while someone waits, so every second in a queue is a second of latency.

Batch inference takes requests that can wait for hours:

  • an eval over 50,000 prompts
  • a classification pass over a support backlog
  • summaries of a document archive

The customer sends them together in one file and collects the results later.

The contract is a window, not a latency. Most batches finish in under an hour, and the promise is 24. Everything in between is slack. The scheduler can spend it on interactive peaks, on retries and on bad deploys.

In the editor, write plan(jobs). Each job is a name, the hours until its result is needed, and its cost at standard prices. Return the jobs that can wait the whole 24-hour window, and the total bill when those jobs pay half.

Anthropic and OpenAI make nearly the same promise

Both labs sell this product, and their terms line up closely.

Predict

You send three requests in one batch. In what order do both providers return the results?

Pick an answer above to see the rest

Every request gets its own outcome

A batch holds up to 100,000 requests, and some of them will go wrong.

Predict

One request in a batch of 100,000 is invalid. What happens to the batch?

Pick an answer above to see the rest

Batch means two things

The customer's batch is one file of up to 100,000 requests, with 24 hours to run. The service spreads it across the fleet: each GPU runs a decode batch, one token per sequence per step, mixed with other customers' requests.

The customer's batch is a file of requests with a 24-hour promise.

The decode batch is the set of sequences one GPU moves forward together, one token each per forward pass.

One customer's batch is spread over many decode batches, and one decode batch can hold requests from many customers. Keep the two apart out loud in an interview, because the design touches both.

Why batch costs half

Why can a provider sell the same tokens at half the price?

Predict

Why can a batch API charge half price?

Pick an answer above to see the rest
Part 1 done
Part 2 of 7about 23 min
The service

The service, piece by piece

Now the inside of the service, from submit to results.

The batch service, piece by pieceInteractive
submit API. The client sends the batch. The input goes to a durable store first.

That's the whole service. A request enters at the top and leaves at the bottom, as one line of a results file.

Submit checks the envelope fast

The submit call gets the batch somewhere durable, quickly, and says yes or no. It checks what is cheap and fatal for the whole file:

  • the caller is signed in, and the tenant is under quota
  • the file is within the size limits and parses
  • every custom_id is unique, and the model is known

Reject the whole batch only for envelope problems like these. Everything else is per request. Anthropic checks each request's parameters later, while the batch runs, and reports those errors once the whole batch has ended. So one malformed line out of 100,000 becomes one errored result.

MODELS and MAX_REQUESTS in the editor are what this service accepts. Write envelope_problems(model, requests): which of too many requests, unknown model and duplicate custom_id the batch has. A bad parameter inside one request is not on the list.

Store the input before you say yes, then make a row per request

Inside the submit call, the order of the steps matters.

Predict

The server replies accepted, then crashes before it writes the file. What's left?

Pick an answer above to see the rest
Predict

The reply to create batch is lost, and the client sends it again. With no idempotency key, what happens?

Pick an answer above to see the rest

A request moves through six states

Once accepted, every request moves through a fixed set of states.

FromEventTo
queueda worker takes a leaserunning
runningthe result is writtensucceeded
runningthe lease lapses: attempt + 1queued
runninginvalid, or failed for gooderrored
queuedthe batch is canceled before a worker took itcanceled
queuedthe window closed before a worker took itexpired

A request is in exactly one state at a time:

  • queued: stored, and its batch passed the envelope checks.
  • running: a worker holds a live lease on it.
  • succeeded, errored, canceled and expired are final. A request never leaves them.

A running request whose lease lapses goes back to queued, with its attempt count raised by one.

One queue per model, with a sub-queue per tenant

A worker can serve only the model whose weights it has loaded, and loading a large model takes minutes. So queues are per model.

OpenAI builds the same limit into its API: each input file may hold requests for one model only.

Inside each model's queue, keep a sub-queue per tenant. Part 4, on fairness, shows why.

MOVES in the editor is the table of states, written as (state, event) to the next state. Write replay(events): start queued at attempt 1, apply each event the table allows from the current state, skip the rest, and raise the attempt by one on every lapse.

Workers pull work when they have room

Something has to hand requests to the GPUs, and which side starts that exchange matters.

Predict

With push, a dispatcher deals requests out round-robin. What happens at a worker that's already full?

Pick an answer above to see the rest

Room means KV cache memory, not a count of requests

Capacity means KV cache memory. A request with a 2,000-token prompt and max_tokens of 4,096 can grow to 6,096 tokens of cache.

Llama 3 8B's cache takes 128 KiB a token, as the KV cache lesson works out. That lesson also finds about 65 GiB left for the cache on an 80 GiB GPU.

Reserve per requestTokensSizeHow many fit in 65 GiB
the most it might need2,000 + 4,096 = 6,0966,096 × 128 KiB = 762 MiB66,560 MiB ÷ 762 MiB = 87
what it usually needs2,4002,400 × 128 KiB = 300 MiB66,560 MiB ÷ 300 MiB = 221

The second row assumes the average request really ends at 2,400 tokens.

So admit on the expected size, and let memory grow in pages, as vLLM's paged attention does. Keep preemption, evicting a running sequence to free its memory, as the safety valve when many sequences run long at once.

The constants in the editor are the numbers from the table: 128 KiB of cache per token, and 65 GiB free. Write take(queue, free_kib): pull from the front of the queue while the next request's cache fits in what's still free, and return how many the worker takes. Each queue item is the tokens of cache that request will hold.

Continuous batching refills a slot on the next step

Inside a worker, requests share a decode batch, and they finish at different times.

Predict

64 sequences decode together. Answers average 400 tokens, and the longest is 4,000. If no slot is refilled until the batch ends, what share of the slot-steps is useful?

Pick an answer above to see the rest

The batch ends when every request is final

A customer waits for the whole batch, so the service needs a clear rule for when it's done.

Predict

A batch of 100,000 requests ends. What do its six state counts add up to?

Pick an answer above to see the rest
Part 2 done
Part 3 of 7about 12 min
Sizing

How many GPUs drain a day of work

With the pieces in place, size the fleet.

Count input and output tokens separately

Predict

20 billion input tokens and 4 billion output. A replica prefills 40,000 tokens a second and decodes 4,000. Which takes more replica time?

Pick an answer above to see the rest

As filler, the day's work clears with 10 hours to spare

There's a cheaper fleet than a dedicated one: the idle hours of the interactive fleet.

A 100-replica interactive fleet, one dayHoursBusyIdle replicasIdle replica-hours
peak885%158 × 15 = 120
off-peak1647.5%52.516 × 52.5 = 840
total960

Now run the same work as filler. Assume 100 replicas serve interactive traffic. They are 85% busy for 8 peak hours and 47.5% busy for the other 16.

That averages (8 × 85 + 16 × 47.5) ÷ 24 = 60% busy. The idle capacity is 15 replicas at peak and 52.5 off-peak, so the day has 960 idle replica-hours. Batch needs 417.

Take the worst case: the whole day's work lands at the start of the peak.

  • The 8 peak hours drain 8 × 15 = 120 replica-hours.
  • The other 416.7 - 120 = 296.7 take 296.7 ÷ 52.5 = 5.7 off-peak hours.
  • The backlog clears 8 + 5.7 = 13.7 hours after it arrived.

That leaves about 10 hours of window, on GPUs that were already paid for. That's the discount, in arithmetic.

One customer's batch of 100,000 requests, Anthropic's per-batch maximum, costs 400 ÷ 4,000 + 2,000 ÷ 40,000 = 0.15 replica-seconds per request, so 15,000 replica-seconds. Ten idle replicas clear it in 15,000 ÷ 10 = 1,500 seconds, 25 minutes. So finishing most batches within an hour is easy when the backlog ahead of them is small.

In the editor, write hours_to_clear(work, idle). idle[h] is how many replicas the interactive fleet leaves free in hour h after the work arrives. Return the hours until work replica-hours are done, with a fractional last hour, or None if they don't fit.

CheckpointBatch as filler, hour by hour

idle[h] is how many replicas the interactive fleet leaves free during hour h after the work arrives. Write hours_to_clear(work, idle): how many hours, with a fractional last hour, until work replica-hours are done, or None if they don't fit in those hours.

Compare the window spent with the work done

A 24-hour promise needs a way to tell, hours ahead, that it will be missed.

4 hours after the day's work arrived at the peak
window spent
4 ÷ 24 = 17%
work done
60 ÷ 416.7 = 14%

Work done behind the window spent is the early warning.

While a backlog drains, compare window burn, the share of the window gone, with progress, the share of the work done.

Four hours into the worst case, the peak has drained 4 × 15 = 60 replica-hours. Burn is 17% and progress is 14%. The off-peak hours will close that gap.

Page on the projected finish: now, plus the remaining work divided by the forecast drain rate. Page when it crosses a set share of the window, say 80%. Here the projected finish is 13.7 hours, 57% of the window, so nobody gets paged.

The editor holds hours_to_clear from the last step. Write page(now, done, total, forecast): page when the projected finish passes 80% of the 24-hour window, or when the work left doesn't fit in the forecast at all. forecast is the idle replicas for each hour from now on, and the print line is the worst case, four hours in.

Part 3 done
Part 4 of 7about 15 min
Sharing the fleet

People first, batch fills the gaps

Batch and interactive traffic share the GPUs, so one of them has to come first.

Interactive traffic is what you provision for

Predict

Google ranks request criticality from CRITICAL_PLUS down to SHEDDABLE. Where does batch sit?

Pick an answer above to see the rest

Bring evicted sequences back, but cap the evictions

vLLM brings an evicted sequence back in one of two ways. It can swap the cache out to CPU memory and back in, or it can recompute it.

Recompute is cheaper than it sounds. The tokens generated so far join the prompt, and the whole thing runs as one prefill pass. That can take much less time than generating those tokens did.

Preemption needs a guard. A sequence evicted ten times pays for a prefill on every resume, and may never finish. Cap evictions per request. When interactive load stays high, move batch to dedicated replicas.

Name the hardware trade:

LayoutUtilizationRisk to interactiveCost
Shared replicas with preemptionhighestlong batch prompts and cache pressure interfere with interactive stepsa priority-aware engine and careful reserves
Dedicated batch replicaslowestnoneidle when batch is empty, no help at interactive peaks
Replicas that move between tiers by hourin betweenlowminutes of model loading on every move

In the editor, write evict(running, need_gib). Each running batch sequence has an id, its cache in GiB, the tokens it has generated, and how many times it was already evicted. Evict the ones with the fewest generated tokens first, since they are cheapest to recompute, until need_gib is free. Skip any sequence already evicted cap times.

Serve tenants in turn, or a small one waits 20 minutes

Ten replicas are free for batch. A sends 100,000 requests at 9:00, and B sends 100 at 9:05.

QueueingAB
one FIFO queueruns to about 9:25waits until A is done, then starts
a sub-queue per tenant, served in turndone about 1.5 s later than alonedone about 13 s after 9:05

First come, first served sounds fair. Run the numbers.

Tenant A submits 100,000 requests at 9:00, 15,000 replica-seconds of work. Ten replicas have room for batch, so A takes 15,000 ÷ 10 = 1,500 seconds, 25 minutes.

Tenant B submits 100 requests at 9:05. Under one FIFO queue, first in, first out, B waits until A drains at 9:25. That's 20 minutes of waiting for 100 × 0.15 = 15 replica-seconds of work.

Now give each tenant a sub-queue, and serve them in turn.

Assume each replica decodes 128 sequences at once. Then each sequence gets 4,000 ÷ 128 = 31 tokens a second, and a 400-token answer takes 400 ÷ 31, about 13 seconds.

B's requests start within a step or two and finish about 13 seconds later. A finishes 15 ÷ 10 = 1.5 seconds later than it would have.

Fairness costs the big tenant almost nothing and saves the small one 20 minutes. Amazon's Builders' Library makes the general point: in some ways, a single queue and many tenants are at odds.

In the editor, write round_robin(queues). queues maps each tenant to its requests, in order. Serve one request from each tenant that has work, round after round, until every queue is empty.

Share tokens, not requests

Turns by request aren't fair when requests differ in size.

A request with a 100,000-token prompt costs at least as much prefill as fifty 2,000-token requests. It costs more once attention counts, since attention's cost grows with the square of the length. So count each tenant's share in tokens.

Deficit round-robin does it. Each round, every tenant with work gets a fixed allowance of tokens and keeps what it doesn't spend. A queue sends its next request only once its saved allowance covers that request.

Predict

Deficit round-robin gives each tenant 4,000 tokens of allowance a round. A's next prompt is 100,000 tokens. When does it go?

Pick an answer above to see the rest

Cap each tenant, and shard when tenants are many

Fair turns still let one huge tenant fill every queue. Three more defenses stop that.

Predict

Shuffle sharding hashes each tenant to 2 of 8 queues. Tenant A floods its two. What do the others keep?

Pick an answer above to see the rest
Part 4 done
Part 5 of 7about 30 min
Failure handling

Failure handling: one result per request, whatever dies

This is where the reported round went. For each failure, know exactly what your design does.

Exactly once isn't on offer, so build at-least-once

Predict

A worker writes the result, then dies before it tells the queue. What does the queue do?

Pick an answer above to see the rest

A lease, renewed by heartbeats

A worker can die in the middle of a request. The service has to notice, and give the request to another worker.

Predict

A 60-second lease with a heartbeat every 15 s. The worker dies at 40 s, and its last beat was at 30 s. When does the lease lapse?

Pick an answer above to see the rest

An attempt number stops a worker that wakes up late

A lease has one gap: a worker that was paused, not dead.

Predict

W1 stalls past its lease, and W2 succeeds as attempt 2. W1 wakes and writes failed, if the attempt is still 1. What happens?

Pick an answer above to see the rest

Write results by key, and the first write wins

Even with attempt numbers, two workers can finish the same request. The result store has to cope.

Predict

Two workers both finish doc-7, and each appends its answer to the batch's results.jsonl. What does the customer get?

Pick an answer above to see the rest

Sort failures before you retry them

Not every failure deserves a retry.

FailureRetry?Why
Invalid request: bad parameters, prompt too longNo, mark erroredit fails the same way every time
Worker died, lease lapsed, transient server errorYes, with backoffusually transient, and another worker will do
Preempted, or no capacityRequeue with a delay, without counting an attemptit's capacity, not the request
On a worker that crashed, twiceNo, quarantine itprobably a poison request

A retry helps only when the next try can go differently. So decide which kind of failure you have first.

Back off, by a random time up to a cap

Retries in the busiest second
no jitter
10
full jitter
2

Ten requests fail together and back off up to 8 s. Without jitter all 10 retry at second 8. With full jitter they spread out, at most 2 in any second.

Back off with capped exponential delays and jitter. In capped exponential backoff, each retry waits a constant factor longer than the last, up to a maximum.

The AWS Architecture Blog post that made this standard simulated it. Retries backed off in step still arrive in clusters, as in the first row. So its full jitter version sleeps a random time between zero and the capped backoff:

sleep = random_between(0, min(cap, base * 2 ** attempt))

random_between stands for any uniform random draw, such as Python's random.uniform. The name isn't the point.

Attempt (base 1 s, cap 60 s)0123456 and later
Longest sleep1 s2 s4 s8 s16 s32 s60 s
Average sleep0.5 s1 s2 s4 s8 s16 s30 s

The post's verdict: the return on the extra complexity is huge, and jittered backoff should be a standard approach for remote clients.

Cap the attempts too. Google's SRE book uses a per-request retry budget of up to three attempts.

In batch the delay is nearly free, since a request with 20 hours left can wait a minute unnoticed. So back off generously.

In the editor, write next_step(kind, crashes, attempt): the decision for a failed request, from the table, and how long to sleep before it. draw is the random draw, random.uniform unless a test passes its own.

Watch · 16 min

The retries, backoff and jitter segment of Amazon's Builders' Library talk, on why retries are selfish, how jitter spreads them out and where to cap them.

AWS re:Invent 2019: Introducing The Amazon Builders’ Library (DOP328) · AWS Events · Dec 2019YouTube

A poison request takes its decode batch down, so bisect to find it

Some requests crash the worker every time, and they take the rest of their decode batch with them.

Predict

8 suspects crash a worker together. Halve the suspects on each run. About how many runs find the poison?

Pick an answer above to see the rest

Never hold finished results for the stragglers

A batch can also end early, by a cancel or by its deadline.

StateCancel at 10:00The window closes
queuedcanceledexpired
runningfinish, or stop after a short boundfinish, and count
succeededkept, deliveredkept, delivered

Partial results. Never hold finished results hostage to stragglers. When the window closes, what succeeded is delivered and what never started is expired.

Cancellation. Set the batch to canceling. The dispatcher stops granting its leases, and queued requests become canceled. In-flight ones finish, or are stopped after a short bound, and written results stay.

OpenAI keeps a batch in cancelling until its in-flight requests are complete, for up to 10 minutes. Make cancel idempotent, and don't delete the input while an in-flight request may still read its prompt.

Expiry. Store expires_at as the creation time plus 24 hours. The dispatcher refuses leases for expired batches, and a sweeper marks what's still queued as expired.

Anthropic draws the line at dispatch: a request expires if the deadline passed before it was sent to the model. So requests already running at the deadline finish and count.

In the editor, write close(states, why): each request's state after the batch closes, where why is cancel or expire. Queued requests become canceled or expired, running ones keep running, and final states stay as they are.

Pin the model version per batch

A deploy in the middle of a batch raises a quieter problem.

Predict

A deploy rolls the workers halfway through an eval batch. Without pinning, what does the eval measure?

Pick an answer above to see the rest
Part 5 done
Part 6 of 7about 17 min
Overload and monitoring

Overload protection, from the front door down

Overload in a batch system has two faces:

  • more work is submitted than the window can hold
  • the GPU tier loses capacity while the backlog is large

The defenses run from the front door down.

Admit against the window

Model M, next 24 hours, replica-hours
forecast idle
400
queued + new
450

300 already queued plus the new 150 is 450, so about 50 replica-hours of work would expire.

Per-tenant caps are the first layer. The second is special to queues with a deadline: admit against the window. Use a forecast of batch capacity for the next 24 hours, and the work already queued.

Suppose a model's queue holds 300 replica-hours, the forecast is 400 idle replica-hours, and a 150-replica-hour batch arrives. 300 + 150 = 450 doesn't fit in 400.

Accept it anyway, and about 50 replica-hours of requests expire tomorrow. The customer learns that after 24 hours instead of in the submit response. So reject with a retry-after, or accept with an honest estimate.

Anthropic's docs describe the trade from the customer's side. Processing can slow down with current demand and your request volume, and then more requests may expire after 24 hours.

LLM requests make this check possible because their work is bounded. max_tokens caps the output, and the prompt length is known at submit. The Builders' Library explains why that matters: admission control is very hard when a server has no idea what a request will take.

Backpressure between stages

A pull dispatcher is backpressure by construction, since full workers stop asking. Keep that property everywhere.

If the result store slows, workers stop pulling rather than hold finished results in memory. Upstream, tie submit limits to the backlog. The Builders' Library calls it scaling an inbound throttle limit inversely with the backlog's size.

In the editor, write bound_hours(requests): the most replica-hours a batch can take, with every answer running to its max_tokens. Each request is its prompt tokens and its max_tokens. Then write would_expire(queued, new, forecast): the replica-hours that would expire if you accepted, 0 when it all fits.

Shed in an order that protects goodput

Under overload, throughput is the wrong number. The Builders' Library article on load shedding defines goodput as the part of throughput handled without errors and soon enough for the client to use the response.

For a batch service, goodput is tokens from requests that succeed inside the window. Duplicates, recompute after preemption and work on requests that expire anyway are all waste.

Shed in an order that protects goodput:

  1. Stop granting new batch leases before interactive traffic feels anything.
  2. Within batch, defer the work furthest from its deadline.
  3. Finish what was started. Evicting a sequence that is 90% done throws away 90% of its cost. The load-shedding article makes the same point with a service that has start() and end() calls: it should serve the end() calls first.

The curve below is the 8-worker queue from the design round lesson. It starts at 95% load: say 70% from people and 25% from batch, all in one first-come queue. That's what a design without priorities builds.

Everyone's p99, the latency 99% of requests beat, is about 4.9 seconds.

Drag the load down to 70%, roughly what interactive requests see when batch is preempted first. The p99 falls to about 1.9 seconds.

Batch was the 25% that pushed everyone into the knee, and it's the 25% that can wait. For batch, shed only means later.

Utilization and tail latencyInteractive
over capacity: no steady state02.5 s5.0 s0%50%100%150%
p99 time in the system (waiting plus service) on the y axis, 8 workers at 400 ms a request on average.
Stable on paper, but p99 is 4.9 s
Served per second
19.0
p50
964 ms
p99
4.9 s
Waiting, on average
16.0

In the editor, write shed_order(work): the ids in the order to shed them. Each item says whether it started, the hours left to its deadline, and the share done. Shed what hasn't started first, furthest from its deadline first, then running work, least done first.

Retries multiply down the layers, so retry in one layer

Retries help one request, but across layers they can turn a small failure into an outage.

Predict

Three layers each make up to 4 attempts. How many attempts can one user action send to the database?

Pick an answer above to see the rest

Watch the queue's age, not just the errors

The last piece is knowing when something is wrong.

Queue age shows what errors and latency hide

Hour123456
GPU utilization95%95%95%95%95%95%
error rate0.1%0.1%0.1%0.1%0.1%0.1%
oldest queued0.5 h1.4 h2.3 h3.2 h4.1 h5.0 h

Error rate and GPU utilization can both look healthy while a batch service quietly misses its promise. Only the last row shows it.

Start where the Builders' Library does for queue-based systems: measure the age of the messages in the queue.

Backlogs are dangerous because draining one takes spare capacity you may not have. After an hour-long outage, recovering takes double the system's capacity for another hour.

Latency graphs can mislead too:

10 requests: 6 shed in 1 ms, 4 served in 5 sMedian
all 101 mslooks amazing
the 4 served5 swhat customers get

Shed requests fail fast, and fast failures pull latency graphs down. The load-shedding article gives the example: a service shedding 60% of its traffic can show an amazing median latency while its successful requests are terribly slow. Graph successful-request latency on its own.

In the editor, write oldest_age(queued_at, now): the age of the oldest request still queued, 0 for an empty queue. Then write served_median(requests): the median latency of only the requests that were served. The print line is the 10-request table.

What to graph, and when to page

Put these on the dashboard, each with a rule for when it pages someone.

MetricWhat it isPage when
Oldest queued request ageper model and per tenantit passes a few hours
Projected finishnow plus remaining work over forecast drain rate, against expires_atit crosses 80% of the window for any batch
Outcomes by typesucceeded, errored by error class, canceled, expiredany rise in expired, or errored above baseline
Goodputtokens from in-window successes over all tokens processedit falls, meaning work is being wasted
Lease expirations, retries, crashesper model and per worker poola step change, usually a deploy or a poison request
Dead-letter queuequarantined requestsanything at all
Interactive p99what batch must never hurtit moves when batch load moves

The first two rows are the early warnings.

Part 6 done
Part 7 of 7about 9 min
A worked example and follow-ups

A worked example: a worker dies at token 3,000

Now put the pieces together on one failure.

Follow the request through every piece

A worker dies at token 3,000Interactive
W1 generates r = attempt 1. At token 3,000 of 4,000, the machine dies.

Rehearse this one, because it touches every piece. Worker W1 holds attempt 1 of request r. It has generated 3,000 of a 4,000-token answer when its machine dies.

  • One crash is bad luck. Poison handling starts at two.
  • The lost work is 3,000 ÷ 31 = 97 seconds of one decode slot.

The customer sees one result, pays once, and sees none of the rest. The retry cost a minute and some GPU time, out of a window measured in hours.

Checkpoints save most of the lost tokens

A strong candidate offers a refinement: checkpoint long generations, say every 512 tokens. A checkpoint saves the tokens generated so far, so a retry can start from them.

Predict

A checkpoint every 512 tokens, and the worker dies at token 3,000. How many generated tokens are lost?

Pick an answer above to see the rest

What interviewers ask next

Once the review is done, expect follow-ups that stress one piece at a time.

One tenant submits ten times its usual volume at 9 a.m.

Ten times the usual volume arrives at 9 a.m.What happens
tenant capover quota: rejected at submit
window checktoo big for the forecast: retry-after, or an honest estimate
tenant sub-queueholds what was accepted, and others keep their share
fair sharethe big tenant gets the idle capacity nobody else wants
projected finishif it crosses the window: add capacity, or tell the customer today

Walk the layers, from the front door down.

Without those layers, the Builders' Library's arithmetic applies. A spike that queues ten times what the consumers can process, met by an operator 30 minutes later, takes 300 minutes to work through.

The inference tier starts failing 20% of requests

Predict

The inference tier starts failing 20% of requests. What keeps that from turning into a total outage?

Pick an answer above to see the rest

The practice round, start to finish

That's every piece the practice round needs. Here it is in order, from the first question to the last minute.

Check yourself
5 questions
  1. 1.Tenant A submits 100,000 requests (15,000 replica-seconds of work) at 9:00. Tenant B submits 100 requests at 9:05. Ten replicas are free for batch. Under one FIFO queue per model, when does B finish?

  2. 2.A design uses a fixed 10-minute timeout, with no heartbeats, to reset requests stuck in running. Generation runs at 31 tokens a second. What happens to a request with a 32,000-token answer?

  3. 3.With full jitter, a base of 1 second and a cap of 60 seconds, how long does a client sleep before its retry at attempt 4?

  4. 4.A model's queue holds 300 replica-hours of work, the next 24 hours offer about 400 idle replica-hours, and a 150-replica-hour batch arrives. What does admission against the window say?

  5. 5.GPU utilization is 95% and the worker error rate is flat. Which metric tells you the service is about to break its promise?

Where this shows up

The reports behind this lesson, each with its source.

Staff SWE candidate (L6, US, interviewed about Sep 2026, in progress): the system design phone round, listed on the page as 'Design Doc Review - Batch Sampling Service', asked them to review an existing design doc and give feedback.

Candidate report·Aced, formerly Exponent (candidate report)Source

Same Staff report: the review turned into a deep dive on failure handling and overload protection.

Candidate report·Aced, formerly Exponent (candidate report)Source

Practice

Sources (14)
  1. Batch processing · Claude Platform Docs (undated page, read 2026-11-06) · Nov 6, 2026
    “A Message Batch is limited to either 100,000 Message requests or 256 MB in size, whichever is reached first.”
  2. Rate limits · Claude Platform Docs (undated page, read 2026-11-06) · Nov 6, 2026
    “a limit on the number of batch requests that can be in the processing queue at the same time”
  3. Model IDs and versions · Claude Platform Docs (undated page, read 2026-11-06) · Nov 6, 2026
    “When you use a model ID in an API request, the underlying model remains constant for the lifetime of that ID.”
  4. Batch API · OpenAI API docs (undated page, read 2026-11-06) · Nov 6, 2026
    “For now, the completion window can only be set to 24h.”
  5. Orca: A Distributed Serving System for Transformer-Based Generative Models · OSDI 2022 · Jul 11, 2022
    “In this paper, we propose iteration-level scheduling, a new scheduling mechanism that schedules execution at the granularity of iteration (instead of request) where the scheduler invokes the execution engine to run only a single iteration of the model on the batch.”
  6. Efficient Memory Management for Large Language Model Serving with PagedAttention · arXiv 2309.06180 · Sep 12, 2023
    “After each iteration, completed requests are removed from the batch, and new ones are added.”
  7. Exponential Backoff And Jitter · AWS Architecture Blog · Mar 4, 2015
    “Capped exponential backoff means that clients multiply their backoff by a constant after each attempt, up to some maximum value.”
  8. Timeouts, retries, and backoff with jitter · Amazon Builders' Library · Dec 5, 2019
    “When failures are caused by overload, retries that increase load can make matters significantly worse.”
  9. Using load shedding to avoid overload · Amazon Builders' Library · Dec 5, 2019
    “Goodput is the subset of the throughput that is handled without errors and with low enough latency for the client to make use of the response.”
  10. Avoiding insurmountable queue backlogs · Amazon Builders' Library · Dec 5, 2019
    “Therefore, we focus more on measuring the age of messages that are in the queue.”
  11. Handling Overload · Site Reliability Engineering (Google, O'Reilly), chapter 21 · Apr 1, 2016
    “This is the default for batch jobs, which can retry requests minutes or even hours later.”
  12. Addressing Cascading Failures · Site Reliability Engineering (Google, O'Reilly), chapter 22 · Apr 1, 2016
    “A cascading failure is a failure that grows over time as a result of positive feedback.”
  13. Amazon SQS visibility timeout · Amazon SQS Developer Guide (undated page, read 2026-11-06) · Nov 6, 2026
    “Implement a heartbeat mechanism to periodically extend the visibility timeout, ensuring the message remains invisible until processing is complete.”
  14. Amazon SQS at-least-once delivery · Amazon SQS Developer Guide (undated page, read 2026-11-06) · Nov 6, 2026
    “Design your applications to be idempotent (they should not be affected adversely when processing the same message more than once).”