Skip to content

How to design a text-to-video service

The first sections are free. The deep dives, level expectations and quiz are part of Pro.

On this page
Asked at
Practice this question

The problem

A text-to-video service takes a prompt and a few settings, has a model on a GPU render the clip over several minutes, and hands the user a file to watch or download. The answer turns on one figure: a minute of video holds a GPU for about 12 minutes, and there are far fewer GPUs than people waiting. That makes this a job system rather than a request system: a durable store of jobs, a scheduler that shares GPU time across users, workers that hold a lease while they render, and admission control that keeps the queue and its wait estimate honest during a burst.

Clarifying questions

AskWhy it mattersA typical answer

How long does one job hold a GPU, and does a job ever span more than one GPU?

The GPU time per job decides everything downstream: whether the API can be synchronous, how fairness is measured, and how much a failed job costs to redo.

About 12 GPU minutes per minute of video on an H100, following the Factorial Funds estimate for Sora. Each job runs on one GPU; multi-GPU jobs are out of scope.

How many users and how many GPUs are we planning for?

If GPUs outnumber waiting users, a plain queue is fine. If not, the queue and who gets served next become the heart of the design.

Thousands of users submitting prompts and far fewer GPUs than people waiting. No fleet size is given: state an assumption and work from it.

Which settings can a user choose, and do they change the GPU cost?

Duration and resolution change how long a job holds a GPU, which is what a fair scheduler should charge for.

Duration and resolution. Assume a longer clip costs more GPU time in proportion to its length, and treat resolution as a multiplier you would measure in production.

Do users need live progress, or is a status they can poll enough?

Jobs run for minutes, so a push channel buys little; polling keeps the API stateless.

Polling with an estimated start time is enough. A push notification when the clip is ready is a nice extra, not a requirement.

Can a user cancel a job that is already running, and should the GPU come back right away?

Canceling a running job needs a path from the API to the worker; canceling a queued job is a row update.

Yes, queued or running, and the GPU should go back to the pool promptly rather than finishing a clip nobody wants.

Are there paid tiers that should wait less?

Tiers turn fairness from equal shares into weighted shares, and may justify reserved capacity.

Assume a free and a paid tier. Model the paid tier as a higher weight in the scheduler and say what reserving GPUs for it would cost.

The requirements menu

RequirementScopeWhy

Submit a prompt with settings such as duration and resolution, and get a job id back

Core

The entry point. Returning a job id instead of the clip is what makes the whole design asynchronous.

See a job’s status and an honest estimate of the wait

Core

People wait minutes to hours; a status and a believable estimate are what make that wait tolerable, and the estimate is a computed value the design has to produce.

Cancel a job that is queued or running

Core

A canceled running job frees a GPU for someone else, so cancel is a capacity feature as much as a user feature.

Watch and download the finished clip

Core

Clips are large files; serving them belongs to object storage and a CDN, not to the API servers.

Priority for a paid tier, as a higher scheduler weight or reserved GPUs

Optional

Worth taking: it fits the fair scheduler as a weight with no new component. Reserved GPUs are a separate decision because they sit idle when paid users are quiet.

A notification (webhook, email or push) when the clip is ready

Optional

Take it if time allows, since it is a consumer of the job store’s state changes. Polling already covers the requirement when jobs run for minutes.

Prompt moderation before a job is admitted

Optional

Checking prompts before spending GPU time is worth naming as a step in admission. Name it and move on; the classifier itself is another system.

Retention: delete or archive clips after a period

Optional

Storage grows every day with large files. A lifecycle rule on object storage covers it; mention it when you size storage.

Image-to-video: a reference frame alongside the prompt

Optional

Adds an upload path and a larger input, but the job system is unchanged. Leave it unless asked.

The model and its training

Out of scope

You run the generation backend. Treat the model as a program that holds one GPU for a known time.

Editing a clip after it is made

Out of scope

Edits are new jobs with a different input, and the editing tools are a separate product.

Jobs that need several GPUs

Out of scope

Gang scheduling across GPUs is a harder problem. Say that the scheduler would need to hold several GPUs at once, and park it.

Non-functional requirements

RequirementWhat it forces

Each job runs on exactly one GPU for minutes, never split across GPUs

The scheduler matches one job to one free GPU of the right type, and a worker is busy for the whole job. No batching across requests, no sharing a GPU between jobs: throughput is the GPU count divided by the job length.

Fair share: no single user can take the whole fleet

The scheduler keeps per-user queues and picks the next job by GPU time already used, not by arrival order, with a cap on how many jobs one user runs at once.

Bursts far above GPU capacity queue up instead of failing

Jobs are accepted into a durable store and wait there; the API answers with a job id without waiting for any GPU work. Admission control bounds the queue per user so waiting stays meaningful rather than endless.

A worker that dies mid-job does not send the job back to zero

Workers write checkpoints to object storage during a job, and a retry resumes from the last one. The job store, not the worker, owns the job’s state, and the death is detected by a lapsed lease.

Estimates

QuantityWorkingResultWhat it sizes

Minutes of video one GPU makes an hour

60 minutes an hour ÷ 12 GPU minutes per minute of video = 5

About 5 minutes of finished video per GPU per hour

Fleet throughput: multiply by the GPU count to get minutes of video an hour, the denominator of each wait estimate.

GPU time by clip length

A 20-second clip: 20 ÷ 60 × 12 = 4 GPU minutes. A 1-minute clip: 12. A 2-minute clip: 24. Resolution adds a multiplier we would measure rather than guess

4, 12 and 24 GPU minutes for clips of 20 seconds, 1 minute and 2 minutes

Why fairness counts GPU time, not jobs: one 2-minute clip costs as much as six 20-second clips.

