SlideShare a Scribd company logo
Saga: The new era of transactions in a
microservices architecture
Giovanni Marigi - Senior Middleware Consultant
Mauro Vocale - Solution Architect
BOSTON, MA | MAY 7-9, 2019
Microservices
The microservice architecture is the main trend in
information technology and we learned a lot about it
during these years ...
What are Microservices?
“…an approach to developing a single application as a
suite of small services, each running in its own process
and communicating with lightweight mechanisms,
often an HTTP resource API.”
Martin Fowler
• Fast to develop, easier to maintain and understand
• Starts faster, speeds up deployments
• Fault isolation
• Services can be scaled independently
• Deltas and patches can be applied to each microservice individually
• Local changes can be deployed easily
• Flexible choice of technology
• Security can be applied to each microservice as opposed to the whole system
in a blanket approach
MICROSERVICES ADVANTAGES
• Additional architectural complexity of distributed systems
○ Maintaining strong consistency is extremely difficult
○ Testing a distributed system is difficult
○ Requires a shift in coding paradigm:
Change in approach to application architecture design and testing
• Significant operational complexity. Requires a high degree of automation
○ Deployments require coordination and rollout plan
MICROSERVICES DISADVANTAGES
MICROSERVICES FRAMEWORKS
There are many ways to build a microservice
Microservices’ilities
MyService
Monitoring
Tracing
API
Discovery
Invocation
Resilience
Pipeline
Authentication
Logging Elasticity
Platform and frameworks
cover a lot … but not all ...
MICROSERVICES DILEMMA: How to handle transactions?
SAGA!
2PC, XA, BULK
BATCH!
Microservices and transactions
You’ve successfully decomposed your monolithic
application into several microservices.
Every microservice has its own state and a local store (RDBMS, NoSQL, file store, ...)
Microservices can emit events when a state changes.
Microservices can react to events.
But you still want that a business process spanning several services to be
consistent and correct regardless of the level of decomposition of your
application.
Why distributed transactions don’t work
Traditional distributed transactions are implemented using a two-phase commit,
briefly 2PC.
Why can’t we use 2PC in microservices architecture?
● You don’t have a single shared store anymore, every service has its own data
store (micro-db)
● A microservices architecture involves many parties, realized using different
technologies that adhere to different specifications: 2PC implicitly assumes
closely coupled environment
● Synchronization and isolation reduces performance and scalability.
● A business function potentially lasting for hours or days: lock strategy doesn't
work well in long duration activities
Distributed transactions
Ticket Service Insurance Service
2PC: a magic box
XA resource XA resource
book a ticket
book a ticket
Simple rule:
2PC would try to reserve both the ticket and the insurance
at the same time. If it doesn’t succeed, none of them will be
booked.
Microservices: eventual consistency
Consistency states that the entire software system should be in a valid state.
2PC guarantees the consistency with a pessimistic approach; all the changes must be
done at the same time or rollback.
Microservices architectures at the opposite guarantee the consistency with a more
relaxed approach. The state of the entire system can’t be valid at any time but at the
end of the business transaction. The system is eventually consistent.
Ticket service and Insurance service will try to book independently. In case of failure in
one of the two, the other one will be canceled.
Eventual consistency is not easy achieve and there is no a magic box out there.
Saga Pattern
Le Radeau de la Méduse -
Théodore Géricault, 1818-19
Saga Pattern: overview
Saga is the de facto solution to guarantee consistency in a microservices architecture.
Saga is not a new pattern [1] and it can be applied also in traditional monolithic
architectures.
“For specific applications, it may be possible to alleviate the problems by relaxing the
requirement that an LLT be executed as an atomic action. In other words, without
sacrificing the consistency of the database, it may be possible for certain LLTs to release
their resources before they complete, thus permitting other waiting transactions to
proceed”
Saga usually performs better than distributed transactions and doesn’t require all the
services to be available at the same time.
Developers need to take care of the implementation of the Saga.
[1]
https://www.cs.cornell.edu/andru/cs711/2002fa/reading/sagas.pdf
Transaction ACID Properties
● Atomicity: this property guarantees that each transaction is treated as a single "unit", which
either succeeds completely, or fails completely
● Consistency: this property is related to the logical consistency of the data. When a new
transaction starts, it must ensure that the data maintains a state of logical consistency,
regardless of the final outcome
● Isolation: this property ensures that concurrent execution of transactions leaves the database
in the same state that would have been obtained if the transactions were executed
sequentially
● Durability: this property guarantees that all of the changes made during a transaction, once it
is committed, it must be persistent and definitive, even in the case of system crashes
Saga Pattern: ACD
Saga is a series of local transactions; every local transaction happens within the
boundary of the (micro)-service.
Saga has ACD characteristics, distributed transactions ACID characteristics [1]; the
real challenge is to deal with the lack of isolation (I) in an elegant and effective way.
A transaction in a microservice architecture should be eventually consistent.
Compensations are the actions to apply when a failure happens to leave the system in
an inconsistent state.
Compensations actions must be idempotent; they might be called more than once.
[1]
https://www.ibm.com/support/knowledgecenter/en/SSGMCP_5.4.0/product-overvi
ew/acid.html
Saga Pattern: the lack of I
Lack of isolation causes:
● Dirty reads: a transaction read data from a row that is currently modified by another
running transaction
● Lost updates: two different transactions trying to update the same “data”. One of
them doesn’t see the new value when trying to update
● Non-repeatable reads: re-reads of the same record (during an inflight transaction)
don’t produce the same results
A Saga should take actions to minimize the impact of lack of isolation.
How you implement this set of countermeasures (against isolation anomalies)
determine how good is a microservice.
Several techniques available: semantic lock, design commutative operations, ...
Saga Pattern: semantic lock
*_PENDING states, saved into the local microservice store, indicate that a Saga
instance is in progress and it is manipulating some data needing an isolation level (for
example a customer’s account)
If another Saga instance starts, it must evaluate the existing *_PENDING states and
pay attention on them.
Some strategies when detecting PENDING states:
● The Saga instance will fail.
● The Saga instance will block until the lock is released.
Saga Pattern
Book
ticket
Book
ticket
insurance
Payment
Cancel
ticket
Cancel
ticket insurance
compensation
Book
ticket
Book
ticket
insurance
Payment
Ticket Saga
Ticket Saga (Payment Error)
book a ticket
book a ticket
Payment
error
Saga Choreography vs Orchestration
How to implement a Saga and how to coordinate the execution of local transactions within
a microservice?
Two approaches:
● Choreography: the (micro)-service is responsible for emitting events at the end
of its local transaction. The event triggers the start of new local transactions in
(micro)-services subscribed to this event.
The (micro)-service must provide the logic to compensate.
● Orchestration: there is a central coordinator (a stateful entity) that triggers the
local transactions in (micro)-services. The coordinator has the logic to
compensate and maintain the status of the global transaction.
Saga Choreography
Every (micro)-service is responsible for sending events and subscribing to events.
It must define a strategy to handle the events.
Decentralized approach, all the systems work independently and they cooperate for a
common goal (without having knowledge on what is it).
Participants cannot be available during the execution of a Saga instance, no SPOF.
Events are sent to a message broker system (Apache Kafka, ActiveMQ, ...) and they
contain a correlation-id
It works if you have a limited number of services participating in the transaction
(basic sagas)
Easy to code but difficult to govern it. It’s difficult to monitor and reconstruct the
overall status of a Saga.
Saga Choreography
Ticket Service
Insurance
Service
Payment
Service
Message Broker System
PAYMENT_ACCEPTED event
must be handled by
Insurance Service
Ticket Service
ticket table
insurance table
payment table
TICKET_CREATED
ORDER_CREATED
ticket topic
order topic
payment topic
PAYMENT_ACCEPTED
TICKET_BOOKED_PENDING
TICKET_BOOKED
INSURANCE_BOOKED_PENDING
INSURANCE_BOOKED
PAYMENT_CONFIRMED
Saga Choreography
Ticket Service
Insurance
Service
Payment
Service
Message Broker System
PAYMENT_REFUSED event
must be handled by
Insurance Service
Ticket Service
ticket table
insurance table
payment table
TICKET_CREATED
ORDER_CREATED
ticket topic
order topic
payment topic
PAYMENT_REFUSED
TICKET_BOOKED_PENDING
TICKET_PAYMENT_REFUSED
INSURANCE_BOOKED_PENDING
INSURANCE_PAYMENT_REFUSED
PAYMENT_CONFIRMED
Saga Choreography
One approach could be the usage of the outbox pattern:
● Create a database table for the events.
● Atomically update the internal microservice database and insert a record into
the table for the events.
The Change Data Capture Component (Connector) reads the table for the events and
publish the events to the message broker.
https://github.com/debezium/debezium-examples/tree/master/outbox
ticket table
Ticket Service
ticket events table
update ticket state
ticket events topic
Change Data
Capture
transactional
We don’t want to lose any events and leave the system inconsistent.
How to atomically update the store and send the event?
Saga Choreography
Other approaches:
● Event Sourcing: services only store changing-state events using an
Event Store. Event Store is the events database and also behaves as a message
broker.
The state of an entity is reconstructed by a service, replaying the events from
the Event Store.
● Database transaction log mining: a process extracts the database updates using
the database transaction log and publish them to the message broker.
We don’t want to lose any events and leave the system inconsistent.
How to atomically update the store and send the event?
Saga Choreography
Services must discard duplicate events.
A message log table can be used to track all events already processed.
The correlation-id (event-id) can be used to find the event into message log table.
Saga Choreography
Let’s imagine that we don’t receive a PAYMENT_ACCEPTED or
PAYMENT_REFUSED event.
Are we sure that the Payment Service authorized the operation?
How long should we wait before compensating (timeout)?
The real limit of choreography is the complexity in implementing the logic
to coordinate the overall business transaction.
The lack of a Saga Coordinator is the real limit of the Saga Choreography
approach.
Saga Choreography
a custom solution with Quarkus, Debezium and Kafka
● Ticketing Service, a java native ms with quarkus
● Insurance Service, a java native ms with quarkus
● Payment Service, a java native ms with quarkus
● Debezium is the change data capture:
streams events from event database to Kafka
● Debezium also sends data to Elasticsearch (Kibana)
● Apache Kafka as message broker
● Run all on OpenShift
● Apache Kafka on OpenShift using AMQ Streams
● Some Prometheus and Grafana stuff
● Some images from quay.io
https://github.com/redhat-italy/rht-summit2019-saga
Why Quarkus?
Supersonic Subatomic Java
The new era of Java application, a 100% cloud native stack
Super fast boot time, low RSS memory (not only java heap)
A lot of well known libraries are already ported to Quarkus
Ticket Service
Insurance
Service
Payment
Service
AMQ Streams
ticket topic
order topic
payment topic
quarkus
eclipse-microprofile
ticket table ticket event table
insurance event table insurance table
payment event table payment table
Postgres
Postgres
Postgres
Ticket Connector
debezium-kafka-connect
quarkus
eclipse-microprofile
quarkus
eclipse-microprofile
debezium-kafka-connect
Insurance Connector
debezium-kafka-connect
Payment Connector
Saga Choreography
a custom solution with Quarkus, Debezium and Kafka
ElasticSearch +Kibana
DEMO
Saga - Choreography
Saga Orchestration
Saga is a series of local transactions; every local transaction happens within the
boundary of the (micro)-service.
In an orchestration implementation the SAGA is handled by a Saga Execution
Coordinator.
This coordinator service is responsible for centralizing the saga’s decision making and
sequencing business logic.
It's a trusted third party framework designed to specifically cater to environments
where failures can happen.
It will be part of the Microprofile specification: the reaction to the slow pace of Java EE
development.
What is Eclipse MicroProfile?
An open-source community specification for Enterprise Java
microservices
A community of individuals, organizations, and vendors
collaborating within an open source (Eclipse) project to bring
microservices to the Enterprise Java community
Community - individuals, organizations, vendors
Current MicroProfile implementations
JAX-RS 2.1JSON-P 1.1CDI 2.0
Config 1.3
Fault
Tolerance
2.0
JWT
Propagation
1.1
Health
Check 1.0
Metrics 1.1
Open
Tracing 1.3
Open API 1.1
Rest Client
1.2
JSON-B 1.0
MicroProfile 2.2
Eclipse MicroProfile 2.2 (Feb 2019)
= Updated
= No change from last release (MicroProfile 2.1)
= New
Eclipse MicroProfile 3.0 (June 2019)
JAX-RS 2.1JSON-P 1.1CDI 2.0
Config 1.3
Fault
Tolerance
2.0
JWT
Propagation
1.1
Health
Check 2.0
Metrics 2.0
Open
Tracing 1.3
Open API 1.1
Rest Client
1.2
JSON-B 1.0
MicroProfile 3.0
= Updated
= No change from last release (MicroProfile 2.2)
= New
Outside
Concurrency
1.0
LRA 1.0
Reactive
Streams
Operators 1.1
Umbrella
GraphQL 1.0
Microprofile Long Running Action
Specification that defines the behaviour of SAGA orchestration.
MicroProfile LRA proposal in progress.
Provides an “all-or-nothing” property to work that is conducted within its scope.
Guarantees shared state is protected from conflicting updates from multiple users.
Removes the Isolation (locking) ACID property. It uses the BASE (Basically Available,
Soft state, Eventual consistency) approach.
Eventual Consistency where each resource will move from a valid state to another.
Saga Orchestration Model
Book
Ticket
Book
Ticket
Insurance
TRANSACTION MANAGER
LRA COORDINATOR
Joins SAGA
Complete /
Compensate
Joins SAGA
Complete /
Compensate
Payment
Joins SAGA
Complete /
Compensate
Business Flow
Saga Orchestration - Complete Phase
Book
Ticket
Book
Ticket
Insurance
Payment
Confirm
Book Ticket
Insurance
Confirm
Book Ticket
Final
State
Initial
State
@Complete
TRANSACTION MANAGER
LRA COORDINATOR
Joins SAGA
Joins SAGA
Send
Complete to
coordinator
@Complete
Joins SAGA
Saga Orchestration - Compensation Phase
Book
Ticket
Book
Ticket
Insurance
Payment
Cancel
Book Ticket
Insurance
Cancel
Book Ticket
Final
State
Initial
State
@Compensate
TRANSACTION MANAGER
LRA COORDINATOR
Joins SAGA
Joins SAGA
Send
Compensate
to coordinator
@Compensate
Joins SAGA
Saga Orchestration
with Narayana
3 microservices with rest endpoints
● Ticketing Service /ticket
● Insurance Service /insurance
● Payment Service /payment
● Narayana LRA coordinator
● Run all the stuff on OpenShift
● Some Prometheus and Grafana stuff
https://github.com/redhat-italy/rht-summit2019-saga
Eclipse MicroProfile Community
DEMO
Saga - Orchestration
Saga Orchestration
with Apache Camel
● API Gateway: a sample camel app that is the main entry point
● Flight Service: a service that sells flights
● Train Service: a service that sells train tickets
● Payment Service: a service that allows both services to request
payments
● Narayana LRA coordinator
https://github.com/nicolaferraro/camel-saga-quick
start
Saga as state machines
Saga is essentially a state machine.
A BPMN process can represents well the workflow behind a Saga flow.
A business process executes the steps required.
A business process talks to the services.
A business process handles the failure executing compensating steps.
Easy to visualize the progress of a Saga instance.
Saga Orchestration
with jBPM
● A demo showing and IT Hardware Order application build on the case
management features and technology of
Red Hat Process Automation Manager 7.x
● The process implements the Saga pattern via standard BPMN2 compensation
flows, showing the powerful concepts and ease of semantical expression that
Red Hat Process Automation Manager 7 brings to a modern microservices
architecture.
● The order in the order service is cancelled via a BPMN2 compensation flow
when the order time’s out.
https://github.com/jbossdemocentral/rhpam7-order-it-hw-demo
Credits
Ugo Landini - Principal Solutions Architect @ Red Hat
Fabio Massimo Ercoli - Senior Software Engineer - Hibernate & Data Platform @ Red Hat
Nicola Ferraro - Senior Software Engineer - Fuse @ Red Hat
Andrea Spagnolo - Cloud Consultant @ Red Hat
Stefano Linguerri - Architect @ Red Hat
Rigel Di Scala - Architect @ Red Hat
Luigi Fugaro - Architect @ Red Hat
Noel O’Connor - Senior Principal Consultant @ Red Hat
DISCOVERY
SESSION THEATER
7:45 - 8:30 PM - 4 ways to
jump start an open source
& agile automation culture
TUESDAY
WEDNESDAY
THURSDAY
10:15-11:00 AM -
Day-in-the-Life: Designing
Software for Open
Innovation Labs
11:15-12:00 PM - How
Volkswagen used microservices
& automation to develop
self-service solutions
12:15-1:00 PM - Container
adoption at scale:
Metrics-driven framework and
other lessons learned
3:15-4:00 PM - The road to
RHEL 8: Best practices for
optimizing your operating
system
4:15-5:00 PM - Adoptando
RHEL 8: Las mejores
practicas para optimizar tu
Sistema Operativo
5:15-6:00 PM - A DevOps
survival guide: Small
changes lead to big results
6:15-7 PM - Digital Nudge:
How automation, machine
learning, A.I., and more
shape our digital decisions
10:45-11:30 AM - OpenShift
DevSecOps: Making your
enterprise more secure for
tomorrow, today
11:45-12:30 PM - To the
Edge and Beyond: Network
Automation for
Telecommunications
12:45-1:30 PM - People first, digital
second: Using open principles to
drive transformation at Heritage
Bank
1:45-2:30 PM - Monoliths in
OpenShift: Application
onboarding strategies for
containers
Saga transactions msa_ architecture

