SlideShare una empresa de Scribd logo
1 de 23
EVENT - DRIVEN
ARHITECTURE
Agenda
01
02
03
04
Introduction To Event Driven Architecture
What is Saga Pattern?
Choreography-Based Saga
Orchestration-Based Saga
Benefits of Event Driven Architecture
Message Brokers
What is Message Broker?
Vert.x
What is Vert.x?
How Does It Work?
Spring Web Reactive
What is WebFlux?
Spring MVS vs WebFlux
Event Driven Programming
Event-driven programming is a programming paradigm in which the
flow of program execution is determined by events - for example a
user action such as a mouse click, key press, or a message from th
e operating system or another program.
An event-driven application is designed to detect events as they
occur, and then deal with them using an appropriate event-handling
procedure.
What is a distributed transaction?
When a microservice architecture decomposes a monolithic system into self-encapsulated services,
it can break transactions. This means a local transaction in the monolithic system is now distributed
into multiple services that will be called in a sequence.
Monolithic System Microservices
03
What Is The Problem?
In a database system,
atomicity means that in a
transaction either all steps
complete or no steps
complete. The microservice-
based system does not have
a global transaction
coordinator by default. In the
example above, if the
CreateOrder method fails,
how do we roll back the
changes we applied by the
CustomerMicroservice?
How do we
keep the
transaction
atomic?
Do we
isolate user
actions for
concurrent
requests?
If an object is written by a
transaction and at the same
time (before the transaction
ends), it is read by another
request, should the object
return old data or updated
data? In the example above,
once UpdateCustomerFund
succeeds but is still waiting
for a response from
CreateOrder, should
requests for the current
customer’s fund return the
updated amount or not?
Possible SolutionsThe problems are important for microservice-based systems. Otherwise, there is no way to tell
if a transaction has completed successfully.
2pc Pattern
2pc is widely used in database
systems. For some situations,
you can use 2pc for
microservices. Just be careful;
not all situations suit 2pc and,
in fact, 2pc is considered
impractical within a
microservice architecture
Saga Pattern
The Saga pattern is another
widely used pattern for
distributed transactions. It is
different from 2pc, which is
synchronous. The Saga pattern
is asynchronous and reactive.
So what is a two-phase commit?
As its name hints, 2pc has two phases: A prepare phase and a commit phase. In the prepare phase, all
microservices will be asked to prepare for some data change that could be done atomically. Once all microservices
are prepared, the commit phase will ask all the microservices to make the actual changes.
Agenda Style2pcPattern
2pc is a very strong
consistency protocol. First, the
prepare and commit phases
guarantee that the transaction
is atomic. The transaction will
end with either all
microservices returning
successfully or all
microservices have nothing
changed. Secondly, 2pc allows
read-write isolation. This means
the changes on a field are not
visible until the coordinator
commits the changes.
Advantages
While 2pc has solved the
problem, it is not really
recommended for many
microservice-based systems
because 2pc is synchronous
(blocking). The protocol will
need to lock the object that will
be changed before the
transaction completes. This is
not good. In a database
system, transactions tend to
be fast—normally within 50 ms.
However, microservices have
long delays with RPC calls.
Disadvantages
The SAGA Pattern
A saga is a sequence of local transactions where each transaction updates data within a single service The first transac
tion is initiated by an external request corresponding to the system operation, and then each subsequent step is triggere
d by the completion of the previous one.
Events/Choreography: When there is no
central coordination, each service produces
and listen to other service’s events and
decides if an action should be taken or not.
Command/Orchestration: when a
coordinator service is responsible for
centralizing the saga’s decision making
and sequencing business logic
Events/Choreography
1.Order Service saves a new order, set the state as pe
nding and publish an event called ORDER_CREATED
_EVENT.
2. The Payment Service listens to ORDER_CREATED
_EVENT, charge the client and publish the event
BILLED_ORDER_EVENT.
3. The Stock Service listens to BILLED_ORDER_EVE
NT, update the stock, prepare the products bought in t
he order and publish ORDER_PREPARED_EVENT.
4. Delivery Service listens to ORDER_PREPARED_E
VENT and then pick up and deliver the product. At the
end, it publishes an ORDER_DELIVERED_EVENT
5. Finally, Order Service listens to
ORDER_DELIVERED_EVENT and set the state of th
e order
Rolling back in Saga’s Events/Choreography
1.Stock Service produces
PRODUCT_OUT_OF_STOCK_EVE
NT;
2.Both Order Service and Payment S
ervice listen to the previous message:
3.Payment Service refund the client
4.Order Service set the order state
as failed
Command/Orchestration
1.Order Service saves a pending order
and asks Order Saga Orchestrator (OS
O) to start a create order transaction.
2.OSO sends an Execute Payment co
mmand to Payment Service, and it repli
es with a Payment Executed message
3.OSO sends a Prepare Order comman
d to Stock Service, and it replies with a
n Order Prepared message
4.OSO sends a Deliver Order comman
d to Delivery Service, and it replies with
an Order Delivered message
Rolling back in Saga’s Command/Orchestration
1.Stock Service replies to OSO with an
Out-Of-Stock message;
2. OSO recognizes that the transaction
has failed and starts the rollback
In this case, only a single operation wa
s executed successfully before the failu
re, so OSO sends a Refund Client com
mand to Payment Service and set the o
rder state as failed
Agenda StyleSagaPattern
One big advantage of the Saga
pattern is its support for long-
lived transactions. Because
each microservice focuses only
on its own local atomic
transaction, other
microservices are not blocked if
a microservice is running for a
long time. This also allows
transactions to continue waiting
for user input. Also, because all
local transactions are
happening in parallel, there is
no lock on any object.
Advantages
The Saga pattern is difficult to
debug, especially when many
microservices are involved.
Also, the event messages
could become difficult to
maintain if the system gets
complex. Another
disadvantage of the Saga
pattern is it does not have read
isolation. For example, the
customer could see the order
being created, but in the next
second, the order is removed
due to a compensation
transaction.
Disadvantages
Message Broker
In its core, a message broker is “a program that
translates a message to a formal messaging
protocol of the sender, to the formal messaging
protocol of the receiver”
Which Message Brokers are out there to process my events?
There are tons of message brokers out there (ActiveMQ, Kafka, RabbitMQ, OMS, JMS, Redis
, Service Bus, …) three popular ones
Apache
Kafka
Azure
Event Hub RabbitMQ
RabbitMQ was one of the first open source message
brokers, developed to implement AMQP to work across
different platforms and languages.
Apache Kafka is a Message Broker originally developed by
LinkedIn and open sourced early 2011. It is just like Azure Event
Hub a platform capable of handling millions of events.
Azure Event Hub allows you to set up a scalable Event Hub that suits your
needs in a couple of seconds. It is a PaaS offering by Microsoft Azure, so that
you do not need to manage it, but rather just consume it.
Blocking vs. Non-Bloking
Blocking
In traditional MVC applications,
when a request come to server, a
servlet thread is created. It
delegates the request to worker
threads for I/O operations such as
database access etc. During the
time worker threads are busy,
servlet thread (request thread)
remain in waiting status and thus it
is blocked. It is also called
synchronous request processing.
Non-Bloking
All incoming requests come with a event
handler and call back information.
Request thread delegates the incoming
requests to a thread pool (generally
small number of threads) which
delegate the request to it’s handler
function and immediately start
processing other incoming requests
from request thread.
When the handler function is complete,
one of thread from pool collect the
response and pass it to the call back
function.
Eclipse Vert.x is event driven and
non blocking. This means your app
can handle a lot of concurrency
using a small number of kernel
threads. Vert.x lets your app scale
with minimal hardware.
Vert.x is incredibly flexible -
whether it's simple network utilities,
sophisticated modern web
applications, HTTP/REST
microservices, high volume event
processing or a full blown back-
end message-bus application,
Vert.x is a great fit.
You can use Vert.x with multiple
languages including Java,
JavaScript, Groovy, Ruby, Ceylon,
Scala and Kotlin.
01
02
03
04
Vert.x
Eclipse Vert.x is a tool-kit for building reactive applications on the JVM.
Polyglot
Scale
Flexible
Vert.x is an ideal choice for
creating light-weight, fast, high-
performance, microservices.
Fast
How does it look like?
Vert.x
Spring MVC
As you can see, you add a request handler to
your verticle. Then this handler will be invoked
by the event loop for every request.
After that you filter the requests (e.g. by HttpM
ethod and path) and respond. You also have to
start your HTTP server.
The difference is here that Spring Boot
provides defaults which allow you an easy
start and get fast results. Spring MVC
combined with Spring Boot has a higher
usability and an easier readability in general.
Also, you do not have to understand all that is
going on in the background to create your
Hello World application.
Spring WebFlux
Spring WebFlux framework is part of Spring 5 and provides reactive programming support for web applications.
Web
Flux
A non-blocking approach which makes it possible to handle
concurrency with a small number of threads and to scale effectively
Functional programming
Less memory
Availibility to serve traffic
Spring WebFlux is a reactive web framework based on a reactive HTTP
layer; such apps can be deployed on Netty or Undertow (with native
adapters) or Jetty/Tomcat/any Servlet 3.1 container (thanks to a Servlet
3.1 adapter).
Agenda Style
Servletvs.Reactive
5000Users
Spring-boot
web 2.0
Spring-boot
reactive web 2.0
Agenda Style
Servletvs.Reactive
10000Users
Spring-boot
web 2.0
Spring-boot
reactive web 2.0
Thank you
Betül Çetinkaya

