SAGA Orchestration — Overview

Anderson
2 min readDec 1, 2024

--

In monolithic or microservice architecture, event-driven architecture is a common way to decouple services/modules which means its could avoid broken OCP in large scale/complexity code-based application.

When we first committed a project include a create order API, we can implement it like,

function createOrder(creatingOrder) {
return OrderRepository.createOrder(creatingOrder);
}

One day, customer ask a new requirement to do daily stats. Maybe we will do it like: A Atomic Operation of creating order & doing daily stats.

async function createOrder(creatingOrder) {
const txn = new Transaction();

return await txn.commit(transaction => {
const order = await OrderRepository.createOrder(creatingOrder, { transaction });

await StatsRepository.incrementDailyStats(new Date(), { transaction });

return order;
}
}

Another day, customer ask a new requirement again, send a notification API to their advertisement vendor. We will do it like,

async function createOrder(creatingOrder) {
const txn = new Transaction();

const order await txn.commit(transaction => {
const order = await OrderRepository.createOrder(creatingOrder, { transaction });

await StatsRepository.incrementDailyStats(new Date(), { transaction });

return order;
}

await AdvertisementVendorSDK.sendOrder(order);

return order;
}

Notice, the development process always break OCP again and again. it make your application easily face accidents likes bugs or function broken. We need a good architecture like event-driven to avoid broken OCP.

Saga orchestration is a one of event-driven architectures. It is a way to coordinate sagas where a centralized controller tells the saga participants what local transactions to execute.

Outbox transaction pattern is used resolved the dual write operations issue that occurs in distributed systems when a single operation involves both a database write operation and a message or event notification.

We propose a robust saga orchestration by combine outbox transaction pattern, which show as below:

At next topic, we will introduce how to implement code details using MySQL8.

--

--

Anderson
Anderson

No responses yet