saga-coordinator-java icon indicating copy to clipboard operation
saga-coordinator-java copied to clipboard

Saga Coordinator sample for long-lived transactions using Kafka as the event stream.

Saga Coordinator as a Finite State Machine (FSM) in Java

Background

Coordination is a Saga approach where the coordination logic of business processes (e.g. financial transactions) is centralized in a Saga Coordinator, also known as Reactive Orchestrator. It uses the concept of commands and events, where commands are tasks that need to be done and events are tasks that have been done.

The Saga Coordinator produces commands to an event stream and the respective saga participants consume these commands. These participants produce their events after performing their operations and the coordinator consume these Event.

Saga Coordinator

The Saga Coordinator can be implemented as a Finite State Machine (FSM), where it produces commands and waits for events produced by the participants to drive the flow. Events are represented as nodes, while commands are represented as transitions between nodes.

About the sample

The sample contains an FSM Saga Coordinator using Spring Statemachine as the foundation and Confluent Kafka as the distributed streaming platform. The state machine is built with:

Prerequisites

  • Java JDK 8 or later
  • Maven 3.0 or later
  • Confluent Kafka + Zookeper + Schema Registry services running. If you want to run locally as Docker containers, follow the instructions here.
  • Redis instance running. If you want to run locally as Docker container, follow the instructions here.
  • MongoDB instance running. If you want to run locally as Docker container, follow the instructions here.

Getting Started

The lab is divided in the following steps:

  • Step 1: Understanding the workflow
  • Step 2: Configuring Application Properties
  • Step 3: Build and run as Docker container (WIP)