Katkat

Design a Translation API That Batches Requests on a Fixed Clock

AnthropicSoftware Engineer · Onsite

Last updated

Design a hosted translation API where a GPU worker runs one batch of pending requests every fixed round, and the candidate must derive throughput, batch-closing policy, and failure handling from that one constraint.

You are designing the backend for a hosted text-translation API. Clients submit one sentence at a time and wait for the translated result. To keep the translation model's GPU busy, the service does not run one sentence through the model at a time — it collects pending requests into a batch and runs the whole batch through the model together.

The interviewer gives you one fixed number to design around: every batch, regardless of its size, takes 80 ms to run on a worker. Your job is to design everything around the client, the batch formation policy, and the worker fleet under that assumption, and to be explicit about what the 80 ms does and does not include.

Constraints and Clarifications

  • Treat the 80 ms batch-run time as a given constant for your core design.
  • Peak request rate, the maximum batch size, the number of GPU workers, and the end-to-end latency target are not specified — state your own assumptions or ask for them.

Clarifying Questions

  • Does the 80 ms cover only the model's forward pass, or does it also include moving the batch onto and off of the GPU?
  • Is there a cap on how many sentences fit in one batch, and does the 80 ms hold at that cap?
  • Is there one model deployment, or several language pairs that cannot share a batch?
  • What request-per-second rate and what p99 latency target must the service hit?
  • Are results delivered as a single response per sentence, or can a client subscribe to a stream?

What a Strong Answer Covers

  • Capacity math. Derive how many sentences one worker can translate per second as a function of batch size, given the fixed 80 ms, and use that to size the worker fleet for a target request rate.
  • Batch-closing policy. Decide what closes a batch — it filling up, a timer expiring, or a worker becoming free — and discuss the latency/utilization trade-off of each, especially under bursty or low-traffic load.
  • Routing results back. A batch returns many translations at once; explain how each one reaches the right waiting client connection, and what happens if that client already disconnected.
  • Failure handling. What happens to the rest of a batch if the model crashes partway, and how retries avoid re-running sentences that already finished.
  • Scaling and admission control. How the fleet scales with load, and what the service does when it cannot keep up (queue, shed load, or degrade).

Part 1 — Core design

Design the path from an incoming request to a batch running on a worker and back to the client, under the fixed 80 ms assumption.

Part 2 — Pushing past the fixed assumption

The 80 ms assumption breaks once you account for GPU memory limits, variable sentence lengths, and multiple language pairs. Discuss how your design would need to change, and what you would measure in production to know if the assumption still holds.

Hints

Hint 1

Start from the fixed 80 ms and work out requests-per-second-per-worker as a function of batch size before you design anything else — that number should drive your worker count.

Hint 2

Pick one trigger for closing a batch (full, timeout, or free worker) and argue why it fits the target latency, rather than listing all three as equally good.

Hint 3

A batch response fans out to many waiting clients at once — design the data structure that maps an in-flight sentence to the connection waiting on it, including the disconnect case.

Hint 4

Treat prompt/response length variance as a stated simplification you're relaxing in Part 2, not a flaw in your Part 1 design.

Follow-up questions

  • How would you change the batching policy if 10% of requests are much longer than the rest and dominate batch compute time?
  • How would you support request cancellation once a request has already joined a batch that's running?
  • How would you roll out a new model version without interrupting in-flight batches?
  • What metrics would tell you the fixed-batch-time assumption no longer holds in production?