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: Projections — read models kept up to date by the projection runner
- Part 5: Background Processing — automations that work off a todo list
A runnable version of everything built across these parts lives in
examples/todolist.
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 when you cannot tell whether an append landed - The aggregate variant — when to use it and when not to
Events - Register events for serialization - Version events when the schema changes - Read an event's old shape with UnmarshalJSON
Queries - Build a projection - Rebuild a projection without downtime - Move from the event bus to a projection runner
Infrastructure - Use KurrentDB as the event store - Add OpenTelemetry tracing - Use middleware, such as structured logging - Test event-sourced code
Reference¶
Complete API documentation.
- Core interfaces —
Event,Command,Query,EventStore,GlobalReader - 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 - Serialization — the JSON contract every store follows
- Iterator —
Iterator[T],NewIteratorFunc - GlobalReader —
ReadAll,Head,ReadOptions, the contract every store keeps - projection —
Definition,Runner,Probe,Store, phases and errors - automation —
Definition,TodoList,Segmented,Deferred,Store,Scheduler - dashboard —
New, options, routes and states - telemetry — every wrapper, span, metric and attribute
- Context helpers — envelope propagation through context
- Errors — error types and sentinel values
- Implementations
- memory.EventStore
- postgres.EventStore
- sqlite.EventStore
- kurrentdb.EventStore
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
- Personal data and events — why personal data stays out of the log
- What the library does not do — non-goals, and the doors left open