SlideShare a Scribd company logo
1 of 54
Download to read offline
@rafabene e @roanbrasil - https://bit.ly/sagakafka 1
Saga Pattern and Event
Sourcing with Kafka
https://bit.ly/sagakafkaLink
@rafabene
rafael.benevides@oracle.com
@roanbrasil
rmonteiro@astek-canada.ca
@rafabene e @roanbrasil - https://bit.ly/sagakafka
rafael.benevides@gmail.com
@rafabene
apiVersion: oracle/v1
kind: PrincipalSolutionArchitect
metadata:
name: Rafael Benevides
namespace: Oracle Linux team
annotations:
apache/contributor: Apache DeltaSpike
PMC
labels:
developer: Java, NodeJS
hobby: 4x4, drones
spec:
replicas: 1
containers:
image: benevides/rafael:latest
Rafael Benevides
@rafabene e @roanbrasil - https://bit.ly/sagakafka
roanbrasil@gmail.com
@roanbrasil
apiVersion: astek-canada/v1
kind: JavaDeveloper
metadata:
name: Roan Brasil Monteiro
namespace: Java Developer team
labels:
developer: Java, NodeJS
hobby: guitar, video game, snorkeling,
soccer
spec:
replicas: 1
containers:
image: brasilmonteiro/roan:latest
Roan Brasil Monteiro
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Before we get started…
● I don't use microservices and love my monolith.
● I've started using microservices.
● I've heard about Event Sourcing and Sagas before.
● I do microservices using Event Sourcing at work.
● I've implemented Saga Patterns.
Who are you?
@rafabene e @roanbrasil - https://bit.ly/sagakafka
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Monolithic architecture
Order
Module
Booking
Module
Payment
Module
Web
UI Database
Browser /
Client
BEWARE: This is
NOT an anti-pattern!
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Moving to Microservices
Database
Browser /
Client
Order
Module
Booking
Module
Payment
Module
Web
UI
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Moving to Microservices
Database
Browser /
Client
Order
Service
Booking
Service
Payment
Service
Web
UI Database
Database
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Microservices Architecture (synchronous calls)
Database
Browser /
Client
Order
Service
Booking
Service
Payment
Service
Web
UI
Database
Database
1) New
Order
2) Room
Reservation
3) ProcessPayment
REST Calls
@rafabene e @roanbrasil - https://bit.ly/sagakafka
No ACID transaction that span services
Database
Browser /
Client
Order
Service
Booking
Service
Payment
Service
Web
UI
Database
Database
1) New
Order
2) Room
Reservation
3) ProcessPayment
T1
T2
T3
REST Calls
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Exceptions: No room available (synchronous calls)
Database
Browser /
Client
Order
Service
Booking
Service
Web
UI
Database1) New
Order
2) Room
Reservation
3) Exception
happened4) Cancel
order
REST Calls
1:1 services involved
That was easy!
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Exceptions: Payment Denied (synchronous calls)
Database
Browser /
Client
Order
Service
Booking
Service
Payment
Service
Web
UI
Database
Database
1) New
Order
2) Room
Reservation
3) ProcessPayment
6) Cancel Booking???6) Cancel
Booking???
REST Calls
4) Exception
happened
5) Cancel
order
● What if I have 10 microservices
to rollback?
● Can you spot the complexity?
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Death Star Architectures
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Can I use 2PC?
Prepare phase
Database
Browser /
Client
Order
Service
Booking
Service
Payment
Service
Web
UI
Database
Database
1) New
Order
2) Room
Reservation
3) ProcessPayment
Prepare
Prepare
Prepare
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Can I use 2PC?
Prepare phase
Database
Browser /
Client
Order
Service
Booking
Service
Payment
Service
Web
UI
Database
Database
1) New
Order
2) Room
Reservation
3) ProcessPayment
Prepared
Prepared
Prepared
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Can I use 2PC?
Commit phase
Database
Browser /
Client
Order
Service
Booking
Service
Payment
Service
Web
UI
Database
Database
1) New
Order
2) Room
Reservation
3) ProcessPayment
Commit/
Abort
Commit/
Abort
Commit/
Abort
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Can I use 2PC?
Commit phase
Database
Browser /
Client
Order
Service
Booking
Service
Payment
Service
Web
UI
Database
Database
1) New
Order
2) Room
Reservation
3) ProcessPayment
Done
Done
Done
Problems of 2 Phase commit
● Transaction coordinator is the SPF.
● Others have to wait until the slowest resource finish its confirmation.
○ Ex. Credit card payment can take up to 30 seconds to reply.
○ Databases are locked during that time.
○ Can cause deadlocks.
● Reduced throughput due to locks.
● Not supported by many NoSQL databases.
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Saga: A solution from 1987
https://www.cs.cornell.edu/andru/cs711/2002fa/reading/sagas.pdf
@rafabene e @roanbrasil - https://bit.ly/sagakafka
How does the saga work?
Order
Service
Order
createOrder()
Order{
state = PENDING
}
Order
Service
Order
Order{
state = APPROVED
}
Payment
Service
Account
PaymentInfo{
state = APPROVED
}
@rafabene e @roanbrasil - https://bit.ly/sagakafka
How does the rollback work?
Use compensating transactions to "undo" the business logic.
Order
createOrder()
Booking
reserveRoom()
Payment
withdraw()
Order
cancelOrder()
No rooms
available
Booking
cancel
Reservation()
T1 T2 T3
C1 C2
T1 T2 C1
T3 and C2 were not called
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Rollback: Payment Denied
Order
Service
Order
createOrder()
Order{
state = PENDING
}
Order
Service
Order
Order{
state = CANCELED
}
Payment
Service
Account
PaymentInfo{
state = DENIED
}
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Rollback exception: Payment service unavailable
Order
Service
Order
createOrder()
Order{
state = PENDING
}
Order
Service
Order
Order{
state = PENDING
}
Payment
Service
Account
REST Call
Client and Server must be
always available
Order will be PENDING
forever
We need to go asynchronous
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Event Sourcing
(An express explanation)
@rafabene e @roanbrasil - https://bit.ly/sagakafka
What is event sourcing?
Architectural style where you:
● Don't save the current state of objects
● Save the events that lead to the current state (ORDER IS IMPORTANT)
● Events happened in the past
● Example:
AccountDeposit
accountNumber: 123456-700
value: 100.50
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Creating events to change to state
BankAccountCreated
Id: 123
Owner: Rafael
BankAccount
Events State
BankAccount
Id: 123
Owner: Rafael
Balance: 0
MoneyDeposited
account: 123
value: 100
BankAccount
Id: 123
Owner: Rafael
Balance: 100
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Creating events to change to state
MoneyWithdraw
account: 123
value: 60
Events State
BankAccount
Id: 123
Owner: Rafael
Balance: 100
BankAccount
Id: 123
Owner: Rafael
Balance: 40
MoneyWithdraw
account: 123
value: 60
BankAccount
Id: 123
Owner: Rafael
Balance: 40
Event not possible to
be handled
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Command Sourcing
(An express explanation)
@rafabene e @roanbrasil - https://bit.ly/sagakafka
What is command sourcing?
Architectural style where you:
● Persist commands
● Says what command/intention should be performed
● Wait for replies
● Example:
ExecuteAccountWithdraw
accountNumber:
123456-700
value: 100.50
InsuficientBalanceReply
accountNumber:
123456-700
requestedValue: 100.50
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Saga Patterns
● Choreography-based sagas - services collaborate by exchanging domain events
● Orchestration-based sagas - a centralized coordinator sending command
messages to participants, which respond with reply messages
https://eventuate.io/post/eventuate/2020/02/24/why-eventuate.html
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Saga Pattern:
Choreography-based
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Order
Service
Event Store
createOrder()
Publish
OrderCreatedEvent
Booking
Service
Consume
OrderCreatedEvent
Publish
BookCreatedEvent
Payment
Service
Consume
BookCreatedEvent
Publish
PaymentSuccess
Consume
BookConfirmedEvent
Choreography
Consume
PaymentSuccess
Publish
BookConfirmedEvent
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Order
Service
Event Store
createOrder()
Publish
OrderCreatedEvent
Booking
Service
Consume
OrderCreatedEvent
Publish
NoRoomEvent
Payment
Service
Consume
NoRoomEvent
Choreography: No rooms available
Compensating
transaction
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Order
Service
Event Store
createOrder()
Publish
OrderCreatedEvent
Booking
Service
Consume
OrderCreatedEvent
Publish
BookCreatedEvent
Payment
Service
Consume
BookCreatedEvent
Publish
PaymentDenied
Consume
BookCanceledEvent
Choreography: Payment denied
Compensating
transactions
Consume
PaymentDenied
Publish
BookCanceledEvent
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Advantages and disadvantages of Choreography
● Simple to implement
● Tight coupling - highly dependent upon each other
● The decision logic is distributed - difficulty to maintain and manage the overall
process
● Hard to debug
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Event Command Transformation Pattern
Order
Service
NoRoomEvent
BookConfirmedEvent
...
Booking has to know all
events that triggers a
Order action
BookCanceledEvent
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Event Command Transformation Pattern
Order
Service
Booking
ServiceOrderCreatedEvent BookCommand
Event
Something has
happened in the past
Command
Something has to
happen in the future
Event
Command
Transformation
Where we do
the coupling
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Order
Service
Broker
createOrder()
Publish
BookingCommand
Booking
Service
Consume
BookingCommand
Publish
PaymentCommand
Payment
Service
Consume
PaymentCommand
Publish
BookCommand
Consume
OrderCommand
Event Command Transformation Pattern
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Saga Pattern:
Orchestration-based
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Order
Service
Broker
createOrder()
Publish
OrderCreatedEvent
Consume
OrderConfirmation
Command
Orchestration
Orchestrator
Consume
OrderCreatedEvent
Produce
ReservationCommand
Booking
Service
Consume
Reservation
Command
Payment
Service
Publish
ReservationResult
Consume
Payment
Command
Publish
PaymentResult
Consume
ReservationResult
Produce
PaymentCommand
Consume
PaymentResult
Produce
BookingConfirmation
Command
OrderConfirmation
Command
Consume Booking
Confirmation
Command
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Order
Service
Broker
createOrder()
Publish
OrderCreatedEvent
Consume
OrderCancelation
Command
Orchestration: Payment Denied
Orchestrator
Consume
OrderCreatedEvent
Produce
ReservationCommand
Booking
Service
Consume
Reservation
Command
Payment
Service
Publish
ReservationResult
Consume
Payment
Command
Publish
PaymentDenied
Consume
ReservationResult
Produce
PaymentCommand
Consume
PaymentDennied
Produce
BookingCancelationC
omand and
OrderCancelation
Command
Consume Booking
Cancelation
Command
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Advantages and disadvantages of Orchestration
● Centralized business logic - Easy to understand and maintain.
● Loose coupling as each service consumes only their commands
● Orchestrator is the SPF
● Needs Event -> Command transformation
@rafabene e @roanbrasil - https://bit.ly/sagakafka
A note about
Aggregator vs Chain
Patterns
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Choreographed
Aggregator
(Parallel)
Chain
(Serial) Order
Service
Booking
Service
Payment
Service
Order
Service
Booking
Service
Payment
Service
Order triggers
compensation
Each service triggers
compensation from
previous transaction
O
rder holds
the
logic
for the
use
case
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Orchestrated
Aggregator (Parallel)
Chain (Serial)
Order
Service
Booking
Service Payment
Service
Order
Service
Booking
Service Payment
Service
Orchestrator
Orchestrator
Orchestrator needs to
coordinate states before
calling proper compensation
transactions
Orchestrator flow is
easier to handle
and implement
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Aggregator vs Chain Patterns
● Which pattern do you think it is easier
to implement and handle States
● Tip:
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Event sourcing with Kafka
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Creating an Orchestrator
using Kafka Streams
@rafabene e @roanbrasil - https://bit.ly/sagakafka
API to Consume, process and publish to Kafka Topics
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Asynchronous chained orchestrated saga
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Demo use cases
● Book a room
● Payment offline
● Payment denied
● No rooms available
● Orchestrator offline?
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Demo
rafabene/saga-demo
@rafabene e @roanbrasil - https://bit.ly/sagakafka
Run them on Linux
VirtualPhysical Private Public
Oracle Linux
Node NodeNode
Master
API ServerDev
Ops
SCM
(Git/Svn)
CI/CD
Automation
Controllers
- Scheduler
- Replication
- Services
- Builds
- Routes
- Deployment
Kubernetes
Ingress Gateway
@rafabene e @roanbrasil - https://bit.ly/sagakafka
@rafabene e @roanbrasil - https://bit.ly/sagakafka@rafabene e @roanbrasil
@RAFABENE
@ROANBRASIL

