Building a Short Video Generation SaaS from Scratch: Lessons from Long-Horizon AI Agent Development
Building a commercial-ready short video generation platform involves much more than creating an upload page. It requires coordinated work across product design, frontend and backend development, media processing, asynchronous task execution, authentication, billing, storage, testing, and operations. This article examines how to use specification-driven development and long-horizon AI coding agents to build such a system, with a focus on task orchestration, reliability, security, and the path from a working prototype to a production-ready SaaS platform.
In the past, building a short video generation platform with commercial potential typically required collaboration among product managers, frontend and backend engineers, algorithm developers, testers, and operations teams. Users upload assets, configure generation parameters, and submit a task. The system then handles queuing, model processing, result delivery, and resource billing. Although the product may appear to be a simple application for uploading images and generating videos, it actually involves a complete software engineering system.
In recent years, AI coding tools have evolved from code completion and page generation toward longer-running and more complex task execution. Instead of generating only a function or a single page, these tools increasingly attempt to understand an entire requirement, break the system into modules, create project structures, write frontend and backend code, design databases, and correct errors through testing.
For a project such as a short video generation SaaS, the most important question is not whether the interface looks attractive. It is whether an AI agent can maintain context over an extended period and consistently complete engineering tasks across multiple modules.
1. Why Use a Short Video Generation SaaS as a Validation Scenario?
A short video generation platform is a representative test case for engineering capability because it combines content uploading, asynchronous computing, user management, task tracking, result storage, and commercial billing.
From the user’s perspective, the typical workflow is:
- Register and complete authentication;
- Upload product images, copy, or reference assets;
- Select parameters such as video style, duration, aspect ratio, and voice-over;
- Submit a video generation task;
- Receive a task ID and view processing progress;
- Preview or download the result after processing is complete;
- Deduct credits or quota based on the resources consumed by the task.
The difficult part is not generating a page. It is making all of these modules work together. Video processing may take tens of seconds or several minutes, so the user’s request cannot remain open until processing finishes. Tasks may fail and require retries. Users may click the submit button repeatedly, which could result in duplicate charges. Generated files must also be stored, eventually cleaned up, and protected by access controls.
For these reasons, this type of project is well suited to evaluating long-horizon AI agents.
2. Use Specification-Driven Development Instead of Directly Requesting Code
For a complex project, one of the least reliable approaches is to enter a single instruction such as, “Build me a short video generation website.” Such a request has no clear boundaries. An AI agent will often prioritize visible pages while overlooking data consistency, error handling, and security controls.
A more reliable approach is specification-driven development: first define what the system should do, then determine how it should work, and only then begin implementation. The overall process can be divided into three stages.
2.1 Requirements Research and Scope Definition
The first step is to define user roles, core workflows, and out-of-scope features.
For example, the initial platform could focus on:
- User registration, login, and logout;
- User profile and account balance display;
- Asset uploading;
- Video generation task creation;
- Task lists and status queries;
- Generated result previews;
- Basic administrative task viewing.
It should also explicitly exclude features such as complex team collaboration, multi-level affiliate programs, highly granular advertising operations, and large-scale content moderation. The clearer the boundaries, the more stable the generated system will be.
2.2 Architecture Design
During the architecture phase, the AI agent should be asked to produce module boundaries, data models, API contracts, and exception flows rather than immediately writing pages.
A typical system can be divided into the following components:
- Web frontend: Handles forms, task lists, progress displays, and result previews;
- API service: Handles authentication, business logic, and data access;
- Task scheduling module: Creates, queues, executes, and retries tasks;
- Media processing module: Calls video generation capabilities and organizes outputs;
- Database: Stores users, tasks, credits, assets, and result information;
- Object storage: Stores large files such as images and videos;
- Message queue: Decouples user requests from time-consuming tasks;
- Logging and monitoring: Records task execution, error causes, and system metrics.
The key principle is that a user request should only create a task. It should not synchronously wait for video generation to finish.
2.3 Phased Implementation
During development, it is generally more effective to implement the main workflow first and add reliability features afterward.
The first phase should establish the minimum end-to-end loop:
User login → asset upload → task creation → background execution → result delivery
The second phase can add:
- Task failure handling and retries;
- Credit deduction;
- File access control;
- Parameter validation;
- Empty states and error messages;
- Administrative queries;
- Logging and monitoring.
This approach avoids handling too many details at once and makes it easier to verify whether the primary workflow actually works.
3. The Asynchronous Task System Is the Core of the Platform
Short video generation is usually a long-running operation and must use an asynchronous architecture.
3.1 Task State Design
Tasks should have an explicit state machine, for example:
created: The task has been created and is waiting to enter the queue;queued: The task has entered the queue;processing: The task is being generated;succeeded: Generation completed successfully;failed: Generation failed;cancelled: The user cancelled the task or the system terminated it.
State transitions must be constrained. A completed task, for example, should not be allowed to arbitrarily return to the processing state. Each state change should also record the timestamp, error details, and execution node so that problems can be traced later.
3.2 Why the Frontend Should Not Wait on a Long-Lived Connection
If the server keeps a request open while waiting for video generation to complete, several problems may occur:
- Requests can time out;
- Server connections remain occupied for long periods;
- Resources can be quickly exhausted as concurrency increases;
- Failures become difficult to recover from;
- Users may lose visibility into progress after refreshing the page.
A more appropriate workflow is:
- The frontend submits a task;
- The API immediately returns a task ID;
- A background worker retrieves the task from the queue;
- The worker performs media generation;
- The system continuously updates the task status;
- The frontend receives the latest status through polling or real-time updates.
For small and medium-sized systems, polling is simple and reliable. The frontend can query the task status every few seconds and stop polling when the task succeeds or fails. Systems with larger workloads can adopt push-based updates to reduce unnecessary requests.
3.3 Idempotency and Duplicate Submissions
Users may click the submit button repeatedly because of network delays. They may also retry a request after the task was successfully created but the response was lost. The task creation API should therefore support idempotency.
A common approach is for the client to generate a request identifier. The server stores the relationship between that identifier and the created task. If the same identifier is submitted again, the server returns the original task instead of creating another one.
Credit deduction must also remain consistent with task creation. One possible approach is a reserve, execute, and settle model:
- Reserve the estimated cost when the task is created;
- Complete the charge after the task succeeds;
- Return or release the reserved balance if the task fails;
- Ensure that retries do not cause duplicate charges.
4. Authentication, Credits, and Data Permissions Cannot Be Ignored
A SaaS platform intended for public use must address at least three categories of security and accounting concerns.
4.1 Identity Authentication
The system can use verification-code login or username-and-password login. After a successful login, it issues an access token, which is then used to identify the user in subsequent requests.
Tokens should have a reasonable expiration period and support invalidation. High-risk operations, such as changing account information, exporting large numbers of videos, or modifying billing configurations, should also require additional verification.
4.2 Resource Access Control
Uploaded images and generated videos should not be protected only by obscuring their file URLs. The server must verify that the current user owns or is authorized to access the resource.
For example, when returning task details, the server should not look up the task only by its ID. It must also verify that the task belongs to the requesting user. Otherwise, an attacker who guesses another task ID could potentially retrieve someone else’s video.
4.3 Credit Ledger Design
A credit system should not store only a mutable balance. If a dispute occurs, a single balance is difficult to audit. A more reliable design uses a credit ledger containing entries such as:
- Top-up or promotional credit records;
- Task reservation records;
- Successful charge records;
- Refund records for failed tasks;
- Administrative adjustment records.
The balance can be calculated from the ledger, or a summary field can be maintained for faster queries. In either case, every change must leave an auditable record.
5. Media Files Require Independent Design
Videos and images differ from ordinary business data because they are large, slow to process, and expensive to store.
The upload process should consider:
- File type and size limits;
- File content validation;
- Resumable uploads after interruptions;
- Virus and security checks after upload completion;
- Separate storage for original and processed files.
After generation, the system should store video metadata such as duration, resolution, file size, codec, and generation time. Files that have not been accessed for a long period can be moved to lower-cost storage or automatically removed through lifecycle policies.
Storing large files directly on application servers causes disks to grow rapidly and makes service scaling more difficult. Production environments should generally use object storage, while the application stores only file identifiers and access references.
6. What AI Coding Tools Must Actually Solve
For projects of this type, the value of an AI coding tool is not merely that it generates code faster. More importantly, it must be able to perform continuous work across files and modules.
A capable long-horizon development process should provide the following capabilities.
6.1 Maintaining Global Context
The APIs called by the frontend, the data structures returned by the backend, database fields, and task states must remain consistent. If an agent focuses only on the current file, it can easily produce inconsistent field names, conflicting API paths, and duplicated type definitions.
6.2 Automatically Finding and Fixing Errors
Errors during the first run are normal. The important question is whether the system can read logs, identify the cause, modify the code, and verify the result again.
An ideal workflow should include:
- Installing dependencies;
- Starting the development environment;
- Running API tests;
- Checking database connectivity;
- Checking page interactions;
- Correcting errors based on logs;
- Repeating the process until the main workflow passes.
6.3 Following Established Conventions
Before coding begins, the project should define its directory structure, naming rules, error-handling approach, API format, and commit standards. The more specific the conventions, the easier the generated code is to maintain.
7. Common Problems During a Three-Hour Development Session
Long-running automated development does not eliminate the need for human involvement. Common issues include:
- Incompatible dependency versions;
- Missing environment variables;
- Database migrations that were not executed;
- Inconsistent field definitions between the frontend and backend;
- Incomplete asynchronous task state updates;
- Failed tasks that do not correctly return credits;
- Pages that implement only the success state while ignoring loading and error states;
- Exposed file URLs without permission checks.
Developers should therefore treat an AI agent as an engineering assistant capable of working continuously, not as an unsupervised automated factory. Human review remains necessary at critical checkpoints, especially for authentication, billing, file access, and task retry logic.
8. Moving from a Runnable Prototype to a Commercial System
A project completed in three hours can usually reach the prototype stage, where the main workflow is functional. It is still significantly different from a production-ready commercial system.
The next stage should focus on:
- Observability: Add structured logs and monitor task duration, failure rates, and queue length;
- Elastic scaling: Dynamically increase the number of workers as task volume grows;
- Rate limiting: Limit the frequency of submissions by each user to prevent resource abuse;
- Cost control: Track per-task compute costs, storage costs, and the cost of failed retries;
- Content safety: Review uploaded assets and generated results;
- Data backups: Establish database backup and file recovery procedures;
- Role-based permissions: Distinguish regular users, operations staff, and system administrators;
- Gradual releases: Expose new versions to a small group of users before expanding availability.
These capabilities determine whether a platform can operate reliably over time, rather than merely whether it can be demonstrated locally.
Conclusion
Long-horizon AI agents are changing how software development is organized. In the past, developers had to manually connect requirements analysis, architecture design, coding, debugging, and testing. Today, when provided with clear specifications, AI coding tools can continuously complete a significant portion of this work.
This does not mean software engineering has become simple. On the contrary, the more complex the system, the more important clear boundaries, sound architecture, and rigorous validation become.
The short video generation SaaS case demonstrates that the most valuable capability is not generating a page in a few minutes. It is building a runnable, maintainable, and extensible system around asynchronous tasks, data consistency, permission security, and cost control.
For developers, the most important skills will gradually shift from writing code alone toward defining problems, designing systems, establishing constraints, and reviewing results. AI agents can improve execution efficiency, but engineers remain responsible for ensuring that the final system is reliable.
