State Recovery
Every step commits its serialized output before the next runs. On restart, completed steps replay straight from storage — never re-executed.
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.
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))
} Compile-time guarantees, Tokio async ergonomics, and predictable memory usage — no GC pauses and no serialization proxies.
Embed Zart directly in your Rust binary. No external workflow server, no JVM cluster, and no new infrastructure to operate.
Durable checkpoints, retries, and worker locks live in standard PostgreSQL tables via SKIP LOCKED.
Built for production Rust services. Every primitive is deterministic, inspectable in SQL, and engineered to survive partial failures by default.
Every step commits its serialized output before the next runs. On restart, completed steps replay straight from storage — never re-executed.
Per-step retry policies with fixed, linear, or exponential backoff. Configure max attempts, base delay, and jitter independently on each step.
Workers claim tasks across replicas using PostgreSQL SKIP LOCKED — zero lock contention, zero leader election, horizontal scaling out of the box.
Declare execution deadlines right on the handler attribute. Workflows exceeding their budget cancel cleanly with zero orphaned tasks.
Deterministic execution IDs prevent duplicate scheduling at the storage layer. A payment step that succeeded never fires twice — even under duplicate triggers.
Suspend workflows durably while waiting on webhooks, human approvals, or external services — consuming zero worker threads until signaled.
Start with ergonomic attribute macros that read like plain async Rust, or drop down to explicit traits when you want manual struct dependency injection.
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(())
}
} Ship your first durable Rust workflow against PostgreSQL in minutes — zero extra clusters required.