Example applications demonstrating Runtara - a durable execution platform for crash-resilient workflows in Rust.
# Build all examples
cargo build --all
# Run a specific example
cargo run -p durable-example --bin basic_example| Crate | Description |
|---|---|
durable-example |
SDK examples demonstrating checkpoints, signals, sleep, and the #[durable] macro |
durable-examples-embedded |
Embedded mode with SQLite persistence (no server required) |
workflows-example |
JSON workflow DSL compilation to native Rust code |
Examples that demonstrate the runtara-sdk for building durable workflows. These examples connect to runtara-core when available, or run in demo mode showing the patterns.
SDK lifecycle fundamentals
Demonstrates the basic SDK workflow: initialization, connection, registration, heartbeat reporting, and completion.
cargo run -p durable-example --bin basic_exampleConcepts covered:
RuntaraSdk::localhost()- Create SDK for local developmentsdk.connect()- Establish QUIC connection to runtara-coresdk.register()- Register instance with the serversdk.heartbeat()- Simple "I'm alive" signalssdk.completed()- Signal successful completion with output
Durable state persistence
Shows how to save workflow state at checkpoints for crash recovery. If the process crashes, it can resume from the last checkpoint.
cargo run -p durable-example --bin checkpoint_exampleConcepts covered:
sdk.checkpoint()- Save serialized state to PostgreSQL- Resume from existing checkpoint data
- Progress tracking through checkpoint IDs
Durable sleep for long-running tasks
Demonstrates durable sleep between workflow phases. Unlike tokio::sleep, durable sleep preserves state if the process crashes.
cargo run -p durable-example --bin sleep_exampleConcepts covered:
sdk.sleep()- Durable sleep with checkpoint- Multi-phase workflows with delays
- State preservation across sleep periods
Use cases:
- Rate limit backoff
- Scheduled batch processing
- Throttling API calls
Cancel, pause, and resume handling
Shows how to handle external control signals for graceful shutdown and pause/resume functionality.
cargo run -p durable-example --bin signal_exampleConcepts covered:
sdk.check_cancelled()- Simple cancellation check in loopssdk.poll_signal()- Manual signal polling for pause/resumesdk.acknowledge_signal()- Confirm signal handlingsdk.suspended()- Report paused stateSignalType::Cancel,SignalType::Pause,SignalType::Resume
Error handling and recovery patterns
Demonstrates different error handling strategies: retry with exponential backoff, unrecoverable errors, timeouts, and partial failure tolerance.
cargo run -p durable-example --bin error_exampleConcepts covered:
- Exponential backoff retry pattern
sdk.failed()- Report workflow failuretokio::timeout()- Operation timeouts- Partial failure with continue (process remaining items)
- Checkpoint before risky operations
Real HTTP requests with checkpointing
Fetches URLs from runtara.com with checkpoint-based crash recovery. Demonstrates real-world I/O with durability.
cargo run -p durable-example --bin http_exampleConcepts covered:
- Pre-fetch and post-fetch checkpoints
- HTTP client integration with
reqwest - Progress reporting during I/O operations
- Graceful handling of fetch failures
The #[durable] attribute macro
Demonstrates the #[durable] proc macro for transparent checkpoint-based caching. Functions decorated with #[durable] automatically cache their results.
cargo run -p durable-example --bin durable_macro_exampleConcepts covered:
#[durable]- Basic durable function with automatic caching#[durable(max_retries = 3, strategy = ExponentialBackoff, delay = 100)]- Retry configuration- Idempotency keys for cache lookup
- Cached results on repeat calls
Example:
#[durable]
pub async fn get_order(key: &str, order_id: &str) -> Result<Order, AppError> {
// First call executes, subsequent calls with same key return cached result
db.fetch_order(order_id).await
}Complete order processing workflow
A realistic e-commerce order fulfillment pipeline with multiple durable steps: validation, inventory, payment, shipping, and notifications.
cargo run -p durable-example --bin durable_advanced_exampleConcepts covered:
- Multi-step workflow orchestration
- Nested durable functions
- Service integration patterns (payment gateway, inventory, shipping)
- Complete workflow caching (entire workflow returns cached result on repeat)
Workflow steps:
- Validate order
- Reserve inventory
- Capture payment
- Create shipment
- Send notifications
Checkpoint-based pause/resume
Shows how to detect pause signals via checkpoint responses and cleanly exit for later resume.
cargo run -p durable-example --bin pauseable_example
# Resume with same instance ID
RUNTARA_INSTANCE_ID=<id> cargo run -p durable-example --bin pauseable_exampleConcepts covered:
result.should_pause()- Check for pause signal in checkpoint responseresult.should_cancel()- Check for cancel signalresult.existing_state()- Resume from checkpoint- Clean exit on pause for later restart
SQLite persistence without a server
Demonstrates embedded mode where the SDK uses local SQLite for persistence instead of connecting to runtara-core. Ideal for development, testing, or single-node deployments.
cargo run -p durable-examples-embedded --bin basic_embedded_exampleConcepts covered:
RuntaraSdk::embedded()- Create SDK with local persistenceSqlitePersistence- SQLite-backed checkpoint storage#[durable]macro with retry in embedded mode
Example:
let persistence: Arc<dyn Persistence> =
Arc::new(SqlitePersistence::from_path(".data/example.db").await?);
RuntaraSdk::embedded(persistence, instance_id, tenant_id)
.init(None)
.await?;JSON DSL to native Rust compilation
Demonstrates the workflow compilation system: load JSON workflow definitions, generate Rust code, and optionally compile to native binaries.
# Code generation only
cargo run -p workflows-example
# With compilation (requires pre-built stdlib)
cargo run -p workflows-example -- --compileConcepts covered:
ExecutionGraph- Workflow definition structuretranslate_scenario()- Generate Rust code from JSONcompile_scenario()- Compile to native binary- Workflow agents and step types
Included workflows:
| File | Description |
|---|---|
simple_passthrough.json |
Passes input directly to output |
transform_workflow.json |
Uses transform agent with retry configuration |
workflow_with_variables.json |
Demonstrates scenario variables |
- Rust 1.75+ (Edition 2024)
- runtara-core running on
localhost:8001(for non-embedded examples)- Examples fall back to demo mode if server unavailable
- PostgreSQL (for runtara-core persistence)
| Variable | Default | Description |
|---|---|---|
RUNTARA_SERVER_ADDR |
127.0.0.1:8001 |
Core server address |
RUNTARA_INSTANCE_ID |
Auto-generated | Instance identifier (for resume) |
RUNTARA_TENANT_ID |
demo-tenant |
Tenant identifier |
To run examples with full server integration:
# Terminal 1: Start runtara-core
cd ../runtara
RUNTARA_DATABASE_URL=postgres://user:pass@localhost/runtara cargo run -p runtara-core
# Terminal 2: Run examples
cd ../runtara-examples
cargo run -p durable-example --bin checkpoint_exampleAGPL-3.0-or-later - See LICENSE for details.