Durable Execution · Rust + PostgreSQL

Agents that
survive failure.

Give Rust AI agents durable execution out of the box. Every LLM call and tool result is checkpointed to PostgreSQL before advancing — crashes, rate limits, and deploys resume from the last completed step.

Build payment flows where every step commits its output before moving on. A charge that succeeded is never executed twice — completed steps replay straight from storage after any crash.

Orchestrate multi-day onboarding pipelines — welcome emails, billing setup, async human verification — with zero lost state and zero duplicate side effects on restart.

brewery_finder.rs
tokio · sqlx PgBackend
use zart::prelude::*;
use zart::{zart_durable, zart_step};

#[zart_step("extract", retry = "exponential(3, 2s)")]
async fn extract_city(query: &str) -> Result<City> {
    LlmFunction::<City>::new(llm).run(query).await
}

#[zart_step("fetch", retry = "exponential(3, 1s)")]
async fn fetch_breweries(city: &str) -> Result<Vec<Brewery>> {
    reqwest::get(&api_url(city)).await?.json().await
}

#[zart_durable("ai-brewery-finder", timeout = "10m")]
async fn brewery_finder(query: String) -> Result<Report> {
    let city = extract_city(&query).await?;
    let data = fetch_breweries(&city.name).await?;
    Ok(Report::summarize(&data))
}
use zart::prelude::*;
use zart::{zart_durable, zart_step};

#[zart_step("charge")]
async fn charge_card(order: &Order) -> Result<Charge> {
    stripe.charge(&order.card, order.total).await
}

#[zart_step("receipt")]
async fn send_receipt(charge: &Charge, email: &str) -> Result<()> {
    mailer.send(email, charge).await
}

#[zart_durable("checkout", timeout = "10m")]
async fn checkout(order: Order) -> Result<Receipt> {
    let charge = charge_card(&order).await?;
    send_receipt(&charge, &order.email).await?;
    let _: Shipped = zart::wait_for_event("shipped", Some(Duration::from_secs(86400))).await?;
    Ok(Receipt::from(charge))
}
use zart::prelude::*;
use zart::{zart_durable, zart_step};

#[zart_step("welcome")]
async fn send_welcome(email: &str) -> Result<()> {
    mailer.send(email, "Welcome!").await
}

#[zart_step("billing", retry = "exponential(3, 2s)")]
async fn setup_billing(user: &NewUser) -> Result<CustomerId> {
    stripe.create_customer(user).await
}

#[zart_durable("onboarding", timeout = "30m")]
async fn onboard(user: NewUser) -> Result<Welcome> {
    send_welcome(&user.email).await?;
    setup_billing(&user).await?;
    let _: Verified = zart::wait_for_event("email-confirmed", Some(Duration::from_secs(172800))).await?;
    provision(&user).await?;
    Ok(Welcome::for_user(&user))
}
PostgreSQL Checkpoint Trace zart_steps
PERSIST step="extract" · City("Portland") committed
SIGTERM worker killed mid-request · state intact
REPLAY extract skipped (0ms) · resuming at fetch
PERSIST step="charge" · ch_3Qx9 committed to PG
CRASH pod OOM after Stripe 200 · no double charge
REPLAY charge replayed · executing send_receipt
PERSIST welcome + billing committed · zero locks held
SUSPEND waiting on "email-confirmed" (48h window)
RESUME webhook received · provisioning workspace
01 / RUNTIME RUST + TOKIO
Zero-overhead native execution

Compile-time guarantees, Tokio async ergonomics, and predictable memory usage — no GC pauses and no serialization proxies.

02 / TOPOLOGY LIBRARY CRATE
Zero sidecars or coordinators

Embed Zart directly in your Rust binary. No external workflow server, no JVM cluster, and no new infrastructure to operate.

03 / PERSISTENCE POSTGRESQL 14+
State in the database you already run

Durable checkpoints, retries, and worker locks live in standard PostgreSQL tables via SKIP LOCKED.

