durare (Latin durāre, "to last") is a durable-execution library for Rust.
Write ordinary async functions; durare checkpoints each step to your database
and, after a crash, restart, or redeploy, resumes every unfinished workflow
exactly where it stopped. Completed steps are never re-run.
durare is a Rust SDK for DBOS durable execution,
aligned by design with the DBOS Transact SDKs for Python, Go, TypeScript, and
Rust: the same programming model, the same semantics, and the same system schema
on the same database. There is no server to operate and no sidecar — the engine
is a library inside your process that talks directly to Postgres or SQLite.
See DBOS compatibility. Full API documentation is on
docs.rs.
DBOS also publishes an official Rust SDK,
dbos-transact-rust. durare is
community-maintained. Both use the DBOS system schema.
use std::time::Duration;
use durare::{DurableContext, DurableEngine, Result, WorkflowOptions};
#[durare::step]
async fn charge_card(ctx: &DurableContext, order_id: String) -> Result<String> {
// Any side effect: an HTTP call, an email, a write to another system.
// Use an idempotency key: a crash before checkpointing can retry this call.
Ok(format!("ch_{order_id}"))
}
#[durare::workflow]
async fn process_order(ctx: DurableContext, order_id: String) -> Result<String> {
let charge_id = charge_card(&ctx, order_id).await?;
ctx.sleep(Duration::from_secs(24 * 3600)).await?; // durable timer
Ok(charge_id)
}
#[tokio::main]
async fn main() -> Result<()> {
let engine = DurableEngine::connect("postgres://localhost/app").await?.build().await?;
engine.recover().await?; // resume whatever a previous process left unfinished
let handle = engine
.start_with(ProcessOrder, "1001".into(), WorkflowOptions::with_id("order-1001"))
.await?;
println!("charged: {}", handle.await?);
Ok(())
}The workflow above sleeps for a day between charging and returning. Kill the
process at any point — mid-sleep included — and the next recover() picks it
up from the recorded results with only the remaining sleep to wait. Make the
charge request idempotent: a crash between charging and checkpointing can
repeat the external call.
Workflows take a DurableContext argument and pass it to helpers that perform
durable work. Steps reserve their position in the workflow's history when they
are constructed, inline, in a helper, or as a prebuilt join! argument, so
poll order cannot move them.
The context parameter is what lets durare reject step placements that would
silently lose a checkpoint. A step constructed inside a spawned task, or inside
another step's body, is an error rather than plain work that re-runs on
recovery. Construction order still has to be deterministic, and patches must be
awaited sequentially.
The design guide covers the
checks and caller rules; the
design note
explains the alternatives considered and the trade-offs behind explicit context.
- Steps.
#[durare::step]functions orctx.stepclosures. Per-step retry policy with exponential backoff and a retry predicate (StepOptions). - Transactions.
#[durare::transaction]runs your SQL and records the step's completion in the same database transaction, so the write and its checkpoint commit or roll back together. This makes the step exactly-once, not at-least-once. - Timers.
ctx.sleeppersists its wake instant; a replay waits only the remaining time. - Queues. Per-process and global concurrency limits, rate limiting, priorities, delayed enqueue, deduplication (reject or return-existing), and partitioned queues.
- Scheduling. Six-field cron via
#[durare::workflow(schedule = "…")], plus a managed schedule API: create, pause, resume, trigger, backfill. - Messaging, events, streams. Durable FIFO
send/recvbetween workflows and from the outside, idempotency-key sends, key-valueset_event/get_event, and append-only streams that consumers can tail live. - Child workflows.
ctx.start_workflowwith deterministic child ids and parent links. - Recovery and versioning.
recover()resumes by application version, a version registry routes work across a fleet, and runaway workflows park after a recovery-attempt cap. - Management. List, cancel, resume, and fork (from an arbitrary step)
workflows; per-workflow timeouts;
ctx.patchfor changing workflow code while old runs are still in flight; debouncing for coalescing bursts. - Operations. An admin HTTP server with the standard DBOS endpoints, and a
client for DBOS Conductor (behind the
conductorfeature). - Out-of-process producers. A registry-free
Clientfor services that submit and observe workflows but run none of them.
[dependencies]
durare = "0.3"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }The repository ships twelve examples, one per primitive plus dependency injection and tracing export:
| Example | Shows |
|---|---|
order |
workflow + steps, crash recovery via a fault-injection crash |
saga |
compensation on failure |
pipeline |
queues: fan-out under a concurrency limit |
scheduled |
cron workflows |
transfer |
#[transaction]: exactly-once money movement, proven by re-run |
approval |
human-in-the-loop: durable recv, events for observers |
client |
out-of-process submit and observe |
timer |
durable sleep |
subworkflow |
child-workflow fan-out |
stream |
live-tailed progress feed |
dependencies |
dependency injection: deps in a global, read inside steps |
telemetry |
OTLP trace export; compose stack with Tempo and Grafana |
cargo run --example saga # in-memory, no database needed
# Crash recovery, for real:
createdb app
export DATABASE_URL=postgres://localhost:5432/app
FAILPOINTS=after_charge=return cargo run --example order # charges, then crashes
cargo run --example order # resumes; does not re-chargeBackends are compiled behind features, all on by default; enable just one to
drop the other's driver. At least one backend is required — a build with
neither is a compile error. InMemoryProvider is always available (no feature).
| Feature | Default | Enables |
|---|---|---|
postgres |
✅ | The PostgresProvider backend (sqlx Postgres driver). |
sqlite |
✅ | The SqliteProvider backend (sqlx SQLite driver — a bundled C library). |
conductor |
— | The DBOS Conductor client (Conductor, ConductorConfig, AlertHandler) — a websocket client for the DBOS control plane; pulls in a TLS websocket stack and gzip framing. |
admin |
— | The AdminServer HTTP control surface — health, recovery, and workflow-management endpoints for the DBOS console/conductor and health probes; pulls in the axum/hyper/tower stack. |
otel |
— | WorkflowOptions::propagate_trace_context: carry the caller's W3C trace context with a workflow so queued and recovered runs join its trace; pulls in the OpenTelemetry API and the tracing-opentelemetry bridge. |
For a Postgres-only build (no SQLite C compile) that also enables the Conductor client:
durare = { version = "0.3", default-features = false, features = ["postgres", "conductor"] }Each side-effecting operation a workflow performs — a step, a sleep, a message
receive, a child start — is recorded in the operation_outputs table, keyed by
a deterministic per-execution counter and guarded by the operation's name. When
a workflow is re-executed after a failure, operations that already ran return
their recorded results instead of running again, and execution proceeds from
the first checkpoint that is missing.
The consequence, as in every durable-execution system: workflow control flow must be deterministic. Wall-clock reads, random numbers, and anything else non-repeatable belong inside a step, where the result is recorded. The execution layers note describes how this workflow-level contract stays separate from the engine's dispatch, recovery and ownership machinery, and gives the rule for deciding which side a new error belongs to.
What the guarantees actually are:
| Operation | Guarantee |
|---|---|
| Workflow state transitions, completion | exactly once |
| Step side effect | at least once — make external calls idempotent |
#[transaction] SQL |
exactly once (commits with its own checkpoint) |
recv message consumption |
exactly once |
| Cron tick | once per tick, across any number of executors |
A crash can land between an external call and its checkpoint, so external side effects must be safe to retry. Transactions close that window for SQL against the workflow database, which is why they exist as a separate primitive.
| Backend | Intended use | Notes |
|---|---|---|
PostgresProvider |
production, multi-executor | LISTEN/NOTIFY wakes blocked recv/get_event; queue claims use FOR UPDATE SKIP LOCKED; connect_with_schema for a custom schema |
SqliteProvider |
single-node deployments, local development | full durability on a file database |
InMemoryProvider |
tests and examples | no cross-process durability |
All three implement one trait, StateProvider, which is also the seam for
adding further backends. PostgresProvider and SqliteProvider are gated by the
postgres and sqlite Cargo features (both on by default);
InMemoryProvider is always available. Application tests can run workflows
against InMemoryProvider with no infrastructure at all; the crate's own test
suite runs against all three backends on every commit, with Postgres against a
live server in CI.
durare uses the DBOS system schema and supports DBOS tooling integrations.
See DBOS compatibility
for storage formats and integration details.
durare-benchmarks/ measures workflow throughput,
tail latency under load, and memory per in-flight workflow. Database
round-trips are a major part of durable-execution cost; the harness README
documents the workloads and measurement methodology.
durare builds on Rust 1.88 and later, enforced by a dedicated CI job.
Raising the MSRV is a semver-minor change (it will never happen in a patch
release).
Bug reports and pull requests are welcome — see CONTRIBUTING.md for the development setup and the checks to run before submitting.
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.