event sourcing reactive english - meetupfiles.meetup.com/14341692/event sourcing... · event...
TRANSCRIPT
![Page 1: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/1.jpg)
Event Sourcing Intro & Challenges
![Page 2: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/2.jpg)
Michael PlödinnoQ
Principal Consultant@bitboss
![Page 3: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/3.jpg)
Most current systems only store the current
state
![Page 4: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/4.jpg)
IncidentRestController
IncidentBusinessService
IncidentDAO
Incident
ID USER_ID DATE TEXT1 23423 11.03.2014 Maus defekt 2 67454 12.03.2014 EMail Empfang3 93729 12.03.2014 Monitor defekt… … … …
Classical Architecture
![Page 5: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/5.jpg)
IncidentRestController
IncidentBusinessService
IncidentDAO
Incident
ID USER_ID DATE TEXT1 23423 11.03.2014 Maus ist kaputt2 67454 12.03.2014 EMail Empfang3 93729 12.03.2014 Monitor defekt… … … …
Update
The dataset is directly being changed, no history
![Page 6: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/6.jpg)
1 Audit Log only with extra effort
2 No replay
3 Snapshots only with extra effort or via backups
![Page 7: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/7.jpg)
? Issues
![Page 8: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/8.jpg)
Many applications are working well with the classic
approach
![Page 9: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/9.jpg)
However there are areas where this approach reaches
it’s limitations
![Page 10: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/10.jpg)
? Reactive
![Page 11: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/11.jpg)
? Responsive
? Resilient
? Elastic
? Message driven
![Page 12: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/12.jpg)
IncidentRestController
IncidentBusinessService
IncidentDAO
Incident
Not quite reactive…
Database
![Page 13: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/13.jpg)
Event Sourcing is an architectural pattern in which the state of the
application is being determined by a
sequence of events
![Page 14: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/14.jpg)
Building Blocks
Applications
Event Queue
Applications issues events to a queue
Event Handler
The Event handler is processing the
events
Event Store
The event store is persisting the
events
![Page 15: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/15.jpg)
An event is something that happened in the past
tjetzt
EventEventEventEventEvent
![Page 16: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/16.jpg)
The names of the Events are part of the
Ubiquitous Language
D D D
![Page 17: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/17.jpg)
ShipmentDeliveredEvent
CustomerVerifiedEvent
CartCheckedOutEvent
CreateCustomerEvent WillSaveItemEvent
DoStuffEvent
![Page 18: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/18.jpg)
Code Examplepublic class CustomerVerifiedEvent {
private String eventId;
private Date eventDate;
private CustomerNumber customerNumber;
private String comment;
public CustomerVerifiedEvent(CustomerNumber custNum, String comment) {this.customerNumber = cusNum;this.comment = comment;this.eventDate = new Date();
}
}
![Page 19: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/19.jpg)
Scope your events on the basis of
Aggregates
D D D
![Page 20: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/20.jpg)
An Event is always immutable!
![Page 21: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/21.jpg)
The sequence of events in the queue is also called
Event Stream
tnow
EventEventEventEventEvent
![Page 22: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/22.jpg)
IncidentCreatedEvent incidentNumber: 1 userNumber: 23423timestamp: 11.03.2014 12:23:23 text: „Maus defekt“status: „offen“
Event Stream Example
IncidentTextChangedEvent incidentNumber: 1 text: „Maus ist Kaputt“
IncidentClosedEvent incidentNumber: 1 solution: „Neue Maus“status: „geschlossen“
![Page 23: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/23.jpg)
Let’s reuse the ESB from the failed SOA
project
![Page 24: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/24.jpg)
NO
![Page 25: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/25.jpg)
NO
![Page 26: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/26.jpg)
NO
![Page 27: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/27.jpg)
!Prefer dumb pipes with smart endpoints as a suitable message broker architecture
![Page 28: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/28.jpg)
1 Complete rebuild is possible
2 Temporal Queries
3 Event Replay
![Page 29: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/29.jpg)
Well known examples
=Version Control Systems
or Database Transaction Logs
![Page 30: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/30.jpg)
The Event Store has a very high business value
![Page 31: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/31.jpg)
There is no delete!!
![Page 32: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/32.jpg)
A delete is just another
event
IncidentCreatedEvent incidentNumber: 1 userNumber: 23423timestamp: 11.03.2014 12:23:23 text: „Maus defekt“status: „offen“
IncidentChangedEvent incidentNumber: 1 text: „Maus ist Kaputt“
IncidentClosedEvent incidentNumber: 1 solution: „Neue Maus“status: „geschlossen“
IncidentRemovedEvent incidentNumber: 1
![Page 33: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/33.jpg)
Aren’t there performance issues attached to this kind of
data storage?
![Page 34: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/34.jpg)
YES!
![Page 35: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/35.jpg)
Application State
Think about applciation state
Application
Event Queue
Event Handler
Event Store
Application State
The application queries the pre-processed application state
![Page 36: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/36.jpg)
CQRS
![Page 37: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/37.jpg)
Command Query Responsibility Separation
![Page 38: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/38.jpg)
IncidentSOAPEndpoint
IncidentBusinessService
IncidentDAO
IncidentBusiness Model
Client
Incident DTO
Incident View Model
RDBMS
Incident ER-Model
Netzwerk
Netzwerk
![Page 39: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/39.jpg)
EventHandler EventsEvents
Event Sourcing & CQRSIncidentCommandEndpoint
IncidentCommandService
IncidentCommandDAO
IncidentQueryEndpoint
IncidentQueryService
IncidentQueryDAO
Read Storage
Events
Select * from
Event Store
![Page 40: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/40.jpg)
Event Sourcing is an interesting architectural option. However there are various challanges,
that have to be taken care of
![Page 41: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/41.jpg)
1 Consistency
2 Validation
3 Parallel Updates
![Page 42: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/42.jpg)
YES
![Page 43: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/43.jpg)
!Systems based on CQRS and Event
Sourcing are mostly eventually
consistent
![Page 44: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/44.jpg)
EventHandler EventsEvents
Eventual ConsistencyIncidentCommandEndpoint
IncidentCommandService
IncidentCommandDAO
IncidentQueryEndpoint
IncidentQueryService
IncidentQueryDAO
Read Storage
Events
Select * from
Event Store
![Page 45: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/45.jpg)
BUT
![Page 46: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/46.jpg)
!You can build a fully consistent system which follows Event
Sourcing principles
![Page 47: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/47.jpg)
EventHandler
EventsEvents
Full ConsistencyIncidentCommandEndpoint
IncidentCommandService
IncidentCommandDAO
IncidentQueryEndpoint
IncidentQueryService
IncidentQueryDAO
Read Storage
EventsSelect * from
Event Store
![Page 48: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/48.jpg)
Your business domain drives the level of consistency not
technologyDeeper Insight
D D D
![Page 49: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/49.jpg)
Increased (but still eventual) consistency
EventHandler
EventsEvents
IncidentCommandEndpoint
IncidentCommandService
IncidentCommandDAO
IncidentQueryEndpoint
IncidentQueryService
IncidentQueryDAO
Read Storage
EventsSelect * from
Event Store
async
![Page 50: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/50.jpg)
! There is no standard solution
![Page 51: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/51.jpg)
1 Consistency
2 Validation
3 Parallel Updates
![Page 52: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/52.jpg)
Example DomainUser
Guid idString emailString password
RegisterUserCommand ChangeEmailCommand
UserRegisteredEvent Guid idDate timestampString emailString password
EmailChangedEvent Guid userIdDate timestampString email
![Page 53: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/53.jpg)
We process 2 million+ registrations per day. A user
can change her email address. However the emails address
must be unique
![Page 54: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/54.jpg)
?How high is the
probability that a validation fails
Which data is required for the validation
Where is the required data stored
![Page 55: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/55.jpg)
$What is the business
impact of a failed validation that is not
recognized due to eventual consistency and how high is the
probability of failure
![Page 56: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/56.jpg)
Your business domain drives the level of consistency
Deeper Insight
D D D
![Page 57: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/57.jpg)
1 Validate from Event Store
2 Validate from Read Store
3 Perform Validation in Event Handler
![Page 58: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/58.jpg)
EventHandler EventsEvents
ValidationIncidentCommandEndpoint
IncidentCommandService
IncidentCommandDAO
IncidentQueryEndpoint
IncidentQueryService
IncidentQueryDAO
Read Storage
Events
Select * from
Event Store
![Page 59: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/59.jpg)
1 Consistency
2 Validation
3 Parallel Updates
![Page 60: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/60.jpg)
Example DomainUser
Guid idString emailString password
RegisterUserCommand ChangeEmailCommand
UserRegisteredEvent Guid idDate timestampString emailString password
EmailChangedEvent Guid userIdDate timestampString email
![Page 61: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/61.jpg)
What happens when Alice and Bob share an
account and both update the email address at the same
time
![Page 62: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/62.jpg)
? What would we do in a
„classic old school architecture“
![Page 63: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/63.jpg)
UserRestController
UserBusinessService
UserDAO
User
ID EMAIL PASSWORD… … …
2341 [email protected] lksjdaslkdjas … … …
Update
Pessimistic or optimistic locking
![Page 64: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/64.jpg)
Your business domain drives the locking quality
Deeper Insight
D D D
![Page 65: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/65.jpg)
!Pessimistic locking on a
data-level will hardly work in event sourcing architectures
![Page 66: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/66.jpg)
EventHandler
EventsEvents
Where to „pessimistically“ lock?
Read Storage
Events
Event Store
UserRestController
UserBusinessService
UserDAO
User
Commands
Consider a business lock with a UserLockedEvent
![Page 67: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/67.jpg)
? Do you
REALLY need a full lock
Most „classic architecture“
applications are already running fine with
optimistic locks
![Page 68: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/68.jpg)
Introduce a version field for the domain entity
User
Guid idLong versionString emailString password
RegisterUserCommand ChangeEmailCommand
UserRegisteredEvent Guid idDate timestampString emailString password
EmailChangedEvent Guid userIdDate timestampString emailLong version
![Page 69: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/69.jpg)
Each writing event increases the version
UserRegisteredEvent {guid: 12, version: 0, email: [email protected], password: werwe2343}
EmailChangedEventversion: 0
EmailChangedEventversion: 1
EmailChangedEventversion: 1
{guid: 12, version: 1, email: [email protected], password: werwe2343}
{guid: 12, version: 2, email: [email protected], password: werwe2343}
EmailChangeFailedEvent
![Page 70: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/70.jpg)
Also here:you should be as
consistent as your domain
requires
![Page 71: Event Sourcing Reactive English - Meetupfiles.meetup.com/14341692/Event Sourcing... · Event Sourcing is an architectural pattern in ... application is being determined by a sequence](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece5935a59d69109e45e4ce/html5/thumbnails/71.jpg)
Thanks!Michael Plöd
https://www.innoq.com/de/trainings/microservices-training/
@bitbosshttp://slideshare.net/[email protected]