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.

Coordination of serverless functions (AWS ComSum)

353 views

Published on

Slides from my talk at the AWS Community Summon about the coordination and orchestration of serverless functions / AWS Lambda. Code is here: https://github.com/berndruecker/trip-booking-saga-serverless/

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Coordination of serverless functions (AWS ComSum)

  1. 1. @berndruecker Coordination of Serverless Functions
  2. 2. An example for today – the classical one λ Book Car λ Book Hotel λ Book Flight @berndruecker
  3. 3. Function collaboration λ Book Car λ Book Hotel λ Book Flight Book a trip? @berndruecker
  4. 4. Choreography λ (Car) $.post(carHireUrl, ... invokeHotel() λ (Hotel) $.post(carHireUrl, ... Chaining λ (Car) $.post(carHireUrl, ... carBookedEvent() λ (Hotel) $.post(carHireUrl, ... Event-Chain No extra framework needed The flow is scattered across functions and thus invisible Changing the sequence is hard
  5. 5. Orchestration / coordinator function λ (Trip) λ (Car) $.post(carHireUrl, ... λ (Hotel) $.post(carHireUrl, ... // book har invokeCar() // book hotel invokeHotel() @berndruecker
  6. 6. Orchestration / coordinator function λ (Trip) λ (Car) $.post(carHireUrl, ... λ (Hotel) $.post(carHireUrl, ... // book har invokeCar() // book hotel invokeHotel() @berndruecker
  7. 7. Orchestration / coordinator function λ (Trip) λ (Car) $.post(carHireUrl, ... λ (Hotel) $.post(carHireUrl, ... // book har invokeCar() // book hotel invokeHotel() Not idempotent Idempotent bookHotel(hotel, duration) bookHotel(tripId, hotel, duration) @berndruecker
  8. 8. It is impossible to differentiate certain failure scenarios: Independant of communication style! @berndruecker
  9. 9. Orchestration / coordinator function λ (Trip) λ (Car) $.post(carHireUrl, ... λ (Hotel) $.post(carHireUrl, ... // book har invokeCar() // book hotel invokeHotel() @berndruecker
  10. 10. // book hotel try { bookHotel() } catch (err) { cancelHotel() } Cleanup! λ (Trip) λ (Car) $.post(carHireUrl, ... λ (Hotel) $.post(carHireUrl, ... PUT& DELETE // book har invokeCar() @berndruecker
  11. 11. Weaknesses Car HotelTrip Flight @berndruecker
  12. 12. Weaknesses: Latency creep Car HotelTrip Flight 300 ms 1150 + x ms 600 ms 250 ms @berndruecker $$$ Coordinator get‘s long running!
  13. 13. Weaknesses: Availabiliy erosion Car HotelTrip Flight 99 % uptime 99 % uptime 99 % uptime 97 % uptime @berndruecker
  14. 14. Orchestration with workflow λ (Trip) // book har startTripWorkflow() λ (Car) $.post(carHireUrl, ... λ (Hotel) $.post(carHireUrl, ... Workflow Engine Car -> Hotel -> ... @berndruecker Functions keep independant No long running function Extra component involved
  15. 15. Warning: Contains Opinion
  16. 16. Berlin, Germany bernd.ruecker@camunda.com @berndruecker Bernd Ruecker Co-founder and Chief Technologist of Camunda
  17. 17. Example λ (Car) λ (Hotel) Workflow Engine λ (Flight)λ (Trip)
  18. 18. Leverage retrying λ (Car) λ (Hotel) Workflow Engine λ (Flight)λ (Trip)
  19. 19. Leverage stateful retrying λ (Car) λ (Hotel) Workflow Engine λ (Flight)λ (Trip)
  20. 20. Let‘s talk about consistency All or nothing
  21. 21. That means Temporarily inconsistent Eventually consistent againt Consistent Local ACID Local ACID @berndruecker λ Book Car λ Book Hotel
  22. 22. Compensation – 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
  23. 23. Live hacking https://github.com/berndruecker/trip-booking-saga-serverless Camunda Cloud - Process Automation as a Service Workflow engine based on BPMN Cloud-native, Source-available, horizontally scalable
  24. 24. Demo Architecture Camunda Cloud Your AWS account Zeebe Client BPMN Workflow Definition Trip Booking Function Hotel Booking Function … Zeebe start native invocation Zeebe Client Lambda Worker pub/sub Deployed onto Zeebe
  25. 25. Choreography & orchestration @berndruecker
  26. 26. Event-driven choreography Hotel Flight Car Trip Trip booked Flight booked Trip requested Hotel booked Car booked Request trip @berndruecker
  27. 27. 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) @berndruecker
  28. 28. 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 @berndruecker
  29. 29. 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 @berndruecker
  30. 30. 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 @berndruecker
  31. 31. 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! @berndruecker
  32. 32. 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! @berndruecker
  33. 33. What we wanted Photo by Lijian Zhang, available under Creative Commons SA 2.0 License and CC BY-SA 4.0 @berndruecker
  34. 34. Orchestration Hotel Flight Car Trip Trip booked Request trip Book hotel Hotel booked Car booked Flight booked Book car Book flight @berndruecker
  35. 35. 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! @berndruecker
  36. 36. Graphical models? @berndruecker
  37. 37. Clemens Vasters Architect at Microsoft http://vasters.com/archive/Sagas.html @berndruecker
  38. 38. Clemens Vasters Architect at Microsoft http://vasters.com/archive/Sagas.html @berndruecker
  39. 39. Clemens Vasters Architect at Microsoft http://vasters.com/archive/Sagas.html @berndruecker
  40. 40. Living documentation for long-running behaviour @berndruecker
  41. 41. BizDevOps @berndruecker
  42. 42. Step Functions https://read.acloud.guru/how-the-saga-pattern-manages-failures-with-aws-lambda-and- step-functions-bc8f7129f900
  43. 43. Think of more complicated scenarios…
  44. 44. Recap • Function coordination might include orchestration and workflow • Carefully decide about choreography vs. orchestration • Learn to handle eventual consistency and related business problems (e.g. transactions), e.g. by the Saga Pattern • Idempotency is super important!
  45. 45. Thank you! @berndruecker
  46. 46. 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/

×