More Related Content

What's hot

Risk Management in Retail with Stream Processing
Risk Management in Retail with Stream ProcessingRisk Management in Retail with Stream Processing
Risk Management in Retail with Stream Processing
confluent
 
Securing the Cloud Native Stack
Securing the Cloud Native StackSecuring the Cloud Native Stack
Securing the Cloud Native Stack
Apcera
 
Microservices with Spring
Microservices with SpringMicroservices with Spring
Microservices with Spring
Carlos Cavero Barca
 
NATS in action - A Real time Microservices Architecture handled by NATS
NATS in action - A Real time Microservices Architecture handled by NATSNATS in action - A Real time Microservices Architecture handled by NATS
NATS in action - A Real time Microservices Architecture handled by NATSRaül Pérez
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architecture
Mohammad Dameer
 
SingleStore & Kafka: Better Together to Power Modern Real-Time Data Architect...
SingleStore & Kafka: Better Together to Power Modern Real-Time Data Architect...SingleStore & Kafka: Better Together to Power Modern Real-Time Data Architect...
SingleStore & Kafka: Better Together to Power Modern Real-Time Data Architect...
HostedbyConfluent
 
Microservices
MicroservicesMicroservices
Microservices
Anderson Carvalho
 
Cloud Native Patterns Using AWS
Cloud Native Patterns Using AWSCloud Native Patterns Using AWS
Cloud Native Patterns Using AWS
Anderson Carvalho
 
