Microservices & Event-Driven Architecture (EDA) Mastery

API Gateways: YARP (Yet Another Reverse Proxy) vs Ocelot

1 Views Updated 5/4/2026

The Entry Point: API Gateways

You should never expose your internal microservices directly to the internet. An API Gateway acts as a single door, handling auth, rate-limiting, and routing.

1. YARP (Microsoft's Choice)

YARP is built by Microsoft using the high-performance .NET libraries. It is extremely fast, fully extensible via C# code, and is designed for the modern cloud. It's the recommended choice for new project. **Architect Rule:** If you need custom routing logic that depends on your business rules, YARP allows you to write that logic in pure C#.

2. Ocelot

Older, battle-tested, but relies heavily on JSON configuration. It has built-in support for things like **Request Aggregation** (calling 3 services and combining the results into 1 JSON for the mobile app). While still great, it is seeing less development than YARP.

3. Backend for Frontend (BFF) Pattern

Instead of 1 giant gateway, use a BFF. Have 1 gateway for the Web app, and 1 for the Mobile app. This allows each frontend to get exactly the data they need without over-fetching, while keeping the gateway code small and maintainable.

4. Interview Mastery

Q: "Why would you use an API Gateway instead of just a Load Balancer?"

Architect Answer: "A Load Balancer is 'Dumb'—it just moves packets. An API Gateway is 'Smart'—it understands the **Application Layer**. It can verify a JWT token, transform a request from XML to JSON, and handle **Canary Routing** (sending 5% of users to a new version of a service based on their UserID)."

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)