KatInterview

Design a GPU-Backed Video Generation Service with Fair Scheduling

System DesignModel answer
MediumModel answerSystem Designsystem-designqueuesdistributed-systems

Last updated

Design the backend for a text-to-video service where each job occupies exactly one GPU, covering task lifecycle, fair multi-user queueing, and cancellation at every stage.

Background

Your team is building the backend for a text-to-video product. A user submits a text prompt along with generation parameters (resolution, clip length, style), the system converts it into a long-running job that executes on a single GPU, and when the job finishes the user retrieves the resulting video.

One constraint simplifies scheduling considerably: a job always runs on exactly one GPU from start to finish. You never need to coordinate multiple GPUs for a single job.

GPU capacity is finite and shared. At peak times, more jobs are submitted than there are available GPUs, so jobs wait. Many users with different usage patterns compete for the same fleet.


What to Design

Part 1 — End-to-End Architecture and Job Lifecycle

Describe the full system: the client-facing API, the complete set of states a job can be in, how the queue hands jobs to GPU workers, and where everything is stored.

Your answer should address:

  • A state machine covering all job states from submission through completion (or failure/cancellation), including which states a cancellation can legally interrupt.
  • How the dispatch layer moves jobs from the queue to workers, and how a worker crash mid-job is detected and recovered from.
  • Why task metadata and video output should live in separate stores, and how a finished video is delivered to the user.

Part 2 — Fair Sharing Across Users

Some users submit many more jobs than others. Jobs vary widely in how long they actually run on a GPU. Propose at least two distinct approaches to sharing the GPU fleet fairly across users, compare them honestly, and pick one.

Your answer should address:

  • At least two fairness strategies with a concrete weakness for each.
  • How each strategy handles jobs of variable cost, bursty submission patterns, and users who return after a long idle period.
  • Where the scheduling policy lives and what happens to its state when the scheduler process restarts.

Two useful clarifying questions to consider: when only one user has pending jobs, should that user be allowed to use the whole fleet? Should a user who has been idle for a while receive a priority boost when they return?

Part 3 — Cancellation

A user can cancel a job while it is waiting in the queue, while it is in the middle of being dispatched to a GPU, or while it is actively running. Design how cancellation works in each case.

One specific proposal to evaluate: because each job holds at most one GPU and cancellations are rare compared with submissions, the cancel API could simply make a direct RPC or HTTP call to whichever worker is running the job. Assess when this is sufficient and where it breaks down.

Your answer should address:

  • Correct cancellation behavior for each job state, including the race between a cancel request and a job that just finished.
  • The direct-RPC approach weighed against at least one alternative, using the one-GPU-per-task constraint and low cancel volume to drive the comparison.
  • Delivery guarantees: idempotent cancel handling, what happens when a worker is unreachable, and exactly when the GPU is returned to the available pool.

Constraints and Assumptions

  • One job uses exactly one GPU for its entire duration.
  • Demand routinely exceeds GPU capacity; queueing is expected, not exceptional.
  • Cancellations are infrequent relative to submissions.
  • No specific fleet size, latency target, or throughput number is given — state the assumptions your design depends on.

Hints

Hint 1

Start with the state machine before anything else. Every interesting design question — dispatch, cancellation, recovery — reduces to "what state is this job in and who owns it right now." Draw it out explicitly: QUEUED → DISPATCHING → RUNNING → DONE/CANCELLED/FAILED.

Hint 2

For fair queueing, think about what the unit of fairness actually is (user, org, subscription tier) and whether fairness means equal GPU-seconds consumed or equal jobs completed. Weighted fair queueing and token buckets answer different questions — be precise about which problem each one solves.

Hint 3

The direct-RPC cancellation proposal is reasonable under the given constraints but has one specific failure mode worth calling out: the worker address has to come from somewhere reliable, and if that record is stale (worker restarted, job just finished), the RPC either fails or hits the wrong target. Walk through what happens in each case and how you make cancel idempotent regardless.