KatInterview

Build an Async Text-to-Video Service on a Shared GPU Cluster

System DesignModel answer
MediumModel answerSystem Designgpu-schedulingdistributed-systemsjob-queue

Last updated

Design an asynchronous text/image-to-video platform: job lifecycle, moderation, GPU scheduling, checkpoint-based recovery, and autoscaling for a mixed H100/A100 fleet.

Problem

You are asked to design a backend for an asynchronous video generation product. Users send a text prompt (optionally with a reference image) and receive a rendered video clip some minutes later. The underlying diffusion model is very heavy: one generation typically occupies a full 8-GPU node for several minutes.

Functional requirements

  • Submit and track: a request carries a prompt, an optional image, clip duration, resolution, and a model version. Clients must be able to poll for status, subscribe to a progress stream, or register a webhook.
  • Two-stage moderation: inputs (text and image) are screened before any GPU time is spent, and the rendered frames are screened again before the result is released.
  • Job control: users can cancel at any time. Transient infrastructure failures are retried a bounded number of times. Publishing the finished artifact to object storage must be idempotent.
  • Versioning: several model checkpoints and inference runtime versions must run side by side.

Scale and non-functional targets

  • 50,000 requests per day. The brief describes this as roughly 2-5 requests/s on average with bursts up to 15 requests/s.
  • A typical generation takes about 3 minutes on one 8-GPU node.
  • A heterogeneous fleet of 2,000-4,000 GPUs (for example H100 and A100-80GB).
  • Hardware faults (out-of-memory errors, silent data corruption, host reboots) must never lose a user's job or leave a GPU stuck forever.
  • GPU utilization above 80%, elastic scaling, and per-tenant rate and cost limits.

What your answer should cover

  1. Public API and a durable job state machine (for example QUEUED, MODERATING, SCHEDULED, RUNNING, VALIDATING, SUCCEEDED, FAILED, CANCELLED).
  2. Overall architecture, separating control plane, scheduler, and compute/data plane.
  3. Scheduling and fleet management: placement that accounts for GPU memory and where model weights are already loaded, lease-based heartbeats, and draining nodes.
  4. Mid-generation checkpointing and how you limit wasted compute when a worker disappears.
  5. Autoscaling and cost control, given slow GPU provisioning, spot/preemptible capacity, and per-user concurrency quotas.

State your assumptions and sanity-check the numbers given above.

Hints

Hint 1

Convert the traffic numbers into GPU-hours and into a maximum sustainable jobs-per-second for the fleet, then compare with the stated peak. What does that imply about the queue and about what the API promises users?

Hint 2

Think of every job as a row with a version and a fencing token (lease epoch). Which writes (state changes, checkpoint commits, artifact commits) must be rejected if they come from a worker whose lease has expired?

Hint 3

Diffusion sampling is iterative and the intermediate state (latents, step index, RNG state) is tiny compared with the model weights. Use that to decide what to checkpoint, how often, and why scheduling should prefer nodes that already hold the right weights.