Durable Execution with DBOS and CockroachDB Cockroach Labs partner solutions architect Amine El Kouhen explains how DBOS embeds durable execution directly into applications as a library, using CockroachDB to persist workflow state and recover from failures without additional infrastructure. The approach eliminates the need for separate orchestration clusters, reducing complexity and cost for long-running AI agent workflows. This article originally appeared on the personal blog of Amine El Kouhen. Amine is Senior Partner Solutions Architect for Cockroach Labs. Modern AI applications are no longer single-shot inference calls. They are long-running agents https://www.cockroachlabs.com/blog/agentic-ai-database-architecture/ that plan, act, observe, and retry across time. An AI agent loop that retrieves context from a , calls an LLM, writes results to a database, waits for human approval, and then triggers downstream actions can run for minutes, hours, or even days. https://www.cockroachlabs.com/glossary/distributed-db/vector-database/ vector store As these workflows become longer-lived and more autonomous, infrastructure reliability becomes a business concern as much as a technical one. Restarting an interrupted workflow can increase cloud costs https://www.cockroachlabs.com/blog/agentic-ai-costs-at-scale/ , delay downstream processes, and produce duplicate actions that require manual cleanup. Durable execution helps organizations keep AI agent workflows progressing safely without sacrificing operational efficiency. Without a durable orchestration layer , any transient infrastructure failure https://www.cockroachlabs.com/blog/surviving-application-database-failures/ restarts the entire loop from scratch: re-billing expensive LLM calls, duplicating side effects, and losing all accumulated context. Platforms like Temporal https://temporal.io/ solve this by deploying a dedicated orchestration cluster a separate server process with its own persistence backend that your application workers connect to over gRPC. This is powerful, but it means an extra service to provision, monitor, scale, and keep available before your first workflow can run. How DBOS embeds durable execution into your application Traditional workflow orchestration platforms often introduce an additional operational layer that teams must deploy, monitor, secure, and scale alongside their applications. For organizations building AI systems, reducing infrastructure complexity https://www.cockroachlabs.com/blog/database-for-ai-applications/ can be just as valuable as improving workflow reliability. DBOS https://dbos.dev/ takes a fundamentally different approach: it embeds durable execution directly into your application as a Python or TypeScript library, using the database you already have. There is no orchestration server, no task queue, no sidecar process. Your application writes workflow state to tables in its own database as a natural side effect of execution, and recovers from those tables on restart. Pair DBOS with CockroachDB https://www.cockroachlabs.com/product/overview/ and you get a globally distributed, self-healing execution platform with no additional infrastructure to manage. A durable workflow is a function whose execution state which steps have completed, what they returned, what inputs were given is persisted to the database after every step. If the process crashes mid-run, it restarts and replays from the last committed step: no work is lost, no step is re-executed, no external side effect is duplicated. Built for AI-driven scale Unify operational data, vector search, and durable agent state in one resilient, distributed SQL database. Start with $400 in free credits. Trusted by Fortune 50 financial institutions and teams in 40+ countries. What Is DBOS? DBOS is a Python and TypeScript library that decorates ordinary functions with durable execution guarantees. There is no server to deploy, no task queue to operate, or separate persistence cluster to manage. DBOS writes workflow state to tables in your application database as a side effect of normal execution, and recovers from those tables on restart. Core Concepts Architecture DBOS is implemented entirely as an open-source library embedded in your application: There is no orchestration server and no external dependencies except a PostgreSQL-compatible database. While your application runs, DBOS checkpoints workflow and step state to that database. On failure, it uses those checkpoints to resume each workflow from the last completed step. DBOS architecture: the durable execution library lives inside your application process; the only external dependency is a Postgres-compatible database How does DBOS checkpoint workflow execution? Every workflow execution produces a fixed number of database writes regardless of complexity. Understanding this write pattern helps explain both DBOS's recovery model and the benchmark results discussed later. Specifically, each workflow generates: One write at workflow start : inputs are persisted before any step runs One write per completed step : the step’s return value is stored so replay can skip it One write at workflow end : the final status is committed Write sizes are proportional to your inputs and outputs. For large payloads files, embeddings , the recommended pattern is to store them externally e.g., S3 and have steps return pointers only. How does DBOS scale across multiple servers? DBOS scales naturally to a fleet of servers. All application servers connect to the same system database , the only coordination point. By default, each workflow runs on a single server; durable queues distribute work across the fleet with configurable rate and concurrency limits. For multi-application setups e.g., an API server, a data-ingestion service, and an AI agent loop , each application connects to its own isolated system database. A single physical database host can serve multiple system databases. The DBOS Client lets external code enqueue jobs and monitor results across application boundaries. How does DBOS recover interrupted workflows? When a process crashes, DBOS detects incomplete workflows and replays them in three steps: Detection – at startup, DBOS scans for pending workflows. In distributed deployments,coordinates detection across the fleet. Conductor Restart – each interrupted workflow is called again with its original checkpointed inputs. Resume – as the workflow re-executes, every step whose output is already checkpointed is skipped instantly. Execution resumes from the first un-checkpointed step. To resume execution safely without repeating completed work, DBOS relies on two principles : Determinism – the workflow function must produce the same steps in the same order given the same inputs. Non-deterministic operations DB access, API calls, random numbers, timestamps must live inside @DBOS.step decorators, never directly in the workflow body. Idempotency – steps may be retried on recovery and must be safe to re-execute. For engineering teams, durable recovery reduces the operational burden of managing long-running workflows. Instead of building custom retry logic, recovery scripts, or compensating transactions for every failure scenario, teams can rely on workflow state that survives process restarts and infrastructure interruptions. What is DBOS Conductor? For production deployments, DBOS recommends connecting to Conductor , a management service that adds distributed recovery coordination, workflow dashboards, and queue observability. Conductor is architecturally off the critical path: Each server opens an outbound websocket connection to it, and if the connection drops the application continues operating normally. Conductor has no direct access to your database and is never involved in workflow execution itself. Conductor is out of band: application servers open outbound websocket connections to it for observability and recovery, never for workflow execution Why use CockroachDB for DBOS? DBOS uses the PostgreSQL wire protocol https://www.cockroachlabs.com/glossary/distributed-db/postgresql-wire-protocol/ , so it connects to CockroachDB directly without any driver changes. What CockroachDB adds over a single-node PostgreSQL is the persistence tier you always wanted, but couldn’t justify operating separately. For long-running AI workflows https://www.cockroachlabs.com/docs/stable/cockroachdb-and-ai , the database becomes more than a place to store application data; it also becomes the system of record for workflow progress. As workflow volume grows, organizations need that execution state to remain available during node, zone, or regional failures without introducing another distributed system to manage. CockroachDB provides those capabilities through these architectural features: – concurrent workflow executions never produce lost updates or phantom reads Serializable isolation Multi-region active-active replication – workflow state is durable across data-center failures without manual intervention– the system database scales with your application without re-sharding Horizontal scalability – CockroachDB node failures are transparent to DBOS, which simply retries on the next available node Automatic failover When DBOS connects to CockroachDB, it provides three categories of tables in the system database. Together, these tables persist workflow progress, completed steps, and application events that enable durable execution and recovery. They include: Tables created by DBOS in CockroachDB: workflow state, step outputs, and events, all in your existing database Workflow status table – one row per execution, tracking ID, status, and function inputs Operation outputs table – one row per completed step, storing the serialized return value for replay Events table – named key-value pairs published within workflows and consumed via get event For teams that want globally resilient agentic workflows https://www.cockroachlabs.com/blog/agentic-ai-production-infrastructure/ without the complexity of a Temporal cluster, DBOS + CockroachDB is the lowest-overhead path. How to deploy DBOS on CockroachDB There are two required configuration changes when using CockroachDB instead of PostgreSQL. Prerequisites pip install "dbos otel ==2.15.0" "fastapi standard " psycopg2-binary sqlalchemy-cockroachdb export DBOS COCKROACHDB URL="postgresql://