Eventastic
A type-safe event sourcing and CQRS library for Rust with PostgreSQL persistence.
Features
- Strongly-typed aggregates and events - Define your domain model with Rust structs and enums
- Mandatory transactions for ACID guarantees
- Built-in idempotency prevents duplicate event processing
- Optimistic concurrency control detects conflicting modifications
- Transactional outbox pattern for reliable side effects
- Snapshot optimization for fast aggregate loading
- In-memory repository for testing and development
Quick Start
Define your domain aggregate and events:
use ;
use DomainEvent;
use InMemoryRepository;
use Repository;
// Define a no-op side effect type
;
Use the aggregate with transactions:
async
Architecture
Eventastic is built around four core concepts:
- Aggregates - Domain entities that apply events to update their state
- Events - Immutable records of what happened in your domain
- Context - Wrapper that tracks aggregate state and uncommitted events
- Repository - Persistence layer with transactional guarantees
Why Eventastic?
Transaction-First Design
Unlike many event sourcing libraries, Eventastic requires transactions for all write operations. This provides:
- ACID compliance - All changes are atomic and consistent
- Idempotency - Duplicate events are detected and handled gracefully
- Concurrency safety - Optimistic locking prevents data races
- Side effect reliability - External operations are processed via outbox pattern
Rust Benefits
Using Rust provides compile-time guarantees:
- Events must implement required traits (DomainEvent, Clone, etc.)
- Aggregates must handle all event types in match statements
- Error handling is explicit with Result types
- No null pointer exceptions or runtime type errors
Production Ready
Eventastic includes features needed for production systems:
- Automatic snapshot creation and loading
- Comprehensive error types with structured information
- Transaction-based consistency guarantees
Persistence
The library provides multiple repository implementations:
eventastic::memory::InMemoryRepository- For testing and developmenteventastic_postgres::PostgresRepository- For production PostgreSQL storage with:- Event and snapshot storage with versioning
- Full transaction support with optimistic concurrency control
- Optional encryption for sensitive data
- Database migrations support
eventastic_outbox_postgres::TableOutbox- Transactional outbox pattern for reliable side effect processing
Examples
See the examples/ directory for complete implementations:
- Bank - Full banking domain demonstrating:
- Account creation and management
- Transaction processing
- Side effects via outbox pattern
- Idempotency and concurrency handling