lost in transaction
play

Lost in transaction? Strategies to deal with (in)consistency in - PowerPoint PPT Presentation

Lost in transaction? Strategies to deal with (in)consistency in distributed systems @berndruecker Once upon a time: try { tx.begin(); doA(); Do A doB(); tx.commit(); All or + } catch (Exception e) { tx.rollback(); nothing } Do B Or


  1. Lost in transaction? Strategies to deal with (in)consistency in distributed systems @berndruecker

  2. Once upon a time: try { tx.begin(); doA(); Do A doB(); tx.commit(); All or + } catch (Exception e) { tx.rollback(); nothing } Do B Or simply: @Transactional public void createCustomer(Customer cust) { // ... }

  3. A Atomicity C Consistency I Isolation D Durability

  4. Distributed systems

  5. Distributed systems

  6. Distributed systems

  7. But there is two-phase commit (XA)!! Resource TX Managers Coordinator Prepare Phase Commit Phase

  8. “ Pat Helland Distributed Systems Guru Worked at Amazon, Microsoft & Salesforce

  9. “ Grown- Ups Don’t Use Distributed T ransactions Pat Helland Distributed Systems Guru Worked at Amazon, Microsoft & Salesforce

  10. Starbucks does not use two phase commit https://www.enterpriseintegrationpatterns.com/ramblings/18_starbucks.html Photo by John Ingle

  11. Atomicity Eric Brewer Consistency Isolation Durability http://pld.cs.luc.edu/courses/353/spr11/notes/brewer_keynote.pdf

  12. That means Consistent Violates „I“ Local Do A ACID of ACID Temporarily inconsistent Local Do B ACID Eventually consistent 1 (micro-)service again 1 aggregate t 1 program 1 resource

  13. Consistent You might know this from: Do A Temporarily inconsistent Do B Eventually consistent again t Photo by Gerhard51, available under Creative Commons CC0 1.0 license.

  14. A C I D 2.0 Pat Helland „Building on Quicksand“ Paper

  15. Associative (a + b) + c = a + (b + c) Commutative a + b = b + a Idempotent f(x) = f( f(x) ) Distributed 2.0 Pat Helland „Building on Quicksand“ Paper

  16. Photo by pixabay, available under Creative Commons CC0 1.0 license.

  17. Requirement: Idempotency of services! Photo by pixabay, available under Creative Commons CC0 1.0 license.

  18. Requirement: Idempotency of services! Photo by Chr.Späth , available under Public Domain.

  19. Distributed

  20. It is impossible to Client Service Provider differentiate certain failure scenarios: Independant of communication style!

  21. Network problems Credit Payment Card charge

  22. Strategy: retry has to be idempotent Credit Payment Card charge Charge Credit Card Not Not idempotent cardNumber amount Charge Credit Card cardNumber Idempotent amount transactionId

  23. Strategy: Cleanup Credit Payment Card charge Raise payment failed Make sure it is not charged! Cancel charge cardNumber amount transactionId

  24. Some communication challenges require state.

  25. Strategy: Stateful retry Credit Payment Card charge

  26. Strategy: Stateful retry Credit Payment Card charge Make sure it is not charged!

  27. Warning: Contains Opinion

  28. Bernd Ruecker Co-founder and Chief T echnologist of Camunda Berlin, Germany bernd.ruecker@camunda.com @berndruecker

  29. Let‘s use a lightweight OSS workflow engine for this:

  30. Stateful retry Credit Payment Card REST

  31. Stateful retry & cleanup Credit Payment Card REST Cancel charge

  32. Live hacking https://github.com/flowing/flowing-retail/tree/master/rest

  33. Embedded Engine Example (Java) https://blog.bernd-ruecker.com/architecture-options-to-run-a-workflow-engine-6c2419902d91

  34. Remote Engine Example (Polyglot) https://blog.bernd-ruecker.com/architecture-options-to-run-a-workflow-engine-6c2419902d91

  35. A relatively common pattern Kafka / Rabbit 1. Receive 3. Send response ? ACK 4. Send additional events Service (e.g. Go) 2. Business Logic RDMS

  36. That means Consistent Do A Temporarily inconsistent Do B In case of failure: Compensate or apologise Eventually consistent t

  37. https://blogs.msdn.microsoft.com/pathelland/2007/05/15/memories-guesses-and-apologies/

  38. Compensation – the classical example Saga 1. 2. 3. book book book hotel car flight book trip In case of failure cancel cancel trigger compensations hotel car 6. 5.

  39. 2 alterntive approaches: choreography & orchestration

  40. Event-driven choreography Hotel booked Hotel T rip Car requested Request trip T rip Car booked T rip booked Flight Flight booked

  41. Event-driven choreography Perform undo (cancel hotel) Hotel booked Perform undo (cancel car booking) Hotel T rip Car requested Request Car trip canceled Hotel T rip canceled Car booked T rip Flight failed Flight failed

  42. 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

  43. 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

  44. 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

  45. Classical example Saga 1. 2. 3. book book book hotel car flight book trip In case of failure cancel cancel trigger compensations hotel car 6. 5.

  46. 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 Denis Rosa Couchbase which events. Moreover, it also might add a cyclic dependency between services as they have to subscribe to one another’s events. https://blog.couchbase.com/saga-pattern-implement-business-transactions-using-microservices-part/

  47. Microservice pioneers have become aware

  48. We have a new basic agreement Implementing changes in the process with the car rental agency and can cancel for free within 1 hour – do that first! Hotel booked Hotel T rip Car requested Request Car trip canceled Hotel T rip canceled Car booked T rip Flight failed Flight failed

  49. We have a new basic agreement Implementing changes in the process with the car rental agency and can cancel for free within 1 hour – do that first! Hotel booked Hotel T rip Car requested Request Car trip canceled Hotel T rip canceled Car booked T rip Flight failed Flight failed You have to adjust all services and redeploy at the same time!

  50. Photo by born1945, available under Creative Commons BY 2.0 license.

  51. What we wanted Photo by Lijian Zhang, available under Creative Commons SA 2.0 License and Pedobear19 / CC BY-SA 4.0

  52. Orchestration Hotel Book Car Book hotel car Request Hotel trip booked Car T rip booked T rip Book booked flight Flight Flight booked

  53. We have a new basic agreement Orchestration with the car rental agency and can cancel for free within 1 hour – do that first! Hotel Book Car Book hotel car Request Hotel trip booked Car T rip booked T rip Book booked flight Flight Flight booked You have to adjust one service and redeploy only this one!

  54. Describe orchestration with BPMN Request trip T rip T rip booked

  55. The workflow is part of the service T rip

  56. The workflow is part of the service T rip Payment

  57. The workflow is part of the service T rip Workflow engine itself can run decentralized or centralized Payment

  58. Caitie McCaffrey | @caitie

  59. „Can this really handle 15k requests per second ?“

  60. Graphical models?

  61. Clemens Vasters Architect at Microsoft http://vasters.com/archive/Sagas.html

  62. Clemens Vasters Architect at Microsoft http://vasters.com/archive/Sagas.html

  63. Clemens Vasters Architect at Microsoft http://vasters.com/archive/Sagas.html

  64. BPMN Business Process Model and Notation ISO Standard

  65. Living documentation for long-running behaviour

  66. Visual HTML reports for test cases

  67. BizDevOps

  68. Saga with AWS Step Functions https://theburningmonk.com/2017/07/applying-the- saga-pattern-with-aws-lambda-and-step-functions/

  69. Thoughts on the state machine | workflow engine market

  70. Thoughts on the state machine | workflow engine market Camunda, Zeebe, jBPM, Activiti , Mistral, … Stack Vendors, OSS Workflow or Integration Frameworks Pure Play BPMS Orchestration Engines Apache Camel, Low Code Platforms Balerina , … PEGA, IBM, SAG, … Data Homegrown frameworks Pipelines Cloud Offerings to scratch an itch Apache Airflow, Spring Data Flow, … AWS Step Functions, Uber, Netflix, AirBnb , ING, … Azure Durable Functions , …

  71. Does it support stateful operations? Does it support the necessary flow logic? Does it support BizDevOps? Does it scale?

Recommend


More recommend