Microservices & Event-Driven Architecture (EDA) Mastery

The Saga Pattern: Orchestration vs Choreography

1 Views Updated 5/4/2026

Transactions in Microservices

Since we can't use SQL transactions across services, we use the Saga Pattern. A Saga is a sequence of local transactions where each step has a "Compensating Action" to undo the work if a later step fails.

1. Choreography (Event-Based)

Each service does its work and publishes an event. The next service listens and does its work. - **Pros:** No central point of failure, very decoupled. - **Cons:** Hard to keep track of the 'State' of the whole process. Best for simple, linear workflows.

2. Orchestration (Centralized)

One service (The Orchestrator) acts as the 'Director'. It tells Service A to work, waits for the result, then tells Service B. - **Pros:** Easy to see exactly where an order is stuck. - **Cons:** The Orchestrator can become a 'Fat Service' that contains too much business logic. **Architect Tip:** Use **MassTransit State Machines** to implement Orchestration. It provides a visual, testable way to manage complex multi-service workflows.

4. Interview Mastery

Q: "What is a 'Compensating Transaction'?"

Architect Answer: "It is an 'Undo' operation. If the 'Payment' service succeeds but the 'Shipping' service fails because the address is invalid, the Saga must trigger the 'Refund' action in the Payment service. We don't 'Delete' the old record; we create a new 'Reversal' record to maintain a perfect audit trail."

Microservices & Event-Driven Architecture (EDA) Mastery
1. Foundations of Microservices
The Monolith to Microservices transition: When and why? Domain Driven Design (DDD): Bounded Contexts and Aggregates Database Per Service: Managing data consistency Service Discovery and Health Checks in .NET
2. Communication Patterns
Synchronous Communication: HTTP/gRPC and Service Mesh Asynchronous Communication: Message Brokers (RabbitMQ/Kafka) API Gateways: YARP (Yet Another Reverse Proxy) vs Ocelot Protobuf and Shared Contracts: Managing breaking changes
3. Event-Driven Architecture (EDA)
Introduction to EDA: Producers, Consumers, and Topics The Publisher/Subscriber Pattern in .NET Event Sourcing: Capturing every state change CQRS (Command Query Responsibility Segregation) with MediatR
4. Distributed Transactions & Resiliency
The Saga Pattern: Orchestration vs Choreography The Outbox Pattern: Ensuring reliable message delivery Idempotency: Preventing duplicate message processing Distributed Locking with Redis (Redlock)
5. Observability & Monitoring
Distributed Tracing with OpenTelemetry Centralized Logging: ELK Stack (Elasticsearch, Logstash, Kibana) Metrics and Dashboards: Prometheus and Grafana Correlation IDs: Tracking requests across services
6. Security & Identity
Centralized Authentication: IdentityServer4 & Duende Identity OAuth2 and OIDC Flow for Microservices API Key Management and Rate Limiting Mutual TLS (mTLS) for Internal Service-to-Service Security
7. Infrastructure & Deployment
Containerization: Production-grade Dockerfiles Kubernetes for .NET: Pods, Services, and Ingress Helm Charts: Managing complex deployments Blue-Green and Canary Deployments in K8s
8. FAANG Microservices Case Studies
Case Study: Designing a Global Notification Engine (Reliability at Scale) Case Study: Building a High-Performance Logging Pipeline (PB/Day)