Micro services Architecture
Micro services ArchitectureMicro services Architecture
Micro services Architecture
Jenis Dharmadurai
 
What is reactive
What is reactiveWhat is reactive
What is reactive
Lightbend
 
Microservices, Monoliths, SOA and How We Got Here
Microservices, Monoliths, SOA and How We Got HereMicroservices, Monoliths, SOA and How We Got Here
Microservices, Monoliths, SOA and How We Got Here
Lightbend
 
Big Data LDN 2018: CHARTING ZERO LATENCY FUTURE WITH REDIS
Big Data LDN 2018: CHARTING ZERO LATENCY FUTURE WITH REDISBig Data LDN 2018: CHARTING ZERO LATENCY FUTURE WITH REDIS
Big Data LDN 2018: CHARTING ZERO LATENCY FUTURE WITH REDIS
Matt Stubbs
 
Microservices Architecture
Microservices ArchitectureMicroservices Architecture
Microservices Architecture
Srinivasan Nanduri
 
[WSO2Con USA 2018] Microservices, Containers, and Beyond
[WSO2Con USA 2018] Microservices, Containers, and Beyond[WSO2Con USA 2018] Microservices, Containers, and Beyond
[WSO2Con USA 2018] Microservices, Containers, and Beyond
WSO2
 
