Review a design doc for a batch sampling service

design reviewhardAnthropic
45:00

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/batches uploads a JSONL file. Each line has a custom_id and the sampling parameters. Returns a batch_id.
  • GET /v1/batches/{id} returns RUNNING, DONE or FAILED.
  • GET /v1/batches/{id}/results returns the results file once the batch is DONE.
  • POST /v1/batches/{id}/cancel deletes the batch and its input file.

Data model. Two tables. batches holds batch_id, tenant_id, model, status, created_at and request_count. requests holds batch_id, custom_id, status, worker_id and updated_at. Inputs and results live in object storage under the batch id.

Architecture.

  1. Submit. The submit service writes the input file to object storage, inserts one row per request into the requests table with status PENDING, and publishes each request id to the model's queue.
  2. Queueing. One FIFO queue per model. First come, first served keeps ordering simple and fair.
  3. 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.
  4. 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.
  5. Validation. Workers validate each request's parameters before sampling. If any request in a batch fails validation, the batch moves to FAILED so the customer can fix the file and resubmit.
  6. 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.
  7. Completion. A job runs every 5 minutes and marks a batch DONE when all of its rows are DONE.

Failure handling.

  • When a worker picks up a request, it sets the row to RUNNING. A sweeper resets rows that have been RUNNING for more than 10 minutes back to PENDING. 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 RUNNING until every one of its requests is DONE.

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.

Your answer
0 words