terraskye/eventsourcing Documentation¶
A Go library for building event-sourced systems with CQRS support.
go get github.com/terraskye/eventsourcing
Tutorials¶
Step-by-step guides to learn event sourcing by building a real application.
- Getting Started — overview and prerequisites
- Part 1: Your First Command — commands, events, event store
- Part 2: Your First Query — queries and live read models
- Part 3: Business Rules — state, validation, and the decide/evolve pattern
- Part 4: Real-time Projections — event bus and cached projections
- Part 5: Background Processing — processors and sagas
How-to guides¶
Practical recipes for specific tasks.
Commands - Handle concurrency conflicts with optimistic locking - Add metadata to events - Customise stream names (multi-tenancy) - Retry commands on conflict - The aggregate variant — when to use it and when not to
Events - Register events for serialization - Subscribe to events with the event bus - Version events when the schema changes
Queries - Build a live read model - Build a cached projection
Infrastructure - Use KurrentDB as the event store - Add OpenTelemetry tracing - Add structured logging - Test event-sourced code
Reference¶
Complete API documentation.
- Core interfaces —
Event,Command,Query,EventStore,EventBus - CommandHandler —
NewCommandHandler, options - EventHandler & EventGroupProcessor —
OnEvent,NewEventGroupProcessor - QueryBus & QueryGateway —
NewQueryBus,RegisterQueryHandler,NewQueryGateway - CommandBus —
NewCommandBus,Register,Dispatch - Stream states —
Any,NoStream,StreamExists,Revision - Event registry —
RegisterEvent,NewEventByName - Iterator —
Iterator[T],NewIteratorFunc - Context helpers — envelope propagation through context
- Errors — error types and sentinel values
- Implementations
- memory.EventStore
- memory.EventBus
- postgres.EventStore
- postgres.EventBus
- file.EventStore
- kurrentdb.EventStore
- kurrentdb.EventBus
Explanation¶
Background reading to understand the design and concepts.
- Event sourcing concepts — what, why, and how events model state
- CQRS — separating reads from writes
- The decide/evolve pattern — how commands become events
- Concurrency and optimistic locking
- Vertical slice architecture — recommended project layout