Kestrel

1 min read
On trails:ASPNETstep 1/7

ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-based, internet-connected applications, such as web apps, APIs and microservices. It’s a redesign of ASP.NET 4.x, built for modularity and performance.

What it is

Kestrel is the default, cross-platform HTTP server for ASP.NET Core applications. It’s lightweight and extremely fast, and it’s designed to handle a large number of concurrent connections efficiently. It was originally built on libuv, a multi-platform C library for asynchronous I/O. Since ASP.NET Core 2.1, its default transport has been managed sockets instead.

How it’s used

Kestrel can serve as an edge server exposed directly to the internet, especially since ASP.NET Core 2.0. In production environments, though, it’s often run behind a more robust reverse proxy like IIS (on Windows), Nginx or Apache (on Linux). The reverse proxy can handle tasks like SSL termination, request filtering, load balancing and serving static content.

Kestrel’s ability to run as a public-facing edge server gives deployment flexibility. A reverse proxy adds features, but for simpler scenarios or internal services, Kestrel alone might be enough, which reduces deployment complexity.

Configuration

Kestrel’s server options can be configured programmatically in Program.cs, or in Startup.cs in older templates. The options include endpoint configuration, port numbers, SSL certificates, request body size limits and connection limits. You do it with the UseKestrel() extension method on IWebHostBuilder, or with ConfigureWebHostDefaults.

Requests that reach Kestrel go through the middleware pipelineThe middleware pipelineHow a request passes through a chain of components, and why their order matters.Opens in a new tab. The host that starts Kestrel is covered in its own noteThe host and WebApplicationBuilderWhat starts an ASP.NET Core application and keeps it running.Opens in a new tab.

How it serves so many connections with a small pool of threads is in how many threads handle one requestHow many threads handle one request?One at a time, but not always the same one.Opens in a new tab.


Sources