Katkat

Design an Asynchronous Text-to-Video Generation Service

OpenAISoftware Engineer · Onsite

Last updated

This question tests the ability to design a high-latency, asynchronous job-processing pipeline with a focus on fault tolerance, job state management, and reliable resource handling.

System Design: Asynchronous Text-to-Video Generation Service

Design a service that accepts text prompts from users and generates short-form videos. The generation process is computationally expensive (minutes to hours per job) and must be handled asynchronously.

Functional Requirements

  1. Submit Jobs: Users submit a prompt and receive a Job ID immediately.
  2. Status Tracking: Users can poll or be notified via webhook regarding the status of their generation (Pending, Processing, Completed, Failed).
  3. Retrieve Media: Once complete, users can fetch the final video URL.
  4. Idempotency: Users should be able to retry submission without creating duplicate jobs for the same request.

Non-Functional Requirements

  1. Scalability: The system should support high bursts of user submissions.
  2. Reliability: No jobs should be lost due to worker crashes or transient infrastructure failures.
  3. Fairness: Ensure that heavy users cannot monopolize the limited GPU worker pool.

Task

  1. Propose a high-level architecture. Which messaging patterns and data stores would you use?
  2. Define the lifecycle of a job, including state transitions and how you handle "long-running" tasks that exceed typical API timeouts.
  3. Explain how you would manage worker failures. What happens if a worker dies halfway through a generation process?

Include a diagram description or API definition (request/response schemas) and explain the trade-offs of your chosen queueing strategy (e.g., SQS vs. Kafka/Pub-Sub).

Hints

Hint 1

Consider using a database to track the 'Source of Truth' for job state alongside a distributed queue for worker task distribution.

Hint 2

Address how you would handle workers that get 'stuck' or crash by implementing a heartbeat mechanism or lease management for active jobs.

Hint 3

Think about how to store large video files and generate time-limited secure access URLs for the client to retrieve the output.

Follow-up questions

  • How would you implement a priority system so that 'Premium' subscribers get their videos processed before 'Free' users?
  • If the underlying AI model is updated, how would you handle jobs that were submitted while the system was transitioning between model versions?
  • How would you design the cancellation flow if a user decides to stop a job while it is currently being processed by a GPU worker?