SlideShare a Scribd company logo
SAGAS OF ELIXIR
ABOUT ME
▸ Elixir dev for 2+ years
▸ Worked on NHS of Ukraine and few other large
projects
▸ Maintain 20+ public Elixir repos used in
production
▸ Contribute back as much as I can
WE ARE GOING TO TALK ABOUT
▸ Why do we need distributed transactions?
▸ Sagas pattern
▸ Sage Elixir library
▸ Structuring your domain contexts (bonus)
IMAGINE WE ARE BUILDING A SIMPLE BOOKING WEBSITE
Invariants:
- We should not charge card if request was not fulfilled
- We should not hold booking if charge is failed
Sagas os Elixir
WITH COMPILES TO NESTED CASES
HANDLING FAILURES
Sagas os Elixir
LET'S MAKE IT HARDER
OOPS, FAILED TO BOOK A FLIGHT
Sagas os Elixir
WHAT IS WRONG?
▸ Bad for latency - can't book concurrently
▸ The syntax to track step on which failure occurred is ugly
▸ To test it you need a complex failure injection for API client stubs
▸ Easy to miss some errors - monster else clause
Sagas os Elixir
CAN WE DO BETTER?
▸ Refactor
▸ 2PC
▸ Sagas
SAGAS PATTERN
Failure management pattern that originates from 1987’s paper on long running
transactions for databases.
A long lived transaction is a Saga if it can be written as a sequence of transactions
that can be interleaved with other transactions.
The database management system guarantees that either all the transactions in a
Saga are successfully completed or compensating transactions are run to amend a
partial execution.
HOW DOES IT WORK?
▸ Transaction is split into a multiple atomic steps
▸ Each step consist from transaction and compensation
▸ When transaction fails compensation are run to
semantically amend it's effects
▸ Compensation and transactions should be idempotent
BOOKING SITE WITH SAGAS
AWESOME!
ANYTHING FOR ELIXIR?
SAGE
Sage is a dependency-free pure Elixir library inspired by Sagas pattern.
Provides set of additional features on top of steps, transactions and
compensations defined by the original paper.
It's like Ecto.Multi but across business
logic and third-party APIs.
— @jayjun from #elixir-lang Slack channel
BOOKING EXAMPLE WITH SAGE
ASYNCHRONOUS TRANSACTIONS
RETRIES
Sagas os Elixir
CIRCUIT BREAKERS
Sagas os Elixir
AND MORE
▸ Final callback
▸ Tracing
▸ Works with Ecto
ERROR HANDLING
▸ Sage transaction abort
▸ Compensation failure
▸ Bugs in Sage
THINGS TO COME
▸ Saga execution log
▸ Plug-style module callbacks
▸ Compile-time type checking
AND IT MAKES YOUR DOMAIN
CONTEXTS BETTER
Sagas os Elixir
RECAP
Use Sage to:
▸ Synchronize state across microservices
▸ Synchronize state across databases
▸ To run distributed transactions
Sage can help to elegantly organize logic in your domain contexts.
Still young but well-documented and covered with tests.
THANK YOU! QUESTIONS?
github.com/nebo15/sage
GitHub: AndrewDryga
Twitter: andrew_dryga
Elixir-Lang Slack: AndrewDryga
Email: andrew@dryga.com

More Related Content

PDF
A Microservices Journey - Susanne Kaiser
PPTX
EXPERTALKS: Jul 2012 - Build using Gradle
PPTX
Henry been - Multi-tenant applications using 30k databases
PDF
Azure Management Basics
PPTX
MongoDB .local London 2019: New Product Announcements: MongoDB Atlas Autoscal...
PPTX
Amazon EKS: the good, the bad, and the ugly
PDF
Choosing the right messaging service for your serverless app [with lumigo]
PDF
CICD in the World of Serverless
A Microservices Journey - Susanne Kaiser
EXPERTALKS: Jul 2012 - Build using Gradle
Henry been - Multi-tenant applications using 30k databases
Azure Management Basics
MongoDB .local London 2019: New Product Announcements: MongoDB Atlas Autoscal...
Amazon EKS: the good, the bad, and the ugly
Choosing the right messaging service for your serverless app [with lumigo]
CICD in the World of Serverless

What's hot (6)

PPTX
Building Real time Application with Azure SignalR Service
PDF
Security Webinar: Harden the Heart of Your WordPress SiteSe
PDF
Rob Gruhl and Erik Erikson - What We Learned in 18 Serverless Months at Nords...
PDF
Donald Ferguson - Old Programmers Can Learn New Tricks
PDF
The Journey from Monolith to Microservices: a Guided Adventure
PDF
OpenFaaS
Building Real time Application with Azure SignalR Service
Security Webinar: Harden the Heart of Your WordPress SiteSe
Rob Gruhl and Erik Erikson - What We Learned in 18 Serverless Months at Nords...
Donald Ferguson - Old Programmers Can Learn New Tricks
The Journey from Monolith to Microservices: a Guided Adventure
OpenFaaS
Ad

Similar to Sagas os Elixir (20)

