SlideShare una empresa de Scribd logo
1 de 52
welcome to the
(state) machine
It’s all right, I know where you’ve been
mauroservienti
Mauro Servienti
All I want to do when I wake up in
the morning is…
(cit. Rosanna, Toto, Toto IV)
mauroservienti
mauroservienti
buy ticket(s)
stage dive… :-)
mauroservienti
All what they want to do is…
mauroservienti
mauroservienti
display available tickets
reserve ticket(s)
charge my credit card
ship ticket(s)
mauroservienti
sometimes order doesn’t matter
sometimes it does!
mauroservienti
Naïve way
var seats = await DisplayAvailableSeats();
var selectedSeats = seats.Take(2);
var reservation = await ReserveSeats(selectedSeats);
var authorization = await AuthorizeCard(reservation);
if (authorization.Succeeded)
{
await ChargeCard(authorization);
await ShipTickets(reservation);
}
mauroservienti
Naïve way
var seats = await DisplayAvailableSeats();
var selectedSeats = seats.Take(2);
var reservation = await ReserveSeats(selectedSeats);
var authorization = await AuthorizeCard(reservation);
if (authorization.Succeeded)
{
await ChargeCard(authorization);
await ShipTickets(reservation);
}
Remote requests
mauroservienti
Remote requests
Tickets Selection
Credit Card
Gateway/ACL
Orders Manager
Order Checked-out
AuthorizeCard
request/response
Reservation
ConfirmTickets
request/response
Credit Card
Gateway/ACL
ChargeCard
request/response
Shipping
Gateway/ACL
Shiptickets
request/response
mauroservienti
Reservation
SelectTickets
request/response
Process Managers
Tickets Selection
Credit Card
Gateway/ACL
Orders Manager
Checkout request
AuthorizeCard
request/response
Reservation
ConfirmTickets
request/response
Credit Card
Gateway/ACL
ChargeCard
request/response
Shipping
Gateway/ACL
Shiptickets
request/response
Some sort of orchestration is still required
mauroservienti
Reservation
SelectTickets
request/response
Process Managers
Orchestration is not the only
issue we should get rid of…
Process Managers (a different point of view)
New requirement: collect tickets at the venue
OrderId ShippingId ShippingStatus Etc
12 1337 Delivered …
58 1338 Pending …
Orders table
mauroservienti
mauroservienti
like a punch card
Process Managers
own the process
Ticket(s)
Insurance
mauroservienti
Process Managers, a retrospective.
•Violate Single Responsibility Principle
•Single Unit of Deployment
•Conflicting Changes/Merge Conflicts
•Contention/Performance Bottleneck
mauroservienti
mauroservienti
there is no Spoon
Process Manager
chop
up
mauroservienti
Autonomy
Collaborative Domains
mauroservienti
sagas autonomy in
collaborative domains
mauroservienti
multiple workflows,
each providing
compensating
actions for every
step of the
workflow where it
can fail
mauroservienti
multiple workflows,
each providing
compensating
actions for every
step of the
workflow where it
can fail
mauroservienti
reserve ticket(s)
charge my credit card
ship tickets
mauroservienti
Shipping
Finance
Tickets Ordering Saga
mauroservienti
ReservationReservation
Checked-out
Payment Authorized
Order Created
Payment Succeeded
Available Tickets
Select tickets
Shopping Cart
Proceed to checkout
workflow
workflow
workflow
Shipping
Finance
Tickets Ordering Saga
mauroservienti
ReservationReservation
Checked-out
Payment Authorized
Order Created
Payment Succeeded
Available Tickets
Select tickets
Shopping Cart
Proceed to checkout
Policy
Policy
Policy
Shipping
Finance
mauroservienti
Reservation
Available Tickets
Select tickets
Shopping Cart
Proceed to checkout
Policy
Policy
Policy
Reservation
Checked-out
Payment Authorized
Order Created
Payment Succeeded
Pivotal Events
mauroservienti
Let’s open the black box
Shipping
ReservationPayment
Gateway
Finance
Finance
Initiate Payment
Authorize Card
Courier
Gateway
Tickets Ordering Saga
mauroservienti
Available Tickets
Select tickets
Reservation
Shopping Cart
Proceed to checkout
Reservation
Reservation
Checked-out
Payment Authorized
Order CreatedFinance
Payment
Gateway
Charge Card
Payment Succeeded Delivery Pick-up
Sounds more complex than
the naïve approach, doesn’t it?
mauroservienti
New requirement
• Collect tickets at the venue
mauroservienti
Shipping
ReservationPayment
Gateway
Finance
Finance
Initiate Payment
Authorize Card
Courier
Gateway
mauroservienti
Available Tickets
Select tickets
Reservation
Shopping Cart
Proceed to checkout
Reservation
Reservation
Checked-out
Payment Authorized
Order CreatedFinance
Payment
Gateway
Charge Card
Payment Succeeded Delivery Pick-up
Shipping Policy
Order Created Payment Succeeded
NY
Batch Shipping
at the Venue
Policy
Store for Venue
Delivery
Mark as Complete
Courier
Gateway
Batch Delivery Pick-up
Courier
Gateway
Delivery Pick-up
Deliver Tickets
Mark as Complete
mauroservienti
Shipping Policy
Shipping Policy
Delivery-Mode:
- Collect-at-the-Venue
- Ship-at-Home
?
Is Collect-at-the-Venue?
Order Created Payment Succeeded
NY
Store for Venue
Delivery
Mark as Complete
Courier
Gateway
Delivery Pick-up
Deliver Tickets
Mark as Complete
mauroservienti
Shipping Policy
Shipping Policy
Delivery-Mode:
- Collect-at-the-Venue
- Ship-at-Home
?
Is Collect-at-the-Venue?
Batch Shipping
at the Venue
Policy
Courier
Gateway
Batch Delivery Pick-up
Mark as Complete
multiple workflows,
each providing
compensating
actions for every
step of the
workflow where it
can fail
mauroservienti
Shipping
ReservationPayment
Gateway
Finance
Finance
Initiate Payment
Authorize Card
Courier
Gateway
Tickets Ordering Saga
mauroservienti
Available Tickets
Select tickets
Reservation
Shopping Cart
Proceed to checkout
Reservation
Reservation
Checked-out
Payment Authorized
Order CreatedFinance
Payment
Gateway
Charge Card
Payment Succeeded Delivery Pick-up
Payment
Gateway
Finance
Finance
Initiate Payment
Authorize Card
Payment Policy
mauroservienti
Reservation
Checked-out
Payment Authorized
Finance
Payment
Gateway
Charge Card
Payment Succeeded
Do we need a
Reservation Failed event?
Payment
Gateway
Finance
Finance
Initiate Payment
Authorize Card
Payment Policy
mauroservienti
Payment Authorized
48hrs to release money
Reservation
Checked-out
Reservation
Checked-out
Payment
Gateway
Finance
Finance
Initiate Payment
Authorize Card
Payment Policy
mauroservienti
Payment Authorized
Finance
Payment
Gateway
Charge Card
Payment Succeeded
48hrs to release money
Payment
Gateway
Release Money
Reserved?N
Y
Do nothing… Reservation
Order Created
48hrs later…
Mark as Complete
What’s a timeout?
void Handle(ReservationCheckedout evt)
{
Send(new AuthorizationRequest(…));
}
void Handle(AuthorizationRequest msg)
{
var authId = await AuthorizeCard(…);
Reply(new AuthorizationResponse(authId));
}
void Handle(AuthorizationResponse msg)
{
Publish(new PaymentAuthorized());
RequestTimeout(TimeSpan.FromHours(48));
}
void Timeout()
{
if(NotReserved){ … }
}
Payment
Gateway
Finance
Authorize Card
Payment Authorized
48hrs to release money
Reservation
Checked-out
Reserved?
Payment
Gateway
FinanceFinanceFinance
What’s a timeout?
void Handle(ReservationCheckedout evt)
{
Send(new AuthorizationRequest(…));
}
void Handle(AuthorizationRequest msg)
{
var authId = await AuthorizeCard(…);
Reply(new AuthorizationResponse(authId));
}
void Handle(AuthorizationResponse msg)
{
Publish(new PaymentAuthorized());
RequestTimeout(TimeSpan.FromHours(48));
}
void Timeout()
{
if(NotReserved){ … }
}
Payment
Gateway
Finance
Authorize Card
Payment Authorized
48hrs to release money
Reservation
Checked-out
Reserved?
Payment
Gateway
FinanceFinanceFinance
What’s a timeout?
void Handle(ReservationCheckedout evt)
{
Send(new AuthorizationRequest(…));
}
void Handle(AuthorizationRequest msg)
{
var authId = await AuthorizeCard(…);
Reply(new AuthorizationResponse(authId));
}
void Handle(AuthorizationResponse msg)
{
Publish(new PaymentAuthorized());
RequestTimeout(TimeSpan.FromHours(48));
}
void Timeout()
{
if(NotReserved){ … }
}
Payment
Gateway
Finance
Authorize Card
Payment Authorized
48hrs to release money
Reservation
Checked-out
Reserved?
Payment
Gateway
FinanceFinanceFinance
Sagas (a different point of view)
OrderId ShippingId ShippingStatus Etc
12 1337 Delivered …
58 1338 Pending …
Orders table
Reservation Shipping Finance
OrderId TicketId
12 ABC
58 ACD
Reservations table
OrderId Address
12 Milan, Italy
58 Paris, France
Shipping table
OrderId Status
12 Paid
58 Overdue
Invoices table
VS
mauroservienti
Sagas (a different point of view)
Reservation Shipping Finance
Reservations table
OrderId Address
12 Milan, Italy
58 Paris, France
Shipping table
OrderId Status
12 Paid
58 Overdue
Invoices table
mauroservienti
Each service can evolve independently
OrderId TicketId
12 ABC
58 ACD
Sagas
•Business Process is distributed
•Respect Single Responsibility Principle
•Simpler/not conflicting evolution
•Independent Units of Deployment
•Independent scale out
mauroservienti
Every year is getting shorter
never seem to find the time…
Sagas Demo
bit.ly/eddd-state-machine
Udi Dahan about Sagas
go.particular.net/eddd-state-machine
mauroservienti
Demos: bit.ly/eddd-state-machine
Videos: go.particular.net/eddd-state-machine
Pitfalls
• Monitor the (distributed) state
mauroservienti
Demos: bit.ly/eddd-state-machine
Videos: go.particular.net/eddd-state-machine
Takeaways
• Behaviors define how to designs processes
• Follow the coupling, not the data
• Identify processes and chop them up by “service”
mauroservienti
Demos: bit.ly/eddd-state-machine
Videos: go.particular.net/eddd-state-machine
Takeaways
• Behaviors define how to designs processes
• Use Delayed Messaging to model time
• Simplifies making decisions in an async world
mauroservienti
there is no
such thing as
orchestration
mauroservienti
@mauroservienti | #EDDD
Mauro Servienti
Solution Architect @ Particular Software
the makers of NServiceBus
mauro.servienti@particular.net
@mauroservienti
//github.com/mauroservienti
//milestone.topics.it
mauroservienti
@mauroservienti | #EDDD
Demos: bit.ly/eddd-state-machine
Videos: go.particular.net/eddd-state-machine
mauroservienti

