SlideShare ist ein Scribd-Unternehmen logo
1 von 53
Downloaden Sie, um offline zu lesen
allardbz nklmish
Scaling CQRS in Theory,
Practice and Reality
Allard Buijze
Founder & CTO, AxonIQ
allard@axoniq.io
allardbz
Nakul Mishra
Sr. Engineer & Architect
nklmish@protonmail.com
nklmish
allardbz nklmish
allardbz nklmish
allardbz nklmish
allardbz nklmish
Layered architecture
User Interface
Service Layer
Data Access Layer
DomainModel
allardbz nklmish
Service
Service
Service
allardbz nklmish
‘Normal’ SQL QUERY
22 JOINS 6 SUBQUERIES
allardbz nklmish
Layered architecture
Ponder and deliberate before you make a move. —Sun Tzu
User Interface
Service Layer
Data Access Layer
DomainModel
Method invocation Cache
Worker pools
Web
Cache
Session replication
Distributed 2nd level cache Query Cache
allardbz nklmish
Source: http://www.sabisabi.com/images/DungBeetle-on-dung.JPG
allardbz nklmish
Microservices systems
• Splittingup systemsinto smaller,
simplercomponents
• Agility
• Scalability
allardbz nklmish
CQRS
allardbz nklmish
Command Query Responsibility
Segregation
Command
model
Projections
Client
Events
T: 1 mln / s
Resp: < 10 ms
T: Thr. 20 / s
Resp: < 100 ms
T: 10 mln / s
Resp. < 100 ms
T: 1 / s
Resp. < 10 ms
allardbz nklmish
allardbz nklmish
Are you tall enough?
Source: martinfowler.com/bliki/MicroservicePrerequisites.html
allardbz nklmish
“Noun Driven Design”
allardbz nklmish
“Entity Services”
è
allardbz nklmish
Monoliths
St Breock Downs Monolith - www.cornwalls.co.uk
allardbz nklmish
$
allardbz nklmish
Location transparency
A Component should not be aware, nor make any
assumptions, of the location of Components it
interacts with
A component should neither be aware of nor make any
assumptions about the location of components it interacts with.
Location transparency starts with good API design
(but doesn’tend there)
allardbz nklmish
Microservices Messaging
Commands Events Queries
Route to single handler
Use consistent hashing
Provide result
Distribute to all logical handlers
Consumers express ordering req’s
No results
Route with load balancing
Sometimes scatter/gather
Provide result
"Event" and “Message" is not the same thing
allardbz nklmish
allardbz nklmish
allardbz nklmish
ComponentB
ComponentAWrites / event sourcing
consume event-A
ComponentC
Projection
consume event - A
Read / replay
Built with Axon Framework
publish event - C
BigData Platform
Readshistoricalevents
consumes new events
EventStore
(Percona)
allardbz nklmish
Casumo
• Event storewith >30 billionevents
• Hundreds of millions of events, every day
• Every event is EQUALLY important
“I was thinkingI might win 50 poundsbut when it went all the way
to the jackpotI was shocked.” - Mega Fortune£2,700,000 jackpot
won on the 3rd spin.
allardbz nklmish
allardbz nklmish
allardbz nklmish
Event Store operations
• Append
• Validate‘sequence’
allardbz nklmish
Event Store operations
• Full sequentialread
allardbz nklmish
Event Store operations
• Read aggregate’sevents
allardbz nklmish
Serialized form
• Keep it small
• Use aliases & abbreviations
• Carefully select serializer
allardbz nklmish
Partitioning and archiving
allardbz nklmish
0: Wallet created
€ 7 in wallet @ 3
2: € 1 wagered
3: € 2 wagered
1: € 10 deposited
4: € 1 wagered
5: € 2000 won
6: € 1000 withdrawn
7: € 10 wagered
8: € 1M jackpot won!!
€ 996 in wallet @ 7
Loading aggregates - snapshots
allardbz nklmish
Replays
Event Handler
TRUNCATE TABLE xyz;Projection
allardbz nklmish
Partial replays
Event Handler
TRUNCATE TABLE xyz;
“Reasonable” timeframe
Idempotent event
handling
Perform selective,
ad-hoc, replays
Projection
allardbz nklmish
allardbz nklmish
Exchange
Queue
Queue
Event Store
allardbz nklmish
Exchange
Queue
Queue
Event Store
Queue
allardbz nklmish
allardbz nklmish
Evolutionary microservices
Commands Events Queries
allardbz nklmish
allardbz nklmish
allardbz nklmish
allardbz nklmish
Unmanageable mess
Bet Placed
Bet Accepted
Bet Won
Bet Lost
Bet Reverted
As a Wallet
module I want to
know when to
withdraw money
from the wallet
allardbz nklmish
Communication = Contract
allardbz nklmish
Bounded context
Explicitlydefinethe context within which a model applies.Explicitly
set boundaries in terms of team organization,usage within specific
parts of the application, and physical manifestationssuch as code
bases and databaseschemas. Keep the model strictly consistentwithin
these bounds,but don’t be distractedor confused by issues outside.
allardbz nklmish
Within a context, share ‘everything’
allardbz nklmish
Between contexts, share ‘consciously’As a Wallet
module I want to
know when to
withdraw money
from the wallet
Bet Placed
Bet Accepted
Bet Won
Bet Lost
Bet Reverted
Bet placed
à Claim Funds
allardbz nklmish
Lessons learned
allardbz nklmish
allardbz nklmish
allardbz nklmish
allardbz nklmish
allardbz nklmish
Thank you!

