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.

Lighning Talk: Event-Driven architecture for microservices

655 views

Published on

These days building applications using microservice approach has become a defacto standard in many cases. Microservices are all about splitting large applications into smaller ones, which means that there must be some sort of communication between them. During this session Martins will go over how event-driven architecture can be applied for communication between various services, describe the pros and cons, and gives real world examples of how it can be used with PHP and other programming languages.

Published in: Technology

Lighning Talk: Event-Driven architecture for microservices

  1. 1. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES MARTINS SIPENKO
  2. 2. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES ABOUT ME ▸ Located in Riga, Latvia ▸ martinssipenko ▸ Lead engineer @ KASKO, a fintech startup (insurance) ▸ Worked with PHP since around 2002 ▸ AWS Certified ▸ Student at University of Latvia
  3. 3. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES WHY MICROSERVICES? ▸ Single responsibility services based on business logic ▸ Different technology for each service
 (PHP, Golang, Node.js, AWS Lambda) ▸ Allows to scale individual service
  4. 4. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES HOW DO THE SERVICES COMMUNICATE WITH EACH OTHER?
  5. 5. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES ▸ Customer places an order ORDER SERVICE THE EXAMPLE
  6. 6. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES ▸ Customer places an order ▸ Then we need to generate a PDF invoice document ORDER SERVICE PDF
 SERVICE THE EXAMPLE
  7. 7. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES ▸ Customer places an order ▸ Then we need to generate a PDF invoice document ▸ PDF needs to be stored ORDER SERVICE PDF
 SERVICE THE EXAMPLE
  8. 8. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES ▸ Customer places an order ▸ Then we need to generate a PDF invoice document ▸ PDF needs to be stored ▸ Order needs to be updated with a link to PDF document ORDER SERVICE PDF
 SERVICE THE EXAMPLE
  9. 9. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES INITIAL APPROACH ▸ Order service makes HTTP call to PDF service ▸ PDF is generated and stored asynchronously ▸ PDF service makes an HTTP call to update Order ORDER SERVICE PDF
 SERVICE POST POST PATCH POST
  10. 10. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES THE PROBLEM ▸ Services have to be aware of each other ▸ PDF Service must know how to update an Order ORDER SERVICE PDF
 SERVICE POST POST POST PATCH
  11. 11. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES THE PROBLEM ▸ Services have to be aware of each other ▸ PDF Service must know how to update an Order ▸ What if we throw in more services? ORDER SERVICE PDF
 SERVICE POST POST POST PATCH EMAIL SERVICE Send PDF to customer CUSTOMER SERVICE GET
  12. 12. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES THIS DOES NOT SCALE VERY WELL!
  13. 13. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES ▸ Turn things the other way around ▸ But how will PDF service know when order was placed? ORDER SERVICE PDF
 SERVICE POST POST ? THE SECOND APPROACH
  14. 14. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES HERE COME EVENTS!
  15. 15. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES ▸ All services send notifications to a central BUS ▸ There is one notification queue per service ▸ Each services queue is subscribed to BUS ▸ Each service runs a background worker that listens to respective event queue THE SECOND APPROACH
  16. 16. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES ORDER SERVICE API POST EMAIL SERVICE QUEUE CUSTOMER SERVICE API ORDER SERVICE QUEUE CUSTOMER SERVICE QUEUE PDF SERVICE QUEUE CENTRAL MESSAGE BUS EMAIL SERVICE WORKER ORDER SERVICE WORKER CUSTOMER SERVICE WORKER PDF SERVICE WORKER THE SECOND APPROACH
  17. 17. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES ORDER SERVICE API POST EMAIL SERVICE QUEUE CUSTOMER SERVICE API ORDER SERVICE QUEUE CUSTOMER SERVICE QUEUE PDF SERVICE QUEUE CENTRAL MESSAGE BUS Order created EMAIL SERVICE WORKER ORDER SERVICE WORKER CUSTOMER SERVICE WORKER PDF SERVICE WORKER THE SECOND APPROACH
  18. 18. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES ORDER SERVICE API POST EMAIL SERVICE QUEUE CUSTOMER SERVICE API ORDER SERVICE QUEUE CUSTOMER SERVICE QUEUE PDF SERVICE QUEUE CENTRAL MESSAGE BUS Order created Order created EMAIL SERVICE WORKER ORDER SERVICE WORKER CUSTOMER SERVICE WORKER PDF SERVICE WORKER THE SECOND APPROACH
  19. 19. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES ORDER SERVICE API POST EMAIL SERVICE QUEUE CUSTOMER SERVICE API ORDER SERVICE QUEUE CUSTOMER SERVICE QUEUE PDF SERVICE QUEUE CENTRAL MESSAGE BUS Order created Order created EMAIL SERVICE WORKER ORDER SERVICE WORKER CUSTOMER SERVICE WORKER PDF SERVICE WORKER Order created THE SECOND APPROACH
  20. 20. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES ORDER SERVICE API POST EMAIL SERVICE QUEUE CUSTOMER SERVICE API ORDER SERVICE QUEUE CUSTOMER SERVICE QUEUE PDF SERVICE QUEUE CENTRAL MESSAGE BUS Order created Order created EMAIL SERVICE WORKER ORDER SERVICE WORKER CUSTOMER SERVICE WORKER PDF SERVICE WORKER Ignore Store Ignore Ignore Order created THE SECOND APPROACH
  21. 21. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES ORDER SERVICE API POST EMAIL SERVICE QUEUE CUSTOMER SERVICE API ORDER SERVICE QUEUE CUSTOMER SERVICE QUEUE PDF SERVICE QUEUE CENTRAL MESSAGE BUS Order created Order created EMAIL SERVICE WORKER ORDER SERVICE WORKER CUSTOMER SERVICE WORKER PDF SERVICE WORKER Ignore Store Ignore Ignore Order created PDF Generated THE SECOND APPROACH
  22. 22. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES ORDER SERVICE API POST EMAIL SERVICE QUEUE CUSTOMER SERVICE API ORDER SERVICE QUEUE CUSTOMER SERVICE QUEUE PDF SERVICE QUEUE CENTRAL MESSAGE BUS PDF Generated EMAIL SERVICE WORKER ORDER SERVICE WORKER CUSTOMER SERVICE WORKER PDF SERVICE WORKER THE SECOND APPROACH
  23. 23. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES ORDER SERVICE API POST EMAIL SERVICE QUEUE CUSTOMER SERVICE API ORDER SERVICE QUEUE CUSTOMER SERVICE QUEUE PDF SERVICE QUEUE CENTRAL MESSAGE BUS PDF Generated PDF Generated EMAIL SERVICE WORKER ORDER SERVICE WORKER CUSTOMER SERVICE WORKER PDF SERVICE WORKER THE SECOND APPROACH
  24. 24. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES ORDER SERVICE API POST EMAIL SERVICE QUEUE CUSTOMER SERVICE API ORDER SERVICE QUEUE CUSTOMER SERVICE QUEUE PDF SERVICE QUEUE CENTRAL MESSAGE BUS EMAIL SERVICE WORKER ORDER SERVICE WORKER CUSTOMER SERVICE WORKER PDF SERVICE WORKER PDF Generated PDF Generated Ignore IgnoreUpdate reference Email PDF THE SECOND APPROACH
  25. 25. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES THE SECOND APPROACH ORDER SERVICE API POST EMAIL SERVICE QUEUE CUSTOMER SERVICE API ORDER SERVICE QUEUE CUSTOMER SERVICE QUEUE PDF SERVICE QUEUE CENTRAL MESSAGE BUS EMAIL SERVICE WORKER ORDER SERVICE WORKER CUSTOMER SERVICE WORKER PDF SERVICE WORKER PDF Generated PDF Generated Ignore IgnoreUpdate reference Email PDF Order updated Email sent
  26. 26. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES THE BENEFITS ▸ If error raises on service, the message remains in queue ▸ It will be picked up later ▸ Services don't need to know about how to make updates to other services ▸ Adding more services is easy ▸ Scales well
  27. 27. EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES THANKS! martinssipenko
 martins.sipenko@gmail.com
 https://joind.in/talk/f1078

×