Design an AI Video Generation Service
Understanding the Problem
🎬 What is an AI video generation service? A user types a prompt like "a corgi surfing a wave at sunset, slow motion," picks a length and resolution, and a few minutes later gets a video clip. Behind the scenes, a large generative model runs for minutes on a group of expensive GPUs to produce each clip. The service exposes this through an app for consumers and an API for developers, who usually want to be told by webhook when their video is ready.
The model is not the interview here. Treat it as a black box that takes a prompt and parameters and, after a few minutes on a GPU node, produces frames. The system design question is everything around it: accepting jobs that take minutes, sharing a small and costly GPU fleet among many users, telling people when their video is done, and delivering it.
Functional Requirements
Core Requirements
- Users should be able to submit a generation request (prompt, optional reference image, duration, resolution, aspect ratio) and get a job ID back immediately.
- Users should be able to check a job's status and progress, and API customers should be notified by webhook when it finishes or fails.
- Users should be able to view and download the finished video.
Below the line (out of scope)
- Training or fine-tuning the model.
- Editing tools (remix, extend, storyboard).
- Billing beyond deducting credits per generation.
Non-Functional Requirements
Ask about volume and GPU budget. We'll assume 200,000 generations per day, split between free users, paid subscribers and API customers.
Core Requirements
- Asynchronous with honest timing: submission returns in under 200 ms; a paid job should start within a minute or two of submission at the median; users see a queue position or ETA.
- GPU efficiency: the GPU fleet is the dominant cost, so we want it busy, not idle or reloading models.
- Fairness across tiers: paid and API traffic get priority, but free users aren't starved forever, and no single customer can take over the fleet.
- Reliability: an accepted job is never lost; if a GPU fails mid-job, it's retried; users aren't charged for failures.
- Notifications: webhooks are delivered at least once, within seconds of completion, even when customer endpoints are slow or down.
Below the line (out of scope)
- Real-time or streaming generation.
- Running the model on users' devices.
Back-of-the-envelope. We don't know any real model's cost, so state an assumption and do the math: say a 10-second 1080p clip takes one 8-GPU node about 2 minutes, or 16 GPU-minutes. Then:
- 200,000 clips × 16 GPU-minutes = 3.2M GPU-minutes per day.
- ÷ 1,440 minutes per day ≈ 2,200 GPUs busy around the clock on average, or about 280 nodes.
- Traffic peaks in the evening at maybe 2× average, so ~4,400 GPUs to serve the peak without a queue. GPUs cost on the order of dollars per hour each, so that's a very large bill.
The output is small by comparison: a 10-second 1080p clip is roughly 5-10 MB encoded, so 200,000 clips is 1-2 TB of new video per day. Storage and CDN delivery are ordinary problems.
The core insight: demand will often exceed GPU supply, and you can't autoscale GPUs in seconds. So the queue isn't a temporary buffer, it's part of the product. Design how the queue is ordered, how long people wait, and what they're told while they wait.