Everything durable execution needs.

Built for production Rust services. Every primitive is deterministic, inspectable in SQL, and engineered to survive partial failures by default.

01 // CHECKPOINT REPLAY deterministic

State Recovery

Every step commits its serialized output before the next runs. On restart, completed steps replay straight from storage — never re-executed.

Crash at 3am? Resume from step 4, not step 1.
02 // BACKOFF POLICY jittered

Smart Retries

Per-step retry policies with fixed, linear, or exponential backoff. Configure max attempts, base delay, and jitter independently on each step.

Transient network blip? Self-heals before anyone notices.
03 // WORKER DISPATCH lock-free

Concurrent Workers

Workers claim tasks across replicas using PostgreSQL SKIP LOCKED — zero lock contention, zero leader election, horizontal scaling out of the box.

Add more replicas. No config, no coordinator, no drama.
04 // HARD DEADLINES bounded

Timeouts & Deadlines

Declare execution deadlines right on the handler attribute. Workflows exceeding their budget cancel cleanly with zero orphaned tasks.

No zombie tasks eating DB connections at 100% CPU.
05 // IDEMPOTENCY KEY unique index

Idempotency Built-in

Deterministic execution IDs prevent duplicate scheduling at the storage layer. A payment step that succeeded never fires twice — even under duplicate triggers.

Double-charge bug in prod? That's a chargeback. Not anymore.
06 // DURABLE SIGNALS event-driven

Events & Async Waits

Suspend workflows durably while waiting on webhooks, human approvals, or external services — consuming zero worker threads until signaled.

Pause 3 days for human approval. Resume in milliseconds.

Two APIs. Same durability.

Start with ergonomic attribute macros that read like plain async Rust, or drop down to explicit traits when you want manual struct dependency injection.

onboarding.rs
use zart::prelude::*;
use zart::{zart_durable, zart_step};

/// Define each step as a standalone async function
#[zart_step("send-welcome", retry = "exponential(3, 2s)")]
async fn send_welcome(email: &str) -> Result<(), StepError> {
    send_email(email).await
}

#[zart_step("setup-billing")]
async fn setup_billing(email: &str) -> Result<String, StepError> {
    create_stripe_customer(email).await
}

/// Compose steps — no ctx threading, just plain .await
#[zart_durable("onboarding", timeout = "30m")]
async fn onboarding(data: OnboardingData) -> Result<(), TaskError> {
    send_welcome(&data.email).await?;
    let _customer_id = setup_billing(&data.email).await?;

    // Durable wait — workflow suspends, survives any restart
    let _: VerifyPayload =
        zart::wait_for_event("email-verified", Some(Duration::from_secs(172_800))).await?;

    Ok(())
}
use zart::prelude::*;
use async_trait::async_trait;
use std::borrow::Cow;

/// Define a step struct — holds your dependencies
struct SendEmailStep { email: String }

impl ZartStep for SendEmailStep {
    type Output = ();
    fn step_name(&self) -> Cow<'static, str> { Cow::Borrowed("send-email") }
    fn retry_config(&self) -> Option<RetryConfig> {
        Some(RetryConfig::exponential(3, Duration::from_secs(2)))
    }
    // No ctx parameter — use zart::context() for introspection
    async fn run(&self) -> Result<(), StepError> {
        send_email(&self.email).await
    }
}

/// Compose steps — no ctx, no threading boilerplate
struct OnboardingTask;

#[async_trait]
impl DurableExecution for OnboardingTask {
    type Data   = OnboardingData;
    type Output = ();

    async fn run(&self, data: OnboardingData) -> Result<(), TaskError> {
        zart::step(SendEmailStep { email: data.email }).await?;
        let _: VerifyPayload = zart::wait_for_event(
            "email-verified",
            Some(Duration::from_secs(172_800)),
        ).await?;
        Ok(())
    }
}

Stop losing in-flight state.

Ship your first durable Rust workflow against PostgreSQL in minutes — zero extra clusters required.