Wait behind one user’s flood under first-come first-served

Assume 100 GPUs and one user who queues 300 one-minute clips first. 300 × 12 = 3,600 GPU minutes ÷ 100 GPUs = 36 minutes. With one job per user in rotation, the next user starts when the next GPU frees, at most about 12 minutes later and usually sooner

36 minutes before anyone else starts, against at most about 12 minutes with per-user rotation

The cost of a single shared queue, and the first thing a fair scheduler buys back.

Backlog after an hour-long burst

Assume 100 GPUs: 100 × 5 = 500 minutes of video an hour. If users submit 1,500 minutes of video during one hour, 1,000 minutes are left over, which is 2 hours of the whole fleet’s work

A new job arriving at the end of the burst waits about 2 hours

Why admission control exists: without a bound, the wait estimate becomes hours and keeps growing while the burst lasts.

Work lost when a worker dies near the end

A 1-minute clip without checkpoints: up to 12 GPU minutes redone, and the user waits a further 12 minutes. With a checkpoint after each tenth of the work: at most 1.2 GPU minutes redone

12 GPU minutes lost without checkpoints, about 1.2 with ten per job

The value of checkpoints, to weigh against the time and space the writes cost.

How fast a dead worker is noticed

Assume a heartbeat every 10 seconds and a lease of 30 seconds. A dead worker is noticed within 30 seconds, which is 30 ÷ 720 ≈ 4% of a 12-minute job

About 30 seconds of idle GPU and delay per failure

The lease length: long enough to ride out a slow heartbeat, short against the job.

GPU time wasted by a canceled running job

With the same 10-second heartbeat, a worker reads the canceled state within about 10 seconds of the cancel

About 10 seconds of GPU time after the user clicks cancel

Why reading the job store on each heartbeat is prompt enough, with no need to reach the worker over the network.

Storage for finished clips

Assume a 1080p clip at about 10 Mbit a second: a 1-minute clip is 600 Mbit, about 75 MB. Assume 10,000 clips a day: 10,000 × 75 MB ≈ 750 GB a day, about 270 TB a year

Roughly 750 GB a day, 270 TB a year at the assumed volume

Object storage growth and the case for a retention rule; the API servers don't hold these bytes.

Core entities

EntityWhat it holds

Job

One row per request: the prompt, the settings, where the job is in its life, and which attempt on which worker is running it.

User

Who submits jobs: their tier, their limits, and how much GPU time they have been served.

GPU worker

One worker for each GPU in this design: what kind of GPU it has, which job it holds, and when it last reported in.

Video

The finished clip: which job produced it and where its bytes live.

The API

EndpointNotes

POST /v1/videos { prompt, duration, resolution } → { job_id }

Checks the settings against the user’s quota, writes a queued job row and returns 202 Accepted with the id, without waiting for any GPU work. Over quota or a queue already at its bound: 429 Too Many Requests with the earliest time to retry. An idempotency key header lets a client that timed out resubmit without making a second job.

GET /v1/videos/{job_id} → { status, estimated_start, url? }

In this design a status call is a read of the job row. estimated_start comes from the GPU minutes queued ahead of this job, divided by the fleet’s minutes per hour, recomputed on each read. url appears when the job is done and is a short-lived signed link to the clip. Clients poll every few seconds; with jobs running for minutes, a push channel is an extra rather than a need.

POST /v1/videos/{job_id}/cancel

Writes the wanted state as canceled and returns 202. A queued job flips to canceled at once; a running one stops when its worker next reads the job row. Calling it twice, or on a finished job, changes nothing and returns the current state, so clients can retry safely.

The high-level design

submitjobclippullClientVideo APIJob storeGPU workersObject storage

Step 1 of 4

A job, not a request

The first decision is that POST /v1/videos does not wait for the clip. A request held open for the 12 minutes a one-minute clip takes would tie up a connection, break on any proxy timeout, and be lost if the API server restarted. So the API writes a job row to a durable store and answers with the id; the client polls GET /v1/videos/{job_id}. GPU workers pull queued jobs from the store, render, and write the finished clip to object storage, recording its key on the job. The store is the one place a job’s state lives, which the later steps all rely on.

submitwatchquotasjobnextdispatchchargesheartbeatclipmissClientVideo APICDNAdmissionJob storeFair schedulerGPU workersGPU time usedObject storage
The whole design

What breaks first

The deep dives

Fair queueing. One user submits hundreds of clip jobs a moment before everyone else, and each job holds a GPU for minutes. Who runs next, and how do you keep the order when the scheduler restarts?

A concept that helps here: Fair queuing across tenantsA concept that helps here: GPU batching and schedulingA concept that helps here: Multi-tenant isolation

Failures in long jobs. A GPU worker dies near the end of a long clip, many minutes in. How does the system notice, what happens to the job, and what stops a slow worker that was given up on from overwriting the retry?

A concept that helps here: Distributed locks and leasesA concept that helps here: Heartbeats and presenceA concept that helps here: Retries and dead-letter queues

Cancellation and bursts. A user cancels a job just as a worker picks it up, while submissions are running far past the number of GPUs. How does the GPU get back to the pool, and what pushes back on the flood?

A concept that helps here: State machines in database rowsA concept that helps here: Backpressure and load sheddingA concept that helps here: Rate limiting algorithms

Concepts this guide uses

Sources

  1. Analytics India Mag: Sora takes about 12 minutes to generate 1 minute of video on an H100 (Factorial Funds’ estimate)
  2. Techovedas: How much time does OpenAI’s Sora take to generate a 1-minute video on an NVIDIA H100
  3. Martin Kleppmann: How to do distributed locking
  4. Slurm Workload Manager: Multifactor Priority Plugin
Sign in to report a mistake