Architecture: event-sourcing
This course covers event sourcing in Rails applications, where every change is stored as an immutable event and the current state is derived by replaying those events. It compares this model with CRUD and explains when each one fits. Lessons cover naming and versioning events, building an event store with streams in PostgreSQL, projections and read models, CQRS, and sagas with compensating actions. The last lesson shows the rails_event_store gem, a hybrid architecture, a phased migration from CRUD and testing at three levels.
What you'll learn
- ✓How event sourcing differs from CRUD and when each one fits
- ✓Naming, designing and versioning immutable events with metadata
- ✓Building an append-only event store with streams in PostgreSQL
- ✓Projections, read models and CQRS in Rails
- ✓Sagas, process managers and compensating actions
- ✓A hybrid Rails architecture with rails_event_store and a phased migration
What is event sourcing?
Your bank account shows $2,847.63. You expected $3,347.63. You call the bank and ask where the $500 went. The bank says: "We don't know. We only store your current balance."
Read the full lesson free →Curriculum
7 lessonsWhat is event sourcing?
Compares state-based CRUD with storing immutable events, and shows when event sourcing fits and when it is overkill.
Events as first-class citizens
Covers past-tense event names, schemas holding values from the moment, metadata, immutability and three strategies for versioning events.
Event stores & streams
Builds an append-only event store in one PostgreSQL table, with streams per aggregate and optimistic concurrency control.
Projections: rebuilding state from events
Explains projections that build read models from events, synchronous versus asynchronous updates, and rebuilding projections by replaying events.
CQRS: separating reads from writes
Separates the write model for commands from read models for queries, with and without event sourcing in Rails.
Sagas & process managers
Coordinates multi-step processes with sagas and process managers, using compensation and retries instead of distributed transactions.
Event sourcing in Rails: practical patterns
Applies rails_event_store in a hybrid architecture, with a phased migration from CRUD, a decision matrix and tests.