More Related Content

What's hot

Securing Kafka
Securing Kafka Securing Kafka
Securing Kafka confluent
 
How Prometheus Store the Data
How Prometheus Store the DataHow Prometheus Store the Data
How Prometheus Store the DataHao Chen
 
Fluentd v1.0 in a nutshell
Fluentd v1.0 in a nutshellFluentd v1.0 in a nutshell
Fluentd v1.0 in a nutshellN Masahiro
 
API Security in a Microservice Architecture
API Security in a Microservice ArchitectureAPI Security in a Microservice Architecture
API Security in a Microservice ArchitectureMatt McLarty
 
How we eased out security journey with OAuth (Goodbye Kerberos!) | Paul Makka...
How we eased out security journey with OAuth (Goodbye Kerberos!) | Paul Makka...How we eased out security journey with OAuth (Goodbye Kerberos!) | Paul Makka...
How we eased out security journey with OAuth (Goodbye Kerberos!) | Paul Makka...HostedbyConfluent
 
The Patterns of Distributed Logging and Containers
The Patterns of Distributed Logging and ContainersThe Patterns of Distributed Logging and Containers
The Patterns of Distributed Logging and ContainersSATOSHI TAGOMORI
 
Hashicorp Vault Open Source vs Enterprise
Hashicorp Vault Open Source vs EnterpriseHashicorp Vault Open Source vs Enterprise
Hashicorp Vault Open Source vs EnterpriseStenio Ferreira
 