Más contenido relacionado

Más de Mauro Servienti

Más de Mauro Servienti (20)

PO is dead, long live the PO - Italian Agile Day 2018
PO is dead, long live the PO - Italian Agile Day 2018PO is dead, long live the PO - Italian Agile Day 2018
PO is dead, long live the PO - Italian Agile Day 2018
 
Design a UI for your Microservices @ Do IT Better
Design a UI for your Microservices @ Do IT BetterDesign a UI for your Microservices @ Do IT Better
Design a UI for your Microservices @ Do IT Better
 
Microservices and pineapple on pizza what do they have in common - dos and ...
Microservices and pineapple on pizza   what do they have in common - dos and ...Microservices and pineapple on pizza   what do they have in common - dos and ...
Microservices and pineapple on pizza what do they have in common - dos and ...
 
All our aggregates are wrong (ExploreDDD 2018)
All our aggregates are wrong (ExploreDDD 2018)All our aggregates are wrong (ExploreDDD 2018)
All our aggregates are wrong (ExploreDDD 2018)
 
Designing a ui for microservices
Designing a ui for microservicesDesigning a ui for microservices
Designing a ui for microservices
 
Po is dead, long live the po
Po is dead, long live the poPo is dead, long live the po
Po is dead, long live the po
 
Shipping code is not the problem, deciding what to ship it is!
Shipping code is not the problem, deciding what to ship it is!Shipping code is not the problem, deciding what to ship it is!
Shipping code is not the problem, deciding what to ship it is!
 
