| REST-vs-GraphQL :👈 | 👉:ASP.NET Core request processing |
Kestrel - Simple Guide |
Kestrel
Kestrel is the default, cross-platform web server that comes built-in with ASP.NET Core. Itβs lightweight, high-performance, and designed to run on Windows, Linux, and macOS without needing IIS or Apache in front of it.
π What Kestrel Is
Type: Web server implementation for ASP.NET Core.
Role: Listens for incoming HTTP requests, processes them through ASP.NET Coreβs middleware pipeline, and sends back responses.
Protocols Supported: HTTP/1.1, HTTP/2, HTTP/3, and WebSockets.
Deployment Modes:
- Standalone β Kestrel directly serves requests.
- Behind a Reverse Proxy β e.g., IIS, Nginx, Apache for SSL termination, load balancing, or extra security.
π Why Kestrel Is Used in .NET Core
| Reason | Benefit |
|---|---|
| Cross-Platform | Runs on Windows, Linux, macOS β ideal for containerized and cloud deployments. |
| High Performance | Optimized for handling thousands of concurrent connections using async I/O. |
| Lightweight | Minimal overhead, great for microservices and APIs. |
| Security Hardened | Supports HTTPS/TLS and is resistant to common web server vulnerabilities. |
| Flexible | Works with Minimal APIs, MVC, Razor Pages, SignalR, Blazor, gRPC, and custom workloads. |
| Extensible | Can be customized via configuration, middleware, and custom transports. |
π§ How It Fits in ASP.NET Core
- Kestrel starts and binds to a port.
- It listens for HTTP requests from clients.
- Requests go through the middleware pipeline (auth, logging, routing, etc.).
- The app generates a response, which Kestrel sends back to the client.
In short: Kestrel is the engine that powers ASP.NET Core apps. Itβs fast, portable, and production-ready β whether you run it alone for simplicity or behind a reverse proxy for enterprise-grade deployments.
Kestrel Deployment Modes
Diagram and explanation of how Kestrel works in both standalone and reverse proxy modes, so you can visualize its role in a .NET Core deployment.
πΌ Kestrel in Reverse Proxy Mode
[ Client Browser / Mobile App ]
|
v
βββββββββββββββββββββ
β Reverse Proxy β β IIS / Nginx / Apache
β (SSL termination, β
β load balancing, β
β request filtering) β
βββββββββββββββββββββ
|
v
βββββββββββββββββββββ
β Kestrel Server β β ASP.NET Core app host
β (Middleware, β
β Routing, MVC/API) β
βββββββββββββββββββββ
|
v
[ Application Logic / DB / Services ]
π How It Works
- Client Request: A browser, mobile app, or API client sends an HTTP/HTTPS request.
-
Reverse Proxy Layer (optional but common in production):
- IIS (Windows), Nginx (Linux), or Apache sits in front of Kestrel.
- Handles SSL/TLS termination (offloading encryption work).
- Can perform load balancing across multiple Kestrel instances.
- Adds extra security filtering and request buffering.
-
Kestrel Web Server:
- Listens on internal ports (e.g., localhost:5000 or unix:/tmp/kestrel.sock).
- Processes requests through the ASP.NET Core middleware pipeline.
- Routes to controllers, minimal APIs, Razor Pages, SignalR hubs, etc.
-
Application Logic:
- Executes business logic, queries databases, calls external APIs.
- Returns a response back through Kestrel β Reverse Proxy β Client.
π Why Use a Reverse Proxy with Kestrel
- Security: Hide Kestrel from direct internet exposure.
- Performance: Offload SSL/TLS and static file serving to a highly optimized proxy.
- Scalability: Distribute requests across multiple app instances.
- Compatibility: Integrate with existing enterprise infrastructure.
π‘ Pro Tip for .NET Core APIs
For development, you can run Kestrel standalone. For production, Microsoft recommends Kestrel behind a reverse proxy β especially if you need SSL termination, multiple app instances, or advanced routing.
| REST-vs-GraphQL :👈 | 👉:ASP.NET Core request processing |