Long-Horizon AI Coding in Practice: Building a Video-Commerce SaaS from Scratch
This article reports on a hands-on experiment in which a single person used an AI coding assistant with long-horizon, agentic capabilities to build a commercial short-video product-sales SaaS platform from the ground up. It explains why the product topic was chosen, why a commercial platform is a categorically harder problem than a demo page, and how Spec-Driven Development (research → architecture → module-by-module implementation) kept multi-hour automated runs from drifting. Illustrative code covers data modeling with row-level ownership checks, an asynchronous task queue with status polling, and atomic credit deduction. It closes with the practical pitfalls of long-running agentic workflows and three takeaways for how AI coding should be evaluated.
1. Introduction: AI Coding Is Moving from “Writing Code” to “Building Systems”
For a long time, the benchmark for an AI coding tool was narrow and local: do the generated pages look good, can it autocomplete a single function. But real software engineering is never an isolated snippet. It is a system composed of requirement decomposition, architecture design, module coordination, error handling, and long-term maintenance.
I recently ran an extreme experiment: using only one coding assistant with long-horizon task and agentic capabilities, I built a commercial short-video product-sales (video commerce) generation SaaS platform from scratch. This is fundamentally different from “generate a demo page.” The system had to keep context coherent, the architecture consistent, and the modules self-consistent across multi-hour, multi-round automated tasks — which is precisely what systems engineering capability means.
What struck me most was a signal in the product’s own official documentation: the emphasis falls on agents, long-horizon tasks, and systems engineering, rather than on whether the output looks well laid out. That framing is itself worth noticing. The industry’s coordinate system for evaluating AI coding is shifting from “code generation” to “system delivery.”
After running the whole flow, one conclusion became clear: AI coding is genuinely moving up a level — from completing code toward owning end-to-end, system-level delivery.
2. Choosing the Topic: Why Video-Commerce Generation, and “Give Them the Fish”
The topic was not picked arbitrarily. The short-video product-sales wave is obvious, and content generation and distribution opportunities on the platform side are abundant.
I used to enjoy sharing various automation workflows and teaching people how to assemble a product-sales video step by step. But I recently noticed something counterintuitive: merchants who actually run a business do not want to learn complex workflows.
They care about one thing — return on input. Does a video cost cents or dollars to produce? Can they reliably run a thousand videos a day? Is there a ready-made platform where one click generates everything?
So I reached a conclusion: in the AI era, instead of teaching people to fish, it is better to hand them the fish. Instead of delivering a tool that requires learning, deliver a product that works out of the box and charges by usage.
That judgment directly determined every architectural trade-off that followed. The first principle of the system is not “flashy features” but “low barrier to entry, high throughput, controllable cost.”
3. Why a Commercial SaaS Is Not a “Write Some Code” Problem
Once the goal shifts from “demo” to “commercial platform,” complexity rises exponentially, because you must answer a chain of interdependent engineering questions at the same time:
- Frontend architecture: With a modern frontend framework, how should a file-based routing application structure be organized? How do components, data fetching, and state management get layered?
- Backend services: How do you build a high-concurrency API in an async-friendly backend language? How are interface contracts designed?
- Data modeling: How is the relational schema designed? How is per-user data isolation implemented?
- Task scheduling: Video generation often takes several minutes, so synchronous waiting will inevitably time out. How do you design an asynchronous queue and a task state machine?
- Authentication and billing: How do SMS-code login, token authentication, and credit deduction work together? Under concurrency, how do you prevent over-deduction?
The difficulty is not whether each block can be written in isolation, but whether they hold together coherently once combined. That is a problem a senior architect reasons about systematically, not a “coding” problem. I used to think this was out of reach without a team of roughly five people. This time, I used one AI coding assistant and one person.
4. Methodology: Spec-Driven Development (SDD)
The reason long-running tasks did not go off the rails is Spec-Driven Development. The core idea is not to let the model “start writing code immediately,” but to force it through a research → architecture → development sequence, producing a reviewable specification document at each step as an anchor for the steps that follow.
Concretely, this has three layers:
- Research and requirement clarification: Turn vague requirements into explicit items — which source assets are supported, what the per-user concurrency limit is, what the retry strategy on failure is — to avoid guessing while coding.
- Architecture and contract definition: Fix the technology choices, directory structure, database schema, API contracts, and the task state machine. This layer is the “constitution” for all code; every subsequent module must comply with it.
- Module-by-module development: Implement in the order data layer → service layer → API layer → frontend, writing the specification back after each block so context does not drift during a long task.
The value of the specification documents is this: when an automated run spans several hours and dozens of interaction rounds, they become the anchor that prevents “architecture amnesia” and “style drift.”
5. Key Implementation Breakdown (Illustrative Code)
The following generic pseudocode covers the parts that carry the most systems-engineering weight.
Data modeling: Separate the user table from the task table, with the task table recording state machine transitions. Row-level access control — isolation based on user identity — is the foundation of SaaS multi-tenant safety.
CREATE TABLE users (id BIGINT PRIMARY KEY,phone VARCHAR(20) UNIQUE,credits INTEGER NOT NULL DEFAULT 0, -- credit balancecreated_at TIMESTAMP DEFAULT now());CREATE TABLE video_tasks (id BIGINT PRIMARY KEY,user_id BIGINT REFERENCES users(id),source_image VARCHAR(500), -- asset URL in object storagestatus VARCHAR(20), -- pending / running / succeeded / failedoutput_url VARCHAR(500),created_at TIMESTAMP DEFAULT now());
Asynchronous tasks: The endpoint returns a task ID immediately, and the actual generation is handed to a background queue, with the frontend polling for progress. This is the standard way to handle work that takes several minutes.
# Submit: respond immediately, push the heavy work to the queueasync def create_video_task(user_id, image_url):task = await db.insert(video_tasks, {"user_id": user_id, "source_image": image_url, "status": "pending"})await queue.publish("video.generate", {"task_id": task.id})return {"task_id": task.id, "status": "pending"}# Background consumer: pull task -> call generation -> write back resultasync def consume():async for msg in queue.subscribe("video.generate"):task = await db.get(video_tasks, msg["task_id"])await db.update(task, status="running")result = await generate_video(task.source_image)await storage.save(result, task.output_url) # write output to object storageawait db.update(task, status="succeeded")# Polling: includes an ownership check to prevent reading another user's taskasync def poll_status(user_id, task_id):task = await db.get_owned(video_tasks, task_id, owner=user_id)return {"status": task.status, "output_url": task.output_url}
Billing and deduction: Credit deduction must be an atomic operation at the database layer to avoid over-deduction under concurrency. Sketch:
-- Conditional update plus affected-row check: the task only counts as successful if the charge succeededUPDATE users SET credits = credits - :costWHERE id = :user_id AND credits >= :cost;
At the deployment level, this kind of system is usually realized with general-purpose capabilities from cloud providers — for example, a container platform hosting the backend and consumer services, object storage holding images and video outputs, a message queue handling task distribution, and logging plus monitoring and alerting services for observability. Cloud platforms such as Baidu AI Cloud offer such general-purpose product categories; availability varies by provider and region, and the specific choice should depend on your team and business scale.
6. Pitfalls and Lessons from the Real Run
Long-horizon automation is not always smooth. The following problems appeared almost inevitably:
- Context drift: As the number of rounds grows, the model may deviate from the original architecture. The countermeasure is to re-anchor with the specification documents and align on contracts before starting each module.
- Idempotency and retries for async tasks: Consumers may process a message twice or fail midway. The countermeasure is an idempotency key per task, plus a bounded number of retries and a dead-letter fallback for failures.
- Consistency between schema changes and access control: Table definitions and row-level security policies drift apart easily. The countermeasure is to review the schema and the access policy together, as a single specification.
- Concurrent billing: Under high concurrency, read-then-write patterns easily over-deduct. The countermeasure is to insist on atomic deduction at the database layer.
- Polling frequency and cost: Polling too aggressively adds load. The countermeasure is a backoff strategy, or switching to server-side push.
7. Conclusions and Implications
The biggest gain from this experiment was not “a platform built in three hours.” It was validating a new development paradigm: when an AI coding tool has long-horizon and agentic capabilities, and when a specification-driven process constrains it, one person has a real chance to deliver a system-level product that used to require a small team.
Three implications follow.
First, the yardstick for AI coding should shift from code quality to system delivery capability.
Second, the core value of the human moves up to defining the problem, writing the specification, and reviewing the architecture.
Third, engineering fundamentals — asynchronous processing, concurrency, security, observability — have not become obsolete. They matter more in the AI era, because these are the constraints that decide whether long-horizon automation can ultimately land as a commercially usable product.
