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

Event-Driven Microservices Architecture: Reason, how and where to apply

Event-Driven Microservices Architecture: Reason, how and where to apply

During my journey in microservices, it became apparent that the REST standard has been widely used in communication between microservices for a long time. But recently event-driven integrations have started to invade its territory. It turns out that there are some good reasons for this.

In this lecture, I will present an introduction to the Event-Driven Microservices Architecture, its main characteristics and the reasons why large technology companies are adopting such a flexible, performative and scalable architecture.

Ef3b48913ea26665c25b2ad78e449d16?s=128

Luram Archanjo

March 12, 2020
Tweet

Transcript

  1. Event Driven Architecture Reason, how and where to apply Luram

    Archanjo
  2. Who am I? • Software Engineer at Sensedia ◦ Edenred

    ◦ Cielo • MBA in Java projects • Java and Microservice enthusiastic
  3. Agenda • Microservices • REST • Message Driven Architecture •

    Event Driven Architecture • Questions
  4. Moving to Microservices Feature A Feature B Feature C Monolith

    Microservice Microservice Microservices Microservice
  5. • Communication • Security • Network failures • Observability ◦

    Metrics ◦ Logs ◦ Tracing Challenges with Microservices
  6. Communication Microservice Microservice Microservice Microservice Microservice Microservice Microservice Microservice

  7. Representational state transfer (REST)

  8. REST - Representational State Transfer GET GET POST PUT DELETE

    /movies /movies/{movieId} /movies /movies/{movieId} /movies/{movieId}
  9. • Web already built on top of HTTP • Easy

    to understand • Variety of http implementation in any languages • Loose coupling between client and server Representational State Transfer
  10. Microservice Communication Microservice Microservice Microservice Microservice Microservice Microservice Microservice Microservice

  11. Cheers We have a system

  12. Unfortunately We will have problems

  13. Microservice Communication Microservice Microservice Microservice Microservice Microservice Some kind of

    problems • Crash of service • Slow response time • Change of interface
  14. How to handle it?

  15. There is something worse

  16. Microservice Communication Database per service Microservice Microservice Microservice Microservice Microservice

  17. Code is easy, state is hard

  18. Event-Driven Architecture

  19. First, we need to learn the difference between Synchronous vs

    Asynchronous
  20. Synchronous vs Asynchronous

  21. Reasons to Send a Message

  22. Reasons to Send a Message

  23. Message-Driven Architecture Producer Consumer Message Broker Producer Producer Consumer Consumer

    Advantages • Durable Message • Guaranteed delivery • Decoupling
  24. Message-Driven Architecture Producer Consumer Message Broker Producer & Consumer Pattern

    One message, one consumer! Consumer Consumer
  25. Message-Driven Architecture Publisher Subscriber Message Broker Publisher & Subscriber Pattern

    One message, many subscribers! Subscriber Subscriber
  26. Event-Driven Architecture

  27. Event-Driven Architecture Event-Driven Architecture Message-Driven Architecture Broker Producer Consumer

  28. Event-Driven Architecture Event Producer Event Consumer Event Broker Fire &

    Forget Pattern One event, many consumers! Event Consumer Event Consumer
  29. Events are facts that happened in the system

  30. Types of events Low level event “CRUD” Events • OrderCreated

    • OrderUpdated • OrderDeleted Domain level event Business Events • RequestedOrder • ApprovedOrder • RejectedOrder
  31. Saga Pattern

  32. Saga Pattern Orchestration Choreography Event Producer Event Mediator Event Consumer

    Event Consumer Event Event Broker Producer Consumer Event Consumer
  33. “We can query an application's state to find out the

    current state of the world, and this answers many questions. However there are times when we don't just want to see where we are, we also want to know how we got there.” Martin Fowler, 2005
  34. Event Sourcing Persists the state of a entity as a

    sequence of state-changing events Whenever state of entity changes, a new event is appended to the list of Events Saving an event is a single operation (atomic) The application reconstructs an entity’s current state by replaying the events
  35. Event Sourcing

  36. CQRS Optimize different nonfunctional requirements for read and write Write

    Delay Eventual Consistency Database as event publisher (optional) Data Projection and Materialized View Command Service Microservice Event Store Query Service Microservice
  37. Eventual Consistency Command Service Microservice Event Store Query Service Microservice

    I want pizza Pizza = ? Pizza = Preparing
  38. Event Ording 0 100 80 Events Account: Created Deposit: R$

    100 Withdraw: R$ 20 Withdraw: R$ 20 Ordering Not Ordering 60 0 0 0 100
  39. Event Stream Event #1 Event #2 Event #3 Event #4

    Event #5 Event #6 Event #7 Replay Timeline
  40. Why we are talking about Event Driven Architecture (EDA)

  41. “By 2020, event-sourced, real-time situational awareness will be a required

    characteristic for 80% of digital business solutions, and 80% of new business ecosystems will require support for event processing.” Top 10 Strategic Technology Trends for 2018
  42. Summary 2º Place 1º Place 3º Place It enables an

    application to maintain data consistency across multiple services without using distributed transactions It scales well to a very large number of users and allows new services to be added without breaking the streams of data that are currently deployed Analytics • Audit • Near real time • Machine learn
  43. None
  44. Thanks a million! Questions? /larchanjo /luram-archanjo