Apache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing dataApache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing dataDataWorks Summit/Hadoop Summit
 
Rest api standards and best practices
Rest api standards and best practicesRest api standards and best practices
Rest api standards and best practicesAnkita Mahajan
 
OAuth2 - Introduction
OAuth2 - IntroductionOAuth2 - Introduction
OAuth2 - IntroductionKnoldus Inc.
 
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...HostedbyConfluent
 
카프카, 산전수전 노하우
카프카, 산전수전 노하우카프카, 산전수전 노하우
카프카, 산전수전 노하우if kakao
 
Building a fully managed stream processing platform on Flink at scale for Lin...
Building a fully managed stream processing platform on Flink at scale for Lin...Building a fully managed stream processing platform on Flink at scale for Lin...
Building a fully managed stream processing platform on Flink at scale for Lin...Flink Forward
 
Secure your app with keycloak
Secure your app with keycloakSecure your app with keycloak
Secure your app with keycloakGuy Marom
 
Apache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals ExplainedApache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals Explainedconfluent
 
Real-time Stream Processing with Apache Flink
Real-time Stream Processing with Apache FlinkReal-time Stream Processing with Apache Flink
Real-time Stream Processing with Apache FlinkDataWorks Summit
 
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server Push
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server PushReal Time UI with Apache Kafka Streaming Analytics of Fast Data and Server Push
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server PushLucas Jellema
 

What's hot (20)

Securing Kafka
Securing Kafka Securing Kafka
Securing Kafka
 
How Prometheus Store the Data
How Prometheus Store the DataHow Prometheus Store the Data
How Prometheus Store the Data
 
Fluentd v1.0 in a nutshell
Fluentd v1.0 in a nutshellFluentd v1.0 in a nutshell
Fluentd v1.0 in a nutshell
 
Hashicorp Vault ppt
Hashicorp Vault pptHashicorp Vault ppt
Hashicorp Vault ppt
 
API Security in a Microservice Architecture
API Security in a Microservice ArchitectureAPI Security in a Microservice Architecture
API Security in a Microservice Architecture
 
How we eased out security journey with OAuth (Goodbye Kerberos!) | Paul Makka...
How we eased out security journey with OAuth (Goodbye Kerberos!) | Paul Makka...How we eased out security journey with OAuth (Goodbye Kerberos!) | Paul Makka...
How we eased out security journey with OAuth (Goodbye Kerberos!) | Paul Makka...
 
The Patterns of Distributed Logging and Containers
The Patterns of Distributed Logging and ContainersThe Patterns of Distributed Logging and Containers
The Patterns of Distributed Logging and Containers
 
Hashicorp Vault Open Source vs Enterprise
Hashicorp Vault Open Source vs EnterpriseHashicorp Vault Open Source vs Enterprise
Hashicorp Vault Open Source vs Enterprise
 
Apache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing dataApache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing data
 
