Wednesday, October 15, 2025

Oracle Saga Framework

Do you know about Oracle Saga Framework ? #JoelKallmanDay


Saga oracle refers to the Oracle database framework for implementing the Saga pattern, which manages data integrity across distributed microservices by breaking long-running business transactions into a sequence of local transactions. If a step fails, it uses compensating transactions to automatically roll back the changes in the preceding steps. 


This eliminates the need for traditional distributed locks and is integrated into the Oracle database with features like PL/SQL packages, Advanced Queuing (AQ) integration, and lock-free reservations.  


Key features 

  • Database-centric approach: The framework is built directly into the Oracle database, making it a natural fit for data-driven microservices. 
  • Compensation-aware: It automatically handles rollbacks when a saga fails by executing compensating transactions for the services that have already completed. 
  • Leverages database features: It utilizes Oracle's Advanced Queuing (AQ) for messaging and offers lock-free reservations for improved transactional concurrency, which automatically invokes compensating transactions on rollback. 
  • Integration: It integrates with other Oracle technologies like transaction event queues and provides specialized annotations for Java applications, aligning with standards like Eclipse MicroProfile
  • Administrative and client interfaces: It provides interfaces for administrators to manage sagas and for applications to initiate, participate in, and complete them. 

How it works 

Each step in a saga is a local transaction within a single microservice. The framework coordinates these local transactions, ensuring that they either all succeed or are undone in reverse order if any one of them fails. For example, in a travel booking saga: 


  1. Step 1: A local transaction in the "flight" service books a flight and publishes an event to the next service. 
  2. Step 2: The "hotel" service receives the event, books a hotel via its own local transaction, and publishes an event to the next service. 
  3. Step 3: If a "car" service fails to book a car, the framework will trigger a compensating transaction in the "hotel" service to cancel the hotel reservation, and then a compensating transaction in the "flight" service to cancel the flight reservation. 

Developing Applications with Sagas

This chapter covers Saga APIs that allow applications that are built using microservices principles to incorporate efficient transactions across microservices. 

Saga APIs are implemented while closely following the Long Running Action (LRA) specification from Eclipse MicroProfile.


Implementing Sagas with Oracle Database

You can use Oracle Database as a platform to build your Saga-based, on-cloud or on-premises applications. When you implement Sagas with Oracle Database for handling distributed transactions, you can leverage the robust underlying infrastructure built into Oracle Database. 


The Saga infrastructure maintains the global application state for microservices, facilitating development and throughput.

The following are some key benefits of using Oracle Database for Saga implementation:


  • The Saga implementation is integrated in the database to make Sagas simpler to code, deploy, and maintain.
  • Simplified Saga annotations following the Eclipse LRA standard make it easy to enable transactions across microservices using Oracle Database.
  • Data consistency is achievable across microservices.
  • Auto-compensating logic based on lock-free, reservable columns is provided in the database to handle rollbacks on Saga rollback.
  • Advanced Queuing (AQ) and Oracle Transactional Event Queues (TxEventQ) messaging platforms are built into Oracle Database, enabling microservices to produce and consume messages and events as part of database transactions.
  • Support is provided for different languages, including PL/SQL and Java applications.
  • The Saga framework recommends a JSON type for representing the application payload.
  • There is improved availability and scalability for applications that require transactions across microservices. Such transactions are common with monolith applications that are converting to microservices, where transactions may span multiple bounded contexts. Note that a bounded context is an explicit boundary within which a business domain model exists.


Oracle Saga Framework Overview

The Oracle Saga framework provides the foundation to implement and administer Sagas for microservices applications built using Oracle Database. 

The framework provides administrative and client interfaces. Administrative interfaces enable Saga applications to configure and manage Saga participants and message brokers. 


Client interfaces enable applications to initiate, participate, and finalize Sagas. 

Saga participants are automatically configured with message channels and message propagation. 

The Saga framework is compensation-aware and provides for automatic rollback of the affected data when a Saga is rolled back. 