Más contenido relacionado

La actualidad más candente

Domain Driven Design - Strategic Patterns and Microservices
Domain Driven Design - Strategic Patterns and MicroservicesDomain Driven Design - Strategic Patterns and Microservices
Domain Driven Design - Strategic Patterns and MicroservicesRadosław Maziarka
 
Describing Kafka security in AsyncAPI
Describing Kafka security in AsyncAPIDescribing Kafka security in AsyncAPI
Describing Kafka security in AsyncAPIDale Lane
 
Microservice architecture design principles
Microservice architecture design principlesMicroservice architecture design principles
Microservice architecture design principlesSanjoy Kumar Roy
 
Introduction to Event-Driven Architecture
Introduction to Event-Driven Architecture Introduction to Event-Driven Architecture
Introduction to Event-Driven Architecture Solace
 
High Concurrency Architecture at TIKI
High Concurrency Architecture at TIKIHigh Concurrency Architecture at TIKI
High Concurrency Architecture at TIKINghia Minh
 
Developing with the Go client for Apache Kafka
Developing with the Go client for Apache KafkaDeveloping with the Go client for Apache Kafka
Developing with the Go client for Apache KafkaJoe Stein
 
Event-driven microservices
Event-driven microservicesEvent-driven microservices
Event-driven microservicesAndrew Schofield
 
