Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Events, Workflows, Sagas at KanDDDinsky Berlin 2022

Events, Workflows, Sagas at KanDDDinsky Berlin 2022

When dealing with (micro-) services, we often face business processes that span multiple bounded contexts. Different ways of implementing this lead to massively divergent results, varying above all in complexity and manageability. Especially when applying Event-driven Architecture, its asynchronous nature clashes with a desire for global control and synchronous responses, sometimes leading to chimeras that combine the “worst of both worlds”.
This talk will establish some guiding principles, and use them to assess common approaches. It will explore the importance of responsibility boundaries, and of bringing the data to the behavior.
A common mistake in the event-driven world is to replicate monolith workflows, resulting in an excessive need for orchestration or workflow tooling, or (in the worst case) a “distributed monolith”. How can this be avoided? The talk will introduce the concept of microworkflows, and show how challenging and re-designing your processes will lead to better systems. And lastly, we will ask ourselves: Should the saga pattern be considered harmful?

Lutz Hühnken

November 01, 2022
Tweet

More Decks by Lutz Hühnken

Other Decks in Programming

Transcript

  1. In 2008, a large German publishing company announced that they’ll

    switch their IT to Apple Computers. Somewhere down in the press statement, it read “the desktop computers will run Windows XP or Vista”. 3
  2. 4

  3. 5

  4. 6

  5. 7

  6. So what have we looked at so far? Implementing a

    workflow by: - Making one service the coordinator, or - Using a workflow engine for coordination, and - Implementing a saga (can be done with either of the above) What do all approaches have in common? 8
  7. - Introduce a complex piece of software - makes it

    harder to run, change, test - Introduce a split responsibility - Are not event-driven 9
  8. Technical complexity: - Must be able to resume after crash

    - Must be able to handle timeouts - Must be distributed to avoid single point of failure - Needs distributed coordination (stateful) - (Some of) your business logic is now in a YAML or XML file 10
  9. Organizational complexity: - Business logic is split - Error handling

    is split, leading to reduced clarity of responsibility if something goes wrong 11
  10. 12

  11. 13

  12. 14

  13. Q: So how to implement complex workflows over multiple microservices?

    A: Don’t. Instead, break up the workflow. To match actual event driven architecture. Monolith -> Microservices Workflow -> Microworkflows 15
  14. 16

  15. 17

  16. Q: But what about visibility of the end-to-end process? A:

    Don’t mix control and observability! 18
  17. 19

  18. But what about timeouts? - flaky connections, retries - within

    service - processing times - SLA - service needs to scale, e.g. based on consumer lag - overall process - observer 20
  19. But what about error handling? Errors must be handled within

    a service. The service gives a promise. This is a fundamental decoupling in event-driven architecture. 21
  20. Surely, this only works for unrealistic, simplistic examples. No, it’s

    just much harder to fit it on slides in a non-confusing way. 22
  21. Technicalities are not the problem, it’s a mindset issue. Think

    Promises. Enjoy the organizational clarity that it produces. 25
  22. Think Unix Philosophy 1. Make each program do one thing

    well. To do a new job, build afresh rather than complicate old programs by adding new "features". 2. Expect the output of every program to become the input to another, as yet unknown, program. ... 26
  23. 29

  24. Orchestration vs. Choreography While these terms might be fitting to

    describe the concepts, most comparisons are not useful, but based on some folkloristic concerns (e.g. taking a workflow as given, not as something that is designed and can be changed). Hence I tried to avoid them. 30
  25. Workflows are useful tools. Workflow engines too, probably. But not

    for implementing complex workflows on top of Microservices. That use case shouldn’t exist. Consider going event-driven instead. Break the workflow down into microworkflows. 31
  26. People are quick to jump to sagas and workflow engines!

    - Is it someone who’s familiar with it, but not with EDA, and is scared to leave their comfort zone? - Is it someone who wants to sell you something? - Is it someone who really understands EDA, and what you want to achieve, and, after considering all trade-offs, gives genuine, well-founded advice? 32
  27. Summary: Workflows and Sagas are at odds with event driven

    architecture. If you really want to get the benefits of event-driven architecture, go all-in, don’t impose an orchestrator on top of it. Keep your event-driven architecture sane. 33