The Saga framework includes PL/SQL packages, dictionary tables, and Advanced Queuing (AQ) integration that facilitate Sagas in the database.

The Oracle Saga framework leverages two important features of Oracle Database. 

There is a transaction layer with reservable column support that enables recording of appropriate meta-information when reservable columns are updated.

The reservable column support invokes compensating transactions automatically to revert the state of the reservable column updates when a Saga is rolled back. 

Reservable columns are a part of the lock-free reservation feature that Oracle provides to improve transactional concurrency.

Another important layer integrated into the database is the event queues built on the Oracle Advanced Queuing (AQ) technology. 


AQ provides the asynchronous messaging platform that connects various microservice participants. The Saga framework deploys a hub-and-spoke topology to connect Saga initiators, coordinators, and participants. The Saga message broker acts as the hub in this topology.


Saga Framework Features

The Saga framework provides the following features for implementing Sagas on Oracle Database:

  • PL/SQL administrative interfaces to add and manage active Sagas and Saga participants
  • PL/SQL and Java interfaces for applications to interact with the Saga framework, and participate and finalize (commit or rollback) database Sagas
  • Asynchronous message communication across multiple participants that contribute to a Saga, facilitated by microservice-specific AQ message propagation infrastructure from Oracle
  • Reservable column-based Saga finalization (compensation and completion) support to enable recording of reservable column updates, and auto-compensation of transactions to roll back changes for canceled Sagas
  • User-defined Saga finalization (compensation and completion) support to enable users to explicitly define and automatically execute Saga finalization
  • Strong messaging semantics to ensure that interservice messages are delivered exactly once and never lost or duplicated
  • Saga ID support to bind individual transactions to the Saga ID
  • A globally unique name for each participant in a Saga
  • Automatic configuration of message channels and message propagation for Saga participants that are provisioned into the system
  • Various dictionary tables to maintain the status of Sagas
  • System-defined views to report on Sagas and Saga participants in the system
  • Eclipse Microprofile LRA specification emulation


Saga Framework Concepts


Saga Participant and Initiator

A Saga participant represents a spoke (participant microservice) in the Saga topology that either initiates and orchestrates a Saga or enrolls to participate in one. A participant is associated with a message broker (that is local or remote) and optionally with a local Saga coordinator. Saga participants that initiate Sagas are described in this document as "initiators" and non-initiator participants are described as "participants". Saga initiators must be associated with a Saga coordinator. In the initial version, the Saga framework only supports a local Saga coordinator (from the same PDB) for an initiator. Meanwhile, a Saga participant need not be associated with a coordinator and can be remote to the initiator.

Any participant can initiate a Saga. A Saga initiator is a microservice that initiates a Saga and enrolls other microservice participants by sending asynchronous messages.

In the travel agency example that follows, the participant microservices are the flight service, hotel service, and car service. A participant microservice executes one or more participant transactions on behalf of a Saga. Compensation action for a participant transaction is maintained in the local PDB. Participants are responsible for maintaining the local state of their Sagas.


Transaction Coordinator

A transaction coordinator acts as a transaction manager in the Saga topology. The Saga coordinator maintains the Saga state on behalf of the Saga initiator.

A Saga topology can have several Saga coordinators. In the initial release of the Saga framework, a Saga participant can only associate with coordinators who are local (same PDB and schema) to the participants. A coordinator can, however, associate with a local or remote message broker.


Message Broker

A message broker acts as an intermediary and represents the hub in the Saga topology. A broker provides a message delivery service for the message propagation between two or more Saga participants and their coordinator. Each Saga participant or coordinator is associated with a single broker, who can be local or remote. A broker does not maintain any Saga state.


Hope this topic helps you.

No comments:

Post a Comment

Oracle Saga Framework

Do you know about Oracle Saga Framework ?  #JoelKallmanDay Saga   oracle  refers to the Oracle database framework for implementing the Saga ...