Modeling microservices using DDD
Modeling microservices using DDDModeling microservices using DDD
Modeling microservices using DDD
Masashi Narumoto
 
The Bridge to Cloud (Peter Gustafsson, Confluent) London 2019 Confluent Strea...
The Bridge to Cloud (Peter Gustafsson, Confluent) London 2019 Confluent Strea...The Bridge to Cloud (Peter Gustafsson, Confluent) London 2019 Confluent Strea...
The Bridge to Cloud (Peter Gustafsson, Confluent) London 2019 Confluent Strea...
confluent
 
Presentation cloud computing
Presentation cloud computingPresentation cloud computing
Presentation cloud computingAkash Pandey
 
Jay Kreps | Kafka Summit NYC 2019 Keynote (Events Everywhere) | CEO, Confluent
Jay Kreps | Kafka Summit NYC 2019 Keynote (Events Everywhere) | CEO, ConfluentJay Kreps | Kafka Summit NYC 2019 Keynote (Events Everywhere) | CEO, Confluent
Jay Kreps | Kafka Summit NYC 2019 Keynote (Events Everywhere) | CEO, Confluent
confluent
 
Kenzan: Architecting for Microservices
Kenzan: Architecting for MicroservicesKenzan: Architecting for Microservices
Kenzan: Architecting for Microservices
Darren Bathgate
 
Designing microservices part2
Designing microservices part2Designing microservices part2
Designing microservices part2
Masashi Narumoto
 

What's hot (20)

Risk Management in Retail with Stream Processing
Risk Management in Retail with Stream ProcessingRisk Management in Retail with Stream Processing
Risk Management in Retail with Stream Processing
 
Securing the Cloud Native Stack
Securing the Cloud Native StackSecuring the Cloud Native Stack
Securing the Cloud Native Stack
 
Microservices with Spring
Microservices with SpringMicroservices with Spring
Microservices with Spring
 
NATS in action - A Real time Microservices Architecture handled by NATS
NATS in action - A Real time Microservices Architecture handled by NATSNATS in action - A Real time Microservices Architecture handled by NATS
NATS in action - A Real time Microservices Architecture handled by NATS
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architecture
 
SingleStore & Kafka: Better Together to Power Modern Real-Time Data Architect...
SingleStore & Kafka: Better Together to Power Modern Real-Time Data Architect...SingleStore & Kafka: Better Together to Power Modern Real-Time Data Architect...
SingleStore & Kafka: Better Together to Power Modern Real-Time Data Architect...
 
Microservices
MicroservicesMicroservices
Microservices
 
Cloud Native Patterns Using AWS
Cloud Native Patterns Using AWSCloud Native Patterns Using AWS
Cloud Native Patterns Using AWS
 
Micro services Architecture
Micro services ArchitectureMicro services Architecture
Micro services Architecture
 
What is reactive
What is reactiveWhat is reactive
What is reactive
 
Microservices, Monoliths, SOA and How We Got Here
Microservices, Monoliths, SOA and How We Got HereMicroservices, Monoliths, SOA and How We Got Here
Microservices, Monoliths, SOA and How We Got Here
 
Big Data LDN 2018: CHARTING ZERO LATENCY FUTURE WITH REDIS
Big Data LDN 2018: CHARTING ZERO LATENCY FUTURE WITH REDISBig Data LDN 2018: CHARTING ZERO LATENCY FUTURE WITH REDIS
Big Data LDN 2018: CHARTING ZERO LATENCY FUTURE WITH REDIS
 
Microservices Architecture
Microservices ArchitectureMicroservices Architecture
Microservices Architecture
 
[WSO2Con USA 2018] Microservices, Containers, and Beyond
[WSO2Con USA 2018] Microservices, Containers, and Beyond[WSO2Con USA 2018] Microservices, Containers, and Beyond
[WSO2Con USA 2018] Microservices, Containers, and Beyond
 
Modeling microservices using DDD
Modeling microservices using DDDModeling microservices using DDD
Modeling microservices using DDD
 
The Bridge to Cloud (Peter Gustafsson, Confluent) London 2019 Confluent Strea...
The Bridge to Cloud (Peter Gustafsson, Confluent) London 2019 Confluent Strea...The Bridge to Cloud (Peter Gustafsson, Confluent) London 2019 Confluent Strea...
The Bridge to Cloud (Peter Gustafsson, Confluent) London 2019 Confluent Strea...
 
Presentation cloud computing
Presentation cloud computingPresentation cloud computing
Presentation cloud computing
 
Jay Kreps | Kafka Summit NYC 2019 Keynote (Events Everywhere) | CEO, Confluent
Jay Kreps | Kafka Summit NYC 2019 Keynote (Events Everywhere) | CEO, ConfluentJay Kreps | Kafka Summit NYC 2019 Keynote (Events Everywhere) | CEO, Confluent
Jay Kreps | Kafka Summit NYC 2019 Keynote (Events Everywhere) | CEO, Confluent
 
Kenzan: Architecting for Microservices
Kenzan: Architecting for MicroservicesKenzan: Architecting for Microservices
Kenzan: Architecting for Microservices
 
Designing microservices part2
Designing microservices part2Designing microservices part2
Designing microservices part2
 

Similar to Saga transactions msa_ architecture

