Review a design doc for a batch sampling service
The interviewer shares a doc: "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."
Batch Sampling Service: design doc, draft v0.3
Summary. 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.
Goals. Accept batches of up to 1,000,000 requests. Deliver results within 24 hours for 99% of batches. Reuse the interactive serving stack instead of building a second one.
Non-goals. Streaming partial results. Per-request priorities. A dedicated GPU fleet for batch.
API.
POST /v1/batchesuploads a JSONL file. Each line has acustom_idand the sampling parameters. Returns abatch_id.GET /v1/batches/{id}returnsRUNNING,DONEorFAILED.GET /v1/batches/{id}/resultsreturns the results file once the batch isDONE.POST /v1/batches/{id}/canceldeletes the batch and its input file.Data model. Two tables.
batchesholdsbatch_id,tenant_id,model,status,created_atandrequest_count.requestsholdsbatch_id,custom_id,status,worker_idandupdated_at. Inputs and results live in object storage under the batch id.Architecture.
- Submit. The submit service writes the input file to object storage, inserts one row per request into the
requeststable with statusPENDING, and publishes each request id to the model's queue.- Queueing. One FIFO queue per model. First come, first served keeps ordering simple and fair.
- Dispatch. The dispatcher reads the queue and assigns each request to the next worker in round-robin order. Each worker keeps an in-memory queue of the requests assigned to it.
- Workers. Batch workers call the same internal inference endpoint as interactive traffic, on the same GPU pools. To protect interactive latency, batch is capped at 30% of each pool's request rate.
- Validation. Workers validate each request's parameters before sampling. If any request in a batch fails validation, the batch moves to
FAILEDso the customer can fix the file and resubmit.- Results. When a request finishes, the worker appends the result as a JSON line to the batch's results file in object storage and sets the row to
DONE.- Completion. A job runs every 5 minutes and marks a batch
DONEwhen all of its rows areDONE.Failure handling.
- When a worker picks up a request, it sets the row to
RUNNING. A sweeper resets rows that have beenRUNNINGfor more than 10 minutes back toPENDING. This covers workers that crash.- If sampling returns an error, the worker puts the request straight back on the queue, so transient errors clear quickly.
- A batch stays
RUNNINGuntil every one of its requests isDONE.Models and deploys. Workers load the latest build of each model at startup, so batch customers always get our newest improvements. Deploys roll through the worker fleet continuously.
Capacity. At 10 million requests a day, batch is about 116 requests a second for the busiest model. The interactive pool for that model averages about 60% busy, so the 30% request-rate cap leaves plenty of room, and batch fits without new hardware.
Monitoring. Dashboards for GPU utilization, worker error rate and requests completed per minute. Page the on-call if the worker error rate stays above 5% for 10 minutes.
Rollout. Ten design partners for two weeks, then general availability.
Open questions. Should the status call report per-request progress, or only the batch status? Should results be kept for 30 days or 60? Do we need a webhook for completion, or is polling enough for launch?
Write your review. Order the problems by how much damage they'd do, and give a fix for each.
Ask the interviewer
Write your own questions first, then compare.
What's the completion promise to customers?
What volume and sizes should I plan for?
Do batch and interactive traffic share GPUs today?
How fast does one sequence generate, and what's the longest request?
What does one replica sustain in total?
How many tenants are there, and how lumpy is their traffic?
Does the internal inference endpoint know about priorities?
How often do model builds and serving changes ship?
Follow-ups
In the room these come after your design, not before. Write your first pass, then open them and answer each one.