GraphQL - Where are you from? Where are you going?
GraphQL - Where are you from? Where are you going?GraphQL - Where are you from? Where are you going?
GraphQL - Where are you from? Where are you going?
 
Dall'idea al deploy un lungo viaggio che passa per git flow e semver
Dall'idea al deploy   un lungo viaggio che passa per git flow e semverDall'idea al deploy   un lungo viaggio che passa per git flow e semver
Dall'idea al deploy un lungo viaggio che passa per git flow e semver
 
Progettare una UI per i Microservices
Progettare una UI per i MicroservicesProgettare una UI per i Microservices
Progettare una UI per i Microservices
 
The road to a Service Oriented Architecture is paved with messages
The road to a Service Oriented Architecture is paved with messagesThe road to a Service Oriented Architecture is paved with messages
The road to a Service Oriented Architecture is paved with messages
 
La via verso SOA è lastricata di messaggi
La via verso SOA è lastricata di messaggiLa via verso SOA è lastricata di messaggi
La via verso SOA è lastricata di messaggi
 
Implementare il single sign on con IdentityServer
Implementare il single sign on con IdentityServerImplementare il single sign on con IdentityServer
Implementare il single sign on con IdentityServer
 
How we daily manage and work in a dispersed company: Particular Software
How we daily manage and work in a dispersed company: Particular SoftwareHow we daily manage and work in a dispersed company: Particular Software
How we daily manage and work in a dispersed company: Particular Software
 
