Skip to content

Persistence Layer Specification

Document ID: WF-011 Version: 1.0.0 Status: Draft Owner: Workflow Engine Team Last Updated: 2026-06-26


This document defines the Persistence Layer architecture for the Wovyr Workflow Engine.

The Persistence Layer is responsible for durable storage of all workflow runtime data while remaining independent of the underlying database technology.

The persistence subsystem stores:

  • Workflow definitions
  • Workflow executions
  • Activity executions
  • Events
  • Checkpoints
  • Scheduler state
  • Retry state
  • Compensation state
  • Worker leases
  • Audit records
  • Metrics metadata

The persistence layer is the single source of durable runtime state.


The Persistence Layer must provide:

  • ACID transactions where required
  • Horizontal scalability
  • Storage abstraction
  • High availability
  • Encryption
  • Optimistic concurrency
  • Multi-tenant isolation
  • Schema evolution

  1. Storage implementation must be pluggable.
  2. Runtime components never access databases directly.
  3. All persistence occurs through repositories.
  4. Data models are versioned.
  5. Writes are atomic.
  6. Reads are strongly consistent where required.
  7. Storage providers are interchangeable.

Workflow Runtime
Repository Layer
┌───────────────┼────────────────┐
▼ ▼ ▼
Workflow Repo Event Repo Checkpoint Repo
│ │ │
└───────────────┼────────────────┘
Persistence Provider
┌───────────────┼────────────────────┐
▼ ▼ ▼
PostgreSQL CockroachDB FoundationDB
│ │ │
└───────────────┼────────────────────┘
Object Storage

The Persistence Layer stores:

  • WorkflowDefinition
  • WorkflowExecution
  • ActivityExecution
  • WorkflowEvent
  • WorkflowCheckpoint
  • WorkerLease
  • RetryRecord
  • CompensationRecord
  • Schedule
  • AuditLog
  • MetricsSnapshot

Every entity is managed through a repository.

Example:

WorkflowRuntime
WorkflowRepository
Persistence Provider
Database

Repositories isolate the runtime from storage technology.


Supported providers:

ProviderPurpose
PostgreSQLDefault production
CockroachDBDistributed SQL
FoundationDBEnterprise
SQLiteDevelopment
RocksDBEmbedded
DynamoDBCloud
MongoDBMetadata storage (optional)

Additional providers may be implemented through adapters.


Consistency guarantees:

  • Atomic workflow transitions
  • Atomic event persistence
  • Atomic checkpoint creation
  • Atomic lease updates

Distributed consistency uses optimistic concurrency.


Transactional operations include:

  • Workflow creation
  • State transitions
  • Activity completion
  • Checkpoint creation
  • Event persistence
  • Lease assignment

Transactions should remain short-lived.


Each persisted object contains:

id:
version:
updatedAt:
updatedBy:

Updates succeed only when versions match.

Conflicts require retry.


Each table/document stores:

schemaVersion:
entityVersion:
serializationVersion:

Migration is handled through version-aware readers.


Responsibilities:

  • Store workflow definitions
  • Retrieve workflow versions
  • Validate uniqueness
  • Archive obsolete definitions

Stores:

  • Runtime state
  • Variables
  • Activity status
  • Current workflow state
  • Metadata

Execution records are mutable through validated transitions only.


Stores:

  • Immutable events
  • Event metadata
  • Correlation IDs
  • Causation IDs

Events are append-only.


Stores:

  • Full snapshots
  • Incremental snapshots
  • Checkpoint metadata
  • Retention information

Supports efficient lookup of the latest checkpoint.


Stores:

  • Active leases
  • Lease expiration
  • Worker ownership
  • Heartbeat information

Used by the Scheduler.


Stores:

  • Retry attempts
  • Retry delays
  • Failure reasons
  • Retry policies

Supports replay and recovery.


Stores:

  • Compensation stack
  • Compensation state
  • Retry history
  • Rollback metadata

Supports resumable rollback.


Stores immutable audit records.

Examples:

  • Workflow created
  • User approval
  • Workflow cancelled
  • Secret access
  • Configuration changes

Audit records are never modified.


Sensitive fields are encrypted.

Examples:

  • Secrets
  • Credentials
  • API tokens
  • AI prompts
  • Personally identifiable information

Encryption uses AES-256-GCM.


Large objects may be compressed.

Supported:

  • Checkpoints
  • Event payloads
  • Large variables
  • AI responses

Default algorithm:

Zstandard (Zstd)

Backup types:

  • Full backup
  • Incremental backup
  • Continuous WAL archiving
  • Point-in-time recovery

Recovery objectives:

MetricTarget
RPO< 1 minute
RTO< 5 minutes

Recovery procedure:

  1. Restore database.
  2. Validate schema versions.
  3. Restore checkpoints.
  4. Replay events.
  5. Resume workers.

Recovery must preserve deterministic execution.


Every persisted entity contains:

tenantId:

Queries are automatically scoped by tenant.

Cross-tenant access is prohibited.


Persistence enforces:

  • Encryption at rest
  • TLS
  • RBAC
  • Audit logging
  • Secret isolation
  • Key rotation

Metrics:

  • Read latency
  • Write latency
  • Transaction failures
  • Lock conflicts
  • Storage usage
  • Query throughput
  • Replication lag

pub trait Repository<T> {
fn insert(&self, entity: T) -> Result<()>;
fn update(&self, entity: T) -> Result<()>;
fn delete(&self, id: Id) -> Result<()>;
fn find(&self, id: Id) -> Result<Option<T>>;
}

engine-storage/
├── provider/
│ ├── postgres.rs
│ ├── sqlite.rs
│ ├── cockroach.rs
│ ├── foundationdb.rs
│ └── mod.rs
├── repository/
│ ├── workflow.rs
│ ├── execution.rs
│ ├── activity.rs
│ ├── event.rs
│ ├── checkpoint.rs
│ ├── retry.rs
│ ├── compensation.rs
│ ├── lease.rs
│ ├── audit.rs
│ └── mod.rs
├── migration/
├── encryption/
├── compression/
├── transaction/
├── schema/
└── mod.rs

  • CRUD operations
  • Serialization
  • Encryption
  • Compression
  • Transaction rollback
  • Multi-provider support
  • Optimistic concurrency
  • Schema migration
  • One million workflow executions
  • High write throughput
  • Large checkpoints
  • Massive event streams
  • Database failure
  • Storage corruption
  • Replication lag
  • Partial writes

RequirementTarget
Read latency< 5 ms
Write latency< 10 ms
Transaction latency< 20 ms
Availability99.99%
DurabilityNo committed data loss
Horizontal scalingSupported

  • Workflow Overview
  • Execution Model
  • Scheduler
  • State Machine
  • Checkpointing
  • Retry Engine
  • Compensation Engine
  • Event Bus
  • Distributed Execution
  • Rust Crate Design

  • Multi-region replication
  • Automatic sharding
  • Columnar analytics storage
  • Tiered storage
  • Hot/cold data management
  • Transparent database failover
  • AI-assisted query optimization

VersionDateDescription
1.0.02026-06-26Initial Persistence Layer Specification