Previous REST-vs-GraphQL ConfigureServices and Configure methods Next

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

  1. Kestrel starts and binds to a port.
  2. It listens for HTTP requests from clients.
  3. Requests go through the middleware pipeline (auth, logging, routing, etc.).
  4. 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

  1. Client Request: A browser, mobile app, or API client sends an HTTP/HTTPS request.
  2. 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.
  3. 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.
  4. 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.

Back to Index
Previous REST-vs-GraphQL ConfigureServices and Configure methods Next
*