Sagas: Distributed Transactions Without Locks

Sagas: Distributed Transactions Without Locks

This talk discusses the sagas pattern and an Erlang implementation of the pattern from Erlang User Conference 2017

7330b65ea54e1b90a987a552e5c5cf32?s=128

Mark Allen

June 08, 2017
Tweet

Transcript

  1. Sagas: distributed transactions without locks in Erlang MARK ALLEN -

    ALERTLOGIC MARK.ALLEN@ALERTLOGIC.COM @BYTEMEORG
  2. Sagas

  3. None
  4. None
  5. Types of Sagas §Backward Recovery §Forward Recovery §“Recovery Blocks” §Parallel

    Sagas
  6. Sagas in Erlang

  7. The Big Idea Fold over a list of closures…

  8. The Big Idea Fold over a list of closures… ...unless

    there’s an error.
  9. The Big Idea Fold over a list of closures… ...unless

    there’s an error; Then, fold over a list of closures.
  10. Flows Forward 1 Forward 2 Forward 3 Forward 4 Forward

    5 Rollback 1 Rollback 2 Rollback 3 Rollback 4 Rollback 5
  11. Flows Forward 1 Forward 2 Forward 3 Forward 4 Forward

    5 Rollback 1 Rollback 2 Rollback 3 Rollback 4 Rollback 5
  12. Flows Forward 1 Forward 2 Forward 3 Forward 4 Forward

    5 Rollback 1 Rollback 2 Rollback 3 Rollback 4 Rollback 5
  13. Flows Forward 1 Forward 2 Forward 3 Forward 4 Forward

    5 Rollback 1 Rollback 2 Rollback 3 Rollback 4 Rollback 5
  14. Flows Forward 1 Forward 2 Forward 3 Forward 4 Forward

    5 Rollback 1 Rollback 2 Rollback 3 Rollback 4 Rollback 5
  15. Flows Forward 1 Forward 2 Forward 3 Forward 4 Forward

    5 Rollback 1 Rollback 2 Rollback 3 Rollback 4 Rollback 5
  16. Flows Forward 1 Forward 2 Forward 3 Forward 4 Forward

    5 Rollback 1 Rollback 2 Rollback 3 Rollback 4 Rollback 5
  17. Flows Forward 1 Forward 2 Forward 3 Forward 4 Forward

    5 Rollback 1 Rollback 2 Rollback 3 Rollback 4 Rollback 5 BOOM
  18. Flows Forward 1 Forward 2 Forward 3 Rollback 1 Rollback

    2 Rollback 3 BOOM
  19. Flows Forward 1 Forward 2 Forward 3 Rollback 1 Rollback

    2 Rollback 3 BOOM
  20. Flows Forward 1 Forward 2 Forward 3 Rollback 1 Rollback

    2 Rollback 3 BOOM
  21. Flows Forward 1 Forward 2 Forward 3 Rollback 1 Rollback

    2 Rollback 3 BOOM
  22. None
  23. Terminology §Operation §Step §Transaction

  24. Terminology Forward 1 Forward 2 Forward 3 Forward 4 Forward

    5 Rollback 1 Rollback 2 Rollback 3 Rollback 4 Rollback 5
  25. None
  26. Implicit Assumptions and Requirements

  27. Compensating Closures Cannot Abort

  28. Idempotent Requests

  29. What if?? Forward 1 Forward 2 Forward 3 Rollback 1

    Rollback 2 Rollback 3 BOOM
  30. What if?? Forward 1 Forward 2 Forward 3 Forward 4

    Rollback 1 Rollback 2 Rollback 3
  31. Futures in Erlang

  32. Why does Erlang need futures?!

  33. It doesn’t! Except…

  34. Asynchronous Saga Operations

  35. None
  36. Implementation

  37. Semantics?

  38. Property Based Tests

  39. What is it? §Write one or more invariants §Test values

    are automatically generated and the invariant tested §Failures are shrunk to the smallest possible failure case §Modify code (or test case) and restart test §Tests are usually timeboxed §Extremely useful to build confidence in complex scenarios
  40. Academic history QuickCheck: A Lightweight Tool for Random Testing of

    Haskell Programs
  41. Implementations for §Go §C/C++ §Clojure §Scala §Haskell (of course) §…

    lots of others … §Erlang/Elixir (watch Thomas Arts talk at ElixirConf EU 2015)
  42. Erlang implementations §Quviq Commercial QuickCheck (http://www.quviq.com) §Free (but not open

    source) “QuickCheck mini” – doesn’t do statem §PropEr (https://github.com/manopapad/proper) §Triq (https://github.com/triqng/triq)
  43. Generators §All standard basic types: §integers, §floats, §atoms, §binaries, §strings,

    §lists §Lists of basic types §User defined generators using ?LET and ?SUCHTHAT
  44. Propositions §?FORALL(Variable, generator_function(), test_function(Variable))

  45. Resources §https://github.com/mrallen1/gisla §https://github.com/mrallen1/criswell §Sagas paper: http://www.cs.cornell.edu/andru/cs711/2002fa/reading/sagas.pdf §Caitie McCaffrey, Papers We

    Love on Sagas: https://youtu.be/7dc4Tl5ZHRg?t=27m16s §Caitie McCaffrey, Distributed Sagas: https://speakerdeck.com/caitiem20/distributed-sagas-a-protocol-for- coordinating-microservices §These slides: https://speakerdeck.com/mrallen1/sagas-distributed-transactions- without-locks