Building an Async Prompt-to-Clip Rendering Service on a GPU Fleet
System DesignModel answerLast updated
Design a durable, fair, and safe asynchronous service that turns text prompts into 10-second clips using slow, expensive GPU inference at roughly ten thousand requests per hour.
Design a Prompt-to-Clip Rendering Platform
You are building a service where users type a text prompt and get back a 10-second video. A pretrained model is available as an opaque function, generate_video(prompt). Each call occupies one top-tier GPU (H100 class) for about 2 to 5 minutes.
What the product must do
- Accept a prompt through an API and immediately return a job identifier.
- Let users check progress by polling, or be notified through a webhook when the clip is ready.
- Keep a browsable history of each user's past clips.
Quality targets
- Load: about 10,000 submissions per hour.
- Durability: a job must never vanish because a machine died or a transient error occurred.
- Safety: harmful prompts must be rejected, and generated output must be screened before anyone can see it.
- Responsiveness: although rendering is slow, acceptance of a job and the current queue position must be shown right away.
Facts you can rely on
- A finished clip averages about 50 MB.
- Model weights are several gigabytes, so loading and caching on GPU machines needs thought.
- The model is a black box; you cannot assume you can inspect or checkpoint its internals unless you say so explicitly.
Cover in your answer
- Overall architecture: gateway, orchestration, and how the services talk to each other.
- Queueing and scheduling: managing long-running work and sharing a limited GPU fleet fairly.
- Data handling: storing large files, CDN delivery, and metadata.
- Failure handling: what happens when a worker dies mid-render.
Include back-of-envelope sizing for GPUs and storage, and call out trade-offs and follow-up considerations such as autoscaling and cost.
Hints
Hint 1
Apply Little's Law (concurrency = arrival rate x time in system) to find how many GPUs are busy at once, then add headroom for peaks and utilization targets.
Hint 2
Treat each job as a state machine with leases and heartbeats; make every state change a conditional update so a stale worker cannot overwrite a newer result.
Hint 3
Use a private staging bucket for raw output, run moderation there, and only promote approved clips to the CDN-backed serving bucket.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Sizing first
Compute (Little's Law).
- 10,000 jobs/hour is about 2.8 jobs/s.
- At roughly 3.5 minutes (210 s) per job, concurrency is 2.8 x 210, so about 585 GPUs are busy at any moment.
- Target 75-80% utilization and 1.5-2x peak headroom: roughly 750 GPUs baseline and about 1,200 at peak.
- This assumes one GPU per clip. If a clip needs an 8-GPU node, the unit becomes nodes.
- GPU cost dominates everything; this is a scheduling and cost problem wearing a web-service costume.
Storage. 10,000 x 50 MB is 500 GB/hour, about 12 TB/day, about 4.4 PB/year. Lifecycle tiering and retention policy are required.
2. API
POST /v1/videoswith prompt, resolution, optional seed, optional webhook URL, and an idempotency key. Returns202withjob_id,queued,queue_position, and an ETA.GET /v1/videos/{id}returns status, progress, position, and a signed URL when done.GET /v1/videos?cursor=returns paginated history.DELETE /v1/videos/{id}cancels.
Use the asynchronous pattern: a multi-minute synchronous request would hit load-balancer timeouts and lose work on any network blip. The API only authenticates, rate-limits, runs a fast prompt check (tens of ms), persists the job, enqueues it, and returns. Idempotency keys keep client retries from creating duplicates or double-billing.
3. Data model and state machine
A jobs table (Postgres, or DynamoDB at larger scale) holds: id, user, tier, prompt, parameter hash, status, attempt count, lease owner, lease expiry, output keys, moderation verdicts, and timestamps. Index by (user, created_at) for history.
States: QUEUED -> RUNNING -> MODERATING -> SUCCEEDED | BLOCKED | FAILED | CANCELLED.
Every transition is a compare-and-set on status and lease owner, so two workers cannot both finalize one job.
4. Architecture
Client -> gateway (auth, rate limits) -> job service -> jobs DB, then a transactional outbox into a durable queue -> scheduler/dispatcher -> GPU worker pool -> private staging bucket -> output moderation -> serving bucket + CDN, with a notifier for webhooks.
- Queue choice: SQS, RabbitMQ, or a Postgres table using
FOR UPDATE SKIP LOCKED. You need per-message acks and visibility timeouts. Kafka fits poorly because offset-based, partition-ordered consumption makes per-job acks, priorities, and very long processing awkward. - Transactional outbox: the DB insert and the enqueue are atomic, so an accepted job cannot be lost.
- Queue position: a Redis sorted set per tier scored by enqueue time;
ZRANKgives position in O(log n). ETA is roughly position x average job time / active workers, adjusted for tier weights. - Notifier: consumes completion events, sends HMAC-signed webhooks, retries with exponential backoff for about a day, then dead-letters.
5. Scheduling and autoscaling
Fairness.
- Token-bucket rate limits per user at the gateway.
- Per-user concurrency caps (e.g. 2 running for free users, 10 for paid).
- Weighted fair queuing across tiers so paid traffic gets priority without starving free users entirely (aging or minimum share).
Workers. Long-lived processes load multi-GB weights once and then pull jobs; they never cold-load per request. Weights come from the node image or local NVMe filled from a regional blob cache. A new node joins the pool only after a warm-up inference passes its health check.
Autoscaling signals. CPU is meaningless. Use backlog-seconds (depth x avg time / workers), predicted wait versus SLO, and GPU utilization. Because cold start takes minutes, keep a 10-15% warm buffer, scale up fast and down slowly with draining, and pre-scale on time-of-day forecasts.
Capacity mix. Reserved GPUs cover baseline; spot capacity handles bursts, which is safe because interrupted jobs are retryable.
6. Failure handling
- Leases and heartbeats: a worker claims a job with a 60 s lease and renews every ~20 s. A reaper re-queues expired
RUNNINGjobs and incrementsattempt. - Idempotent finalization: output keys are
videos/{job_id}/{attempt}.mp4; finalization succeeds only if the lease owner still matches. A zombie worker returning late cannot overwrite a newer result. - Checkpointing: with a true black box, restart from scratch; losing up to 5 GPU-minutes is acceptable at low failure rates. If the sampling loop can be wrapped, checkpoint latents every N denoising steps, which matters most on spot instances.
- Poison jobs: after 3 attempts mark
FAILED, route to a dead-letter queue, and do not charge. Retry transient errors (OOM, node loss); fail fast on deterministic ones (bad parameters). - Node health: watch ECC/XID errors and evict bad GPUs so one faulty card does not fail hundreds of jobs.
7. Data pipeline and safety
- Workers upload via multipart to a private staging bucket.
- Output moderation samples frames (e.g. 1 fps) and runs image/video classifiers, plus audio checks if applicable. Only approved clips are promoted to the serving bucket.
- Serve through a CDN using short-lived signed URLs; keep metadata in the DB, never in object tags alone.
- Tier storage: hot for recent clips, infrequent-access after weeks, archive or delete per retention policy and user deletion requests.
- Prompt moderation runs synchronously and cheaply at submit; output moderation is the authoritative gate before delivery.
8. Trade-offs and common mistakes
- Mistake: synchronous generation, or letting the queue hold the only copy of job state. Keep the DB as source of truth.
- Mistake: autoscaling on CPU, or scaling down aggressively and paying minutes of cold start.
- Mistake: forgetting idempotency and fencing, which leads to duplicate or overwritten results.
- Trade-off: more warm headroom lowers wait time but raises GPU cost; spot saves money but needs retry or checkpointing.
- Trade-off: caching by prompt plus parameters plus seed only helps if output is deterministic; otherwise users expect fresh results.
- Observability: track queue wait, render time, retry rate, block rate, GPU utilization, and cost per clip, and alert on backlog-seconds breaching the SLO.