Agentic Coding for Long-Horizon Tasks: Building a Video Generation SaaS in Hours
An experiment in agentic coding explores whether AI can build a production-oriented short-video generation SaaS from scratch. The article examines the system architecture challenges involved, explains how specification-driven development helps control long-running AI tasks, and summarizes practical lessons around context management, asynchronous workflows, billing consistency, and infrastructure planning.
1. A Bold Experiment
The capability boundaries of AI coding tools have been advancing rapidly. Early assistants could autocomplete individual lines or generate simple functions. Later, they became capable of producing complete front-end pages in a single pass.
The latest generation of models is shifting the focus from whether a page looks good to three more demanding areas: agentic capabilities, long-horizon tasks, and systems engineering.
This shift means that a model is no longer expected to merely “write code.” It must work more like an experienced architect: independently decompose system-level requirements, maintain context over hours of automated execution, and avoid drifting away from or forgetting earlier decisions.
To test whether these capabilities are reliable in practice, I designed a stress-test experiment: build a short-form video commerce content platform from scratch. Users would upload product images, the system would call a video-generation service, and the resulting videos would be ready for use in marketing campaigns.
2. Why This Is a Systems Architecture Problem, Not Just a Coding Problem
Many people assume that building a website simply means creating a few pages. But when the goal is a commercially viable SaaS platform, the complexity increases dramatically. This experiment involved at least five major areas of engineering:
1. Backend Service Design
Using an asynchronous Python web framework as an example, the system needs clearly separated REST API layers. The routing layer, business logic layer, and data access layer must remain decoupled. Dependency injection must be organized properly, and configuration must be isolated by environment.
2. Database Modeling and Security
How should the relational database schema be designed? What foreign-key relationships should connect users, generation tasks, and credit transaction records?
Beyond the schema itself, row-level security (RLS) must be configured so that users can read and modify only their own data, preventing unauthorized access across accounts.
3. Asynchronous Task Scheduling
Video generation often takes several minutes, so users cannot be expected to wait inside an HTTP request.
The system therefore needs an asynchronous workflow backed by a message queue:
- The API receives a request and immediately returns a task ID.
- A background worker consumes the queued task.
- The worker calls the video-generation service.
- The task status is written back to the database.
- The front end retrieves progress through polling or a persistent connection.
Production systems must also answer several additional questions: How should failed tasks be retried? What happens when a task times out? How is idempotency guaranteed?
4. Authentication and Account Management
A complete phone-based verification login flow includes code generation, storage, rate limiting, and validation. Token issuance and refresh, as well as authentication middleware for protected endpoints, also introduce security considerations at every stage.
5. Billing and Credit Management
How many credits should each generation consume? What happens if a charge fails? How can concurrent requests avoid deducting more credits than the user owns?
These transaction-consistency problems are often what separate a toy demo from a commercially usable system.
In other words, the experiment was not primarily testing code generation. It was testing requirements analysis, architectural trade-offs, and engineering discipline.
3. Methodology: Constraining AI with Specification-Driven Development
To keep the AI’s output under control, I did not simply ask it to “build a video-generation website.” Instead, I used a specification-driven development (SDD) approach and required it to proceed through three stages: research, architecture, and implementation.
Stage 1: Requirements Research and Specification
The AI was first asked to produce a complete product requirements document covering:
- User roles
- Core workflows
- Functional requirements
- Non-functional requirements, such as concurrency targets and availability goals
It was required to wait for confirmation before moving to the next stage.
The value of this step is that it turns a vague intention into an evaluable specification. It also prevents the AI from making uncontrolled design decisions.
Stage 2: System Architecture Design
The next step required the AI to produce:
- A technology selection document
- A database entity-relationship design
- API contract definitions
- A task lifecycle state machine
For example, a video-generation task should have explicit states such as:
Pending → Processing → Succeeded → Failed → Refunded
Every state transition should be traceable and governed by clear rules.
Stage 3: Incremental Development and Self-Validation
The code was generated one module at a time. After completing each module, the AI was required to provide a brief description of how that module could be tested.
This approach divided the context into manageable units and significantly reduced the chance that the AI would forget earlier agreements while working on a long-running task.
In practice, the degree of engineering in the prompt directly affected the outcome. Vague instructions produced demo-level code, while structured specifications and constraints were much more likely to produce production-oriented implementations.
4. Key Lessons and Pitfalls from Implementation
The project ran intermittently for several hours. Several practical lessons stood out.
Context Management Matters More Than Expected
Even when a model supports a very large context window, its implementation can still drift away from decisions made earlier in the process.
A useful solution is to reintroduce a summary of confirmed architectural decisions at the beginning of each stage. This effectively creates a “memory checkpoint” for the AI.
Asynchronous Workflows Are Especially Error-Prone
The asynchronous pipeline was the area most likely to produce bugs. Problems included failed task-status updates, lost callbacks, and front-end polling that was too frequent and overwhelmed the API.
It is better to define the following rules during the design phase:
- Task states should move only in one direction.
- All write operations should be idempotent.
- Polling should use exponential backoff.
Plan Compute Capacity and Quotas in Advance
AI coding tools are generally under heavy demand, and response times can increase significantly during peak periods. Some service plans may also reach capacity.
For team use, it is important to estimate expected consumption and reserve sufficient capacity in advance. Another option is to deploy model capabilities on stable cloud infrastructure and combine them with general-purpose cloud services such as object storage, message queues, container platforms, logging, monitoring, and alerting to build a complete production environment.
5. Conclusion: Has AI Coding Entered Its Next Phase?
My assessment is that agentic coding can already independently deliver a substantial portion of the work for systems with clear specifications and mature architectural patterns.
A project that might previously have required a team of several developers working for weeks can now produce a usable foundation in a few hours when an architecturally capable developer works together with AI.
However, this conclusion depends on several important conditions: you must be able to write a specification, understand the architecture, and investigate bugs.
AI amplifies an engineer’s judgment; it does not replace it.
The most competitive developers in the future may not be the ones who type the fastest. They may be the ones who are best at giving AI precise specifications.
