Design an Asynchronous Text-to-Video Generation Service
OpenAISoftware Engineer · OnsiteLast 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
- Submit Jobs: Users submit a prompt and receive a Job ID immediately.
- Status Tracking: Users can poll or be notified via webhook regarding the status of their generation (Pending, Processing, Completed, Failed).
- Retrieve Media: Once complete, users can fetch the final video URL.
- Idempotency: Users should be able to retry submission without creating duplicate jobs for the same request.
Non-Functional Requirements
- Scalability: The system should support high bursts of user submissions.
- Reliability: No jobs should be lost due to worker crashes or transient infrastructure failures.
- Fairness: Ensure that heavy users cannot monopolize the limited GPU worker pool.
Task
- Propose a high-level architecture. Which messaging patterns and data stores would you use?
- Define the lifecycle of a job, including state transitions and how you handle "long-running" tasks that exceed typical API timeouts.
- 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?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.