O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Serverless Days 2019 - Lost in transaction

418 visualizações

Publicada em

Slides from my talk at Serverless Days Hamburg 2019 about how to avoid getting lost in transaction, how to coordinate multiple functions and how Sagas might help.

Source code is here: https://github.com/berndruecker/trip-booking-saga-serverless

Publicada em: Tecnologia
  • Seja o primeiro a comentar

Serverless Days 2019 - Lost in transaction

  1. 1. @berndruecker Lost in transaction? Strategies to manage consistency in serverless architectures
  2. 2. An example for today – the classical one book hotel book car book flight 1. 2. 3.book trip
  3. 3. Functions λ Book Car λ Book Hotel λ Book Flight
  4. 4. Function collaboration See also e.g. Function Composition in a Serverless World by Timirah James λ Book Car λ Book Hotel λ Book Flight ?
  5. 5. Merged function λ (Trip) // book har $.post(carHireUrl, ... // book hotel $.post(carHireUrl, ... Car.js Hotel.js Easy to do No overhead Big functions Hard to maintain No independent scaling
  6. 6. Choreography λ (Car) $.post(carHireUrl, ... invokeHotel() λ (Hotel) $.post(carHireUrl, ... Chaining λ (Car) $.post(carHireUrl, ... carBookedEvent() λ (Hotel) $.post(carHireUrl, ... Event-Chain No extra framework needed Hard to understand the flow Changing the sequence is hard
  7. 7. Orchestration: Coordinator function λ (Trip) λ (Car) $.post(carHireUrl, ... λ (Hotel) $.post(carHireUrl, ... // book har invokeCar() // book hotel invokeHotel() Functions keep independant Coordinator get‘s long running
  8. 8. Orchestration: Workflow λ (Trip) // book har startTripWorkflow() λ (Car) $.post(carHireUrl, ... λ (Hotel) $.post(carHireUrl, ... Workflow Engine Car -> Hotel -> ... Functions keep independant No long running function Extra component involved
  9. 9. Warning: Contains Opinion
  10. 10. Berlin, Germany bernd.ruecker@camunda.com @berndruecker Bernd Ruecker Co-founder and Technologist of Camunda
  11. 11. Example λ (Car) λ (Hotel) Workflow Engine λ (Flight)λ (Trip)
  12. 12. Distributed
  13. 13. Distributed systems
  14. 14. You might need to leverage retrying λ (Car) λ (Hotel) Workflow Engine λ (Flight)λ (Trip)
  15. 15. You might need to leverage stateful retrying λ (Car) λ (Hotel) Workflow Engine λ (Flight)λ (Trip)
  16. 16. Photo by pixabay, available under Creative Commons CC0 1.0 license.
  17. 17. Requirement: Idempotency of services! Photo by pixabay, available under Creative Commons CC0 1.0 license.
  18. 18. Requirement: Idempotency of services! Photo by Chr.Späth, available under Public Domain.
  19. 19. Make the world a better place. Make your functions idempotent.
  20. 20. @berndruecker Lost in transaction? Strategies to manage consistency in serverless architectures
  21. 21. Book Car Book Hotel All or nothing + try { tx.begin(); bookCar(); bookHotel(); tx.commit(); } catch (Exception e) { tx.rollback(); } Once upon a time:
  22. 22. A C I D Atomicity Consistency Isolation Durability
  23. 23. Pat Helland “ Distributed Systems Guru Worked at Amazon, Microsoft & Salesforce
  24. 24. Pat Helland Grown-Ups Don’t Use Distributed Transactions “ Distributed Systems Guru Worked at Amazon, Microsoft & Salesforce
  25. 25. Starbucks does not use two phase commit https://www.enterpriseintegrationpatterns.com/ramblings/18_starbucks.html Photo by John Ingle
  26. 26. Eric Brewer Atomicity Consistency Isolation Durability http://pld.cs.luc.edu/courses/353/spr11/notes/brewer_keynote.pdf
  27. 27. That means Do A Do B Temporarily inconsistent Eventually consistent again t Consistent Local ACID Local ACID 1 function 1 (micro-)service 1 aggregate 1 program 1 resource Violates „I“ of ACID
  28. 28. Youmightknowthisfrom: Do A Do B Temporarily inconsistent Eventually consistent again t Consistent Photo by Gerhard51, available under Creative Commons CC0 1.0 license.
  29. 29. we need to embrace eventual consistency
  30. 30. function
  31. 31. The classical example Saga book hotel book car book flight cancel hotel cancel car 1. 2. 3. 5.6. In case of failure trigger compensations book trip
  32. 32. Choreography & orchestration
  33. 33. Event-driven choreography Hotel Flight Car Trip Trip booked Flight booked Trip requested Hotel booked Car booked Request trip
  34. 34. Event-driven choreography Hotel Flight Car Trip Trip failed Trip requested Hotel booked Car booked Request trip Flight failed Car canceled Hotel canceled Perform undo (cancel car booking) Perform undo (cancel hotel)
  35. 35. The danger is that it's very easy to make nicely decoupled systems with event notification, without realizing that you're losing sight of that larger-scale flow, and thus set yourself up for trouble in future years. https://martinfowler.com/articles/201701-event-driven.html
  36. 36. The danger is that it's very easy to make nicely decoupled systems with event notification, without realizing that you're losing sight of that larger-scale flow, and thus set yourself up for trouble in future years. https://martinfowler.com/articles/201701-event-driven.html
  37. 37. The danger is that it's very easy to make nicely decoupled systems with event notification, without realizing that you're losing sight of that larger-scale flow, and thus set yourself up for trouble in future years. https://martinfowler.com/articles/201701-event-driven.html
  38. 38. Classical example Saga book hotel book car book flight cancel hotel cancel car 1. 2. 3. 5.6. In case of failure trigger compensations book trip
  39. 39. If your transaction involves 2 to 4 steps, choreography might be a very good fit. However, this approach can rapidly become confusing if you keep adding extra steps in your transaction as it is difficult to track which services listen to which events. Moreover, it also might add a cyclic dependency between services as they have to subscribe to one another’s events. Denis Rosa Couchbase https://blog.couchbase.com/saga-pattern-implement-business-transactions-using-microservices-part/
  40. 40. Implementing changes in the process Hotel Flight Car Trip Trip failed Trip requested Hotel booked Car booked Request trip Flight failed Car canceled Hotel canceled We have a new basic agreement with the car rental agency and can cancel for free within 1 hour – do that first!
  41. 41. Implementing changes in the process Hotel Flight Car Trip Trip failed Trip requested Hotel booked Car booked Request trip Flight failed Car canceled Hotel canceled You have to adjust all services and redeploy at the same time! We have a new basic agreement with the car rental agency and can cancel for free within 1 hour – do that first!
  42. 42. Photo by born1945, available under Creative Commons BY 2.0 license.
  43. 43. What we wanted Photo by Lijian Zhang, available under Creative Commons SA 2.0 License and Pedobear19 / CC BY-SA 4.0
  44. 44. Orchestration Hotel Flight Car Trip Trip booked Request trip Book hotel Hotel booked Car booked Flight booked Book car Book flight
  45. 45. Orchestration Hotel Flight Car Trip Trip booked Request trip Book hotel Hotel booked Car booked Flight booked Book car Book flight We have a new basic agreement with the car rental agency and can cancel for free within 1 hour – do that first! You have to adjust one service and redeploy only this one!
  46. 46. Thoughts on the state machine | workflow engine market
  47. 47. For today… OSS Workflow or Orchestration Engines Stack Vendors, Pure Play BPMS Low Code Platforms Homegrown frameworks to scratch an itch Integration Frameworks Cloud Offerings Data Pipelines Camunda, Zeebe, … AWS Step Functions, Azure Durable Functions, …
  48. 48. Step Functions https://read.acloud.guru/how-the-saga-pattern-manages-failures-with-aws-lambda-and- step-functions-bc8f7129f900
  49. 49. Describe orchestration with BPMN Trip Trip booked Request trip
  50. 50. Live hacking https://github.com/berndruecker/trip-booking-saga-serverless
  51. 51. Think of more complicated scenarios… Including stateful retries
  52. 52. AWS Step Functions Azure Durable Functions Google Cloud Composer Camunda BPM Zeebe Flow Language JSON Source Code Python, acyclic! BPMN BPMN Visualization Simple, proprietary - Simple, proprietary BPMN BPMN Performance & Scale ~ 1k state transitions / sec* ? ? Depends on RDMS Horizontally scalable License and Distribution Cloud Cloud Cloud + OSS (Apache Airflow) OSS + EE, Cloud planned OSS Pricing model 0,025 $ / 1k state transitions Billed as functions $0.074 / vCPU hour web, $0.125 / vCPU hour db, $0.273 per GB storage / month $0.156 / GB trafiic no managed service yet OSS project Please remember that I am biased!
  53. 53. Graphical models?
  54. 54. Clemens Vasters Architect at Microsoft http://vasters.com/archive/Sagas.html
  55. 55. Clemens Vasters Architect at Microsoft http://vasters.com/archive/Sagas.html
  56. 56. Clemens Vasters Architect at Microsoft http://vasters.com/archive/Sagas.html
  57. 57. BPMN Business Process Model and Notation ISO Standard
  58. 58. Living documentation for long-running behaviour
  59. 59. Visual HTML reports for test cases
  60. 60. BizDevOps
  61. 61. Thoughts on the state machine | workflow engine market
  62. 62. Does it support stateful operations? Does it support the necessary flow logic? Does it support BizDevOps? How to operate?
  63. 63. My personal pro-tip for a shortlist ;-) OSS Workflow or Orchestration Engines Stack Vendors, Pure Play BPMS Low Code Platforms Homegrown frameworks to scratch an itch Integration Frameworks Cloud Offerings Data Pipelines Camunda & Zeebe
  64. 64. Recap • Function coordination might include orchestration and workflow • Carefully decide about choreography vs. orchestration • Grown ups don‘t use distributed transactions but eventual consistency • Idempotency is super important! • Know Saga / Compensation as strategy
  65. 65. Thank you!
  66. 66. mail@berndruecker.io @berndruecker https://berndruecker.io https://medium.com/berndruecker https://github.com/berndruecker https://www.infoq.com/articles/events- workflow-automation Contact: Slides: Blog: Code: https://www.infoworld.com/article/3254777/ application-development/ 3-common-pitfalls-of-microservices- integrationand-how-to-avoid-them.html https://thenewstack.io/5-workflow-automation- use-cases-you-might-not-have-considered/

×