Rest api standards and best practices
Rest api standards and best practicesRest api standards and best practices
Rest api standards and best practices
 
OAuth2 - Introduction
OAuth2 - IntroductionOAuth2 - Introduction
OAuth2 - Introduction
 
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
Developing Kafka Streams Applications with Upgradability in Mind with Neil Bu...
 
카프카, 산전수전 노하우
카프카, 산전수전 노하우카프카, 산전수전 노하우
카프카, 산전수전 노하우
 
Building a fully managed stream processing platform on Flink at scale for Lin...
Building a fully managed stream processing platform on Flink at scale for Lin...Building a fully managed stream processing platform on Flink at scale for Lin...
Building a fully managed stream processing platform on Flink at scale for Lin...
 
Secure your app with keycloak
Secure your app with keycloakSecure your app with keycloak
Secure your app with keycloak
 
Apache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals ExplainedApache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals Explained
 
Nginx
NginxNginx
Nginx
 
Real-time Stream Processing with Apache Flink
Real-time Stream Processing with Apache FlinkReal-time Stream Processing with Apache Flink
Real-time Stream Processing with Apache Flink
 
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server Push
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server PushReal Time UI with Apache Kafka Streaming Analytics of Fast Data and Server Push
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server Push
 
Introduction to Apache Beam
Introduction to Apache BeamIntroduction to Apache Beam
Introduction to Apache Beam
 

Similar to Saga pattern and event sourcing with kafka

Cross the Streams! Creating Streaming Data Pipelines with Apache Flink + Apac...
Cross the Streams! Creating Streaming Data Pipelines with Apache Flink + Apac...Cross the Streams! Creating Streaming Data Pipelines with Apache Flink + Apac...
Cross the Streams! Creating Streaming Data Pipelines with Apache Flink + Apac...StreamNative
 
Essential Ingredients of Realtime Stream Processing @ Scale
Essential Ingredients of Realtime Stream Processing @ ScaleEssential Ingredients of Realtime Stream Processing @ Scale
Essential Ingredients of Realtime Stream Processing @ ScaleKartik Paramasivam
 
State management with GraphQL [Angular Minsk, Online, 13.06.20]
State management with GraphQL [Angular Minsk, Online, 13.06.20]State management with GraphQL [Angular Minsk, Online, 13.06.20]
State management with GraphQL [Angular Minsk, Online, 13.06.20]Mikhail Asavkin
 
Socket applications
Socket applicationsSocket applications
Socket applicationsJoão Moura
 
Essential ingredients for real time stream processing @Scale by Kartik pParam...
Essential ingredients for real time stream processing @Scale by Kartik pParam...Essential ingredients for real time stream processing @Scale by Kartik pParam...
Essential ingredients for real time stream processing @Scale by Kartik pParam...Big Data Spain
 
Flink sql for continuous sql etl apps & Apache NiFi devops
Flink sql for continuous sql etl apps & Apache NiFi devopsFlink sql for continuous sql etl apps & Apache NiFi devops
Flink sql for continuous sql etl apps & Apache NiFi devopsTimothy Spann
 
Hadoop application architectures - using Customer 360 as an example
Hadoop application architectures - using Customer 360 as an exampleHadoop application architectures - using Customer 360 as an example
Hadoop application architectures - using Customer 360 as an examplehadooparchbook
 
Architecting a next generation data platform
Architecting a next generation data platformArchitecting a next generation data platform
Architecting a next generation data platformhadooparchbook
 
Hadoop Application Architectures - Fraud Detection
Hadoop Application Architectures - Fraud  DetectionHadoop Application Architectures - Fraud  Detection
Hadoop Application Architectures - Fraud Detectionhadooparchbook
 
Architecting next generation big data platform
Architecting next generation big data platformArchitecting next generation big data platform
Architecting next generation big data platformhadooparchbook
 
Real-time, real estate listings with Apache Kafka
Real-time, real estate listings with Apache KafkaReal-time, real estate listings with Apache Kafka
Real-time, real estate listings with Apache KafkaFerran Galí Reniu
 
High Availability by Design
High Availability by DesignHigh Availability by Design
High Availability by DesignDavid Prinzing
 
HSB - Secure DNS en BGP ontwikkelingen - Benno Overeinder
HSB - Secure DNS en BGP ontwikkelingen - Benno OvereinderHSB - Secure DNS en BGP ontwikkelingen - Benno Overeinder
HSB - Secure DNS en BGP ontwikkelingen - Benno OvereinderSplend
 
Why And When Should We Consider Stream Processing In Our Solutions Teqnation ...
Why And When Should We Consider Stream Processing In Our Solutions Teqnation ...Why And When Should We Consider Stream Processing In Our Solutions Teqnation ...
Why And When Should We Consider Stream Processing In Our Solutions Teqnation ...Soroosh Khodami
 
Exactly-Once Financial Data Processing at Scale with Flink and Pinot
Exactly-Once Financial Data Processing at Scale with Flink and PinotExactly-Once Financial Data Processing at Scale with Flink and Pinot
Exactly-Once Financial Data Processing at Scale with Flink and PinotFlink Forward
 
Stateless authentication for microservices - GR8Conf 2015
Stateless authentication for microservices - GR8Conf 2015Stateless authentication for microservices - GR8Conf 2015
Stateless authentication for microservices - GR8Conf 2015Alvaro Sanchez-Mariscal
 
Let's Get Real (time): Server-Sent Events, WebSockets and WebRTC for the soul
Let's Get Real (time): Server-Sent Events, WebSockets and WebRTC for the soulLet's Get Real (time): Server-Sent Events, WebSockets and WebRTC for the soul
Let's Get Real (time): Server-Sent Events, WebSockets and WebRTC for the soulSwanand Pagnis
 
