Skip to main content

Choreography-Based Sagas: Ensuring Data Consistency in Distributed Systems

What is a Choreography-Based Saga?

A choreography-based saga helps maintain data consistency across microservices without a central coordinator. Instead, services communicate through events.

  • Each service completes its task and publishes an event.
  • Other services listen to these events and take necessary actions.
  • If a failure occurs, compensating transactions undo previous steps.

Implementing the Create Order Saga Using Choreography

Workflow: Happy Path

Here's how multiple services work together to process an order seamlessly:

  1. Order Service: Creates an order (APPROVAL_PENDING) and publishes an OrderCreated event.
  2. Consumer Service: Verifies the consumer and publishes a ConsumerVerified event.
  3. Kitchen Service: Creates a Ticket (CREATE_PENDING) and publishes a TicketCreated event.
  4. Accounting Service: Authorizes the payment and publishes a CreditCardAuthorized event.
  5. Kitchen Service: Moves the ticket to AWAITING_ACCEPTANCE.
  6. Order Service: Approves the order and publishes an OrderApproved event.






Key Considerations When Using Choreography-Based Sagas

Challenges & Design Issues

Benefits

  • No centralized coordinator needed.
  • Scalability through independent services.
  • Loose coupling between microservices.

Drawbacks

Final Thoughts

Choreography-based sagas are a great approach for managing distributed transactions, but they require careful planning to handle failures and dependencies.

Would you use choreography-based sagas in your system? Let us know in the comments! 

Comments

Popular posts from this blog

Hexagonal Architecture (Ports & Adapters Pattern)

Hexagonal Architecture , also known as the Ports and Adapters pattern, is a software design pattern that aims to create a decoupled and maintainable application by separating the core business logic from external concerns (like databases, APIs, and UIs). Structure of Hexagonal Architecture A typical Hexagonal Architecture has three main layers: 1️⃣ Core Domain (Application Logic) This contains the business rules and domain models. It is completely independent of external technologies . Example: If you’re building a banking system , this part would include logic for transactions, withdrawals, and deposits . 2️⃣ Ports (Interfaces) These are interfaces that define how the core interacts with external components. Two types of ports: Inbound Ports (driven by external inputs like APIs, UI, or events) Outbound Ports (used to interact with external services like databases, messaging systems, etc.) 3️⃣ Adapters (Implementation of Ports) These are concrete implementations of the ports, re...

"Action-Oriented, Stakeholder-Focused" MoM Structure

  I. Meeting Header: Meeting Title:  Clear and concise (e.g., "Project X Status Update," "Q3 Planning Meeting"). Date and Time:  Record the date and time the meeting took place. Location/Platform:  Indicate where the meeting was held (e.g., Conference Room A, Zoom). Attendees:  List the names and roles of everyone who attended. Absent:  List the names of key individuals who were invited but did not attend. Meeting Owner : Who was in charge of the meeting ? Document owner : Who is in charge of the documentation ? II. Key Discussion Points (Concise Summary): Purpose:  Briefly summarize the main topics discussed. Format:  Use bullet points for brevity. Content: Decision Points:  Clearly state any decisions that were made. Key Information:  Summarize any crucial information shared. Key Questions : Summarize the key questions that were raised. Open Issues:  Note any issues that remain unresolved. Stakeholder Focus:  Frame the summar...

Frameworks

  I. Frameworks for All Roles (Tech Lead, VP, Individual Contributor): Communication Frameworks: BLUF (Bottom Line Up Front):  For concise and effective communication, especially in emails and reports. SCQA (Situation, Complication, Question, Answer):  For structuring business communications and presentations to present a clear narrative. PAS (Problem, Agitation, Solution):  For a persuasive message. BAB (Before, After, Bridge):  For a persuasive message with a focus on the future. Sparkline:  For persuasive presentation with a focus on change. STAR (Situation, Task, Action, Result):  For structuring behavioral stories, particularly in interviews or performance reviews. Problem-Solving/Decision-Making Frameworks: 5 Whys:  For root cause analysis. Systems Thinking:  For understanding complex systems. The Four Questions:  For a post mortem. Human Factors : For a blame less post mortem. Time Management/Prioritization Frameworks: Eisenhower ...