SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 
Design patterns for microservice architecture
Design patterns for microservice architectureDesign patterns for microservice architecture
Design patterns for microservice architectureThe Software House
 
Real-Life Use Cases & Architectures for Event Streaming with Apache Kafka
Real-Life Use Cases & Architectures for Event Streaming with Apache KafkaReal-Life Use Cases & Architectures for Event Streaming with Apache Kafka
Real-Life Use Cases & Architectures for Event Streaming with Apache KafkaKai Wähner
 
Event Driven Software Architecture Pattern
Event Driven Software Architecture PatternEvent Driven Software Architecture Pattern
Event Driven Software Architecture Patternjeetendra mandal
 
Microservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitectureMicroservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitecturePaul Mooney
 
Introduction to Event Driven Architecture
Introduction to Event Driven ArchitectureIntroduction to Event Driven Architecture
Introduction to Event Driven ArchitectureCitiusTech
 
Hello, kafka! (an introduction to apache kafka)
Hello, kafka! (an introduction to apache kafka)Hello, kafka! (an introduction to apache kafka)
Hello, kafka! (an introduction to apache kafka)Timothy Spann
 
Disaster Recovery Plans for Apache Kafka
Disaster Recovery Plans for Apache KafkaDisaster Recovery Plans for Apache Kafka
Disaster Recovery Plans for Apache Kafkaconfluent
 
Microservice Architecture using Spring Boot with React & Redux
Microservice Architecture using Spring Boot with React & ReduxMicroservice Architecture using Spring Boot with React & Redux
Microservice Architecture using Spring Boot with React & ReduxNexThoughts Technologies
 
Introduction to microservices
Introduction to microservicesIntroduction to microservices
Introduction to microservicesAnil Allewar
 
SpringBoot 3 Observability
SpringBoot 3 ObservabilitySpringBoot 3 Observability
SpringBoot 3 ObservabilityKnoldus Inc.
 
Introduction to Event-Driven Architecture
Introduction to Event-Driven Architecture Introduction to Event-Driven Architecture
Introduction to Event-Driven Architecture Solace
 
실전 서버 부하테스트 노하우
실전 서버 부하테스트 노하우 실전 서버 부하테스트 노하우
실전 서버 부하테스트 노하우 YoungSu Son
 
ksqlDB로 시작하는 스트림 프로세싱
ksqlDB로 시작하는 스트림 프로세싱ksqlDB로 시작하는 스트림 프로세싱
ksqlDB로 시작하는 스트림 프로세싱confluent
 
Microservices Architecture - Bangkok 2018
Microservices Architecture - Bangkok 2018Microservices Architecture - Bangkok 2018
Microservices Architecture - Bangkok 2018Araf Karsh Hamid
 
CQRS and Event Sourcing in Action
CQRS and Event  Sourcing in ActionCQRS and Event  Sourcing in Action
CQRS and Event Sourcing in ActionKnoldus Inc.
 
Microservice Architecture
Microservice ArchitectureMicroservice Architecture
Microservice ArchitectureNguyen Tung
 
Kafka replication apachecon_2013
Kafka replication apachecon_2013Kafka replication apachecon_2013
Kafka replication apachecon_2013Jun Rao
 

Was ist angesagt? (20)

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
 
Design patterns for microservice architecture
Design patterns for microservice architectureDesign patterns for microservice architecture
Design patterns for microservice architecture
 
Real-Life Use Cases & Architectures for Event Streaming with Apache Kafka
Real-Life Use Cases & Architectures for Event Streaming with Apache KafkaReal-Life Use Cases & Architectures for Event Streaming with Apache Kafka
Real-Life Use Cases & Architectures for Event Streaming with Apache Kafka
 
Event Driven Software Architecture Pattern
Event Driven Software Architecture PatternEvent Driven Software Architecture Pattern
Event Driven Software Architecture Pattern
 
Microservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitectureMicroservice vs. Monolithic Architecture
Microservice vs. Monolithic Architecture
 
Introduction to Event Driven Architecture
Introduction to Event Driven ArchitectureIntroduction to Event Driven Architecture
Introduction to Event Driven Architecture
 
Hello, kafka! (an introduction to apache kafka)
Hello, kafka! (an introduction to apache kafka)Hello, kafka! (an introduction to apache kafka)
Hello, kafka! (an introduction to apache kafka)
 
Disaster Recovery Plans for Apache Kafka
Disaster Recovery Plans for Apache KafkaDisaster Recovery Plans for Apache Kafka
Disaster Recovery Plans for Apache Kafka
 
Microservice Architecture using Spring Boot with React & Redux
Microservice Architecture using Spring Boot with React & ReduxMicroservice Architecture using Spring Boot with React & Redux
Microservice Architecture using Spring Boot with React & Redux
 
Introduction to microservices
Introduction to microservicesIntroduction to microservices
Introduction to microservices
 
SpringBoot 3 Observability
SpringBoot 3 ObservabilitySpringBoot 3 Observability
SpringBoot 3 Observability
 
Introduction to Event-Driven Architecture
Introduction to Event-Driven Architecture Introduction to Event-Driven Architecture
Introduction to Event-Driven Architecture
 
실전 서버 부하테스트 노하우
실전 서버 부하테스트 노하우 실전 서버 부하테스트 노하우
실전 서버 부하테스트 노하우
 
ksqlDB로 시작하는 스트림 프로세싱
ksqlDB로 시작하는 스트림 프로세싱ksqlDB로 시작하는 스트림 프로세싱
ksqlDB로 시작하는 스트림 프로세싱
 
Microservices Architecture - Bangkok 2018
Microservices Architecture - Bangkok 2018Microservices Architecture - Bangkok 2018
Microservices Architecture - Bangkok 2018
 
CQRS and Event Sourcing in Action
CQRS and Event  Sourcing in ActionCQRS and Event  Sourcing in Action
CQRS and Event Sourcing in Action
 
Microservice Architecture
Microservice ArchitectureMicroservice Architecture
Microservice Architecture
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 
Kafka replication apachecon_2013
Kafka replication apachecon_2013Kafka replication apachecon_2013
Kafka replication apachecon_2013
 
Kafka internals
Kafka internalsKafka internals
Kafka internals
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von Sistek Yazılım

Mehr von Sistek Yazılım (11)

Javascript Today
Javascript TodayJavascript Today
Javascript Today
 
Amazon web service
Amazon web serviceAmazon web service
Amazon web service
 
Dekleratif Transaction Yönetimi
Dekleratif Transaction YönetimiDekleratif Transaction Yönetimi
Dekleratif Transaction Yönetimi
 
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
 

Kürzlich hochgeladen

Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
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
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
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
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
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
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
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
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROmotivationalword821
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 

Kürzlich hochgeladen (20)

Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
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
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
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
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
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
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
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)
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTRO
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 

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).