KatInterview

Architecting a Scalable Async Text-to-Video Generation Platform

System DesignModel answer
HardModel answerSystem Designsystem-designmachine-learningdistributed-systems

Last updated

Design a robust ML system to handle asynchronous, long-running text-to-video inference, featuring state machine orchestration, GPU worker fault tolerance, and multi-tier scheduling.

Design an asynchronous, distributed backend system for a text-to-video generation service (similar to OpenAI Sora or Runway Gen-2).

Users provide textual descriptions, along with parameters like video length, resolution, frame rate, seed, and optional input media (e.g., initialization images). Because video diffusion models require anywhere from 30 seconds to several minutes of intensive GPU compute per clip, traditional HTTP request-response patterns are unviable. The platform must be fundamentally asynchronous: API calls immediately yield a job handle, while background infrastructure handles scheduling, compute, and artifact delivery via polling or webhooks.

Your design should address:

  1. API & Orchestration: Endpoint schema, request validation, and an explicit job state machine.
  2. GPU Worker & Resource Scheduling: How to efficiently allocate heterogeneous/expensive GPU compute while balancing fairness across user tiers (Free, Paid, API/Enterprise).
  3. Fault Tolerance & Worker Life Cycle: Mechanistic handling of worker crashes, Out-Of-Memory (OOM) exceptions, network partitions, and spot instance preemptions without job duplication or silent hangs.
  4. Safety, Artifact Storage & Delivery: Multi-stage safety moderation (prompt checking and post-generation visual validation), metadata storage, object storage strategy, and content provenance (watermarking/C2PA).
  5. System Metrics & Operations: Monitoring queue latencies versus compute execution, rate-limiting, and cost control.

Focus deeply on state transitions, worker fault isolation, and GPU queue management.


Key Requirements & System Constraints

  • Compute Dynamics: A standard 5-second 720p 24fps clip takes ~60 seconds of un-batched A100/H100 execution time. GPU utilization must be optimized, minimizing idle overhead.
  • Failures are Expected: GPUs run near thermal and memory limits. CUDA OOMs, hardware fault drops, worker node host terminations, and driver crashes occur routinely.
  • Strict Execution Semantics: Exactly-once delivery of video artifacts per submission handle. No double-billing or leaking of partial execution results.
  • Multi-Tenant Fairness: High-paying API customers must not be starved by thousands of free-tier requests.

Hints

Hint 1

Treat GPU nodes as untrusted, highly volatile execution units. Maintain job state ownership in a transactional store, using heartbeats and leasing mechanisms to detect dead workers.

Hint 2

Decouple job admission (pre-flight validation, rate limits, storage of prompt) from model execution. Always validate inputs (safety check on text) BEFORE pushing jobs into expensive GPU queues.

Hint 3

Avoid storing state on GPU worker nodes. If a worker fails mid-generation, make sure partial frames in ephemeral worker disk do not corrupt object storage or lead to duplicate active executions.