Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Welcome to the (state) machine @ Xe One Day Enterprise Applications

72 views

Published on

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)

Published in: Software
  • Be the first to comment

  • Be the first to like this

Welcome to the (state) machine @ Xe One Day Enterprise Applications

  1. 1. #XeOneDay Evento realizzato grazie al supporto di
  2. 2. welcome to the (state) machine It’s all right, I know where you’ve been mauroservienti Mauro Servienti
  3. 3. All I want to do when I wake up in the morning is… (cit. Rosanna, Toto, Toto IV) mauroservienti
  4. 4. mauroservienti
  5. 5. buy ticket(s) stage dive… :-) mauroservienti
  6. 6. All what they want to do is… mauroservienti
  7. 7. mauroservienti
  8. 8. display available tickets reserve ticket(s) charge my credit card deal with insurance ship ticket(s) deal with their stuff mauroservienti
  9. 9. sometimes order doesn’t matter sometimes it does! mauroservienti
  10. 10. Process Manager Connecting the dots… mauroservienti
  11. 11. Tickets Selection Credit Card Gateway/ACL Orders Manager Checkout request AuthorizeCard request/response Reservation Gateway/ACL ConfirmTickets request/response Credit Card Gateway/ACL ChargeCard request/response Insurance Gateway/ACL TicketsInsurance request/response Shipping Gateway/ACL Shiptickets request/response 2-phase commit (kind-of) … mauroservienti Reservation Gateway/ACL SelectTickets request/response
  12. 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
  13. 13. mauroservienti like a Punch Card, a Process Manager owns the process
  14. 14. Ticket(s) Stuff… Insurance mauroservienti
  15. 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
  16. 16. user mental model tends to be UI driven mauroservienti
  17. 17. there is no Spoon Orders Manager mauroservienti
  18. 18. chop up mauroservienti
  19. 19. Autonomy Collaborative Domains mauroservienti
  20. 20. sagas autonomy in collaborative domains mauroservienti
  21. 21. multiple workflows, each providing compensating actions for every step of the workflow where it can fail mauroservienti
  22. 22. multiple workflows, each providing compensating actions for every step of the workflow where it can fail mauroservienti
  23. 23. reserve with the theater charge my credit card deal with insurance ship tickets deal with their stuff mauroservienti
  24. 24. reservation finance insurance shipping stuff mauroservienti
  25. 25. Shipping Finance Tickets Ordering Saga mauroservienti ReservationOrder Checked-out Payment Authorized Order Created Payment Succeeded Available Tickets Select tickets Shopping Cart Proceed to checkout workflow workflow workflow
  26. 26. Shipping Finance Tickets Ordering Saga mauroservienti ReservationOrder Checked-out Payment Authorized Order Created Payment Succeeded Available Tickets Select tickets Shopping Cart Proceed to checkout Policy Policy Policy
  27. 27. Shipping Finance mauroservienti Reservation Available Tickets Select tickets Shopping Cart Proceed to checkout Policy Policy Policy Order Checked-out Payment Authorized Order Created Payment Succeeded Pivotal Events
  28. 28. mauroservienti Let’s open the black box
  29. 29. 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 Order Checked-out Payment Authorized Order CreatedFinance Payment Gateway Charge Card Payment Succeeded Delivery Pick-up Order Shipped
  30. 30. multiple workflows, each providing compensating actions for every step of the workflow where it can fail mauroservienti
  31. 31. 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 Order Checked-out Payment Authorized Order CreatedFinance Payment Gateway Charge Card Payment Succeeded Delivery Pick-up Order Shipped
  32. 32. Payment Gateway Finance Finance Initiate Payment Authorize Card Payment Policy mauroservienti Order Checked-out Payment Authorized Finance Payment Gateway Charge Card Payment Succeeded
  33. 33. Payment Gateway Finance Finance Initiate Payment Authorize Card Payment Policy mauroservienti Order Checked-out Payment Authorized 48hrs to release money
  34. 34. Payment Gateway Finance Finance Initiate Payment Authorize Card Payment Policy mauroservienti Order Checked-out 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…
  35. 35. New requirement • A ticket must be purchased within 10 minutes mauroservienti
  36. 36. 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 Order Checked-out Payment Authorized Order CreatedFinance Payment Gateway Charge Card Payment Succeeded Delivery Pick-up Order Shipped
  37. 37. Reservation Reservation Policy mauroservienti Available Tickets Select tickets Reservation Tickets Reserved 10’ to purchase Reservation Release Tickets N Y Do nothing… Checked-out?Reservation Expired
  38. 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. 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
  40. 40. Shipping ReservationPayment Gateway Finance Finance Initiate Payment Authorize Card Courier Gateway Shipping Policy 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
  41. 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. 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
  43. 43. mauroservienti It’s a business problem
  44. 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. 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. 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. 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
  48. 48. Demos: bit.ly/xe-state-machine Videos: go.particular.net/xe-state-machine Pitfalls • Monitor the (distributed) state mauroservienti
  49. 49. Demos: bit.ly/xe-state-machine Videos: go.particular.net/xe-state-machine Pitfalls • Monitor the (distributed) state • There is no such thing as orchestration • Sagas spanning multiple services mauroservienti
  50. 50. Demos: bit.ly/xe-state-machine Videos: go.particular.net/xe-state-machine Takeaways • Boundaries are key to success • Finding boundaries is the hardest part mauroservienti
  51. 51. Demos: bit.ly/xe-state-machine Videos: go.particular.net/xe-state-machine Takeaways • Boundaries are key to success • Behaviors define how to designs processes • Follow the coupling, not the data • Identify processes and chop them up by “service” mauroservienti
  52. 52. Demos: bit.ly/xe-state-machine Videos: go.particular.net/xe-state-machine Takeaways • Boundaries are key to success • Behaviors define how to designs processes • Use Delayed Messaging to model time • Simplifies making decisions in an async world mauroservienti
  53. 53. @mauroservienti | #EDDD Mauro Servienti Solution Architect @ Particular Software the makers of NServiceBus mauro.servienti@particular.net @mauroservienti //github.com/mauroservienti //milestone.topics.it mauroservienti
  54. 54. @mauroservienti | #EDDD Demos: bit.ly/xe-state-machine Videos: go.particular.net/xe-state-machine mauroservienti

×