Saga Entities

The Saga Entities module is part of the Macha Core Entities suite and provides base classes and utilities for implementing the Outbox Transactional Saga Pattern. It supports distributed transaction management in microservice architectures by defining core entities such as SagaId and SagaIdentifiedObject. These entities serve as foundational components for creating and managing sagas across the core.

Introduction

The Saga Entities module defines base entities required to coordinate and persist saga-related interactions consistently while adhering to Clean Architecture principles. This module encapsulates the core business rules and identification logic needed to support sagas in distributed systems.

Key Features:

  1. Saga Identification:
    • Offers SagaId, a universal identifier for sagas, and SagaIdentifiedObject, which combines universal identification with saga-specific context.
  2. Outbox Pattern Support:
    • Designed for seamless integration with the Outbox Transactional Saga Pattern, ensuring reliable and consistent event-driven transaction workflows.
  3. Reusability:
    • Provides reusable entity definitions for core-wide saga requirements across various modules and projects.
  4. Modular Design:
    • Ensures a separation of concerns while maintaining flexibility for extension in client-specific implementations.

Components

The Saga Entities module comprises the following core components:

  1. SagaId:

    • A dedicated interface that defines a consistent structure for identifying sagas across various services and transactions.
    • Acts as the cornerstone for saga-related identification.
  2. SagaIdentifiedObject:

    • Extends EntityId and implements SagaId.
    • Represents entities that are part of a specific saga, carrying both a universal identifier (UUID) and saga-specific metadata.

Use Case: Outbox Transactional Saga Pattern

The Saga Entities module is specifically designed to support the Outbox Transactional Saga Pattern, which ensures reliable message delivery and distributed consistency in microservices. By leveraging the entities defined in this module, developers can:

  • Coordinate multi-step business processes across independent microservices.
  • Maintain transaction logs and sagas with well-defined entity identifiers.
  • Implement a consistent approach to saga-related events and operations.

Alignment with Clean Architecture

The Saga Entities module adheres to Clean Architecture principles by:

  1. Encapsulating Business Logic:
    • The module defines core business rules for saga identification without introducing dependencies on infrastructure or external systems.
  2. Supporting Domain-Driven Design:
    • Provides entities that align with the domain layer, facilitating reusability and scalability.
  3. Independence and Modularity:
    • The module is self-contained and extensible, enabling flexible adoption in diverse systems.

Dependency Graph

Dependency Graph

Class Diagram

Class Diagram