KatInterview

Building an Asynchronous Job Platform for LLM Requests

System DesignModel answer
HardModel answerSystem Designsystem-designllm-servingjob-queue

Last updated

Design an asynchronous backend that accepts LLM requests, queues and routes them fairly, runs them reliably, and returns results, with cost, security and SLA controls.

Problem

Your company wants to offer an asynchronous service for running large language model requests. A client sends a request to an HTTP API, immediately receives a job handle, and later retrieves the outcome either by polling or through a callback to a URL they supply.

Design the backend for this service.

What to cover

  • API surface: endpoints, request and response shapes, and the job lifecycle states.
  • Queueing and priorities: how jobs are enqueued, how tiers (for example interactive, standard, batch) are scheduled, and how you keep one heavy tenant from starving the others.
  • Workers and model routing: how worker pools are organized and how a request is mapped to a model pool.
  • Prompt versioning: how templates are stored, changed and referenced so that in-flight jobs stay stable.
  • Idempotency: how client retries and duplicate queue deliveries avoid duplicate effects.
  • Failure handling: retry policy, error classification, dead-letter queues and redrive.
  • Result storage: where outputs live, how long they are kept, and how they are protected.
  • Observability: metrics, logs, traces and alerts you would put in place.
  • Cross-cutting concerns: scaling, cost control, rate limiting, PII and security, and SLAs.

Follow-up

Extend the design to support streaming partial output to the client and cancellation of jobs that are queued or already running.

Expectations

State your assumptions and rough scale numbers, justify the main trade-offs, point out edge cases, and explain how you would verify that the system meets its goals.

Hints

Hint 1

Size the system in tokens rather than requests: a few very long prompts can consume as much GPU time as thousands of short ones, so admission control and autoscaling should be token-aware.

Hint 2

Separate the two kinds of duplication: client-side retries are handled by an idempotency key tied to a request hash, while duplicate queue deliveries are handled by leases plus a conditional, attempt-numbered commit of the result.

Hint 3

Resolve prompt aliases to an immutable version at submit time and store the concrete version on the job, so promotions and rollbacks never alter work already accepted.

Hint 4

For the follow-up, think about where the stream is produced versus where it is served, how a client reconnects mid-stream, and how a cancel signal reaches a worker that is already generating tokens.