Weitere ähnliche Inhalte

Ähnlich wie Scaling CQRS in theory, practice, and reality

London devops logging
London devops loggingLondon devops logging
London devops logging
Tomas Doran
 

Ähnlich wie Scaling CQRS in theory, practice, and reality (20)

AWS re:Invent presentation: Unmeltable Infrastructure at Scale by Loggly
AWS re:Invent presentation: Unmeltable Infrastructure at Scale by Loggly AWS re:Invent presentation: Unmeltable Infrastructure at Scale by Loggly
AWS re:Invent presentation: Unmeltable Infrastructure at Scale by Loggly
 
Infrastructure at Scale: Apache Kafka, Twitter Storm & Elastic Search (ARC303...
Infrastructure at Scale: Apache Kafka, Twitter Storm & Elastic Search (ARC303...Infrastructure at Scale: Apache Kafka, Twitter Storm & Elastic Search (ARC303...
Infrastructure at Scale: Apache Kafka, Twitter Storm & Elastic Search (ARC303...
 
London devops logging
London devops loggingLondon devops logging
London devops logging
 
Collecting 600M events/day
Collecting 600M events/dayCollecting 600M events/day
Collecting 600M events/day
 
Getting Buzzed on Buzzwords: Using Cloud & Big Data to Pentest at Scale
Getting Buzzed on Buzzwords: Using Cloud & Big Data to Pentest at ScaleGetting Buzzed on Buzzwords: Using Cloud & Big Data to Pentest at Scale
Getting Buzzed on Buzzwords: Using Cloud & Big Data to Pentest at Scale
 
Solving Visibility and Streaming in The Witcher 3: Wild Hunt with Umbra 3
Solving Visibility and Streaming in The Witcher 3: Wild Hunt with Umbra 3Solving Visibility and Streaming in The Witcher 3: Wild Hunt with Umbra 3
Solving Visibility and Streaming in The Witcher 3: Wild Hunt with Umbra 3
 
MySQL highav Availability
MySQL highav AvailabilityMySQL highav Availability
MySQL highav Availability
 
Distributed Automation(2018) - London Test Automation in Devops Meetup
Distributed Automation(2018) - London Test Automation in Devops MeetupDistributed Automation(2018) - London Test Automation in Devops Meetup
Distributed Automation(2018) - London Test Automation in Devops Meetup
 
Vertically Scaled Design Patters
Vertically Scaled Design PattersVertically Scaled Design Patters
Vertically Scaled Design Patters
 
Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Half way to clean architecture - Dmytro Voronkevych - Droidcon BerlinHalf way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
Half way to clean architecture - Dmytro Voronkevych - Droidcon Berlin
 
Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian GambleClojure Conj 2014 - Paradigms of core.async - Julian Gamble
Clojure Conj 2014 - Paradigms of core.async - Julian Gamble
 
20120116 - NvMgr
20120116 - NvMgr20120116 - NvMgr
20120116 - NvMgr
 
Linux Integrity Mechanisms - Protecting Container Runtime as an example
Linux Integrity Mechanisms - Protecting Container Runtime as an exampleLinux Integrity Mechanisms - Protecting Container Runtime as an example
Linux Integrity Mechanisms - Protecting Container Runtime as an example
 
Performance & Scalability Improvements in Perforce
Performance & Scalability Improvements in PerforcePerformance & Scalability Improvements in Perforce
Performance & Scalability Improvements in Perforce
 
Concurrency in Python
Concurrency in PythonConcurrency in Python
Concurrency in Python
 
GOD MODE Unlocked: Hardware backdoors in x86 CPUs
GOD MODE Unlocked: Hardware backdoors in x86 CPUsGOD MODE Unlocked: Hardware backdoors in x86 CPUs
GOD MODE Unlocked: Hardware backdoors in x86 CPUs
 
FreeBSD 2014 Flame Graphs
FreeBSD 2014 Flame GraphsFreeBSD 2014 Flame Graphs
FreeBSD 2014 Flame Graphs
 
Deploying the 'League of Legends' Data Pipeline with Chef (ARC205) | AWS re:I...
Deploying the 'League of Legends' Data Pipeline with Chef (ARC205) | AWS re:I...Deploying the 'League of Legends' Data Pipeline with Chef (ARC205) | AWS re:I...
Deploying the 'League of Legends' Data Pipeline with Chef (ARC205) | AWS re:I...
 
Finding an unusual cause of max_user_connections in MySQL
Finding an unusual cause of max_user_connections in MySQLFinding an unusual cause of max_user_connections in MySQL
Finding an unusual cause of max_user_connections in MySQL
 
Cucumber
CucumberCucumber
Cucumber
 

Mehr von nklmish

Mehr von nklmish (10)

Demystifying Kafka
Demystifying KafkaDemystifying Kafka
Demystifying Kafka
 
CQRS and EventSourcing with Spring & Axon
CQRS and EventSourcing with Spring & AxonCQRS and EventSourcing with Spring & Axon
CQRS and EventSourcing with Spring & Axon
 
(SPRING)KAFKA - ONE MORE ARSENAL IN A DISTRIBUTED TOOLBOX
(SPRING)KAFKA - ONE MORE ARSENAL IN A DISTRIBUTED TOOLBOX(SPRING)KAFKA - ONE MORE ARSENAL IN A DISTRIBUTED TOOLBOX
(SPRING)KAFKA - ONE MORE ARSENAL IN A DISTRIBUTED TOOLBOX
 
Kotlin boost yourproductivity
Kotlin boost yourproductivityKotlin boost yourproductivity
Kotlin boost yourproductivity
 
Distributed tracing - get a grasp on your production
Distributed tracing - get a grasp on your productionDistributed tracing - get a grasp on your production
Distributed tracing - get a grasp on your production
 
Spock
SpockSpock
Spock
 
Microservice no fluff, the REAL stuff
Microservice no fluff, the REAL stuffMicroservice no fluff, the REAL stuff
Microservice no fluff, the REAL stuff
 
Neo4J
Neo4JNeo4J
Neo4J
 
Mongo - an intermediate introduction
Mongo - an intermediate introductionMongo - an intermediate introduction
Mongo - an intermediate introduction
 
Detailed Introduction To Docker
Detailed Introduction To DockerDetailed Introduction To Docker
Detailed Introduction To Docker
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Scaling CQRS in theory, practice, and reality