APACHE KAFKA / Kafka Connect / Kafka Streams
APACHE KAFKA / Kafka Connect / Kafka StreamsAPACHE KAFKA / Kafka Connect / Kafka Streams
APACHE KAFKA / Kafka Connect / Kafka StreamsKetan Gote
 
Event-Driven Architecture (EDA)
Event-Driven Architecture (EDA)Event-Driven Architecture (EDA)
Event-Driven Architecture (EDA)WSO2
 
Dekleratif Transaction Yönetimi
Dekleratif Transaction YönetimiDekleratif Transaction Yönetimi
Dekleratif Transaction YönetimiSistek Yazılım
 
Microservices Docker Kubernetes Istio Kanban DevOps SRE
Microservices Docker Kubernetes Istio Kanban DevOps SREMicroservices Docker Kubernetes Istio Kanban DevOps SRE
Microservices Docker Kubernetes Istio Kanban DevOps SREAraf Karsh Hamid
 
Integration Patterns and Anti-Patterns for Microservices Architectures
Integration Patterns and Anti-Patterns for Microservices ArchitecturesIntegration Patterns and Anti-Patterns for Microservices Architectures
Integration Patterns and Anti-Patterns for Microservices ArchitecturesApcera
 
Event Driven Architecture
Event Driven ArchitectureEvent Driven Architecture
Event Driven ArchitectureChris Patterson
 