Fix me if you can - DrupalCon prague
Fix me if you can - DrupalCon pragueFix me if you can - DrupalCon prague
Fix me if you can - DrupalCon praguehernanibf
 
Flink Forward Berlin 2018: Steven Wu - "Failure is not fatal: what is your re...
Flink Forward Berlin 2018: Steven Wu - "Failure is not fatal: what is your re...Flink Forward Berlin 2018: Steven Wu - "Failure is not fatal: what is your re...
Flink Forward Berlin 2018: Steven Wu - "Failure is not fatal: what is your re...Flink Forward
 

Similar to Saga pattern and event sourcing with kafka (20)

REACTIVE A New Hope!
REACTIVE A New Hope!REACTIVE A New Hope!
REACTIVE A New Hope!
 
Cross the Streams! Creating Streaming Data Pipelines with Apache Flink + Apac...
Cross the Streams! Creating Streaming Data Pipelines with Apache Flink + Apac...Cross the Streams! Creating Streaming Data Pipelines with Apache Flink + Apac...
Cross the Streams! Creating Streaming Data Pipelines with Apache Flink + Apac...
 
Essential Ingredients of Realtime Stream Processing @ Scale
Essential Ingredients of Realtime Stream Processing @ ScaleEssential Ingredients of Realtime Stream Processing @ Scale
Essential Ingredients of Realtime Stream Processing @ Scale
 
State management with GraphQL [Angular Minsk, Online, 13.06.20]
State management with GraphQL [Angular Minsk, Online, 13.06.20]State management with GraphQL [Angular Minsk, Online, 13.06.20]
State management with GraphQL [Angular Minsk, Online, 13.06.20]
 
Socket applications
Socket applicationsSocket applications
Socket applications
 
Essential ingredients for real time stream processing @Scale by Kartik pParam...
Essential ingredients for real time stream processing @Scale by Kartik pParam...Essential ingredients for real time stream processing @Scale by Kartik pParam...
Essential ingredients for real time stream processing @Scale by Kartik pParam...
 
Flink sql for continuous sql etl apps & Apache NiFi devops
Flink sql for continuous sql etl apps & Apache NiFi devopsFlink sql for continuous sql etl apps & Apache NiFi devops
Flink sql for continuous sql etl apps & Apache NiFi devops
 
Hadoop application architectures - using Customer 360 as an example
Hadoop application architectures - using Customer 360 as an exampleHadoop application architectures - using Customer 360 as an example
Hadoop application architectures - using Customer 360 as an example
 
Architecting a next generation data platform
Architecting a next generation data platformArchitecting a next generation data platform
Architecting a next generation data platform
 
Hadoop Application Architectures - Fraud Detection
Hadoop Application Architectures - Fraud  DetectionHadoop Application Architectures - Fraud  Detection
Hadoop Application Architectures - Fraud Detection
 
Architecting next generation big data platform
Architecting next generation big data platformArchitecting next generation big data platform
Architecting next generation big data platform
 
Real-time, real estate listings with Apache Kafka
Real-time, real estate listings with Apache KafkaReal-time, real estate listings with Apache Kafka
Real-time, real estate listings with Apache Kafka
 
High Availability by Design
High Availability by DesignHigh Availability by Design
High Availability by Design
 
HSB - Secure DNS en BGP ontwikkelingen - Benno Overeinder
HSB - Secure DNS en BGP ontwikkelingen - Benno OvereinderHSB - Secure DNS en BGP ontwikkelingen - Benno Overeinder
HSB - Secure DNS en BGP ontwikkelingen - Benno Overeinder
 
Why And When Should We Consider Stream Processing In Our Solutions Teqnation ...
Why And When Should We Consider Stream Processing In Our Solutions Teqnation ...Why And When Should We Consider Stream Processing In Our Solutions Teqnation ...
Why And When Should We Consider Stream Processing In Our Solutions Teqnation ...
 
Exactly-Once Financial Data Processing at Scale with Flink and Pinot
Exactly-Once Financial Data Processing at Scale with Flink and PinotExactly-Once Financial Data Processing at Scale with Flink and Pinot
Exactly-Once Financial Data Processing at Scale with Flink and Pinot
 
Stateless authentication for microservices - GR8Conf 2015
Stateless authentication for microservices - GR8Conf 2015Stateless authentication for microservices - GR8Conf 2015
Stateless authentication for microservices - GR8Conf 2015
 
Let's Get Real (time): Server-Sent Events, WebSockets and WebRTC for the soul
Let's Get Real (time): Server-Sent Events, WebSockets and WebRTC for the soulLet's Get Real (time): Server-Sent Events, WebSockets and WebRTC for the soul
Let's Get Real (time): Server-Sent Events, WebSockets and WebRTC for the soul
 
Fix me if you can - DrupalCon prague
Fix me if you can - DrupalCon pragueFix me if you can - DrupalCon prague
Fix me if you can - DrupalCon prague
 
Flink Forward Berlin 2018: Steven Wu - "Failure is not fatal: what is your re...
Flink Forward Berlin 2018: Steven Wu - "Failure is not fatal: what is your re...Flink Forward Berlin 2018: Steven Wu - "Failure is not fatal: what is your re...
Flink Forward Berlin 2018: Steven Wu - "Failure is not fatal: what is your re...
 

More from Roan Brasil Monteiro

Java moderno java para Jedis episodio I
Java moderno  java para  Jedis  episodio IJava moderno  java para  Jedis  episodio I
Java moderno java para Jedis episodio IRoan Brasil Monteiro
 
Improving your code design using Java
Improving your code design using JavaImproving your code design using Java
Improving your code design using JavaRoan Brasil Monteiro
 
