The way to Saga pattern part 2

The way to Saga pattern part 2

The Saga design pattern is a way to manage data consistency across microservices in distributed transaction scenarios.

A Saga is a sequence of local transactions.

Each local transaction updates the local database using the familiar ACID transaction frameworks and publishes an event to trigger the next local transaction in the Saga.

local transactions flow

?Compensable transactions

If a local transaction fails, then the Saga executes a series of compensating transactions that undo the changes, which were completed by the preceding local?

The SAGA pattern uses a compensating transaction mechanism to handle errors that may occur during the execution of the saga. If an error occurs during one of the local transactions, the compensating transaction is executed to undo the changes made by the previous local transactions. This ensures that the system is left in a consistent state even if a transaction fails.


Consumer point of view

if the user submit a purchase order through the Saga workflow, it might take a moment to see the order finalized. This is because our system uses eventual consistency, meaning each involved service (like inventory and payment) updates independently. The Saga ensures everything goes smoothly in the background, but there might be a short delay before your order reflects the final processed state.

Communication

the communication between the participating services may happen either synchronously, via HTTP or gRPC, or asynchronously, via message brokers or distributed logs such as Apache Kafka.

For the sake of decoupling, communication between microservices should preferably happen asynchronously.



要查看或添加评论,请登录

Mahmoud Reda的更多文章

  • How to Configure Applications in Pods

    How to Configure Applications in Pods

    Introduction we want to decouple our application configuration from the container image itself as you know you can pass…

  • Building Efficient Persistence Layers with Spring Data JPA

    Building Efficient Persistence Layers with Spring Data JPA

    This article discusses performance optimization techniques for persistence layers built with Spring Data JPA and…

  • The way to Saga pattern part 1

    The way to Saga pattern part 1

    Transaction introduction A transaction is a single unit of logic or work, sometimes made up of multiple operations…

  • Spring Security Architecture Big Picture Part1

    Spring Security Architecture Big Picture Part1

    What Is Spring Security? Spring Security is a framework written on top of the Spring framework that will provide you…

    2 条评论
  • ???? ?? ??? Transaction.

    ???? ?? ??? Transaction.

    ??? Transaction ?? ????? ?? Query ?? ???? ??? ??????? ?????? ??? DBMS, ??? Transaction ?? ??? basic unit ??????? ???…

  • Go - Overview

    Go - Overview

    Go is a modern, generic-purpose, open-source programming language that was officially announced at the end of 2009. Go…

  • MediatRWithApi

    MediatRWithApi

    This article presents a discussion of how we can use MediatR in ASP.Net Core applications.

  • Mediator Pattern

    Mediator Pattern

    Before explaining Mediator, let's see these cases Case1: if object A wants to send a message to object B!! maybe the…

社区洞察

其他会员也浏览了