Slides from my presentation at O'Reilly Software Architecture 2018, co-presented with Allard Buijze.
Much hyped architectural pattern CQRS is getting a lot of attention, but it does actually deliver on its promises of managing complexity and scalability when used with the right abstractions. Casumo, a Malta-based online casino, adopted the principles of CQRS based on these promises. As the company scaled to hundreds of employees and over a hundred services, these promises were put to the challenge.
Allard Buijze and Nakul Mishra discuss the challenges Casumo faced while scaling its system to millions of financial transactions per day and applying event sourcing with billions of events to keep up with the ever-changing demands of the gaming industry.
8. 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
12. 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
19. 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)
20. 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
23. 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)
24. 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.
43. 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
45. 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.
47. 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