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

Microservices need Microworkflows w-jax Munich ...

Microservices need Microworkflows w-jax Munich 2023

Bei Microservices erfreut sich die "Event-driven Architecture" großer Beliebtheit. Zumindest in der Theorie. Es gibt zahlreiche Vorträge und Artikel, die eine ereignisgesteuerte Architektur preisen, weil diese dabei hilft, die Skalierbarkeit und Zuverlässigkeit zu erreichen, die wir uns alle wünschen. Doch die meisten dieser Beschreibungen enden, bevor sie zur Implementierung komplexer Geschäftsprozesse kommen. Wie passen einzelne Services, die über Events kommunizieren, zu einem Workflow, der mehrere Domänen umspannt? Der eine durchgängige Verantwortlichkeit erfordert? In der Praxis greifen vielen Teams schnell (möglicherweise voreilig?) zurück auf „traditionelle“, nicht ereignisgesteuerte Optionen. Dazu gehören Prozessmanager, Workflow-Engines, und das Saga-Pattern. Geht das nicht anders? Dieser Vortrag wird Vor- und Nachteile verschiedener Ansätze untersuchen. Insbesondere wollen wir in die Tiefe gehen, was eine rein Event-basierte Implementierung angeht, basierend auf Events als Fakten, klare Abgrenzung von Verantwortung, Leistungsversprechen und Sichtbarkeit. Kopieren wir nicht einfach die Workflows, die in einem Monolithen funktionierten, in die verteilte Welt. Statt uns über die Bewältigung von Komplexität den Kopf zu zerbrechen – überlegen wir lieber, wie wir Komplexität reduzieren können!

Lutz Hühnken

November 07, 2023
Tweet

More Decks by Lutz Hühnken

Other Decks in Programming

Transcript

  1. @[email protected] Why me? - Built my first message-driven, asynchronous system

    for the Bundesbank starting 2001 - Worked on various event-driven systems, e.g. for Zalando, ING, ista, Maersk - Currently building a bank (!) with Event-driven Architecture, Microservices, DDD 3
  2. @[email protected] Context 1/3 Business Applications (e.g. applications where people can

    buy, rent, book something, perform business transactions) (not: IoT, Big Data…) 4
  3. @[email protected] Context 3/3 Assuming a Preference for Event-driven (Reminder: all

    the advantages of microservices, plus runtime decoupling) 7
  4. @[email protected] 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? 12
  5. @[email protected] - Introduce a (complex) piece of software - Introduce

    a split responsibility - Are not event-driven 13
  6. @[email protected] 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 14
  7. @[email protected] Organizational complexity: - Business logic is split - Error

    handling is split, leading to reduced clarity of responsibility if something goes wrong 15
  8. @[email protected] Reminder: Events vs. Commands 17 Is.. Command An intention

    to perform an operation or change a state Event A fact, something that undisputedly happened in the past
  9. @[email protected] Reminder: Events vs. Commands 18 Is.. Expected Response Communication

    Pattern Command An intention to perform an operation or change a state A confirmation that the command has been executed, or an error message Request-Response Event A fact, something that undisputedly happened in the past None Fire-And-Forget
  10. @[email protected] Q: 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 22
  11. @[email protected] Digression: What the “end” is, is very arbitrary. Does

    it “end” when the parcel is sent? When it has arrived? When the goods have not been returned in 2 weeks? Where does one workflow end, and a new one start? It’s designed. 27
  12. @[email protected] Q: But what about timeouts? A: - flaky connections,

    retries - within service - processing times - SLA - service needs to scale, e.g. based on consumer lag - overall process - observer 28
  13. @[email protected] Q: But what about error handling? A: Errors must

    be handled within a service. The service gives a promise. This is a fundamental decoupling in event-driven architecture. 29
  14. @[email protected] Q: Surely, this only works for unrealistic, simplistic examples?

    A: No, it’s just much harder to fit it on slides in a non-confusing way 󰤇. 31
  15. @[email protected] 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. ... 37 $ Cat file3.txt | grep “dwx” | tee file4.txt | wc –l
  16. @[email protected] Enjoy the (load) testing 41 While you’re freed from

    having e.g. the workflow engine in your end-to-end test, there are other challenges. Also: Testing a microworkflow is still an integration test. But it’s nice to be able to test e.g. throughput in a very isolated way.
  17. 42

  18. @[email protected] Orchestration vs. Choreography While these terms might be fitting

    to describe the concepts, most comparisons are not useful, but based on some folkloristic concerns. Hence I tried to avoid them. 43
  19. @[email protected] Example Heuristic “Complex workflows..” Problem: Taking a workflow as

    given, not as something that is designed and can be changed. 44
  20. @[email protected] 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. 47
  21. @[email protected] 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? 48
  22. @[email protected] 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. 49
  23. Let’s Discuss! Follow me on Mastodon @[email protected] Follow me on

    LinkedIn https://linkedin.com/in/lutzh Read my blog https://www.reactivesystems.eu/ 50