The eBay Architecture: Striking a Balance between Site Stability, Feature Ve...
The eBay Architecture:  Striking a Balance between Site Stability, Feature Ve...The eBay Architecture:  Striking a Balance between Site Stability, Feature Ve...
The eBay Architecture: Striking a Balance between Site Stability, Feature Ve...Randy Shoup
 
IBM Integration Bus High Availability Overview
IBM Integration Bus High Availability OverviewIBM Integration Bus High Availability Overview
IBM Integration Bus High Availability OverviewPeter Broadhurst
 
CQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDDCQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDDDennis Doomen
 
Distributed Transactions: Saga Patterns
Distributed Transactions: Saga PatternsDistributed Transactions: Saga Patterns
Distributed Transactions: Saga PatternsKnoldus Inc.
 
Microservices with Kafka Ecosystem
Microservices with Kafka EcosystemMicroservices with Kafka Ecosystem
Microservices with Kafka EcosystemGuido Schmutz
 

La actualidad más candente (20)

Domain Driven Design - Strategic Patterns and Microservices
Domain Driven Design - Strategic Patterns and MicroservicesDomain Driven Design - Strategic Patterns and Microservices
Domain Driven Design - Strategic Patterns and Microservices
 
Describing Kafka security in AsyncAPI
Describing Kafka security in AsyncAPIDescribing Kafka security in AsyncAPI
Describing Kafka security in AsyncAPI
 
Microservice architecture design principles
Microservice architecture design principlesMicroservice architecture design principles
Microservice architecture design principles
 
Introduction to Event-Driven Architecture
Introduction to Event-Driven Architecture Introduction to Event-Driven Architecture
Introduction to Event-Driven Architecture
 
High Concurrency Architecture at TIKI
High Concurrency Architecture at TIKIHigh Concurrency Architecture at TIKI
High Concurrency Architecture at TIKI
 
Developing with the Go client for Apache Kafka
Developing with the Go client for Apache KafkaDeveloping with the Go client for Apache Kafka
Developing with the Go client for Apache Kafka
 
Event-driven microservices
Event-driven microservicesEvent-driven microservices
Event-driven microservices
 
APACHE KAFKA / Kafka Connect / Kafka Streams
APACHE KAFKA / Kafka Connect / Kafka StreamsAPACHE KAFKA / Kafka Connect / Kafka Streams
APACHE KAFKA / Kafka Connect / Kafka Streams
 
Event-Driven Architecture (EDA)
Event-Driven Architecture (EDA)Event-Driven Architecture (EDA)
Event-Driven Architecture (EDA)
 
Event driven architecture
Event driven architectureEvent driven architecture
Event driven architecture
 
Dekleratif Transaction Yönetimi
Dekleratif Transaction YönetimiDekleratif Transaction Yönetimi
Dekleratif Transaction Yönetimi
 
Microservices Docker Kubernetes Istio Kanban DevOps SRE
Microservices Docker Kubernetes Istio Kanban DevOps SREMicroservices Docker Kubernetes Istio Kanban DevOps SRE
Microservices Docker Kubernetes Istio Kanban DevOps SRE
 
Integration Patterns and Anti-Patterns for Microservices Architectures
Integration Patterns and Anti-Patterns for Microservices ArchitecturesIntegration Patterns and Anti-Patterns for Microservices Architectures
Integration Patterns and Anti-Patterns for Microservices Architectures
 
Event Driven Architecture
Event Driven ArchitectureEvent Driven Architecture
Event Driven Architecture
 
The eBay Architecture: Striking a Balance between Site Stability, Feature Ve...
The eBay Architecture:  Striking a Balance between Site Stability, Feature Ve...The eBay Architecture:  Striking a Balance between Site Stability, Feature Ve...
The eBay Architecture: Striking a Balance between Site Stability, Feature Ve...
 
IBM Integration Bus High Availability Overview
IBM Integration Bus High Availability OverviewIBM Integration Bus High Availability Overview
IBM Integration Bus High Availability Overview
 
CQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDDCQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDD
 
Distributed Transactions: Saga Patterns
Distributed Transactions: Saga PatternsDistributed Transactions: Saga Patterns
Distributed Transactions: Saga Patterns
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 
Microservices with Kafka Ecosystem
Microservices with Kafka EcosystemMicroservices with Kafka Ecosystem
Microservices with Kafka Ecosystem
 

Similar a EVENT-DRIVEN ARCHITECTURE AND MESSAGING

Microservices architecture
Microservices architectureMicroservices architecture
Microservices architectureFaren faren
 
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...apidays
 
Message Driven and Event Sourcing
Message Driven and Event SourcingMessage Driven and Event Sourcing
Message Driven and Event SourcingPaolo Castagna
 
RabbitMQ in Microservice Architecture.docx
RabbitMQ in Microservice Architecture.docxRabbitMQ in Microservice Architecture.docx
RabbitMQ in Microservice Architecture.docxShakuro
 
Data Microservices with Spring Cloud
Data Microservices with Spring CloudData Microservices with Spring Cloud
Data Microservices with Spring CloudOrkhan Gasimov
 
Microservices in a Streaming World
Microservices in a Streaming WorldMicroservices in a Streaming World
Microservices in a Streaming WorldHans Jespersen
 
Modern Cloud-Native Streaming Platforms: Event Streaming Microservices with K...
Modern Cloud-Native Streaming Platforms: Event Streaming Microservices with K...Modern Cloud-Native Streaming Platforms: Event Streaming Microservices with K...
Modern Cloud-Native Streaming Platforms: Event Streaming Microservices with K...confluent
 
Restate: Event-driven Asynchronous Services, Easy as Synchronous RPC
Restate: Event-driven Asynchronous Services, Easy as Synchronous RPCRestate: Event-driven Asynchronous Services, Easy as Synchronous RPC
Restate: Event-driven Asynchronous Services, Easy as Synchronous RPCHostedbyConfluent
 
101 mistakes FINN.no has made with Kafka (Baksida meetup)
101 mistakes FINN.no has made with Kafka (Baksida meetup)101 mistakes FINN.no has made with Kafka (Baksida meetup)
101 mistakes FINN.no has made with Kafka (Baksida meetup)Henning Spjelkavik
 
KinomaJS on Microcontroller
KinomaJS on MicrocontrollerKinomaJS on Microcontroller
KinomaJS on MicrocontrollerRyuji Ishiguro
 
Building Cloud Ready Apps
Building Cloud Ready AppsBuilding Cloud Ready Apps
Building Cloud Ready AppsVMware Tanzu
 
Arsitektur Aplikasi Modern - Faisal Henry Susanto
Arsitektur Aplikasi Modern - Faisal Henry SusantoArsitektur Aplikasi Modern - Faisal Henry Susanto
Arsitektur Aplikasi Modern - Faisal Henry SusantoDicodingEvent
 
ActiveMQ interview Questions and Answers
ActiveMQ interview Questions and AnswersActiveMQ interview Questions and Answers
ActiveMQ interview Questions and Answersjeetendra mandal
 
Event driven architecure
Event driven architecureEvent driven architecure
Event driven architecureTouraj Ebrahimi
 

Similar a EVENT-DRIVEN ARCHITECTURE AND MESSAGING (20)

Microservices architecture
Microservices architectureMicroservices architecture
Microservices architecture
 
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...
 
Message Driven and Event Sourcing
Message Driven and Event SourcingMessage Driven and Event Sourcing
Message Driven and Event Sourcing
 
RabbitMQ in Microservice Architecture.docx
RabbitMQ in Microservice Architecture.docxRabbitMQ in Microservice Architecture.docx
RabbitMQ in Microservice Architecture.docx
 
Microservices
MicroservicesMicroservices
Microservices
 
Microservices
MicroservicesMicroservices
Microservices
 
Data Microservices with Spring Cloud
Data Microservices with Spring CloudData Microservices with Spring Cloud
Data Microservices with Spring Cloud
 
