Xw3qBlog logoXw3qBlog

← Back to Home

YARP vs Envoy vs Ocelot: Choosing an API Gateway for .NET Microservice

43 views·Like (0)·0 comments

A deep comparison of YARP, Envoy, and Ocelot for .NET microservices, covering architecture, internals, performance, use cases, and implementation examples with code.


YARP vs Envoy vs Ocelot: Choosing an API Gateway for .NET Microservices

Last Updated: July 9, 2026
Target Platform: .NET 8, .NET 9, .NET 10, Kubernetes, Cloud-Native Applications

Introduction

As applications evolve from monoliths into distributed systems, an API Gateway becomes a critical component of a microservices architecture. Instead of exposing every service directly to clients, the gateway acts as a single entry point that centralizes cross-cutting concerns such as routing, authentication, rate limiting, observability, and traffic management.

Client
   ↓
API Gateway
   ↓
────────────────────
User Service
Order Service
Product Service
Payment Service
────────────────────

A modern API Gateway typically provides:

  • Request routing
  • Load balancing
  • Authentication and authorization
  • Rate limiting and throttling
  • Service discovery
  • Circuit breaking and retries
  • Logging and observability
  • API aggregation
  • Protocol translation (HTTP, gRPC, WebSocket)

For .NET developers, three gateway technologies are commonly discussed:

  • YARP (Yet Another Reverse Proxy)
  • Envoy Proxy
  • Ocelot

This article compares them from the perspectives of architecture, internal principles, performance, use cases, and implementation.

---

Overview

GatewayLanguageCategoryBest For
YARPC#Reverse Proxy LibraryModern .NET Microservices
EnvoyC++High-Performance ProxyCloud-Native Platforms
OcelotC#API Gateway FrameworkLegacy and Small Projects

---

Architecture and Internal Design

YARP

YARP is Microsoft's open-source reverse proxy built on top of ASP.NET Core.

Architecture

Client
   ↓
Kestrel
   ↓
YARP Middleware
   ↓
Routing
   ↓
Load Balancer
   ↓
Transforms
   ↓
Destination Service

Core Principles

  • Built on the ASP.NET Core middleware pipeline.
  • Fully managed .NET implementation.
  • Uses asynchronous I/O and the HttpClient pipeline.
  • Supports dependency injection and middleware extensions.
  • Configuration can be loaded dynamically.

Advantages

  • Native .NET integration
  • Excellent extensibility
  • Strong performance
  • Easy customization

Limitations

  • No built-in service mesh capabilities.
  • Some advanced traffic management features require custom development.

---

Envoy

Envoy is a high-performance proxy originally developed by Lyft and is now a CNCF graduated project.

Architecture

Client
   ↓
Listener
   ↓
Filter Chain
   ↓
HTTP Connection Manager
   ↓
Cluster
   ↓
Endpoint

Core Principles

  • Event-driven and multi-threaded architecture.
  • Written in C++ for maximum performance.
  • Dynamic configuration through xDS APIs.
  • Designed for service mesh and cloud-native environments.

Advantages

  • Extremely high throughput
  • Advanced traffic management
  • Native gRPC support
  • Excellent observability
  • Service mesh foundation

Limitations

  • Steep learning curve
  • More operational complexity
  • Less developer-friendly for pure .NET teams

---

Ocelot

Ocelot is one of the earliest API gateway frameworks built specifically for .NET microservices.

Architecture

Client
   ↓
Middleware Pipeline
   ↓
Authentication
   ↓
Authorization
   ↓
Load Balancer
   ↓
Downstream Service

Core Principles

  • Configuration-driven gateway.
  • Built on ASP.NET Core middleware.
  • Focuses on simplicity and quick setup.

Advantages

  • Easy to learn
  • Minimal setup
  • Good for small systems

Limitations

  • Lower performance
  • Reduced community activity
  • Limited extensibility compared to YARP

---

Performance Comparison

Performance varies depending on workload, hardware, and configuration, but the following trends are commonly observed.