JS Fest 2019/Autumn. Anton Cherednikov. Choreographic or orchestral architect...
JS Fest 2019/Autumn. Anton Cherednikov. Choreographic or orchestral architect...JS Fest 2019/Autumn. Anton Cherednikov. Choreographic or orchestral architect...
JS Fest 2019/Autumn. Anton Cherednikov. Choreographic or orchestral architect...
JSFestUA
 
'How to build efficient backend based on microservice architecture' by Anton ...
'How to build efficient backend based on microservice architecture' by Anton ...'How to build efficient backend based on microservice architecture' by Anton ...
'How to build efficient backend based on microservice architecture' by Anton ...
OdessaJS Conf
 
Agile integration: Decomposing the monolith
Agile integration: Decomposing the monolith Agile integration: Decomposing the monolith
Agile integration: Decomposing the monolith
Judy Breedlove
 
Enterprise Integration in Cloud Native Microservices Architectures
Enterprise Integration in Cloud Native Microservices ArchitecturesEnterprise Integration in Cloud Native Microservices Architectures
Enterprise Integration in Cloud Native Microservices Architectures
Crishantha Nanayakkara
 
SELECTION MECHANISM OF MICRO-SERVICES ORCHESTRATION VS. CHOREOGRAPHY
SELECTION MECHANISM OF MICRO-SERVICES ORCHESTRATION VS. CHOREOGRAPHYSELECTION MECHANISM OF MICRO-SERVICES ORCHESTRATION VS. CHOREOGRAPHY
SELECTION MECHANISM OF MICRO-SERVICES ORCHESTRATION VS. CHOREOGRAPHY
dannyijwest
 
SELECTION MECHANISM OF MICRO-SERVICES ORCHESTRATION VS. CHOREOGRAPHY
SELECTION MECHANISM OF MICRO-SERVICES ORCHESTRATION VS. CHOREOGRAPHY SELECTION MECHANISM OF MICRO-SERVICES ORCHESTRATION VS. CHOREOGRAPHY
SELECTION MECHANISM OF MICRO-SERVICES ORCHESTRATION VS. CHOREOGRAPHY
IJwest
 
Over view of software artitecture
Over view of software artitectureOver view of software artitecture
Over view of software artitecture
ABDEL RAHMAN KARIM
 
Magiclock: Scalable Detection of Potential Deadlocks in Large-Scale Multithre...
Magiclock: Scalable Detection of Potential Deadlocks in Large-Scale Multithre...Magiclock: Scalable Detection of Potential Deadlocks in Large-Scale Multithre...
Magiclock: Scalable Detection of Potential Deadlocks in Large-Scale Multithre...
KaashivInfoTech Company
 
APIdays Paris 2019 - Cloud native API Management for Microservices on a Servi...
APIdays Paris 2019 - Cloud native API Management for Microservices on a Servi...APIdays Paris 2019 - Cloud native API Management for Microservices on a Servi...
APIdays Paris 2019 - Cloud native API Management for Microservices on a Servi...
apidays
 
Event Driven Software Architecture Pattern
Event Driven Software Architecture PatternEvent Driven Software Architecture Pattern
Event Driven Software Architecture Pattern
jeetendra mandal
 
Monolithic to Microservices Architecture - STM 6
Monolithic to Microservices Architecture - STM 6Monolithic to Microservices Architecture - STM 6
Monolithic to Microservices Architecture - STM 6
Tricode (part of Dept)
 
Building Cloud Ready Apps
Building Cloud Ready AppsBuilding Cloud Ready Apps
Building Cloud Ready Apps
VMware Tanzu
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architecture
Faren faren
 
Event Driven Architecture
Event Driven ArchitectureEvent Driven Architecture
Event Driven Architecture
Sistek Yazılım
 
Reactive - Is it really a Magic Pill?
Reactive - Is it really a Magic Pill?Reactive - Is it really a Magic Pill?
Reactive - Is it really a Magic Pill?
Tech Triveni
 
[APIdays Paris 2019] API Management in Service Mesh Using Istio and WSO2 API ...
[APIdays Paris 2019] API Management in Service Mesh Using Istio and WSO2 API ...[APIdays Paris 2019] API Management in Service Mesh Using Istio and WSO2 API ...
[APIdays Paris 2019] API Management in Service Mesh Using Istio and WSO2 API ...
WSO2
 
Introduction to Microservices Patterns
Introduction to Microservices PatternsIntroduction to Microservices Patterns
Introduction to Microservices Patterns
arconsis
 
Introduction to Microservices Patterns
Introduction to Microservices PatternsIntroduction to Microservices Patterns
Introduction to Microservices Patterns
Dimosthenis Botsaris
 
About microservices on cloud computing services
About microservices on cloud computing servicesAbout microservices on cloud computing services
About microservices on cloud computing services
ssuser53aac4
 
ZhuSem.ppt
ZhuSem.pptZhuSem.ppt
ZhuSem.ppt
SelmaBenSassi1
 

Similar to Saga transactions msa_ architecture (20)

JS Fest 2019/Autumn. Anton Cherednikov. Choreographic or orchestral architect...
JS Fest 2019/Autumn. Anton Cherednikov. Choreographic or orchestral architect...JS Fest 2019/Autumn. Anton Cherednikov. Choreographic or orchestral architect...
JS Fest 2019/Autumn. Anton Cherednikov. Choreographic or orchestral architect...
 
'How to build efficient backend based on microservice architecture' by Anton ...
'How to build efficient backend based on microservice architecture' by Anton ...'How to build efficient backend based on microservice architecture' by Anton ...
'How to build efficient backend based on microservice architecture' by Anton ...
 
Agile integration: Decomposing the monolith
Agile integration: Decomposing the monolith Agile integration: Decomposing the monolith
Agile integration: Decomposing the monolith
 
Enterprise Integration in Cloud Native Microservices Architectures
Enterprise Integration in Cloud Native Microservices ArchitecturesEnterprise Integration in Cloud Native Microservices Architectures
Enterprise Integration in Cloud Native Microservices Architectures
 
SELECTION MECHANISM OF MICRO-SERVICES ORCHESTRATION VS. CHOREOGRAPHY
SELECTION MECHANISM OF MICRO-SERVICES ORCHESTRATION VS. CHOREOGRAPHYSELECTION MECHANISM OF MICRO-SERVICES ORCHESTRATION VS. CHOREOGRAPHY
SELECTION MECHANISM OF MICRO-SERVICES ORCHESTRATION VS. CHOREOGRAPHY
 