Microservices in a Streaming World
Microservices in a Streaming WorldMicroservices in a Streaming World
Microservices in a Streaming World
 
Modern Cloud-Native Streaming Platforms: Event Streaming Microservices with K...
Modern Cloud-Native Streaming Platforms: Event Streaming Microservices with K...Modern Cloud-Native Streaming Platforms: Event Streaming Microservices with K...
Modern Cloud-Native Streaming Platforms: Event Streaming Microservices with K...
 
20240
2024020240
20240
 
Microservices with Spring
Microservices with SpringMicroservices with Spring
Microservices with Spring
 
Whitepaper : Event Driven Micro Services
Whitepaper : Event Driven Micro ServicesWhitepaper : Event Driven Micro Services
Whitepaper : Event Driven Micro Services
 
Restate: Event-driven Asynchronous Services, Easy as Synchronous RPC
Restate: Event-driven Asynchronous Services, Easy as Synchronous RPCRestate: Event-driven Asynchronous Services, Easy as Synchronous RPC
Restate: Event-driven Asynchronous Services, Easy as Synchronous RPC
 
101 mistakes FINN.no has made with Kafka (Baksida meetup)
101 mistakes FINN.no has made with Kafka (Baksida meetup)101 mistakes FINN.no has made with Kafka (Baksida meetup)
101 mistakes FINN.no has made with Kafka (Baksida meetup)
 
KinomaJS on Microcontroller
KinomaJS on MicrocontrollerKinomaJS on Microcontroller
KinomaJS on Microcontroller
 
Building Cloud Ready Apps
Building Cloud Ready AppsBuilding Cloud Ready Apps
Building Cloud Ready Apps
 
Arsitektur Aplikasi Modern - Faisal Henry Susanto
Arsitektur Aplikasi Modern - Faisal Henry SusantoArsitektur Aplikasi Modern - Faisal Henry Susanto
Arsitektur Aplikasi Modern - Faisal Henry Susanto
 
Event driven systems
Event driven systems Event driven systems
Event driven systems
 
ActiveMQ interview Questions and Answers
ActiveMQ interview Questions and AnswersActiveMQ interview Questions and Answers
ActiveMQ interview Questions and Answers
 
Event driven architecure
Event driven architecureEvent driven architecure
Event driven architecure
 

Más de Sistek Yazılım

Más de Sistek Yazılım (10)

Javascript Today
Javascript TodayJavascript Today
Javascript Today
 
Amazon web service
Amazon web serviceAmazon web service
Amazon web service
 
Dashboard Kit
Dashboard KitDashboard Kit
Dashboard Kit
 
So Bot
So BotSo Bot
So Bot
 
Be Agile
Be AgileBe Agile
Be Agile
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Servlet Container Nedir?
Servlet Container Nedir?Servlet Container Nedir?
Servlet Container Nedir?
 
Hybrid Mobile Applications
Hybrid Mobile ApplicationsHybrid Mobile Applications
Hybrid Mobile Applications
 
No SQL & MongoDB Nedir?
No SQL & MongoDB Nedir?No SQL & MongoDB Nedir?
No SQL & MongoDB Nedir?
 
Spring uygulamaların exception handling yönetimi
Spring uygulamaların exception handling yönetimiSpring uygulamaların exception handling yönetimi
Spring uygulamaların exception handling yönetimi
 

Último

Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 

Último (20)

Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 

