際際滷

際際滷Share a Scribd company logo
Event Sourcing
patterns
Stats about me
 Name: Radu Iscu
 Years of copy-pasting code professionally: 10
 Technologies outlived: .net 1.x, Flash, Flex, Web
Forms, Web parts
 Programming languages outlived: Turbo Pascal,
Perl, PHP, Action Script 2-3, Visual Basic .net
 Programming languages: c#, javascript, scala
What is event sourcing?
Event based architecture
Often talked about, never
explained
Data access patterns
Event store
WORM log of events that
happened
Examples
Bank account
Patient journal
Patient journal
Sidequest:
Data structure properties
Multiple kinds of projections
It captures behavior
It captures behavior
It is replayable and undoable
It is easily duplicated
Easy to duplicate through replay
Index
 Events by user ID
 Events by company ID
 Events by event type
 Events by event sender
Snapshots
Hydrator
Cache
Event versioning
ATM pull v1 ATM pull v2 ATM pull v3
Bank
deposit v1
Bank
deposit v2
Bank
deposit v3
Request for
statement
v1
Request for
statement
v2
Request for
statement
v3
Undoing changes
Original
event
 State is OK
Problem
event(s)
 Events are added that put the system in an error state
Changes
 New events are impacted
Re-add
original state
 Read the original state
 Reapply changes
Patterns of use
Projections
Pipelines/Conveyor
belts/Streams
Request
received
Validate
objects
Increment
request
count
Business
logic
Cache
response
send
Map/Transformation
Event
v1
Event v2 Event v3 Event v4
Request
event
Rehydration
transform
Business
logic
transform
Response
event
Dispatcher
Throttle
State machine
Workflow
Composability
Retry pipeline
Event
 Send fail event
 Original event
Transform
 Increment try count on original event
State
machine
 If try count > max tries => dump
 If try count < max tries => send
Dispatcher
 Send message
 Log message send attempt
Load balancer
State
machine
 Use information from the events to
decide where they go
 Mark events accordingly
Dispatcher
 Send events based on markings made
by state machine
Things to consider
Interacting with outside systems
 Time bound values (i.e. money)
 Systems where reads have side effects (i.e. credit
scores)
 Log everything that you send
Technical stuff
(Logo slides)
EventStore (getEventStore.com)
Apache Kafka
Indexers/projections
Reading/watching list
Article about event sourcing with some code
samples
 https://martinfowler.com/eaaDev/EventSourcing.h
tml
Presentation about event sourcing
 https://www.youtube.com/watch?v=JHGkaShoyNs
Presentation about source control as data
https://www.youtube.com/watch?v=KaLROwp-VDY
Call to action

More Related Content

Event sourcing 3