Jumping in Jakarta Open Source Project Everything nobody tells you
Jumping in Jakarta Open Source Project  Everything nobody tells youJumping in Jakarta Open Source Project  Everything nobody tells you
Jumping in Jakarta Open Source Project Everything nobody tells youRoan Brasil Monteiro
 
HTTP / 1, HTTP / 2 and HTTP / 3: Past, present and the future of APIs
HTTP / 1, HTTP / 2 and HTTP / 3: Past, present and the future of APIsHTTP / 1, HTTP / 2 and HTTP / 3: Past, present and the future of APIs
HTTP / 1, HTTP / 2 and HTTP / 3: Past, present and the future of APIsRoan Brasil Monteiro
 
Clean code com features do java 8 a java 14
Clean code com features do java 8 a java 14Clean code com features do java 8 a java 14
Clean code com features do java 8 a java 14Roan Brasil Monteiro
 
Introduction to microservices Jornada Microservices
Introduction to microservices Jornada MicroservicesIntroduction to microservices Jornada Microservices
Introduction to microservices Jornada MicroservicesRoan Brasil Monteiro
 
Creating an api from design to security.
Creating an api from design to security.Creating an api from design to security.
Creating an api from design to security.Roan Brasil Monteiro
 

More from Roan Brasil Monteiro (7)

Java moderno java para Jedis episodio I
Java moderno  java para  Jedis  episodio IJava moderno  java para  Jedis  episodio I
Java moderno java para Jedis episodio I
 
Improving your code design using Java
Improving your code design using JavaImproving your code design using Java
Improving your code design using Java
 
Jumping in Jakarta Open Source Project Everything nobody tells you
Jumping in Jakarta Open Source Project  Everything nobody tells youJumping in Jakarta Open Source Project  Everything nobody tells you
Jumping in Jakarta Open Source Project Everything nobody tells you
 
HTTP / 1, HTTP / 2 and HTTP / 3: Past, present and the future of APIs
HTTP / 1, HTTP / 2 and HTTP / 3: Past, present and the future of APIsHTTP / 1, HTTP / 2 and HTTP / 3: Past, present and the future of APIs
HTTP / 1, HTTP / 2 and HTTP / 3: Past, present and the future of APIs
 
Clean code com features do java 8 a java 14
Clean code com features do java 8 a java 14Clean code com features do java 8 a java 14
Clean code com features do java 8 a java 14
 
Introduction to microservices Jornada Microservices
Introduction to microservices Jornada MicroservicesIntroduction to microservices Jornada Microservices
Introduction to microservices Jornada Microservices
 
