SlideShare a Scribd company logo
@berndruecker
Lost in transaction?
Strategies to deal with
(in)consistency in distributed systems
Do A
Do B
All or
nothing
+
try {
tx.begin();
doA();
doB();
tx.commit();
} catch (Exception e) {
tx.rollback();
}
@Transactional
public void createCustomer(Customer cust) {
// ...
}
Or simply:
Once upon a time:
A
C
I
D
Atomicity
Consistency
Isolation
Durability
Distributed systems
Distributed systems
Distributed systems
But there is two-phase commit (XA)!!
TX
Coordinator
Resource
Managers
Prepare
Phase
Commit
Phase
Pat Helland
“
Distributed Systems Guru
Worked at Amazon,
Microsoft & Salesforce
Pat Helland
Grown-Ups Don’t Use
Distributed Transactions
“
Distributed Systems Guru
Worked at Amazon,
Microsoft & Salesforce
Starbucks does not use two phase commit
https://www.enterpriseintegrationpatterns.com/ramblings/18_starbucks.html
Photo by John Ingle
Eric Brewer
Atomicity
Consistency
Isolation
Durability
http://pld.cs.luc.edu/courses/353/spr11/notes/brewer_keynote.pdf
That means
Do A
Do B
Temporarily
inconsistent
Eventually
consistent
again
t
Consistent
Local
ACID
Local
ACID
1 (micro-)service
1 aggregate
1 program
1 resource
Violates „I“
of ACID
Youmightknowthisfrom:
Do A
Do B
Temporarily
inconsistent
Eventually
consistent
again
t
Consistent
Photo by Gerhard51, available under Creative Commons CC0 1.0 license.
„Building on Quicksand“ Paper
A
C
I
D
2.0Pat Helland
Associative
Commutative
Idempotent
Distributed
2.0
(a + b) + c = a + (b + c)
a + b = b + a
f(x) = f( f(x) )
„Building on Quicksand“ Paper
Pat Helland
Requirement: Idempotency of services!
Photo by pixabay, available under Creative Commons CC0 1.0 license.
Requirement: Idempotency of services!
Photo by Chr.Späth, available under Public Domain.
Associative
Commutative
Idempotent
Distributed
2.0
(a + b) + c = a + (b + c)
a + b = b + a
f(x) = f( f(x) )
„Building on Quicksand“ Paper
Pat Helland
Distributed
It is impossible to
differentiate certain
failure scenarios:
Independant of
communication style!
Service
Provider
Client
Network problems
Credit
Card
Payment
charge
Strategy: retry
Credit
Card
Payment
Charge Credit Card
cardNumber
amount
Charge Credit Card
cardNumber
amount
transactionId
Not idempotent
Idempotent
has to be idempotent
charge
Strategy: Cleanup
Credit
Card
Payment
charge
Make sure it is
not charged!
Cancel charge
cardNumber
amount
transactionId
Raise
payment failed
Some communication challenges
require state.
Strategy: Stateful retry
Credit
Card
Payment
charge
Strategy: Stateful retry
Credit
Card
Payment
charge
Make sure it is
not charged!
Warning:
Contains Opinion
Berlin, Germany
bernd.ruecker@camunda.com
@berndruecker
Bernd Ruecker
Co-founder and
Developer Advocate of
Camunda
Let‘s use a lightweight OSS workflow engine for this:
Payment
Stateful retry
Credit
Card
REST
Stateful retry & cleanup
Credit
Card
Payment
REST
Live hacking
https://github.com/flowing/flowing-retail/tree/master/rest
Embedded Engine Example (Java)
https://blog.bernd-ruecker.com/architecture-options-to-run-a-workflow-engine-6c2419902d91
Remote Engine Example (Polyglot)
https://blog.bernd-ruecker.com/architecture-options-to-run-a-workflow-engine-6c2419902d91
A relatively common pattern
Service
(e.g. Go)
Kafka / Rabbit
RDMS
1. Receive
4. Send additional events
2. Business Logic
3. Send
response? ACK
Out-of-order messages
https://www.enterpriseintegrationpatterns.com/patterns/messaging/Resequencer.html
Lost in transaction - Strategies to deal with (in)consistency in distributed systems
Lost in transaction - Strategies to deal with (in)consistency in distributed systems
That means
Do A
Do B
Temporarily
inconsistent
Eventually
consistent
In case of failure:
Compensate or apologise
t
Consistent
https://blogs.msdn.microsoft.com/pathelland/2007/05/15/memories-guesses-and-apologies/
Lost in transaction - Strategies to deal with (in)consistency in distributed systems
Compensation – the classical example
Saga
book
hotel
book
car
book
flight
cancel
hotel
cancel
car
1. 2. 3.
5.6.
In case of failure
trigger compensations
book
trip
2 alterntive approaches: choreography & orchestration
Event-driven choreography
Hotel
Flight
Car
Trip
Trip
booked
Flight
booked
Trip
requested
Hotel
booked
Car
booked
Request
trip
Event-driven choreography
Hotel
Flight
Car
Trip
Trip
failed
Trip
requested
Hotel
booked
Car
booked
Request
trip
Flight
failed
Car
canceled
Hotel
canceled
Perform undo
(cancel car booking)
Perform undo
(cancel hotel)
The danger is that it's very easy to make
nicely decoupled systems with event
notification, without realizing that you're
losing sight of that larger-scale flow, and
thus set yourself up for trouble in future
years.
https://martinfowler.com/articles/201701-event-driven.html
The danger is that it's very easy to make
nicely decoupled systems with event
notification, without realizing that you're
losing sight of that larger-scale flow, and
thus set yourself up for trouble in future
years.
https://martinfowler.com/articles/201701-event-driven.html
The danger is that it's very easy to make
nicely decoupled systems with event
notification, without realizing that you're
losing sight of that larger-scale flow, and
thus set yourself up for trouble in future
years.
https://martinfowler.com/articles/201701-event-driven.html
Classical example
Saga
book
hotel
book
car
book
flight
cancel
hotel
cancel
car
1. 2. 3.
5.6.
In case of failure
trigger compensations
book
trip
If your transaction involves 2 to 4 steps,
choreography might be a very good fit.
However, this approach can rapidly become confusing
if you keep adding extra steps in your transaction
as it is difficult to track which services listen to
which events. Moreover, it also might add a cyclic
dependency between services as they have to
subscribe to one another’s events.
Denis Rosa
Couchbase
https://blog.couchbase.com/saga-pattern-implement-business-transactions-using-microservices-part/
Microservice pioneers
have become aware
Implementing changes in the process
Hotel
Flight
Car
Trip
Trip
failed
Trip
requested
Hotel
booked
Car
booked
Request
trip
Flight
failed
Car
canceled
Hotel
canceled
We have a new basic agreement
with the car rental agency and
can cancel for free within 1 hour
– do that first!
Implementing changes in the process
Hotel
Flight
Car
Trip
Trip
failed
Trip
requested
Hotel
booked
Car
booked
Request
trip
Flight
failed
Car
canceled
Hotel
canceled
You have to adjust all services and redeploy at the same time!
We have a new basic agreement
with the car rental agency and
can cancel for free within 1 hour
– do that first!
Photo by born1945, available under Creative Commons BY 2.0 license.
What we wanted
Photo by Lijian Zhang, available under Creative Commons SA 2.0 License and Pedobear19 / CC BY-SA 4.0
Orchestration
Hotel
Flight
Car
Trip
Trip
booked
Request
trip
Book
hotel
Hotel
booked
Car
booked
Flight
booked
Book
car
Book
flight
Orchestration
Hotel
Flight
Car
Trip
Trip
booked
Request
trip
Book
hotel
Hotel
booked
Car
booked
Flight
booked
Book
car
Book
flight
We have a new basic agreement
with the car rental agency and
can cancel for free within 1 hour
– do that first!
You have to adjust one service and redeploy only this one!
Describe orchestration with BPMN
Trip
Trip
booked
Request
trip
The workflow is part of the service
Trip
The workflow is part of the service
Trip
Payment
The workflow is part of the service
Trip
Payment
Workflow engine itself can run
decentralized or centralized
Caitie McCaffrey | @caitie
Saga Execution Coordinator (SEC)
Hotel
Flight
Car
Trip
Trip
booked
Request
trip
SEC
Saga Execution Coordinator (SEC)
Hotel
Flight
Car
Trip
SEC Requirement:
Resilient and scalable
Owned by
executed by
Saga Execution Coordinator (SEC)
Hotel
Flight
Car
Trip
SEC Requirement:
SEC is resilient and scalable
„Can this really handle 15k
requests per second?“
Lost in transaction - Strategies to deal with (in)consistency in distributed systems
Lost in transaction - Strategies to deal with (in)consistency in distributed systems
Graphical models?
Clemens Vasters
Architect at Microsoft
http://vasters.com/archive/Sagas.html
Clemens Vasters
Architect at Microsoft
http://vasters.com/archive/Sagas.html
Clemens Vasters
Architect at Microsoft
http://vasters.com/archive/Sagas.html
BPMN
Business Process
Model and Notation
ISO Standard
Living documentation for long-running behaviour
Visual HTML reports for test cases
BizDevOps
Saga with AWS Step Functions
https://theburningmonk.com/2017/07/applying-the-
saga-pattern-with-aws-lambda-and-step-functions/
Visibility gets easy when you know where to look
Thoughts on the state machine | workflow engine market
Thoughts on the state machine | workflow engine market
OSS Workflow or
Orchestration Engines
Stack Vendors,
Pure Play BPMS
Low Code Platforms
Homegrown frameworks
to scratch an itch
Integration Frameworks
Cloud Offerings
Uber, Netflix, AirBnb, ING, … AWS Step Functions,
Azure Durable Functions, …
Camunda, Zeebe, jBPM,
Activiti, Mistral, …
PEGA, IBM, SAG, …
Apache Airflow,
Spring Data Flow, …
Apache Camel,
Balerina, …
Data
Pipelines
Does it support stateful operations?
Does it support the necessary flow logic?
Does it support BizDevOps?
Does it scale?
My personal pro-tip for a shortlist ;-)
OSS Workflow or
Orchestration Engines
Stack Vendors,
Pure Play BPMS
Low Code Platforms
Homegrown frameworks
to scratch an itch
Integration Frameworks
Cloud Offerings
Data
Pipelines
Camunda & Zeebe
Recap
• Grown ups don‘t use distributed transactions
but eventual consistency
• Idempotency is super important in distributed systems
• Some consistency challenges require state
• Know some strategies
• Stateful retry & cleanup
• Saga / Compensation
• Apologies
Thank you!
bernd.ruecker@camunda.com
@berndruecker
https://bernd-ruecker.com
https://blog.bernd-ruecker.com
https://github.com/flowing
https://www.infoq.com/articles/events-
workflow-automation
With thoughts from http://flowing.io
@berndruecker | @martinschimak
Contact:
Slides:
Blog:
Code:
https://www.infoworld.com/article/3254777/
application-development/
3-common-pitfalls-of-microservices-
integrationand-how-to-avoid-them.html
https://thenewstack.io/5-workflow-automation-
use-cases-you-might-not-have-considered/

