Grigoriadis Grigoris Co-Founder & Software Architect @ Microservices enthusiast !
Introduction Event-Based Microservices
What we will cover ● What is Monolithic Architecture ● What is Microservices Architecture ● Pros/Cons ● Moving to Event Based Microservices
Monolithic Architecture DB UI Module Function calls Server ● Building block is the code modules ● Modules communicate with each other using function calls ● System is deployed and run as a single OS process ● A Database is used in order to store the system state, usually a relational database
Microservice Architecture - Bare Minimum UI Microservice HTTP calls API Gateway ● Building block is the microservices ● Services communicate with each other via a lightweight interoperable communication protocol, usually HTTP ● Each service MUST have its own database ● An API Gateway provides a unified API for our system
Q&A
Architectural Factors Scalability Maintainability Evolvability Fault Tolerance How well the system handles a growing amount of data/requests? Is the system simple and easy to understand? Is the system design in such a way that can evolve along with the product requirements and the changing ecosystem? When part of the system fails does it fail completely? Horizontal
Scalability Load Balancer API Gateway API Gateway Load Balancer ● The entire system must be scaled ● Different modules might have different resource requirements ● Services can be deployed on different machines ● Services can be scaled independently Monolithic Microservices ● Databases must be scaled along with microservices ● Service discovery ● Easier to scale
Maintainability Monolithic Microservices ● Easier to debug ● Each service is small in code size and easier to understand ● Easier to work with different teams ● Boundaries between modules tend to break ● Code size becomes intimidating ● A change can impact the whole system ● Communication between services might become complicated and difficult to follow ● Business logic might leak to API Gateway and can become complex API Gateway
Evolvability Monolithic Microservices ● Microservices can be rewritten individually in different language using different database ● Changes in infrastructure can be applied gradually to each microservice ● Refactoring in Database is easier since each database is governed by 1 team ● Any change, such language change, db change etc. must be applied to the whole application ● Refactoring database requires coordination between multiple teams t t
Fault Tolerance Monolithic Microservices ● Part of the system will continue to work even if some services are not working ● If a module has a memory leak or malfunctions the whole system might stop working
Q&A
Microservice Architecture - Event Based ● An event is a fact, something that has already happened and cannot change ● Every state change must generate an event ● Events should NOT be overly generic (e.g. OrderUpdated), prefer more specific events like OrderStatusChanged or even better OrderDispatched etc. ● Events should contain only data relevant to the event. Event +entityId: string +time: DateTime +type: string
Microservice Architecture - Event Based UI Microservice Through Broker (Pub-Sub) API Gateway Broker ● Microservices publish events in the broker and consume events that are of interest in order to update their databases ● Services do not communicate with each other to exchange information, they duplicate the data they need from events ● System has Eventual Consistency ● Better performance ● Fault tolerant ● Service discovery only used by API Gateway ● Difficult to design ● API Gateway is still complex
Microservice Architecture - CQRS UI Command Microservices Through Broker API Gateway Broker Query Microservices ● Command microservices update the state of our system and publish events ● Query microservices deal with keeping the data in a schema appropriate for the UI ● Better performance ● Decoupled read from write schema ● API Gateway does not need to compose calls ● Still need to commit to multiple middleware
Microservice Architecture - Event Sourcing UI Through Event Store API Gateway Event Store Command Microservices Query Microservices ● All state changes in our system are represented as events. ● All events are persisted in an event store. ● Each microservice creates its state from the events in the event store and keeps a snapshot for faster access. ● Better performance ● Each microservice can recreate its state ● Difficult to implement
Q&A Thank you!

Introduction to event based microservices

  • 2.
    Grigoriadis Grigoris Co-Founder &Software Architect @ Microservices enthusiast !
  • 3.
  • 4.
    What we willcover ● What is Monolithic Architecture ● What is Microservices Architecture ● Pros/Cons ● Moving to Event Based Microservices
  • 5.
    Monolithic Architecture DB UI Module Functioncalls Server ● Building block is the code modules ● Modules communicate with each other using function calls ● System is deployed and run as a single OS process ● A Database is used in order to store the system state, usually a relational database
  • 6.
    Microservice Architecture -Bare Minimum UI Microservice HTTP calls API Gateway ● Building block is the microservices ● Services communicate with each other via a lightweight interoperable communication protocol, usually HTTP ● Each service MUST have its own database ● An API Gateway provides a unified API for our system
  • 7.
  • 8.
    Architectural Factors Scalability MaintainabilityEvolvability Fault Tolerance How well the system handles a growing amount of data/requests? Is the system simple and easy to understand? Is the system design in such a way that can evolve along with the product requirements and the changing ecosystem? When part of the system fails does it fail completely? Horizontal
  • 9.
    Scalability Load Balancer API GatewayAPI Gateway Load Balancer ● The entire system must be scaled ● Different modules might have different resource requirements ● Services can be deployed on different machines ● Services can be scaled independently Monolithic Microservices ● Databases must be scaled along with microservices ● Service discovery ● Easier to scale
  • 10.
    Maintainability Monolithic Microservices ● Easier todebug ● Each service is small in code size and easier to understand ● Easier to work with different teams ● Boundaries between modules tend to break ● Code size becomes intimidating ● A change can impact the whole system ● Communication between services might become complicated and difficult to follow ● Business logic might leak to API Gateway and can become complex API Gateway
  • 11.
    Evolvability Monolithic Microservices ● Microservices canbe rewritten individually in different language using different database ● Changes in infrastructure can be applied gradually to each microservice ● Refactoring in Database is easier since each database is governed by 1 team ● Any change, such language change, db change etc. must be applied to the whole application ● Refactoring database requires coordination between multiple teams t t
  • 12.
    Fault Tolerance Monolithic Microservices ● Partof the system will continue to work even if some services are not working ● If a module has a memory leak or malfunctions the whole system might stop working
  • 13.
  • 14.
    Microservice Architecture -Event Based ● An event is a fact, something that has already happened and cannot change ● Every state change must generate an event ● Events should NOT be overly generic (e.g. OrderUpdated), prefer more specific events like OrderStatusChanged or even better OrderDispatched etc. ● Events should contain only data relevant to the event. Event +entityId: string +time: DateTime +type: string
  • 15.
    Microservice Architecture -Event Based UI Microservice Through Broker (Pub-Sub) API Gateway Broker ● Microservices publish events in the broker and consume events that are of interest in order to update their databases ● Services do not communicate with each other to exchange information, they duplicate the data they need from events ● System has Eventual Consistency ● Better performance ● Fault tolerant ● Service discovery only used by API Gateway ● Difficult to design ● API Gateway is still complex
  • 16.
    Microservice Architecture -CQRS UI Command Microservices Through Broker API Gateway Broker Query Microservices ● Command microservices update the state of our system and publish events ● Query microservices deal with keeping the data in a schema appropriate for the UI ● Better performance ● Decoupled read from write schema ● API Gateway does not need to compose calls ● Still need to commit to multiple middleware
  • 17.
    Microservice Architecture -Event Sourcing UI Through Event Store API Gateway Event Store Command Microservices Query Microservices ● All state changes in our system are represented as events. ● All events are persisted in an event store. ● Each microservice creates its state from the events in the event store and keeps a snapshot for faster access. ● Better performance ● Each microservice can recreate its state ● Difficult to implement
  • 18.