From cogs to nirvana
From cogs to nirvanaFrom cogs to nirvana
From cogs to nirvana
 
DevOps e scelte architetturali: tre scenari reali
DevOps e scelte architetturali: tre scenari realiDevOps e scelte architetturali: tre scenari reali
DevOps e scelte architetturali: tre scenari reali
 
Croce e delizia del lavoro remoto
Croce e delizia del lavoro remotoCroce e delizia del lavoro remoto
Croce e delizia del lavoro remoto
 
Croce e delizia del lavoro remoto
Croce e delizia del lavoro remotoCroce e delizia del lavoro remoto
Croce e delizia del lavoro remoto
 
Applicazioni event driven__un_esempio_con_angular_js.
Applicazioni event driven__un_esempio_con_angular_js.Applicazioni event driven__un_esempio_con_angular_js.
Applicazioni event driven__un_esempio_con_angular_js.
 
Designing a ui for microservices
Designing a ui for microservicesDesigning a ui for microservices
Designing a ui for microservices
 

Último

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Último (20)

%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 

Welcome to the (state) machine @ ExploreDDD 2019

Notas del editor

  1. Red Hot Chili Peppers, 1989 Ritmo tribale Litfiba
  2. Surface vs Highways
  3. tricked by domain experts, they talk about tickets ordering process
  4. What’s a collaborative domain? IKEA furniture and shipping at a retail shop