CQRS: Event Processing To Query-Databases
CQRS: Event Processing To Query-Databases
CQRS: Event Processing To Query-Databases
Processing events
Martijn Blankestijn
@MartijnBlankest
Roadmap
Why this talk
Event Sourcing & CQRS
Query side processing
Why?
Appointments
Make
Move
Reassign
Conclude
Cancel
Environment
DC1 DC2
Node 1 Node 2 Node 1 Node 2
Cassandra
Cassandra
Model around your queries
determine what queries to support
create a table for that query 1 partition
Event Sourcing
'ensures that all changes
to application state
are stored as a
sequence of events.
https://martinfowler.com/eaaDev/EventSourcing.html
Time
Created
10:00 12:00 9th Nov
Events with Smith
in Amsterdam
Created Moved
14:00 16:00 2th Nov
10:00 12:00 9th Nov
Events with Smith
with Jones
in Amsterdam
in Amsterdam
Bid has been made
Created Moved
10:00 12:00 9th Nov
14:00 16:00 2th Nov Concluded
Events with Jones 5-star
with Smith
in Amsterdam product sold
in Amsterdam
Bid has been made
projector
projector
projector
projection
query Query
Database
Query
Query
Advantages CQRS with ES
Scale read/write independently
Scale Query side per use-case
CHOOSE
CQRS with Event Sourcing Frameworks
Kafka as event store
Axon Framework
Eventuate
Akka Persistence
Persistence
Persistent Actor
Journal
Datacenter 1 Datacenter 2
http
command
PA
event
cassandra
Cassandra Events table
persistence_id |partition_nr|sequence_nr |timestamp|timebucket
7c7ec816-efc6... |0 |1 |8ef7f9...|20171018
7c7ec816-efc6... |0 |2 |99e314...|20171018
7c7ec816-efc6... |0 |3 |a41f2b...|20171018
eventual-consistency-delay=100ms
id seq timestamp
A 1 04.709
B 1 04.731
delayed-event-timeout = 1000ms
C 1 04.801
A 3 04.824 STOP
C 2 04.957
NOW (920)
eventual-consistency-delay=100ms
id seq timestamp
A 1 04.709
B 1 04.731
A 2 04.768
C 1 04.801
A 3 04.824
C 2 04.957
A 4 04.973
NOW (05.063)
NO ONE WANTS
EVENTUAL CONSISTENCY.
IT'S A NECESSARY EVIL.
IT'S NOT COOL. IT'S USEFUL.
Jonas Bonr
How much
latency
can you
accept ?
Environment
DC1 DC2
Node 1 Node 2 Node 1 Node 2
Cassandra
In parallel
A 3
B 8
A 4
D 1
A 3 B 8
D 1 A 4
Read-side Sharding
Read side Sharding
New &
Original
Shiny
The Dark Side
of Event Sourcing:
Managing Data Conversion
http://files.movereem.nl/2017saner-eventsourcing.pdf
Event store upgrade techniques
Multiple versions
Upcasting
Lazy transformation
In place transformation
Copy and transformation
Event store upgrade techniques
Read-side impact
Multiple versions -
Upcasting +
Lazy transformation +
In place transformation ++
Copy and transformation ++
Pull
Write Event
Side Processor
eventsByTag
Push
Akka Cluster
register
Write Event
notify
Side Processor
eventsByTag
In conclusion
CQRS and Event Sourcing
Query side processing
resumability
event order
requirement changes
scale
push vs pull
@MartijnBlankest