duroxide-cdb
A CosmosDB NoSQL provider for duroxide — a durable execution runtime for Rust.
Stores orchestration state, event history, and work queues in a single CosmosDB container using document-type discrimination and partition-per-instance layout.
Latest Release (0.1.6)
- Updated to duroxide 0.1.25 with KV timestamp support in the provider contract
KeyValueDocumentnow persistslast_updated_at_msfor backward-compatible KV timestamps- Added bulk KV reads via
get_kv_all_values()and timestamped KV snapshots viaKvEntry - KV entries are now instance-scoped during pruning and survive execution cleanup
- See CHANGELOG.md for full version history
Features
- Single-container design — all document types coexist, partitioned by
instanceId - Transactional batch — atomic commits within a partition (up to 100 operations)
- Transactional outbox — reliable cross-partition delivery for sub-orchestrations
- Optimistic concurrency — ETag-based locking, no database-level locks
- Dispatch slot partitioning — 256-slot keyspace eliminates dispatcher contention
- Session affinity — routes work items to the same worker by session ID
- KV store — durable per-instance key-value state for orchestration coordination
- Timestamped KV snapshots — preserves per-key update times and supports bulk reads across all instance keys
- Raw REST client — direct HTTP to CosmosDB, no Azure SDK dependency
Quick Start
1. Start the CosmosDB Emulator
2. Add the dependency
[]
= "0.1.25"
= "0.1.6"
3. Create a provider and run an orchestration
use Runtime;
use ;
use ActivityRegistry;
use CosmosDBProvider;
use Arc;
async
Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
COSMOS_ENDPOINT |
CosmosDB account endpoint | http://localhost:8081 |
COSMOS_KEY |
CosmosDB account key | Emulator default key |
COSMOS_DATABASE |
Database name | duroxide |
Copy .env.example to .env for local development.
Programmatic Configuration
use ;
use Duration;
let config = CosmosDBProviderConfig ;
let provider = new_with_config.await?;
Architecture
See docs/ARCHITECTURE.md for comprehensive design documentation covering:
- Data model (7 document types, indexing policy, composite indexes)
- Core algorithms (fetch/ack orchestration items, work items)
- Transactional outbox pattern for cross-partition writes
- Dispatch slot partitioning (256-slot keyspace)
- Cross-partition query strategy (gateway limitations and workarounds)
- Session affinity implementation
- Error handling and retry strategy
Data Model
All documents live in a single container with /instanceId as the partition key:
| Document Type | Purpose |
|---|---|
instance |
Orchestration metadata, lock state, custom status |
history |
Append-only event log (one doc per event) |
orch_queue |
Messages for the orchestration dispatcher |
worker_queue |
Activity execution requests |
outbox_intent |
Pending cross-partition writes |
session |
Session affinity ownership tracking |
kv |
Per-instance key-value state entries |
Testing
Prerequisites
- CosmosDB Emulator (Docker) or an Azure CosmosDB account
- cargo-nextest for running tests
Run provider validation tests
Run e2e sample tests
Run against Azure CosmosDB
Set environment variables in .env:
COSMOS_ENDPOINT=https://your-account.documents.azure.com:443/
COSMOS_KEY=your-primary-key
COSMOS_DATABASE=duroxide
Module Structure
src/
├── lib.rs Re-exports CosmosDBProvider, CosmosDBProviderConfig
├── provider.rs Provider + ProviderAdmin trait implementations
├── client.rs Raw REST client (HMAC-SHA256 auth, CRUD, query, batch)
├── models.rs Serde structs for all document types
├── query.rs Cross-partition and single-partition query builders
├── batch.rs Transactional batch operations
├── containers.rs Database/container bootstrapping with retry
├── outbox.rs Outbox intent delivery + background reconciler
├── leases.rs Dispatch slot assignment (LeaseProvider trait)
└── errors.rs CosmosDB HTTP status → ProviderError mapping
Contributing
See CONTRIBUTING.md for contribution guidelines.
License
This project is licensed under the MIT License — see the LICENSE file for details.
Copyright (c) Microsoft Corporation. All Rights Reserved.