Ultimamente ci hanno stressato come non mai che stateful è il male. Tutto deve essere stateless, altrimenti non scala, non può essere altamente disponibile, ed è complesso da manutenere ed evolvere. Nonostante questo i sistemi software complessi, essendo basati su processi collaborativi, sono per natura stateful. I processi collaborativi, noti anche come long running business transactions, necessitano di interagiscono con risorse distribuite. L’approccio tradizionale basato su transazioni distribuite, anche se allettante, è una bomba pronta ad esplodere.
Pane quotidiano per le Saghe. Le Saghe consentono di modellare sistemi complessi senza la necessità di transazioni distribuite e coordinamento esterno. Vedremo cosa sono le Saghe, come possono essere usate per modellare domini complessi, e che ruolo giocano quando progettiamo sistemi basati sui concetti di “design for failures” e “eventual consistency”
(It’s all right, I know where you’ve been)
12. Process Manager (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
15. Process Managers, a source of coupling
•Violates Single Responsibility Principle
•Contention/Performance Bottleneck
•Conflicting Changes/Merge Conflicts
•Single Unit of Deployment
•Single Point of Failure
mauroservienti
38. Shipping
ReservationPayment
Gateway
Finance
Finance
Initiate Payment
Authorize Card
Courier
Gateway
Tickets Ordering Saga
mauroservienti
Available Tickets
Select tickets
Reservation Tickets Added to Cart Reservation
Shopping Cart
Proceed to checkout
Reservation
Order Checked-out
Payment Authorized
Order CreatedFinance
Payment
Gateway
Charge Card
Payment Succeeded Delivery Pick-up
Order Shipped
10’ to purchase
48hrs to release money
39. New requirement
• 12-hours delivery SLA with our customers
• if the default shipping courier doesn't respond
• contact another one to deliver the package
mauroservienti
41. Shipping
Order Shipped
…
First Courier
Gateway
Pick-up Request
Shipping
Shipping
Second Courier
Gateway
Pick-up Request
Shipping
Shipping
Have we received a response?
Shipment Failed
…
mauroservienti
8hrs timeout
Shipping Policy
Have we received a response?
?
2hrs escalation timeout
N
N?Y
Y
42. Concurrency
1. Pick-up request to 1st courier
2. 8 hours go by
3. No response yet
4. Pick-up request to 2nd courier
5. 2nd courier replies
6. 1st courier replies…Ooops
mauroservienti
44. Sagas (a different point of view)
OrderId ShippingId ShippingStatus Etc
12 1337 Delivered …
58 1338 Pending …
Orders table
Reservation Shipping Finance
Id TicketId
12 ABC
58 ACD
Reservations table
OrderId Address
12 Haifa, Israel
58 Rotterdam, Holland
Shipping table
OrderId Status
12 Paid
58 Overdue
Invoices table
VS
mauroservienti
45. Sagas (a different point of view)
Reservation Shipping Finance
Id TicketId
12 ABC
58 ACD
Reservations table
OrderId Address
12 Haifa, Israel
58 Rotterdam, Holland
Shipping table
OrderId Status
12 Paid
58 Overdue
Invoices table
mauroservienti
Each service can evolve independently
46. Sagas
•Business Process is distributed
•No overarching Process Manager
•Respect Single Responsibility Principle
•Independent scale out
•Simpler/not conflicting evolution
•Independent Units of Deployment
mauroservienti
47. Every year is getting shorter never seem to find the time…
Sagas Demo
bit.ly/xe-state-machine
Udi Dahan about Sagas
go.particular.net/xe-state-machine
mauroservienti
Let me tell that you of that time when {the vendor I cannot name} gifted me with a nice {flat x86 device with a very thin keyboard}
{the story}
It’s obvious that there are two very different point of views here.