This document discusses event sourcing and the Marten library. Event sourcing uses events to represent state changes, allowing for concurrency and projections. Events are persisted and describe all state changes to an aggregate. Projections transform events into read models. Marten is a .NET library that uses PostgreSQL as an event store for event sourcing applications. The document also discusses evolving aggregates over time by adding new events and features while maintaining backwards compatibility.
3. EVENT SOURCING
• Events as representation of state
• Concurrency
• Projections
• Evolution
• Domain events and integration events
4. EVENTS AS THE REPRESENTATION OF STATE
UserAggregate v1
UserAggregate v2
UserAggregate v3
UserAggregate v4
UserCreatedEve
nt
UsernameAddedEv
ent
AddressAddedEve
nt
UsernameUpdatedEve
nt
5. ALL STATE CHANGES PRODUCE A DOMAIN
EVENT
…so the collection of events describe all state changes
7. CONCURRENCY
• Two threads updating the same aggregate …
• …Version of aggregate is number of applied events
• Optimistic concurrency:
• Only store events with sequence number > aggregate version
14. NEW FEATURE: MULTIPLE ADDRESSES
UserAggregate v1
UserAggregate v2
UserAggregate v3
UserAggregate v4
UserCreatedEve
nt
UsernameAddedEv
ent
AddressAddedEve
nt
AddressAddedEvent
18. NEW FEATURE: CONNECT TO FACEBOOK
UserAggregate v1
UserAggregate v2
UserAggregate v3
UserAggregate v4
UserCreatedEve
nt
UsernameAddedEv
ent
AddressAddedEve
nt
ConnectedToFaceboo
k
19. ALL STATE CHANGES PRODUCE A DOMAIN
EVENT
…so the collection of events describe all state changes
21. ADDING FIELDS TO EVENTS
• In case more data is given in command
• More context becomes relevant
• Tighter business rules
• New feature: Address type
26. NOT ALL EVENTS ARE EQUAL
DOMAIN EVENTS
• Fine grained
• All state changes
• Internal to a service
INTEGRATION EVENTS
• Course grained
• Signifies business events
• Meant for other services