How hodfords-minhngo-be/temporal-saga works
Main Components
• Order Microservice: This service handles order-specific logic, including endpoints (controllers), service layers, and data persistence (using PostgreSQL, as seen in the configurations and migrations).
• Order Saga Orchestrator: This service manages the distributed transaction workflows using Temporal. It is responsible for coordinating multiple steps (or activities) such as order creation, payment, and shipment, and for executing compensation actions if one of the steps fails.
• Temporal Server: Not part of the business logic per se but a core infrastructure element that runs via Docker Compose. It’s essential for the orchestration of workflows.
• External Dependencies: Redis and PostgreSQL, started via Docker Compose. They provide caching/session management and persistence, respectively.
• Docker and Deployment Scripts: The docker-compose files (for Temporal and services) indicate containerization and deployment environment.
Relationships and Interactions
• The Order Saga Orchestrator initiates workflows that orchestrate transactions by calling activities within the microservices like the Order Microservice.
• Communication could be via HTTP or messaging (likely using microservices communication patterns supported by NestJS) between the orchestrator and the order service.
• Both microservices use similar configuration patterns (notably NestJS is in play with controllers, modules, and service layers) and share design elements such as entities, guards, and helpers.
• Databases are accessed by both services – configuration files in both microservice directories indicate database settings, particularly the use of migrations in the Order Microservice.
• Redis and Temporal are infrastructure elements that form part of the orchestration and caching mechanisms.
Key Architectural Patterns and Design Principles
• The Saga Pattern for distributed transactions: Emphasize that each business transaction (workflow) is broken into local transactions with compensation capabilities.
• Microservices Architecture: Clearly separate the Order Microservice from the Order Saga Orchestrator as distinct bounded contexts.
• Containerization and Deployment: Show Docker containers (or orchestration framework) that house the Temporal Server, Redis, and PostgreSQL, as well as the service microservices.
• Use of NestJS: Although not required to show every line of code, note that the project structure’s modules (controllers, services, providers) suggest an MVC-like pattern as used by NestJS.