Cloudflare Workflows plus Durable Objects: Reliable Agent Jobs Without a Giant Backend
We need to stop building giant backends for AI agents.
For the past two years, the default architecture for any non-trivial agent workflow has been a monolithic serverless backend. You spin up a Kubernetes cluster, provision a message queue, set up a database for state, and write complex retry logic to handle the inevitable timeouts. It is expensive, it is operationally heavy, and it is fundamentally the wrong tool for edge-native agent orchestration.
At RodyTech, we refuse to ship monolithic backends for use cases that can be solved with edge primitives. The “giant backend” trap isn’t just about cost; it’s about fragility. When your agent’s state lives in a fragile external database and your orchestration relies on brittle cron jobs, you are duct-taping a solution to a problem that infrastructure should solve.
The alternative is not to abandon reliability, but to embrace durable execution primitives that exist natively on the edge. By combining Cloudflare Workflows with Durable Objects, we can build resilient, scalable agent pipelines without the operational overhead of a traditional backend. This is not a theoretical exercise; it is a practical architectural shift that lowers costs, eliminates capacity planning, and keeps your agents running even when the network drops.
The Problem: The ‘Giant Backend’ Trap
The traditional approach to agent orchestration treats the agent as a stateful application that needs a persistent home. This leads to a cascade of operational burdens. You need to manage ephemeral state across multiple services, implement fragile retry logic that often fails silently, and maintain dead-letter queues that become graveyards for failed tasks.
The cost of this approach is not just financial; it is cognitive. Developers spend more time managing infrastructure than building agent logic. You are essentially building a mini-orchestration engine from scratch, only to realize that your custom retry logic doesn’t handle partial failures correctly, or that your state synchronization is broken under load.
RodyTech’s stance is clear: if you can solve the problem with edge-native primitives, you should. The “giant backend” is a legacy pattern. It assumes that state must be centralized and that compute must be long-lived. Both assumptions are wrong for the modern agent stack. We need a model where state is durable by default, compute is ephemeral but persistent, and orchestration is declarative.
The Solution: Durable Execution Primitives
Cloudflare Workflows and Durable Objects provide the primitives we need to build reliable agents without the bloat. Workflows allows us to write long-running processes as synchronous-looking code, while Durable Objects provide the stateful compute layer at the edge.
The core primitive here is step.do(). This method is not just a function call; it is a checkpoint. When you execute a step, Workflows records the result in a SQLite-backed Durable Object. If the workflow crashes, times out, or is interrupted, it does not simply retry the last step. It replays the entire workflow from the beginning, but because the state is persisted, it skips the completed steps and resumes from the last successful checkpoint.
This deterministic replay is what separates durable execution from simple retries. Simple retries assume that the failure was transient and that re-running the same code will yield the same result. Deterministic replay assumes that the state has changed and that you need to reconstruct the context. For AI agents, this is critical. You cannot just re-run an LLM call; you need to re-evaluate the agent’s context, the user’s input, and the previous steps’ outcomes.
Under the Hood: How It Actually Works
To understand why this works, we need to look at the underlying mechanism. Every workflow instance runs on an Engine backed by a Durable Object. This Engine is responsible for managing the state transitions of the workflow. It uses SQLite for persistence, ensuring that every state change is durable and consistent.
For long-running waits, such as human-in-the-loop approvals or scheduled delays, Workflows uses scheduler.wait() combined with Durable Object alarms. This allows the workflow to sleep for hours or days without consuming compute resources. When the alarm fires, the workflow resumes exactly where it left off, with the full context of the previous steps intact.
The isolation model is equally important. Each workflow instance is an independent Engine. This means that billions of instances can run concurrently without capacity planning. There is no shared state between instances, no locking contention, and no need for sharding. This is a fundamental shift from traditional orchestration engines, which often struggle with scale due to shared database bottlenecks.
For more details on the architectural guidance and the AgentWorkflow class for human-in-the-loop patterns, see Architecting on Cloudflare.
When to Use Workflows vs. Durable Objects
It is important to distinguish between Workflows and Durable Objects. They are complementary, but they serve different purposes.
Use Workflows for sequential steps, human-in-the-loop waits, and standard retry/timeout needs. Workflows is the orchestration layer. It manages the flow of data and control between steps, ensuring that the agent progresses correctly through its lifecycle. It is ideal for multi-step pipelines that require durability and resilience.
Use Durable Objects directly for real-time state access, WebSocket connections, and complex conditional logic. Durable Objects are the stateful compute layer. They are ideal for scenarios where you need low-latency access to state, such as a real-time chat interface or a live dashboard. They are not designed for long-running orchestration, but for persistent, high-frequency state management.
The AgentWorkflow class is a pattern that combines both. It uses Workflows to manage the high-level orchestration of the agent’s lifecycle, while using Durable Objects to manage the real-time state of the agent’s interactions. This allows you to build interactive agents with durable backends, leveraging the strengths of both primitives.
For a technical breakdown of how Workflows uses step.do() for checkpointing and SQLite-backed Durable Objects for state, see Truvisory’s analysis.
Real-World Application: Scaling Agent Jobs
The theoretical benefits of this architecture are clear, but the real-world application is where it matters. Bernstein, a leading financial services firm, has shifted from local-only execution to Cloudflare cloud execution for their AI agents. They leveraged Workers for stateless execution and Workflows for multi-step orchestration, replacing local-only bottlenecks with a scalable, low-cost infrastructure.
The cost efficiency is significant. Workers bill per request, not per VM. This means you only pay for the compute you use, and you never pay for idle time. For a typical 50-task session, the compute cost is often between $0.50 and $2.00, plus pennies for storage in R2 and D1. This is a fraction of the cost of running a dedicated Kubernetes cluster or a set of long-lived VMs.
The operational benefits are equally compelling. By using Workflows, you eliminate the need for local hardware bottlenecks. Your agents can survive disconnects, scale concurrency automatically, and recover from crashes without manual intervention. This is not just a cost savings; it is a reliability improvement.
For a case study on how Cloudflare’s stack enables scalable, low-cost AI agent execution, see Bernstein’s blog post.
Conclusion: Building Resilient Agents Without the Bloat
The architectural shift from monoliths to edge-native primitives is not just a trend; it is a necessity for building reliable AI agents. By leveraging Cloudflare Workflows and Durable Objects, we can build resilient pipelines that are scalable, cost-effective, and operationally simple.
The key is to reject the “giant backend” pattern. Do not build a monolithic backend for a problem that can be solved with durable execution primitives. Use Workflows for orchestration, Durable Objects for state, and let the infrastructure handle the complexity. This is how we build the next generation of AI agents: reliably, efficiently, and at the edge.
For builders looking to implement this architecture, start by mapping your agent’s workflow to the step.do() pattern. Identify the points where durability is critical, and ensure that your state is persisted in a Durable Object. Then, use Workflows to manage the flow of control, leveraging scheduler.wait() for any long-running delays. This will give you a robust, scalable foundation for your agent jobs.
Sources and further reading
- Stop Duct-Taping AI Agents: Cloudflare Workflows and Durable Objects in Practice – RodyTech Blog
- Durable Execution for AI Agents with Cloudflare Workflows
- Chapter 7: Workflows: Durable Execution | Architecting on Cloudflare
- Build durable applications on Cloudflare Workers: you write the Workflows, we take care of the rest
- agents on cloudflare: workers, durable objects | Bernstein
Find more practical writing from the RodyTech archive.
RodyTech publishes practical writing on AI systems, infrastructure, and software that teams can actually ship. Use the archive paths below to keep reading by topic or browse the full library.
- Browse the full archive by publication date and topic
- Hands-on notes from real builds, deployments, and ops work
- Category paths for AI, infrastructure, developer tools, and security
No comments yet