SELECTION MECHANISM OF MICRO-SERVICES ORCHESTRATION VS. CHOREOGRAPHY
SELECTION MECHANISM OF MICRO-SERVICES ORCHESTRATION VS. CHOREOGRAPHY SELECTION MECHANISM OF MICRO-SERVICES ORCHESTRATION VS. CHOREOGRAPHY
SELECTION MECHANISM OF MICRO-SERVICES ORCHESTRATION VS. CHOREOGRAPHY
 
Over view of software artitecture
Over view of software artitectureOver view of software artitecture
Over view of software artitecture
 
Magiclock: Scalable Detection of Potential Deadlocks in Large-Scale Multithre...
Magiclock: Scalable Detection of Potential Deadlocks in Large-Scale Multithre...Magiclock: Scalable Detection of Potential Deadlocks in Large-Scale Multithre...
Magiclock: Scalable Detection of Potential Deadlocks in Large-Scale Multithre...
 
APIdays Paris 2019 - Cloud native API Management for Microservices on a Servi...
APIdays Paris 2019 - Cloud native API Management for Microservices on a Servi...APIdays Paris 2019 - Cloud native API Management for Microservices on a Servi...
APIdays Paris 2019 - Cloud native API Management for Microservices on a Servi...
 
Event Driven Software Architecture Pattern
Event Driven Software Architecture PatternEvent Driven Software Architecture Pattern
Event Driven Software Architecture Pattern
 
Monolithic to Microservices Architecture - STM 6
Monolithic to Microservices Architecture - STM 6Monolithic to Microservices Architecture - STM 6
Monolithic to Microservices Architecture - STM 6
 
Building Cloud Ready Apps
Building Cloud Ready AppsBuilding Cloud Ready Apps
Building Cloud Ready Apps
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architecture
 
Event Driven Architecture
Event Driven ArchitectureEvent Driven Architecture
Event Driven Architecture
 
Reactive - Is it really a Magic Pill?
Reactive - Is it really a Magic Pill?Reactive - Is it really a Magic Pill?
Reactive - Is it really a Magic Pill?
 
[APIdays Paris 2019] API Management in Service Mesh Using Istio and WSO2 API ...
[APIdays Paris 2019] API Management in Service Mesh Using Istio and WSO2 API ...[APIdays Paris 2019] API Management in Service Mesh Using Istio and WSO2 API ...
[APIdays Paris 2019] API Management in Service Mesh Using Istio and WSO2 API ...
 
Introduction to Microservices Patterns
Introduction to Microservices PatternsIntroduction to Microservices Patterns
Introduction to Microservices Patterns
 
Introduction to Microservices Patterns
Introduction to Microservices PatternsIntroduction to Microservices Patterns
Introduction to Microservices Patterns
 
About microservices on cloud computing services
About microservices on cloud computing servicesAbout microservices on cloud computing services
About microservices on cloud computing services
 
ZhuSem.ppt
ZhuSem.pptZhuSem.ppt
ZhuSem.ppt
 

Recently uploaded

Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Yara Milbes
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 

Recently uploaded (20)

Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 

