Building an Async Prompt-to-Clip Rendering Platform on a GPU Fleet
System DesignModel answerLast updated
Design a backend that accepts text prompts, renders short AI-generated videos on a pool of expensive GPUs, and survives bursts, worker crashes, and uneven hardware.
Design a Prompt-to-Clip Rendering Platform
You are asked to design the backend for a product where users type a text description and get back a short generated video. Rendering is performed by a large generative model that runs on expensive GPU machines, and each clip takes anywhere from tens of seconds to several minutes.
What the product must do
- A user submits a prompt along with a preferred clip length (for example 5 or 10 seconds).
- The service immediately returns a unique job identifier.
- The user can check progress at any time, and when rendering is done, receives a link to download the clip.
Operating conditions
- Traffic is bursty. Demand can jump many times above normal with little warning.
- A single render is slow, and GPU time is the dominant cost of the whole system.
- The service must stay available and must not lose jobs it has already accepted.
- The GPU fleet is mixed: different card types, memory sizes, and node shapes.
Areas your design should address
- API and job lifecycle: how submission, status checks (polling and/or callbacks), and retrieval work.
- Scheduling: how queued, long-running jobs get matched to a mixed GPU fleet.
- Load spikes: what happens when request volume suddenly rises tenfold.
- Storage and delivery: where finished video lives and how it reaches users.
- Failures: how you notice a worker dying mid-render and recover without losing or double-running work.
What to deliver
Walk through your answer as you would on a whiteboard:
- A text description of the high-level architecture.
- The data flow for a single job from submission to download.
- A discussion of the trade-offs between throughput (GPU efficiency) and latency (time to a finished clip).
State your own scale assumptions up front and use them to justify your choices.
Hints
Hint 1
Start by estimating jobs per day, render time per clip, and the resulting number of busy GPU nodes. Those numbers show that GPU utilization is the cost driver and that you cannot simply scale GPUs 10x in minutes.
Hint 2
Because the fleet cannot grow quickly, think about a spike in terms of buffering, admission control, priority classes and graceful quality degradation, with autoscaling as the slowest lever.
Hint 3
For crash recovery, think about leases with heartbeats, conditional (versioned) state transitions in a durable job store, idempotency keys on submission, and optional checkpoints so a retry does not always restart from zero.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify and size the problem
State assumptions first, since they shape everything else.
- Traffic: about 500K jobs/day, roughly 6 jobs/s on average, 3x at normal peak, and a 10x burst (about 60 jobs/s) lasting tens of minutes.
- Render cost: a 5s 720p clip takes about 1 minute on one multi-GPU node; a 10s 1080p clip takes about 4 minutes. Average about 90s.
- Fleet size: 6 jobs/s x 90s is about 540 busy nodes on average. GPUs dominate cost, so utilization is the key metric.
- Output: 5-20 MB per clip, so about 5 TB/day of new storage.
- Latency targets: submit returns in under 200 ms; median completion around 2 minutes, allowed to stretch under load with an honest ETA.
- Availability: the control plane (submit, status, download) targets 99.9%. The GPU plane may slow down but must never lose an accepted job.
Core insight: GPU capacity is slow to add (node provisioning plus loading tens of GB of weights). So spike handling is mostly buffering, admission control and prioritization, not autoscaling.
2. API lifecycle
POST /v1/videoswith anIdempotency-Keyheader and a body of prompt, duration, resolution, optional seed and optional webhook URL. It returns202withjob_id,queuedstatus and an ETA.GET /v1/videos/{id}returns status (queued | processing | completed | failed | cancelled), progress, ETA and error. SendRetry-Afterso pollers back off.GET /v1/videos/{id}/contentreturns a redirect to a short-lived signed CDN URL.DELETE /v1/videos/{id}cancels on a best-effort basis.
Idempotency keys prevent duplicate GPU spend on client retries. Webhooks are optional, HMAC-signed and retried with exponential backoff; receivers must be idempotent. Run cheap prompt moderation synchronously before any GPU is used, and a second check on output frames.
3. Data model
A durable job table (Postgres or DynamoDB) is the source of truth: user, tier, parameters, prompt hash, status, a version counter, attempt count, lease owner and expiry, checkpoint location, output location, timestamps and error.
All state changes are conditional writes (UPDATE ... WHERE version = v), so two workers can never both complete the same job. Transitions: queued -> processing -> completed | failed, plus processing -> queued when a lease expires. Redis holds hot status reads and rate-limit counters only, never authoritative state.
4. Architecture and data flow
Client -> API gateway (auth, rate limits) -> job service -> job DB, with moderation on the side. The job service pushes to per-pool, per-priority queues. GPU workers in each pool pull work, heartbeat to a lease manager, and write results to object storage fronted by a CDN. An event bus feeds a webhook notifier. An autoscaler watches queue depth and wait time.
Flow for one job:
- Validate, check quota and moderation, compute a cache key (identical prompt and parameters may reuse an existing result).
- Write the job row as
queuedand enqueue it. Use a transactional outbox so the row and the message cannot diverge. Return 202. - A worker pulls the job and takes a lease with a conditional write.
- It runs text encoding, iterative denoising (the bulk of the time), decode, optional upscale and MP4 encode.
- It uploads to object storage, marks the job
completed, and emits an event. - Downloads go through the CDN, never through API servers.
5. Deep dives
Heterogeneous GPUs. Each job carries requirements (model version, minimum memory, GPU count) that map to a pool. Workers pull only when they have capacity, giving natural backpressure. Avoid plain Kafka partitions for the work queue: multi-minute jobs cause head-of-line blocking and per-message acknowledgement is awkward. Prefer SQS or RabbitMQ with visibility timeouts, or a DB scheduler using SELECT ... FOR UPDATE SKIP LOCKED. Kafka remains fine for events and audit.
Pipeline split. Move encoding, upscaling and safety checks to cheaper GPUs or CPUs so expensive cards only run denoising.
Batching and warm models. Batch same-shape requests (2-4x throughput) but cap the batching wait at a few seconds. Keep weights resident and route jobs to workers that already hold the right model version.
Handling a 10x spike, cheapest lever first:
- Buffer in the queue; the API only writes a row and a message, so it stays fast.
- Admission control: per-user and per-tier token buckets. If projected wait passes a threshold (say 30 minutes), return 429 with
Retry-Afterfor low tiers instead of accepting work you cannot finish. - Prioritize with weighted fair queuing so paid tiers see small slowdowns.
- Degrade gracefully: fewer diffusion steps or a distilled model, 720p with optional later upscale, shorter maximum duration.
- Scale: use reserved headroom, spot capacity, or borrowed internal capacity. New nodes take minutes, so this helps long bursts only.
Storage. Store MP4s and thumbnails in object storage keyed by user and job, serve via CDN with signed URLs (about 1 hour expiry). Use lifecycle rules to move unaccessed outputs to cheaper tiers and expire them per retention policy. Intermediate checkpoints live in a separate short-TTL bucket.
Failure handling.
- Workers heartbeat every few seconds and renew a lease. If the lease lapses, the job returns to
queuedandattemptincrements. - Because completion is a conditional write, a "zombie" worker that wakes up late cannot overwrite a newer attempt's result.
- Save checkpoints every N denoising steps so a retry resumes rather than restarts, trading a little extra I/O for less wasted GPU time.
- Cap attempts (for example 3) and move poison jobs to a dead-letter queue with a clear user-facing error and a refund of quota.
- Treat out-of-memory and driver errors as signals to retry on a different node or pool.
- Make the control plane multi-AZ; the queue and DB are replicated, and API servers are stateless.
6. Throughput vs latency trade-offs
- Batching raises GPU efficiency but adds queue wait; bound it.
- Higher utilization lowers cost but removes headroom for bursts; keep a reserved buffer for paid tiers.
- Fewer diffusion steps cut latency and cost but reduce quality; offer it as a degradation mode or a "fast" option.
- Warm pools cut cold starts but cost idle GPU money; size them from the diurnal pattern.
- Checkpointing speeds recovery but costs storage and I/O.
7. Common mistakes
- Promising that autoscaling absorbs a 10x spike.
- Using synchronous HTTP for generation, or serving video from API servers.
- Using Redis as the only record of a job.
- No idempotency, causing double GPU spend on retries.
- No lease or version check, so duplicate completions happen after a crash.
- Accepting unlimited work with no admission control, leading to hours-long waits and angry users.
- Ignoring moderation until after rendering.
Close by naming metrics you would watch: queue wait by tier, GPU utilization, success rate, retry rate, cost per clip, and p50/p95 time to completion.