EVENT-DRIVEN ARCHITECTURE AND MESSAGING

  • 2. Agenda 01 02 03 04 Introduction To Event Driven Architecture What is Saga Pattern? Choreography-Based Saga Orchestration-Based Saga Benefits of Event Driven Architecture Message Brokers What is Message Broker? Vert.x What is Vert.x? How Does It Work? Spring Web Reactive What is WebFlux? Spring MVS vs WebFlux
  • 3. Event Driven Programming Event-driven programming is a programming paradigm in which the flow of program execution is determined by events - for example a user action such as a mouse click, key press, or a message from th e operating system or another program. An event-driven application is designed to detect events as they occur, and then deal with them using an appropriate event-handling procedure.
  • 4. What is a distributed transaction? When a microservice architecture decomposes a monolithic system into self-encapsulated services, it can break transactions. This means a local transaction in the monolithic system is now distributed into multiple services that will be called in a sequence. Monolithic System Microservices 03
  • 5. What Is The Problem? In a database system, atomicity means that in a transaction either all steps complete or no steps complete. The microservice- based system does not have a global transaction coordinator by default. In the example above, if the CreateOrder method fails, how do we roll back the changes we applied by the CustomerMicroservice? How do we keep the transaction atomic? Do we isolate user actions for concurrent requests? If an object is written by a transaction and at the same time (before the transaction ends), it is read by another request, should the object return old data or updated data? In the example above, once UpdateCustomerFund succeeds but is still waiting for a response from CreateOrder, should requests for the current customer’s fund return the updated amount or not?
  • 6. Possible SolutionsThe problems are important for microservice-based systems. Otherwise, there is no way to tell if a transaction has completed successfully. 2pc Pattern 2pc is widely used in database systems. For some situations, you can use 2pc for microservices. Just be careful; not all situations suit 2pc and, in fact, 2pc is considered impractical within a microservice architecture Saga Pattern The Saga pattern is another widely used pattern for distributed transactions. It is different from 2pc, which is synchronous. The Saga pattern is asynchronous and reactive.
  • 7. So what is a two-phase commit? As its name hints, 2pc has two phases: A prepare phase and a commit phase. In the prepare phase, all microservices will be asked to prepare for some data change that could be done atomically. Once all microservices are prepared, the commit phase will ask all the microservices to make the actual changes.
  • 8. Agenda Style2pcPattern 2pc is a very strong consistency protocol. First, the prepare and commit phases guarantee that the transaction is atomic. The transaction will end with either all microservices returning successfully or all microservices have nothing changed. Secondly, 2pc allows read-write isolation. This means the changes on a field are not visible until the coordinator commits the changes. Advantages While 2pc has solved the problem, it is not really recommended for many microservice-based systems because 2pc is synchronous (blocking). The protocol will need to lock the object that will be changed before the transaction completes. This is not good. In a database system, transactions tend to be fast—normally within 50 ms. However, microservices have long delays with RPC calls. Disadvantages
  • 9. The SAGA Pattern A saga is a sequence of local transactions where each transaction updates data within a single service The first transac tion is initiated by an external request corresponding to the system operation, and then each subsequent step is triggere d by the completion of the previous one. Events/Choreography: When there is no central coordination, each service produces and listen to other service’s events and decides if an action should be taken or not. Command/Orchestration: when a coordinator service is responsible for centralizing the saga’s decision making and sequencing business logic
  • 10. Events/Choreography 1.Order Service saves a new order, set the state as pe nding and publish an event called ORDER_CREATED _EVENT. 2. The Payment Service listens to ORDER_CREATED _EVENT, charge the client and publish the event BILLED_ORDER_EVENT. 3. The Stock Service listens to BILLED_ORDER_EVE NT, update the stock, prepare the products bought in t he order and publish ORDER_PREPARED_EVENT. 4. Delivery Service listens to ORDER_PREPARED_E VENT and then pick up and deliver the product. At the end, it publishes an ORDER_DELIVERED_EVENT 5. Finally, Order Service listens to ORDER_DELIVERED_EVENT and set the state of th e order
  • 11. Rolling back in Saga’s Events/Choreography 1.Stock Service produces PRODUCT_OUT_OF_STOCK_EVE NT; 2.Both Order Service and Payment S ervice listen to the previous message: 3.Payment Service refund the client 4.Order Service set the order state as failed
  • 12. Command/Orchestration 1.Order Service saves a pending order and asks Order Saga Orchestrator (OS O) to start a create order transaction. 2.OSO sends an Execute Payment co mmand to Payment Service, and it repli es with a Payment Executed message 3.OSO sends a Prepare Order comman d to Stock Service, and it replies with a n Order Prepared message 4.OSO sends a Deliver Order comman d to Delivery Service, and it replies with an Order Delivered message
  • 13. Rolling back in Saga’s Command/Orchestration 1.Stock Service replies to OSO with an Out-Of-Stock message; 2. OSO recognizes that the transaction has failed and starts the rollback In this case, only a single operation wa s executed successfully before the failu re, so OSO sends a Refund Client com mand to Payment Service and set the o rder state as failed
  • 14. Agenda StyleSagaPattern One big advantage of the Saga pattern is its support for long- lived transactions. Because each microservice focuses only on its own local atomic transaction, other microservices are not blocked if a microservice is running for a long time. This also allows transactions to continue waiting for user input. Also, because all local transactions are happening in parallel, there is no lock on any object. Advantages The Saga pattern is difficult to debug, especially when many microservices are involved. Also, the event messages could become difficult to maintain if the system gets complex. Another disadvantage of the Saga pattern is it does not have read isolation. For example, the customer could see the order being created, but in the next second, the order is removed due to a compensation transaction. Disadvantages
  • 15. Message Broker In its core, a message broker is “a program that translates a message to a formal messaging protocol of the sender, to the formal messaging protocol of the receiver”
  • 16. Which Message Brokers are out there to process my events? There are tons of message brokers out there (ActiveMQ, Kafka, RabbitMQ, OMS, JMS, Redis , Service Bus, …) three popular ones Apache Kafka Azure Event Hub RabbitMQ RabbitMQ was one of the first open source message brokers, developed to implement AMQP to work across different platforms and languages. Apache Kafka is a Message Broker originally developed by LinkedIn and open sourced early 2011. It is just like Azure Event Hub a platform capable of handling millions of events. Azure Event Hub allows you to set up a scalable Event Hub that suits your needs in a couple of seconds. It is a PaaS offering by Microsoft Azure, so that you do not need to manage it, but rather just consume it.
  • 17. Blocking vs. Non-Bloking Blocking In traditional MVC applications, when a request come to server, a servlet thread is created. It delegates the request to worker threads for I/O operations such as database access etc. During the time worker threads are busy, servlet thread (request thread) remain in waiting status and thus it is blocked. It is also called synchronous request processing. Non-Bloking All incoming requests come with a event handler and call back information. Request thread delegates the incoming requests to a thread pool (generally small number of threads) which delegate the request to it’s handler function and immediately start processing other incoming requests from request thread. When the handler function is complete, one of thread from pool collect the response and pass it to the call back function.
  • 18. Eclipse Vert.x is event driven and non blocking. This means your app can handle a lot of concurrency using a small number of kernel threads. Vert.x lets your app scale with minimal hardware. Vert.x is incredibly flexible - whether it's simple network utilities, sophisticated modern web applications, HTTP/REST microservices, high volume event processing or a full blown back- end message-bus application, Vert.x is a great fit. You can use Vert.x with multiple languages including Java, JavaScript, Groovy, Ruby, Ceylon, Scala and Kotlin. 01 02 03 04 Vert.x Eclipse Vert.x is a tool-kit for building reactive applications on the JVM. Polyglot Scale Flexible Vert.x is an ideal choice for creating light-weight, fast, high- performance, microservices. Fast
  • 19. How does it look like? Vert.x Spring MVC As you can see, you add a request handler to your verticle. Then this handler will be invoked by the event loop for every request. After that you filter the requests (e.g. by HttpM ethod and path) and respond. You also have to start your HTTP server. The difference is here that Spring Boot provides defaults which allow you an easy start and get fast results. Spring MVC combined with Spring Boot has a higher usability and an easier readability in general. Also, you do not have to understand all that is going on in the background to create your Hello World application.
  • 20. Spring WebFlux Spring WebFlux framework is part of Spring 5 and provides reactive programming support for web applications. Web Flux A non-blocking approach which makes it possible to handle concurrency with a small number of threads and to scale effectively Functional programming Less memory Availibility to serve traffic Spring WebFlux is a reactive web framework based on a reactive HTTP layer; such apps can be deployed on Netty or Undertow (with native adapters) or Jetty/Tomcat/any Servlet 3.1 container (thanks to a Servlet 3.1 adapter).