Saga transactions msa_ architecture

  • 1. Saga: The new era of transactions in a microservices architecture Giovanni Marigi - Senior Middleware Consultant Mauro Vocale - Solution Architect BOSTON, MA | MAY 7-9, 2019
  • 2. Microservices The microservice architecture is the main trend in information technology and we learned a lot about it during these years ...
  • 3. What are Microservices? “…an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API.” Martin Fowler
  • 4. • Fast to develop, easier to maintain and understand • Starts faster, speeds up deployments • Fault isolation • Services can be scaled independently • Deltas and patches can be applied to each microservice individually • Local changes can be deployed easily • Flexible choice of technology • Security can be applied to each microservice as opposed to the whole system in a blanket approach MICROSERVICES ADVANTAGES
  • 5. • Additional architectural complexity of distributed systems ○ Maintaining strong consistency is extremely difficult ○ Testing a distributed system is difficult ○ Requires a shift in coding paradigm: Change in approach to application architecture design and testing • Significant operational complexity. Requires a high degree of automation ○ Deployments require coordination and rollout plan MICROSERVICES DISADVANTAGES
  • 6. MICROSERVICES FRAMEWORKS There are many ways to build a microservice
  • 8. MICROSERVICES DILEMMA: How to handle transactions? SAGA! 2PC, XA, BULK BATCH!
  • 9. Microservices and transactions You’ve successfully decomposed your monolithic application into several microservices. Every microservice has its own state and a local store (RDBMS, NoSQL, file store, ...) Microservices can emit events when a state changes. Microservices can react to events. But you still want that a business process spanning several services to be consistent and correct regardless of the level of decomposition of your application.
  • 10. Why distributed transactions don’t work Traditional distributed transactions are implemented using a two-phase commit, briefly 2PC. Why can’t we use 2PC in microservices architecture? ● You don’t have a single shared store anymore, every service has its own data store (micro-db) ● A microservices architecture involves many parties, realized using different technologies that adhere to different specifications: 2PC implicitly assumes closely coupled environment ● Synchronization and isolation reduces performance and scalability. ● A business function potentially lasting for hours or days: lock strategy doesn't work well in long duration activities
  • 11. Distributed transactions Ticket Service Insurance Service 2PC: a magic box XA resource XA resource book a ticket book a ticket Simple rule: 2PC would try to reserve both the ticket and the insurance at the same time. If it doesn’t succeed, none of them will be booked.
  • 12. Microservices: eventual consistency Consistency states that the entire software system should be in a valid state. 2PC guarantees the consistency with a pessimistic approach; all the changes must be done at the same time or rollback. Microservices architectures at the opposite guarantee the consistency with a more relaxed approach. The state of the entire system can’t be valid at any time but at the end of the business transaction. The system is eventually consistent. Ticket service and Insurance service will try to book independently. In case of failure in one of the two, the other one will be canceled. Eventual consistency is not easy achieve and there is no a magic box out there.
  • 13. Saga Pattern Le Radeau de la Méduse - Théodore Géricault, 1818-19
  • 14. Saga Pattern: overview Saga is the de facto solution to guarantee consistency in a microservices architecture. Saga is not a new pattern [1] and it can be applied also in traditional monolithic architectures. “For specific applications, it may be possible to alleviate the problems by relaxing the requirement that an LLT be executed as an atomic action. In other words, without sacrificing the consistency of the database, it may be possible for certain LLTs to release their resources before they complete, thus permitting other waiting transactions to proceed” Saga usually performs better than distributed transactions and doesn’t require all the services to be available at the same time. Developers need to take care of the implementation of the Saga. [1] https://www.cs.cornell.edu/andru/cs711/2002fa/reading/sagas.pdf
  • 15. Transaction ACID Properties ● Atomicity: this property guarantees that each transaction is treated as a single "unit", which either succeeds completely, or fails completely ● Consistency: this property is related to the logical consistency of the data. When a new transaction starts, it must ensure that the data maintains a state of logical consistency, regardless of the final outcome ● Isolation: this property ensures that concurrent execution of transactions leaves the database in the same state that would have been obtained if the transactions were executed sequentially ● Durability: this property guarantees that all of the changes made during a transaction, once it is committed, it must be persistent and definitive, even in the case of system crashes
  • 16. Saga Pattern: ACD Saga is a series of local transactions; every local transaction happens within the boundary of the (micro)-service. Saga has ACD characteristics, distributed transactions ACID characteristics [1]; the real challenge is to deal with the lack of isolation (I) in an elegant and effective way. A transaction in a microservice architecture should be eventually consistent. Compensations are the actions to apply when a failure happens to leave the system in an inconsistent state. Compensations actions must be idempotent; they might be called more than once. [1] https://www.ibm.com/support/knowledgecenter/en/SSGMCP_5.4.0/product-overvi ew/acid.html
  • 17. Saga Pattern: the lack of I Lack of isolation causes: ● Dirty reads: a transaction read data from a row that is currently modified by another running transaction ● Lost updates: two different transactions trying to update the same “data”. One of them doesn’t see the new value when trying to update ● Non-repeatable reads: re-reads of the same record (during an inflight transaction) don’t produce the same results A Saga should take actions to minimize the impact of lack of isolation. How you implement this set of countermeasures (against isolation anomalies) determine how good is a microservice. Several techniques available: semantic lock, design commutative operations, ...
  • 18. Saga Pattern: semantic lock *_PENDING states, saved into the local microservice store, indicate that a Saga instance is in progress and it is manipulating some data needing an isolation level (for example a customer’s account) If another Saga instance starts, it must evaluate the existing *_PENDING states and pay attention on them. Some strategies when detecting PENDING states: ● The Saga instance will fail. ● The Saga instance will block until the lock is released.
  • 20. Saga Choreography vs Orchestration How to implement a Saga and how to coordinate the execution of local transactions within a microservice? Two approaches: ● Choreography: the (micro)-service is responsible for emitting events at the end of its local transaction. The event triggers the start of new local transactions in (micro)-services subscribed to this event. The (micro)-service must provide the logic to compensate. ● Orchestration: there is a central coordinator (a stateful entity) that triggers the local transactions in (micro)-services. The coordinator has the logic to compensate and maintain the status of the global transaction.
  • 21. Saga Choreography Every (micro)-service is responsible for sending events and subscribing to events. It must define a strategy to handle the events. Decentralized approach, all the systems work independently and they cooperate for a common goal (without having knowledge on what is it). Participants cannot be available during the execution of a Saga instance, no SPOF. Events are sent to a message broker system (Apache Kafka, ActiveMQ, ...) and they contain a correlation-id It works if you have a limited number of services participating in the transaction (basic sagas) Easy to code but difficult to govern it. It’s difficult to monitor and reconstruct the overall status of a Saga.
  • 22. Saga Choreography Ticket Service Insurance Service Payment Service Message Broker System PAYMENT_ACCEPTED event must be handled by Insurance Service Ticket Service ticket table insurance table payment table TICKET_CREATED ORDER_CREATED ticket topic order topic payment topic PAYMENT_ACCEPTED TICKET_BOOKED_PENDING TICKET_BOOKED INSURANCE_BOOKED_PENDING INSURANCE_BOOKED PAYMENT_CONFIRMED
  • 23. Saga Choreography Ticket Service Insurance Service Payment Service Message Broker System PAYMENT_REFUSED event must be handled by Insurance Service Ticket Service ticket table insurance table payment table TICKET_CREATED ORDER_CREATED ticket topic order topic payment topic PAYMENT_REFUSED TICKET_BOOKED_PENDING TICKET_PAYMENT_REFUSED INSURANCE_BOOKED_PENDING INSURANCE_PAYMENT_REFUSED PAYMENT_CONFIRMED
  • 24. Saga Choreography One approach could be the usage of the outbox pattern: ● Create a database table for the events. ● Atomically update the internal microservice database and insert a record into the table for the events. The Change Data Capture Component (Connector) reads the table for the events and publish the events to the message broker. https://github.com/debezium/debezium-examples/tree/master/outbox ticket table Ticket Service ticket events table update ticket state ticket events topic Change Data Capture transactional We don’t want to lose any events and leave the system inconsistent. How to atomically update the store and send the event?
  • 25. Saga Choreography Other approaches: ● Event Sourcing: services only store changing-state events using an Event Store. Event Store is the events database and also behaves as a message broker. The state of an entity is reconstructed by a service, replaying the events from the Event Store. ● Database transaction log mining: a process extracts the database updates using the database transaction log and publish them to the message broker. We don’t want to lose any events and leave the system inconsistent. How to atomically update the store and send the event?
  • 26. Saga Choreography Services must discard duplicate events. A message log table can be used to track all events already processed. The correlation-id (event-id) can be used to find the event into message log table.
  • 27. Saga Choreography Let’s imagine that we don’t receive a PAYMENT_ACCEPTED or PAYMENT_REFUSED event. Are we sure that the Payment Service authorized the operation? How long should we wait before compensating (timeout)? The real limit of choreography is the complexity in implementing the logic to coordinate the overall business transaction. The lack of a Saga Coordinator is the real limit of the Saga Choreography approach.
  • 28. Saga Choreography a custom solution with Quarkus, Debezium and Kafka ● Ticketing Service, a java native ms with quarkus ● Insurance Service, a java native ms with quarkus ● Payment Service, a java native ms with quarkus ● Debezium is the change data capture: streams events from event database to Kafka ● Debezium also sends data to Elasticsearch (Kibana) ● Apache Kafka as message broker ● Run all on OpenShift ● Apache Kafka on OpenShift using AMQ Streams ● Some Prometheus and Grafana stuff ● Some images from quay.io https://github.com/redhat-italy/rht-summit2019-saga
  • 29. Why Quarkus? Supersonic Subatomic Java The new era of Java application, a 100% cloud native stack Super fast boot time, low RSS memory (not only java heap) A lot of well known libraries are already ported to Quarkus
  • 30. Ticket Service Insurance Service Payment Service AMQ Streams ticket topic order topic payment topic quarkus eclipse-microprofile ticket table ticket event table insurance event table insurance table payment event table payment table Postgres Postgres Postgres Ticket Connector debezium-kafka-connect quarkus eclipse-microprofile quarkus eclipse-microprofile debezium-kafka-connect Insurance Connector debezium-kafka-connect Payment Connector Saga Choreography a custom solution with Quarkus, Debezium and Kafka ElasticSearch +Kibana
  • 32. Saga Orchestration Saga is a series of local transactions; every local transaction happens within the boundary of the (micro)-service. In an orchestration implementation the SAGA is handled by a Saga Execution Coordinator. This coordinator service is responsible for centralizing the saga’s decision making and sequencing business logic. It's a trusted third party framework designed to specifically cater to environments where failures can happen. It will be part of the Microprofile specification: the reaction to the slow pace of Java EE development.
  • 33. What is Eclipse MicroProfile? An open-source community specification for Enterprise Java microservices A community of individuals, organizations, and vendors collaborating within an open source (Eclipse) project to bring microservices to the Enterprise Java community
  • 34. Community - individuals, organizations, vendors
  • 36. JAX-RS 2.1JSON-P 1.1CDI 2.0 Config 1.3 Fault Tolerance 2.0 JWT Propagation 1.1 Health Check 1.0 Metrics 1.1 Open Tracing 1.3 Open API 1.1 Rest Client 1.2 JSON-B 1.0 MicroProfile 2.2 Eclipse MicroProfile 2.2 (Feb 2019) = Updated = No change from last release (MicroProfile 2.1) = New
  • 37. Eclipse MicroProfile 3.0 (June 2019) JAX-RS 2.1JSON-P 1.1CDI 2.0 Config 1.3 Fault Tolerance 2.0 JWT Propagation 1.1 Health Check 2.0 Metrics 2.0 Open Tracing 1.3 Open API 1.1 Rest Client 1.2 JSON-B 1.0 MicroProfile 3.0 = Updated = No change from last release (MicroProfile 2.2) = New Outside Concurrency 1.0 LRA 1.0 Reactive Streams Operators 1.1 Umbrella GraphQL 1.0
  • 38. Microprofile Long Running Action Specification that defines the behaviour of SAGA orchestration. MicroProfile LRA proposal in progress. Provides an “all-or-nothing” property to work that is conducted within its scope. Guarantees shared state is protected from conflicting updates from multiple users. Removes the Isolation (locking) ACID property. It uses the BASE (Basically Available, Soft state, Eventual consistency) approach. Eventual Consistency where each resource will move from a valid state to another.
  • 39. Saga Orchestration Model Book Ticket Book Ticket Insurance TRANSACTION MANAGER LRA COORDINATOR Joins SAGA Complete / Compensate Joins SAGA Complete / Compensate Payment Joins SAGA Complete / Compensate Business Flow
  • 40. Saga Orchestration - Complete Phase Book Ticket Book Ticket Insurance Payment Confirm Book Ticket Insurance Confirm Book Ticket Final State Initial State @Complete TRANSACTION MANAGER LRA COORDINATOR Joins SAGA Joins SAGA Send Complete to coordinator @Complete Joins SAGA
  • 41. Saga Orchestration - Compensation Phase Book Ticket Book Ticket Insurance Payment Cancel Book Ticket Insurance Cancel Book Ticket Final State Initial State @Compensate TRANSACTION MANAGER LRA COORDINATOR Joins SAGA Joins SAGA Send Compensate to coordinator @Compensate Joins SAGA
  • 42. Saga Orchestration with Narayana 3 microservices with rest endpoints ● Ticketing Service /ticket ● Insurance Service /insurance ● Payment Service /payment ● Narayana LRA coordinator ● Run all the stuff on OpenShift ● Some Prometheus and Grafana stuff https://github.com/redhat-italy/rht-summit2019-saga Eclipse MicroProfile Community
  • 44. Saga Orchestration with Apache Camel ● API Gateway: a sample camel app that is the main entry point ● Flight Service: a service that sells flights ● Train Service: a service that sells train tickets ● Payment Service: a service that allows both services to request payments ● Narayana LRA coordinator https://github.com/nicolaferraro/camel-saga-quick start
  • 45. Saga as state machines Saga is essentially a state machine. A BPMN process can represents well the workflow behind a Saga flow. A business process executes the steps required. A business process talks to the services. A business process handles the failure executing compensating steps. Easy to visualize the progress of a Saga instance.
  • 46. Saga Orchestration with jBPM ● A demo showing and IT Hardware Order application build on the case management features and technology of Red Hat Process Automation Manager 7.x ● The process implements the Saga pattern via standard BPMN2 compensation flows, showing the powerful concepts and ease of semantical expression that Red Hat Process Automation Manager 7 brings to a modern microservices architecture. ● The order in the order service is cancelled via a BPMN2 compensation flow when the order time’s out. https://github.com/jbossdemocentral/rhpam7-order-it-hw-demo
  • 47. Credits Ugo Landini - Principal Solutions Architect @ Red Hat Fabio Massimo Ercoli - Senior Software Engineer - Hibernate & Data Platform @ Red Hat Nicola Ferraro - Senior Software Engineer - Fuse @ Red Hat Andrea Spagnolo - Cloud Consultant @ Red Hat Stefano Linguerri - Architect @ Red Hat Rigel Di Scala - Architect @ Red Hat Luigi Fugaro - Architect @ Red Hat Noel O’Connor - Senior Principal Consultant @ Red Hat
  • 48. DISCOVERY SESSION THEATER 7:45 - 8:30 PM - 4 ways to jump start an open source & agile automation culture TUESDAY WEDNESDAY THURSDAY 10:15-11:00 AM - Day-in-the-Life: Designing Software for Open Innovation Labs 11:15-12:00 PM - How Volkswagen used microservices & automation to develop self-service solutions 12:15-1:00 PM - Container adoption at scale: Metrics-driven framework and other lessons learned 3:15-4:00 PM - The road to RHEL 8: Best practices for optimizing your operating system 4:15-5:00 PM - Adoptando RHEL 8: Las mejores practicas para optimizar tu Sistema Operativo 5:15-6:00 PM - A DevOps survival guide: Small changes lead to big results 6:15-7 PM - Digital Nudge: How automation, machine learning, A.I., and more shape our digital decisions 10:45-11:30 AM - OpenShift DevSecOps: Making your enterprise more secure for tomorrow, today 11:45-12:30 PM - To the Edge and Beyond: Network Automation for Telecommunications 12:45-1:30 PM - People first, digital second: Using open principles to drive transformation at Heritage Bank 1:45-2:30 PM - Monoliths in OpenShift: Application onboarding strategies for containers