Creating an api from design to security.
Creating an api from design to security.Creating an api from design to security.
Creating an api from design to security.
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Recently uploaded (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Saga pattern and event sourcing with kafka

  • 1. @rafabene e @roanbrasil - https://bit.ly/sagakafka 1 Saga Pattern and Event Sourcing with Kafka https://bit.ly/sagakafkaLink @rafabene rafael.benevides@oracle.com @roanbrasil rmonteiro@astek-canada.ca
  • 2. @rafabene e @roanbrasil - https://bit.ly/sagakafka rafael.benevides@gmail.com @rafabene apiVersion: oracle/v1 kind: PrincipalSolutionArchitect metadata: name: Rafael Benevides namespace: Oracle Linux team annotations: apache/contributor: Apache DeltaSpike PMC labels: developer: Java, NodeJS hobby: 4x4, drones spec: replicas: 1 containers: image: benevides/rafael:latest Rafael Benevides
  • 3. @rafabene e @roanbrasil - https://bit.ly/sagakafka roanbrasil@gmail.com @roanbrasil apiVersion: astek-canada/v1 kind: JavaDeveloper metadata: name: Roan Brasil Monteiro namespace: Java Developer team labels: developer: Java, NodeJS hobby: guitar, video game, snorkeling, soccer spec: replicas: 1 containers: image: brasilmonteiro/roan:latest Roan Brasil Monteiro
  • 4. @rafabene e @roanbrasil - https://bit.ly/sagakafka Before we get started… ● I don't use microservices and love my monolith. ● I've started using microservices. ● I've heard about Event Sourcing and Sagas before. ● I do microservices using Event Sourcing at work. ● I've implemented Saga Patterns. Who are you?
  • 5. @rafabene e @roanbrasil - https://bit.ly/sagakafka
  • 6. @rafabene e @roanbrasil - https://bit.ly/sagakafka Monolithic architecture Order Module Booking Module Payment Module Web UI Database Browser / Client BEWARE: This is NOT an anti-pattern!
  • 7. @rafabene e @roanbrasil - https://bit.ly/sagakafka Moving to Microservices Database Browser / Client Order Module Booking Module Payment Module Web UI
  • 8. @rafabene e @roanbrasil - https://bit.ly/sagakafka Moving to Microservices Database Browser / Client Order Service Booking Service Payment Service Web UI Database Database
  • 9. @rafabene e @roanbrasil - https://bit.ly/sagakafka Microservices Architecture (synchronous calls) Database Browser / Client Order Service Booking Service Payment Service Web UI Database Database 1) New Order 2) Room Reservation 3) ProcessPayment REST Calls
  • 10. @rafabene e @roanbrasil - https://bit.ly/sagakafka No ACID transaction that span services Database Browser / Client Order Service Booking Service Payment Service Web UI Database Database 1) New Order 2) Room Reservation 3) ProcessPayment T1 T2 T3 REST Calls
  • 11. @rafabene e @roanbrasil - https://bit.ly/sagakafka Exceptions: No room available (synchronous calls) Database Browser / Client Order Service Booking Service Web UI Database1) New Order 2) Room Reservation 3) Exception happened4) Cancel order REST Calls 1:1 services involved That was easy!
  • 12. @rafabene e @roanbrasil - https://bit.ly/sagakafka Exceptions: Payment Denied (synchronous calls) Database Browser / Client Order Service Booking Service Payment Service Web UI Database Database 1) New Order 2) Room Reservation 3) ProcessPayment 6) Cancel Booking???6) Cancel Booking??? REST Calls 4) Exception happened 5) Cancel order ● What if I have 10 microservices to rollback? ● Can you spot the complexity?
  • 13. @rafabene e @roanbrasil - https://bit.ly/sagakafka Death Star Architectures
  • 14. @rafabene e @roanbrasil - https://bit.ly/sagakafka Can I use 2PC? Prepare phase Database Browser / Client Order Service Booking Service Payment Service Web UI Database Database 1) New Order 2) Room Reservation 3) ProcessPayment Prepare Prepare Prepare
  • 15. @rafabene e @roanbrasil - https://bit.ly/sagakafka Can I use 2PC? Prepare phase Database Browser / Client Order Service Booking Service Payment Service Web UI Database Database 1) New Order 2) Room Reservation 3) ProcessPayment Prepared Prepared Prepared
  • 16. @rafabene e @roanbrasil - https://bit.ly/sagakafka Can I use 2PC? Commit phase Database Browser / Client Order Service Booking Service Payment Service Web UI Database Database 1) New Order 2) Room Reservation 3) ProcessPayment Commit/ Abort Commit/ Abort Commit/ Abort
  • 17. @rafabene e @roanbrasil - https://bit.ly/sagakafka Can I use 2PC? Commit phase Database Browser / Client Order Service Booking Service Payment Service Web UI Database Database 1) New Order 2) Room Reservation 3) ProcessPayment Done Done Done Problems of 2 Phase commit ● Transaction coordinator is the SPF. ● Others have to wait until the slowest resource finish its confirmation. ○ Ex. Credit card payment can take up to 30 seconds to reply. ○ Databases are locked during that time. ○ Can cause deadlocks. ● Reduced throughput due to locks. ● Not supported by many NoSQL databases.
  • 18. @rafabene e @roanbrasil - https://bit.ly/sagakafka Saga: A solution from 1987 https://www.cs.cornell.edu/andru/cs711/2002fa/reading/sagas.pdf
  • 19. @rafabene e @roanbrasil - https://bit.ly/sagakafka How does the saga work? Order Service Order createOrder() Order{ state = PENDING } Order Service Order Order{ state = APPROVED } Payment Service Account PaymentInfo{ state = APPROVED }
  • 20. @rafabene e @roanbrasil - https://bit.ly/sagakafka How does the rollback work? Use compensating transactions to "undo" the business logic. Order createOrder() Booking reserveRoom() Payment withdraw() Order cancelOrder() No rooms available Booking cancel Reservation() T1 T2 T3 C1 C2 T1 T2 C1 T3 and C2 were not called
  • 21. @rafabene e @roanbrasil - https://bit.ly/sagakafka Rollback: Payment Denied Order Service Order createOrder() Order{ state = PENDING } Order Service Order Order{ state = CANCELED } Payment Service Account PaymentInfo{ state = DENIED }
  • 22. @rafabene e @roanbrasil - https://bit.ly/sagakafka Rollback exception: Payment service unavailable Order Service Order createOrder() Order{ state = PENDING } Order Service Order Order{ state = PENDING } Payment Service Account REST Call Client and Server must be always available Order will be PENDING forever We need to go asynchronous
  • 23. @rafabene e @roanbrasil - https://bit.ly/sagakafka Event Sourcing (An express explanation)
  • 24. @rafabene e @roanbrasil - https://bit.ly/sagakafka What is event sourcing? Architectural style where you: ● Don't save the current state of objects ● Save the events that lead to the current state (ORDER IS IMPORTANT) ● Events happened in the past ● Example: AccountDeposit accountNumber: 123456-700 value: 100.50
  • 25. @rafabene e @roanbrasil - https://bit.ly/sagakafka Creating events to change to state BankAccountCreated Id: 123 Owner: Rafael BankAccount Events State BankAccount Id: 123 Owner: Rafael Balance: 0 MoneyDeposited account: 123 value: 100 BankAccount Id: 123 Owner: Rafael Balance: 100
  • 26. @rafabene e @roanbrasil - https://bit.ly/sagakafka Creating events to change to state MoneyWithdraw account: 123 value: 60 Events State BankAccount Id: 123 Owner: Rafael Balance: 100 BankAccount Id: 123 Owner: Rafael Balance: 40 MoneyWithdraw account: 123 value: 60 BankAccount Id: 123 Owner: Rafael Balance: 40 Event not possible to be handled
  • 27. @rafabene e @roanbrasil - https://bit.ly/sagakafka Command Sourcing (An express explanation)
  • 28. @rafabene e @roanbrasil - https://bit.ly/sagakafka What is command sourcing? Architectural style where you: ● Persist commands ● Says what command/intention should be performed ● Wait for replies ● Example: ExecuteAccountWithdraw accountNumber: 123456-700 value: 100.50 InsuficientBalanceReply accountNumber: 123456-700 requestedValue: 100.50
  • 29. @rafabene e @roanbrasil - https://bit.ly/sagakafka Saga Patterns ● Choreography-based sagas - services collaborate by exchanging domain events ● Orchestration-based sagas - a centralized coordinator sending command messages to participants, which respond with reply messages https://eventuate.io/post/eventuate/2020/02/24/why-eventuate.html
  • 30. @rafabene e @roanbrasil - https://bit.ly/sagakafka Saga Pattern: Choreography-based
  • 31. @rafabene e @roanbrasil - https://bit.ly/sagakafka Order Service Event Store createOrder() Publish OrderCreatedEvent Booking Service Consume OrderCreatedEvent Publish BookCreatedEvent Payment Service Consume BookCreatedEvent Publish PaymentSuccess Consume BookConfirmedEvent Choreography Consume PaymentSuccess Publish BookConfirmedEvent
  • 32. @rafabene e @roanbrasil - https://bit.ly/sagakafka Order Service Event Store createOrder() Publish OrderCreatedEvent Booking Service Consume OrderCreatedEvent Publish NoRoomEvent Payment Service Consume NoRoomEvent Choreography: No rooms available Compensating transaction
  • 33. @rafabene e @roanbrasil - https://bit.ly/sagakafka Order Service Event Store createOrder() Publish OrderCreatedEvent Booking Service Consume OrderCreatedEvent Publish BookCreatedEvent Payment Service Consume BookCreatedEvent Publish PaymentDenied Consume BookCanceledEvent Choreography: Payment denied Compensating transactions Consume PaymentDenied Publish BookCanceledEvent
  • 34. @rafabene e @roanbrasil - https://bit.ly/sagakafka Advantages and disadvantages of Choreography ● Simple to implement ● Tight coupling - highly dependent upon each other ● The decision logic is distributed - difficulty to maintain and manage the overall process ● Hard to debug
  • 35. @rafabene e @roanbrasil - https://bit.ly/sagakafka Event Command Transformation Pattern Order Service NoRoomEvent BookConfirmedEvent ... Booking has to know all events that triggers a Order action BookCanceledEvent
  • 36. @rafabene e @roanbrasil - https://bit.ly/sagakafka Event Command Transformation Pattern Order Service Booking ServiceOrderCreatedEvent BookCommand Event Something has happened in the past Command Something has to happen in the future Event Command Transformation Where we do the coupling
  • 37. @rafabene e @roanbrasil - https://bit.ly/sagakafka Order Service Broker createOrder() Publish BookingCommand Booking Service Consume BookingCommand Publish PaymentCommand Payment Service Consume PaymentCommand Publish BookCommand Consume OrderCommand Event Command Transformation Pattern
  • 38. @rafabene e @roanbrasil - https://bit.ly/sagakafka Saga Pattern: Orchestration-based
  • 39. @rafabene e @roanbrasil - https://bit.ly/sagakafka Order Service Broker createOrder() Publish OrderCreatedEvent Consume OrderConfirmation Command Orchestration Orchestrator Consume OrderCreatedEvent Produce ReservationCommand Booking Service Consume Reservation Command Payment Service Publish ReservationResult Consume Payment Command Publish PaymentResult Consume ReservationResult Produce PaymentCommand Consume PaymentResult Produce BookingConfirmation Command OrderConfirmation Command Consume Booking Confirmation Command
  • 40. @rafabene e @roanbrasil - https://bit.ly/sagakafka Order Service Broker createOrder() Publish OrderCreatedEvent Consume OrderCancelation Command Orchestration: Payment Denied Orchestrator Consume OrderCreatedEvent Produce ReservationCommand Booking Service Consume Reservation Command Payment Service Publish ReservationResult Consume Payment Command Publish PaymentDenied Consume ReservationResult Produce PaymentCommand Consume PaymentDennied Produce BookingCancelationC omand and OrderCancelation Command Consume Booking Cancelation Command
  • 41. @rafabene e @roanbrasil - https://bit.ly/sagakafka Advantages and disadvantages of Orchestration ● Centralized business logic - Easy to understand and maintain. ● Loose coupling as each service consumes only their commands ● Orchestrator is the SPF ● Needs Event -> Command transformation
  • 42. @rafabene e @roanbrasil - https://bit.ly/sagakafka A note about Aggregator vs Chain Patterns
  • 43. @rafabene e @roanbrasil - https://bit.ly/sagakafka Choreographed Aggregator (Parallel) Chain (Serial) Order Service Booking Service Payment Service Order Service Booking Service Payment Service Order triggers compensation Each service triggers compensation from previous transaction O rder holds the logic for the use case
  • 44. @rafabene e @roanbrasil - https://bit.ly/sagakafka Orchestrated Aggregator (Parallel) Chain (Serial) Order Service Booking Service Payment Service Order Service Booking Service Payment Service Orchestrator Orchestrator Orchestrator needs to coordinate states before calling proper compensation transactions Orchestrator flow is easier to handle and implement
  • 45. @rafabene e @roanbrasil - https://bit.ly/sagakafka Aggregator vs Chain Patterns ● Which pattern do you think it is easier to implement and handle States ● Tip:
  • 46. @rafabene e @roanbrasil - https://bit.ly/sagakafka Event sourcing with Kafka
  • 47. @rafabene e @roanbrasil - https://bit.ly/sagakafka Creating an Orchestrator using Kafka Streams
  • 48. @rafabene e @roanbrasil - https://bit.ly/sagakafka API to Consume, process and publish to Kafka Topics
  • 49. @rafabene e @roanbrasil - https://bit.ly/sagakafka Asynchronous chained orchestrated saga
  • 50. @rafabene e @roanbrasil - https://bit.ly/sagakafka Demo use cases ● Book a room ● Payment offline ● Payment denied ● No rooms available ● Orchestrator offline?
  • 51. @rafabene e @roanbrasil - https://bit.ly/sagakafka Demo rafabene/saga-demo
  • 52. @rafabene e @roanbrasil - https://bit.ly/sagakafka Run them on Linux VirtualPhysical Private Public Oracle Linux Node NodeNode Master API ServerDev Ops SCM (Git/Svn) CI/CD Automation Controllers - Scheduler - Replication - Services - Builds - Routes - Deployment Kubernetes Ingress Gateway
  • 53. @rafabene e @roanbrasil - https://bit.ly/sagakafka
  • 54. @rafabene e @roanbrasil - https://bit.ly/sagakafka@rafabene e @roanbrasil @RAFABENE @ROANBRASIL