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.
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.
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:
- Spring Cloud Stream with Kafka binder to allow transparent connectivity with Kafka topics
- Apache Avro for data serialization and definition of compatile schemas for events and commands
- Confluent Schema Registry to version and store Avro schemas
- Redis for the state machine context persistence
- Azure Cosmos DB (MongoDB API) to persist all payloads used in transitions between nodes
- 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.
The lab is divided in the following steps: