Autoretto.
← All posts
Infrastructure · July 1, 2026 · 4 min read · Autoretto Daily

how we keep serverless autopilot runs durable at 3am

We run thousands of automated music channels, and we do it without keeping a single permanent server running for any of them. If we kept a dedicated virtual machine active for every creator on Autoretto, the hosting bills would be astronomical. More importantly, those servers would eventually drift. Software configurations would get messy, memory leaks would pile up, and things would crash in the middle of the night. Instead, we run our entire pipeline on serverless infrastructure. Our workers spin up on demand, do a quick job, and immediately shut down. This keeps things incredibly cheap and clean, but it introduces a massive challenge. When a serverless instance wakes up at three in the morning to build and publish a video, it starts with a completely blank memory. It has no idea who the creator is, what kind of music they make, or what happened during the last run. To solve this, we had to design a system that is completely stateless yet perfectly durable.

The secret to making this work is a process called rehydration. We do not try to keep state in memory between runs. Instead, every single execution begins with a blank slate and immediately pulls its brain from the database. When the scheduler triggers a new release run, the fresh serverless instance queries our central database for the creator's state machine. Within milliseconds, the worker downloads everything it needs to know. It learns the channel's aesthetic preferences, the historical performance of previous videos, the current release schedule, and the specific prompt templates designed by Gemini. This rehydration process transforms a generic, empty server into a specialized agent dedicated to that specific music creator. By the time the worker starts its first task, it possesses the exact same context as if it had been running continuously for months.

This rehydration only works because we treat our database as the single source of truth, writing through every change immediately. We never store progress in local variables or temporary files with the hope of saving them later. If the pipeline generates an audio track using Suno, that track metadata and asset URL are immediately committed to the database. When Gemini generates the video description, that text is written through right away. We do this because cloud providers can terminate serverless instances at any moment without warning. If an instance dies mid-run, we do not panic. We do not lose work. The next instance that spins up to retry the job will rehydrate the state and see that the audio is already done. It will simply pick up at the next step, which might be generating cinematic motion with Sora or rendering the final beat-synced MP4.

This architecture completely eliminates the difference between an automated autopilot release at midnight and a manual test run started by a developer in the afternoon. In many systems, manual actions run on a different, more reliable path than background queues. On Autoretto, they are identical. When a user clicks a button in our dashboard to generate a preview, the dashboard triggers the exact same serverless workflow that runs on the scheduler. The system wakes up cold, rehydrates the channel state, performs the work, writes the updates, and dies. Because the code path is identical, we can debug 3 AM autopilot failures during the day with absolute confidence. If a scheduled release succeeds or fails, we can replicate the exact environment by simply triggering the same state rehydration on a developer machine.

To support this constant read-and-write cycle, our database layer has to be incredibly fast and strongly consistent. We cannot use databases that rely on eventual consistency, where a write might take several seconds to appear across all nodes. If a worker completes the Sora video rendering and writes the success state, the subsequent worker that handles the final rendering gate must see that update instantly. If it does not, the system might try to render the video again, wasting precious processing time and money. We keep our active state tables highly optimized and small. We do not load massive historical logs during rehydration. We only pull the active state machine and the minimal metadata required for the current run. This keeps our startup times under a hundred milliseconds, making the serverless overhead practically imperceptible.

This design also acts as our primary defense against external API failures. When you rely on third-party APIs like Suno, Gemini, or Sora, things will fail. Connections drop, rate limits get hit, and services experience outages. If our pipeline was a single, long-running process, an API timeout at the very end of a render would ruin the entire run, forcing us to start over from scratch. With our write-through architecture, an API failure is just a temporary pause. The worker logs the failure to the database and exits. When the API comes back online and our scheduler retries the job, the new worker rehydrates, sees exactly where the failure occurred, and resumes from that specific point. We do not waste API credits regenerating assets that were already successfully created and stored. The system is resilient by default, surviving the chaotic reality of web APIs.