Date post: | 15-Jul-2015 |
Category: |
Technology |
Upload: | jan-kronquist |
View: | 137 times |
Download: | 0 times |
Consistency
User A
User B
Get
Get
Buy!
Buy!!
One ticket left!
One ticket left!
User C Get Buy!!
One ticket left!
User D Get
No tickets!
Consistency
User A
User B
Get
Get
Buy!
Buy!!
One ticket left!
One ticket left!
User C Get Buy!!
One ticket left!
User D Get
No tickets!
Eventual Consistency
User A
User B
Get
Get
Buy!
Buy!!
One ticket left!
One ticket left!
User C Get Buy!!
One ticket left!
User D Get
No tickets!
Buy!!
One ticket left!
CQRS
Command Query Responsibility Segregation!
Commands - action that will modify state!
Queries - anything that view state!
The handling of commands and queries are separated
ProjectionProjection
Common CQRS Architecture
API
Aggregate
Message Bus
Projection
Commands Queries
EventsEventsNot possible to view!
Micro Service Architecture
API Gateway
Service A
Message Bus
Service B
Request Request
MessageMessage
Validation vs Business rules
Validation!Correct structure!
Ranges, lengths, types!
Rules!Should we do this?!
What should happen
When creating the command
When executing the command
CQRS scalability
Queries!Add more nodes for linear scalability!!
Commands!Partitioning!
Process asynchronously
Event vs Command
Event - Something that has happened!UserCreatedEvent!
FriendRequestReceivedEvent!
TicketSoldEvent!
Command - Something we want to happened!
CreateUserCommand!
SendFriendRequestCommand!
BuyTicketCommand
Event sourcing
All changes recorded as Events!
Order (time) is preserved!
The event log is THE persistent source
Aggregates
Unit of consistency!
Example: user, meeting, order, product, game
MeetingCreated
AttendeeAdded A
AttendeeAdded B
AttendeeRemoved A
AttendeeAdded C
Attendees: A
Attendees: A & B
Attendees: B
Attendees: B & C
Event Stream
Application Service
Aggregate
Command Handler
Event Handler
Inside the aggregate
Command HandlerCommand
Old eventsEvent Handler
New events
Event Store
http://rps.com
The future Facebook of Rock Paper Scissors!
Millions of users!
Many games per user
Playing the game
Player A
Player B
Server
rock
paperPlayer B: paper
Player A: rock
Game 123
Game 123 winner: Player B loser: Player A
CREATED WAITING
GAME WON
GAME TIED
any move
other move (victory)
other move (tie)
T