Microservices : The SAGA Pattern for distributed transactions

Example for 2PC — Create Customer Order
  • There is no mechanism to rollback the other transaction if one micro service goes unavailable in commit phase.
  • Others have to wait until the slowest resource finish its confirmation.
  • Choreography : each local transaction publishes domain events that trigger local transactions in other services.
  • Orchestration : an orchestrator (object) tells the participants what local transactions to execute.
Example of Orchestration-based saga for customer order creation
  1. Order Service saves a pending order and asks Saga Execution Coordinator (SEC) to start a create order transaction.
  2. SEC sends an Execute Payment command to Payment Service, and it replies with a Payment Executed message.
  3. SEC sends a Prepare Order command to Stock Service, and it replies with an Order Prepared message.
  4. SEC sends a Deliver Order command to Delivery Service, and it replies with an Order Delivered message.
  • Avoid cyclic dependencies between services. Do not let the participants to call SEC.
  • Always create a Unique ID per transaction and make it flow through every local transactions which is easier for traceability and troubleshooting.
  • Avoid Synchronous Operations.
  • Log the request payloads for re-submission purpose.
  • Make sure you capture all data required before handing over the process to SEC.




Technology evangelist

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Pandora Protocol AMA Summary Recap with Shin Chan Community

MetaDojo’s Q1 Update + Introducing Our Virtual HQ with a Treasure Hunt!

Agile Methodologies: Scrum and Kanban

Sales dashboard in odoo Dynamic odoo sales dashboard with modern UI and responsive sales dashboard…

odoo sales dashboard module, Odoo Sales Dashboard, Sales Dashboard in Odoo, Modern Odoo Sales Dashboard Module, Responsive sales odoo dashboard

How Java Development Will Be Beneficial For Your Business In 2020?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Isuru Jayakantha

Isuru Jayakantha

Technology evangelist

More from Medium


Distributed systems in production

Building Resilient Microservices — A Guide for TPMs

Microservices, Facades, and everything in between