How sacurio/microservices-order-system works
Project Type and Purpose
• The README clearly states that this is an “Order System” using microservices. It includes services for Users, Products, Orders, and Payments, along with an API Gateway.
• The project purpose is to simulate an e-commerce scenario through a microservices architecture that demonstrates various architectural patterns (e.g., API Gateway, CQRS, Event Sourcing, Circuit Breaker, Saga Pattern) and asynchronous communication (using RabbitMQ).
File Structure
• The top-level “src” directory contains separate folders for each microservice:
• ApiGateway: Acts as a single entry point for external requests. It uses Ocelot (as seen with the ocelot.json file) to route calls.
• OrderService: Manages order creation, status management, and publishes events (notably the “OrderCreated” event).
• PaymentService: Processes and validates payments. It subscribes to events like “OrderCreated” via a consumer.
• ProductService: Handles product listings, stock, and availability.
• UserService: Manages user registration, login, profiles, and authentication.
• There is also a “Contracts” directory meant for shared domain models or event definitions (Order, OrderCreated, etc.), which is typical in microservices to ensure consistency in event contracts.
• Several Dockerfiles and configuration files indicate containerization and a deployment-ready structure. Files like docker-compose.yml hint at local multi-container orchestration.
README for Additional Insights
• The README outlines the technical requirements, including the use of REST/gRPC and event-driven communication (RabbitMQ).
• It emphasizes employing API Gateway patterns, service discovery, CQRS, event sourcing, circuit breakers (Polly), and the Saga pattern.
• It includes the intended database (PostgreSQL) and authentication using IdentityServer with JWT.
a. Main Components:
• API Gateway: Front door for incoming requests, using Ocelot.
• Microservices: User Service, Product Service, Order Service, Payment Service.
• Shared Contracts: A common library for event definitions.
• Message Broker: RabbitMQ for asynchronous event communication.
• Database: PostgreSQL for persistent storage (likely each microservice might have its own data store).
• External Authentication: IdentityServer (JWT) for handling authentication across services.
• Infrastructure/Monitoring: Container orchestration with Kubernetes, monitoring with Prometheus and Grafana.
b. Their Relationships and Interactions:
• External clients send requests which hit the API Gateway.
• The API Gateway routes synchronous API calls to the appropriate microservice(s).
• Order Service triggers asynchronous events (e.g., OrderCreated) which are published to RabbitMQ.
• PaymentService (and potentially other services such as an InventoryService if extended) subscribe to those events.
• Each microservice interacts with PostgreSQL for data storage.
• Authentication flows route via IdentityServer and are enforced at the API Gateway and individual service levels.
• The services might also rely on patterns like CQRS for separating read and write operations, and the Saga pattern for distributed transactions.
c. Architectural Patterns and Design Principles:
• Microservices architecture, with each service independent and containerized.
• API Gateway pattern for unified access.
• Event-driven architecture using RabbitMQ.
• Resilience patterns like the Circuit Breaker (Polly) for fault tolerance.
• Distributed transaction management via the Saga pattern.
• Use of shared contracts to maintain consistency for event messaging.
d. Relevant Technologies:
• .NET 8 (for microservice development).
• Docker (for containerization) and Kubernetes (for orchestration).
• Ocelot API Gateway.
• IdentityServer with JWT.
• PostgreSQL as the database.
• RabbitMQ for messaging.
• Monitoring tools (Prometheus, Grafana) for observability.
• Additional middleware components like Polly for circuit breaking.
Specific Elements
• Clear labels: Each microservice (User, Product, Order, Payment, API Gateway), shared Contracts, RabbitMQ, PostgreSQL, IdentityServer.