KatInterview

Design a Real-Time Translation API with Batching

System DesignModel answer
HardModel answerSystem Designsystem-designml-infrastructurebatching

Last updated

Design an inference backend that aggregates single-sentence translation requests into GPU batches running on a fixed 80 ms execution loop.

You are tasked with designing the backend infrastructure for a high-throughput, low-latency text translation API. Clients send individual sentences over a synchronous network connection (such as gRPC or HTTP/2) and block until the translated text is returned.

To maximize GPU hardware efficiency, the backend cannot run sentences individually. Instead, incoming requests are aggregated into dynamic batches before execution on worker nodes.

The core constraint of your system is: Every batch, regardless of how many sentences it contains, requires exactly 80 ms of processing time on a worker.

Key Requirements & Constraints

  1. Capacity & Sizing: Derive the throughput bounds per worker and establish a sizing methodology for the GPU fleet based on peak traffic goals and target latencies.
  2. Batching Policy: Design the trigger mechanisms that close a batch and initiate execution. Analyze the trade-offs between system throughput and end-to-end tail latency across light and bursty traffic patterns.
  3. Request Lifecycle & Async Routing: Detail how an incoming synchronous request transitions into a batch, executes on a worker, and correctly routes its output back to the waiting client. Explain how client disconnects are handled without corrupting batch state.
  4. Resilience & Fault Tolerance: Explain how worker node failures, out-of-memory (OOM) faults, or execution timeouts are managed across the impacted batch.
  5. Real-World Violations: Detail how the design evolves when the assumption of a static 80 ms execution time is relaxed to account for dynamic sentence lengths, token padding, and multiple distinct language pairs.

Present your design systematically, addressing capacity planning, architectural topology, lifecycle routing, and edge-case failure modes.

Hints

Hint 1

Break the batching lifecycle into two distinct delays: assembly time in the queue (accumulation delay) and processing time on the GPU (fixed 80 ms).

Hint 2

Consider using a dual-trigger mechanism for batch closure: max batch size (B) or max waiting time (T).

Hint 3

Map how asynchronous completion futures or channel bridges allow multi-tenant batches to fan out results to individual client HTTP/gRPC streams.