Tutorials Microservices & Event-Driven Architecture (EDA) Mastery

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

On this page

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)."

Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

Microservices & Event-Driven Architecture (EDA) Mastery
Course syllabus
1. Foundations of Microservices
2. Communication Patterns
3. Event-Driven Architecture (EDA)
4. Distributed Transactions & Resiliency
5. Observability & Monitoring
6. Security & Identity
7. Infrastructure & Deployment
8. FAANG Microservices Case Studies
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details