MetricYARPEnvoyOcelot
ThroughputHighVery HighMedium
LatencyLowVery LowModerate
Memory UsageMediumLowMedium
ScalabilityHighExtremely HighModerate
Concurrent Connections100K+MillionsTens of Thousands

Performance Ranking

Envoy > YARP >>> Ocelot

---

Feature Comparison

CapabilityYARPEnvoyOcelot
HTTP/1.1
HTTP/2
HTTP/3
gRPCLimited
Service Discovery
Dynamic ConfigurationLimited
Rate Limiting
Traffic SplittingLimited
Service Mesh
Kubernetes NativeModerateExcellentPoor

---

Implementation Examples

YARP

Installation

dotnet add package Yarp.ReverseProxy

Configuration

{
  "ReverseProxy": {
    "Routes": {
      "users": {
        "ClusterId": "users-cluster",
        "Match": {
          "Path": "/users/{**catch-all}"
        }
      }
    },
    "Clusters": {
      "users-cluster": {
        "Destinations": {
          "destination1": {
            "Address": "https://localhost:7001/"
          }
        }
      }
    }
  }
}

Startup

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddReverseProxy()
    .LoadFromConfig(
        builder.Configuration.GetSection("ReverseProxy"));

var app = builder.Build();

app.MapReverseProxy();

app.Run();

---

Envoy

envoy.yaml

static_resources:
  listeners:
    - name: listener_0
      address:
        socket_address:
          address: 0.0.0.0
          port_value: 8080

      filter_chains:
        - filters:
            - name: envoy.filters.network.http_connection_manager
              typed_config:
                route_config:
                  virtual_hosts:
                    - name: backend
                      routes:
                        - match:
                            prefix: "/"
                          route:
                            cluster: user-service

  clusters:
    - name: user-service
      connect_timeout: 5s
      type: STRICT_DNS
      lb_policy: ROUND_ROBIN

---

Ocelot

Installation

dotnet add package Ocelot

Configuration

{
  "Routes": [
    {
      "DownstreamPathTemplate": "/api/users",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 7001
        }
      ],
      "UpstreamPathTemplate": "/users",
      "UpstreamHttpMethod": ["Get"]
    }
  ]
}

Startup

builder.Services.AddOcelot();

var app = builder.Build();

await app.UseOcelot();

app.Run();

---

Recommended Use Cases

YARP

Best for:

  • Modern .NET microservices
  • Internal enterprise systems
  • SaaS applications
  • Backend-for-Frontend (BFF) architectures

---

Envoy

Best for:

  • Kubernetes platforms
  • Service mesh environments
  • High-throughput systems
  • Large-scale distributed applications

---

Ocelot

Best for:

  • Learning microservices
  • Legacy .NET projects
  • Small and medium applications

---

Which Gateway Should You Choose?

ScenarioRecommendation
Pure .NET TeamYARP
Enterprise SaaSYARP
Kubernetes PlatformEnvoy
Service MeshEnvoy
Legacy ProjectOcelot
Learning PurposeOcelot or YARP

---

Recommended Learning Path

ASP.NET Core
      ↓
YARP
      ↓
.NET Aspire
      ↓
OpenTelemetry
      ↓
Dapr
      ↓
Kubernetes
      ↓
Envoy
      ↓
Istio
      ↓
Service Mesh

---

Final Thoughts

For most modern .NET applications, YARP has become the default choice because it integrates naturally with ASP.NET Core and provides excellent performance and flexibility.

If your architecture is moving toward Kubernetes, multi-cluster deployments, or service mesh, Envoy becomes increasingly important and is worth investing time to learn.

Ocelot still has value for maintaining existing systems, but for new projects, YARP is generally the better long-term investment.

In short:

YARP for .NET developers, Envoy for cloud-native platforms, and Ocelot for legacy systems.

About petercontinue

peter love study

Comments

Sign in to leave a comment.

  • No comments yet. Be the first to comment.