More Related Content

PDF
Complex event flows in distributed systems
PPTX
Chaos engineering and chaos testing
PDF
Agile Capacity Management
PDF
AWS Cloud Center Excellence Quick Start Prescriptive Guidance
PDF
Guia de migración Azure
PDF
MicroCPH - Managing data consistency in a microservice architecture using Sagas
PDF
Cloud-migration-essentials.pdf
PDF
Architecture for Flow w/ Wardley Mapping, Domain-Driven Design, and Team Topo...
Complex event flows in distributed systems
Chaos engineering and chaos testing
Agile Capacity Management
AWS Cloud Center Excellence Quick Start Prescriptive Guidance
Guia de migración Azure
MicroCPH - Managing data consistency in a microservice architecture using Sagas
Cloud-migration-essentials.pdf
Architecture for Flow w/ Wardley Mapping, Domain-Driven Design, and Team Topo...

What's hot (20)

PPTX
MULTI-CLOUD ARCHITECTURE
PPTX
Architecture of Dynamics CRM with Office 365 and Azure
PDF
Best Practices for Streaming IoT Data with MQTT and Apache Kafka®
PDF
An Introduction to Chaos Engineering
PDF
Getting Started with Infrastructure as Code
PDF
AWS Control Tower
PPTX
Seminar On Scrum
PPTX
Hexagonal architecture with Spring Boot
PDF
F5_Active-Active Data Center.pdf
PDF
Scenarios_and_Architecture_SkillsMatter_April_2022.pdf
PDF
Design patterns for microservice architecture
PPTX
MicroServices on Azure
PDF
Model storming - a different approach to collaborative model discovery (Vilni...
PPTX
AWS Solution Architect - Associate Cohort.pptx
PDF
Agile & Scrum Training
PDF
AWS Lake Formation을 통한 손쉬운 데이터 레이크 구성 및 관리 - 윤석찬 :: AWS Unboxing 온라인 세미나
PDF
The Agile Adoption Roadmap (Keynote by Tim Abbott)
PPTX
Aws iam best practices to live by
PPTX
Azure Service Bus
PDF
User Story Slicing - easy way to split user stories
MULTI-CLOUD ARCHITECTURE
Architecture of Dynamics CRM with Office 365 and Azure
Best Practices for Streaming IoT Data with MQTT and Apache Kafka®
An Introduction to Chaos Engineering
Getting Started with Infrastructure as Code
AWS Control Tower
Seminar On Scrum
Hexagonal architecture with Spring Boot
F5_Active-Active Data Center.pdf
Scenarios_and_Architecture_SkillsMatter_April_2022.pdf
Design patterns for microservice architecture
MicroServices on Azure
Model storming - a different approach to collaborative model discovery (Vilni...
AWS Solution Architect - Associate Cohort.pptx
Agile & Scrum Training
AWS Lake Formation을 통한 손쉬운 데이터 레이크 구성 및 관리 - 윤석찬 :: AWS Unboxing 온라인 세미나
The Agile Adoption Roadmap (Keynote by Tim Abbott)
Aws iam best practices to live by
Azure Service Bus
User Story Slicing - easy way to split user stories
Ad

Similar to Lost in transaction - Strategies to deal with (in)consistency in distributed systems (20)

PDF
AWS Community Summit London 2019 - Lost in transaction
PDF
Bernd Rücker - Lost in transaction? Strategies to manage consistency in serve...
PDF
Serverless Days 2019 - Lost in transaction
PDF
Serverless London 2019 - Coordination of Serverless Functions
PDF
DDD Europe 2019: Lost in transaction
PDF
OSDC 2019 | The Benefits of Orchestration in Distributed Systems by Niall Deehan
PDF
Destination Automation: Automating Processes in Modern Hipster Architectures
PDF
Reactive Summit 2020 - How state helps you to stay reactive
PDF
Microservies Vienna - Lost in transactions
PDF
OOP 2021 - Leverage the full potential of your hipster architecture
PDF
2020 06-03 cukenfest-bdd-and-sl_os
PDF
Decision Making in Product Design
PDF
Incident Management in the Age of DevOps and SRE
PPTX
JavaOne 2015 Devops and the Darkside CON6447
PDF
Goto meetup Stockholm - Let your microservices flow
PDF
JAX 2017 talk: Orchestration of microservices
PDF
The Last Mile Continued: Incident Management
PDF
User Stories: Across the Seven Product Dimensions
PDF
Eventos y Microservicios - Santander TechTalk
PDF
Incident Management in the Age of DevOps and SRE
AWS Community Summit London 2019 - Lost in transaction
Bernd Rücker - Lost in transaction? Strategies to manage consistency in serve...
Serverless Days 2019 - Lost in transaction
Serverless London 2019 - Coordination of Serverless Functions
DDD Europe 2019: Lost in transaction
OSDC 2019 | The Benefits of Orchestration in Distributed Systems by Niall Deehan
Destination Automation: Automating Processes in Modern Hipster Architectures
Reactive Summit 2020 - How state helps you to stay reactive
Microservies Vienna - Lost in transactions
OOP 2021 - Leverage the full potential of your hipster architecture
2020 06-03 cukenfest-bdd-and-sl_os
Decision Making in Product Design
Incident Management in the Age of DevOps and SRE
JavaOne 2015 Devops and the Darkside CON6447
Goto meetup Stockholm - Let your microservices flow
JAX 2017 talk: Orchestration of microservices
The Last Mile Continued: Incident Management
User Stories: Across the Seven Product Dimensions
Eventos y Microservicios - Santander TechTalk
Incident Management in the Age of DevOps and SRE
Ad

More from Bernd Ruecker (20)

PDF
QCon London: Mastering long-running processes in modern architectures
PDF
WeAreDevelopers Live 2024 - Mastering long-running processes in modern archit...
PDF
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
PDF
JCon Live 2023 - Lice coding some integration problems
PDF
JFall - Process Oriented Integration
PDF
CamundaCon NYC 2023 Keynote - Shifting into overdrive with process orchestration
PDF
JavaLand 2023 - Process Oriented Integration
PDF
CraftConf: Surviving the hyperautomation low code bubbl
PDF
Mastering Data for Higher Business Impact - at Commerzbank Innovation Summit
PDF
Camunda Chapter Hamburg - Surviving the hyperautomation low code bubble
PDF
Loosely or lousily coupled - Understanding communication patterns in microser...
PDF
CamundaCon 2022 Keynote: The Process Orchestration Journey
PDF
JAX 2022 - Loosely or lousily coupled
PDF
JFS 2021 - The Process Automation Map
PDF
JCon 2021 - Loosely or lousily coupled
PDF
CamundaCon 2021 Keynote :From Human Workflow to High-Throughput Process Autom...
PDF
Kafka Summit 2021 - Apache Kafka meets workflow engines
PDF
Process Automation Forum April 2021 - Practical Process Automation
PDF
Micronaut Webinar 2021 - Process Automation Introduction
PDF
Webinar "Communication Between Loosely Coupled Microservices"
QCon London: Mastering long-running processes in modern architectures
WeAreDevelopers Live 2024 - Mastering long-running processes in modern archit...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
JCon Live 2023 - Lice coding some integration problems
JFall - Process Oriented Integration
CamundaCon NYC 2023 Keynote - Shifting into overdrive with process orchestration
JavaLand 2023 - Process Oriented Integration
CraftConf: Surviving the hyperautomation low code bubbl
Mastering Data for Higher Business Impact - at Commerzbank Innovation Summit
Camunda Chapter Hamburg - Surviving the hyperautomation low code bubble
Loosely or lousily coupled - Understanding communication patterns in microser...
CamundaCon 2022 Keynote: The Process Orchestration Journey
JAX 2022 - Loosely or lousily coupled
JFS 2021 - The Process Automation Map
JCon 2021 - Loosely or lousily coupled
CamundaCon 2021 Keynote :From Human Workflow to High-Throughput Process Autom...
Kafka Summit 2021 - Apache Kafka meets workflow engines
Process Automation Forum April 2021 - Practical Process Automation
Micronaut Webinar 2021 - Process Automation Introduction
Webinar "Communication Between Loosely Coupled Microservices"

Recently uploaded (20)

PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
A Presentation on Artificial Intelligence
PPT
Teaching material agriculture food technology
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Encapsulation theory and applications.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The Rise and Fall of 3GPP – Time for a Sabbatical?
Unlocking AI with Model Context Protocol (MCP)
Mobile App Security Testing_ A Comprehensive Guide.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
20250228 LYD VKU AI Blended-Learning.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
A Presentation on Artificial Intelligence
Teaching material agriculture food technology
Empathic Computing: Creating Shared Understanding
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation_ Review paper, used for researhc scholars
“AI and Expert System Decision Support & Business Intelligence Systems”
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Encapsulation theory and applications.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Electronic commerce courselecture one. Pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

Lost in transaction - Strategies to deal with (in)consistency in distributed systems