PPTX
Microservices Coordination using Saga
PDF
Stockholm Serverless Meetup - Serverless Challenges
PPTX
CAP: Scaling, HA
PDF
Error Handling with Kafka: From Patterns to Code
PDF
CQRS_EventSourcing Architecture Overview.pptx.pdf
PDF
How Adobe uses Structured Streaming at Scale
PDF
On The Building Of A PostgreSQL Cluster
PPTX
Building Cloud Ready Apps
PDF
Healthcare Claim Reimbursement using Apache Spark
PDF
Best Practices with Apex in 2022.pdf
PDF
Document-Driven transactions
PDF
Effective Akka v2
PPTX
Synchronicity of a distributed account system
PDF
Modifying Your AWS Reserved Instances
PDF
Building Asynchronous Applications
PDF
Scalable complex event processing on samza @UBER
PPT
Taking Full Advantage of Galera Multi Master Cluster
PDF
Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017
PDF
JEEconf 2017
PDF
An Introduction To Space Based Architecture
Microservices Coordination using Saga
Stockholm Serverless Meetup - Serverless Challenges
CAP: Scaling, HA
Error Handling with Kafka: From Patterns to Code
CQRS_EventSourcing Architecture Overview.pptx.pdf
How Adobe uses Structured Streaming at Scale
On The Building Of A PostgreSQL Cluster
Building Cloud Ready Apps
Healthcare Claim Reimbursement using Apache Spark
Best Practices with Apex in 2022.pdf
Document-Driven transactions
Effective Akka v2
Synchronicity of a distributed account system
Modifying Your AWS Reserved Instances
Building Asynchronous Applications
Scalable complex event processing on samza @UBER
Taking Full Advantage of Galera Multi Master Cluster
Automated scaling of microservice stacks for JavaEE applications - JEEConf 2017
JEEconf 2017
An Introduction To Space Based Architecture
Ad

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Machine Learning_overview_presentation.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
A Presentation on Artificial Intelligence
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Encapsulation theory and applications.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Machine Learning_overview_presentation.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Machine learning based COVID-19 study performance prediction
NewMind AI Weekly Chronicles - August'25-Week II
The Rise and Fall of 3GPP – Time for a Sabbatical?
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Assigned Numbers - 2025 - Bluetooth® Document
Reach Out and Touch Someone: Haptics and Empathic Computing
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
A Presentation on Artificial Intelligence
MIND Revenue Release Quarter 2 2025 Press Release
Encapsulation_ Review paper, used for researhc scholars
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Programs and apps: productivity, graphics, security and other tools
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Encapsulation theory and applications.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”

Sagas os Elixir

  • 2. ABOUT ME ▸ Elixir dev for 2+ years ▸ Worked on NHS of Ukraine and few other large projects ▸ Maintain 20+ public Elixir repos used in production ▸ Contribute back as much as I can
  • 3. WE ARE GOING TO TALK ABOUT ▸ Why do we need distributed transactions? ▸ Sagas pattern ▸ Sage Elixir library ▸ Structuring your domain contexts (bonus)
  • 4. IMAGINE WE ARE BUILDING A SIMPLE BOOKING WEBSITE Invariants: - We should not charge card if request was not fulfilled - We should not hold booking if charge is failed
  • 6. WITH COMPILES TO NESTED CASES
  • 9. LET'S MAKE IT HARDER
  • 10. OOPS, FAILED TO BOOK A FLIGHT
  • 12. WHAT IS WRONG? ▸ Bad for latency - can't book concurrently ▸ The syntax to track step on which failure occurred is ugly ▸ To test it you need a complex failure injection for API client stubs ▸ Easy to miss some errors - monster else clause
  • 14. CAN WE DO BETTER? ▸ Refactor ▸ 2PC ▸ Sagas
  • 15. SAGAS PATTERN Failure management pattern that originates from 1987’s paper on long running transactions for databases. A long lived transaction is a Saga if it can be written as a sequence of transactions that can be interleaved with other transactions. The database management system guarantees that either all the transactions in a Saga are successfully completed or compensating transactions are run to amend a partial execution.
  • 16. HOW DOES IT WORK? ▸ Transaction is split into a multiple atomic steps ▸ Each step consist from transaction and compensation ▸ When transaction fails compensation are run to semantically amend it's effects ▸ Compensation and transactions should be idempotent
  • 19. SAGE Sage is a dependency-free pure Elixir library inspired by Sagas pattern. Provides set of additional features on top of steps, transactions and compensations defined by the original paper.
  • 20. It's like Ecto.Multi but across business logic and third-party APIs. — @jayjun from #elixir-lang Slack channel
  • 27. AND MORE ▸ Final callback ▸ Tracing ▸ Works with Ecto
  • 28. ERROR HANDLING ▸ Sage transaction abort ▸ Compensation failure ▸ Bugs in Sage
  • 29. THINGS TO COME ▸ Saga execution log ▸ Plug-style module callbacks ▸ Compile-time type checking
  • 30. AND IT MAKES YOUR DOMAIN CONTEXTS BETTER
  • 32. RECAP Use Sage to: ▸ Synchronize state across microservices ▸ Synchronize state across databases ▸ To run distributed transactions Sage can help to elegantly organize logic in your domain contexts. Still young but well-documented and covered with tests.
  • 33. THANK YOU! QUESTIONS? github.com/nebo15/sage GitHub: AndrewDryga Twitter: andrew_dryga Elixir-Lang Slack: AndrewDryga Email: andrew@dryga.com