Top Banner
EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES MARTINS SIPENKO
27

Lighning Talk: Event-Driven architecture for microservices

Apr 16, 2017

Download

Technology

Martins Sipenko
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lighning Talk: Event-Driven architecture for microservices

EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES

MARTINS SIPENKO

Page 2: Lighning Talk: Event-Driven architecture for microservices

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

Page 3: Lighning Talk: Event-Driven architecture for microservices

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

Page 4: Lighning Talk: Event-Driven architecture for microservices

EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES

HOW DO THE SERVICES COMMUNICATE WITH EACH OTHER?

Page 5: Lighning Talk: Event-Driven architecture for microservices

EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES

▸ Customer places an order

ORDER SERVICE

THE EXAMPLE

Page 6: Lighning Talk: Event-Driven architecture for microservices

EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES

▸ Customer places an order

▸ Then we need to generate a PDF invoice document

ORDER SERVICE

PDFSERVICE

THE EXAMPLE

Page 7: Lighning Talk: Event-Driven architecture for microservices

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

PDFSERVICE

THE EXAMPLE

Page 8: Lighning Talk: Event-Driven architecture for microservices

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

PDFSERVICE

THE EXAMPLE

Page 9: Lighning Talk: Event-Driven architecture for microservices

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

PDFSERVICE

POST POST

PATCH

POST

Page 10: Lighning Talk: Event-Driven architecture for microservices

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

PDFSERVICE

POST POST POST

PATCH

Page 11: Lighning Talk: Event-Driven architecture for microservices

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

PDFSERVICE

POST POST POST

PATCH

EMAIL SERVICE Send PDF to customer

CUSTOMER SERVICE

GET

Page 12: Lighning Talk: Event-Driven architecture for microservices

EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES

THIS DOES NOT SCALE VERY WELL!

Page 13: Lighning Talk: Event-Driven architecture for microservices

EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES

▸ Turn things the other way around

▸ But how will PDF service know when order was placed?

ORDER SERVICE

PDFSERVICE

POST POST?

THE SECOND APPROACH

Page 14: Lighning Talk: Event-Driven architecture for microservices

EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES

HERE COME EVENTS!

Page 15: Lighning Talk: Event-Driven architecture for microservices

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

Page 16: Lighning Talk: Event-Driven architecture for microservices

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

Page 17: Lighning Talk: Event-Driven architecture for microservices

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

Page 18: Lighning Talk: Event-Driven architecture for microservices

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

Page 19: Lighning Talk: Event-Driven architecture for microservices

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

Page 20: Lighning Talk: Event-Driven architecture for microservices

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

Page 21: Lighning Talk: Event-Driven architecture for microservices

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

Page 22: Lighning Talk: Event-Driven architecture for microservices

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

Page 23: Lighning Talk: Event-Driven architecture for microservices

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

Page 24: Lighning Talk: Event-Driven architecture for microservices

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

Page 25: Lighning Talk: Event-Driven architecture for microservices

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 updatedEmail sent

Page 26: Lighning Talk: Event-Driven architecture for microservices

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

Page 27: Lighning Talk: Event-Driven architecture for microservices

EVENT DRIVEN ARCHITECTURE FOR MICROSERVICES

THANKS!

[email protected]://joind.in/talk/f1078