In ASP.NET Core, Kestrel is the default cross-platform web server used to run your application.
What is Kestrel?
Kestrel is:
- A lightweight, high-performance web server
- Built into ASP.NET Core
- Responsible for handling HTTP requests and responses
Simple Explanation
When a user opens your website:
Browser → Kestrel → ASP.NET Core App → Response → Browser
Kestrel is the engine that listens to requests and sends responses.
Key Features
1. Cross-platform
Runs on:
- Windows
- Linux
- macOS
2. High Performance
- Built for speed (used in production systems)
- Handles thousands of requests efficiently
3. Supports HTTP protocols
- HTTP/1.1
- HTTP/2
- HTTP/3 (modern apps)
4. Async & non-blocking
- Designed for scalable apps
Where is Kestrel Used?
By default in every ASP.NET Core app:
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.Run();
✔ This automatically starts Kestrel
Kestrel vs IIS
| Feature | Kestrel | IIS (Internet Information Services) |
|---|---|---|
| Type | Lightweight web server | Full-featured web server |
| Platform | Cross-platform | Windows only |
| Usage | Default in ASP.NET Core | Often used as reverse proxy |
Production Setup
Common architecture:
Client → IIS / Nginx → Kestrel → App
- Nginx or IIS acts as:
- Reverse proxy
- Load balancer
- Kestrel handles app logic
Why not expose Kestrel directly?
Kestrel alone:
- Doesn’t handle advanced security features
- No built-in load balancing
- Limited edge features
- IIS (Windows)
- Nginx (Linux)
Load balancing at IIS/Nginx
Distributing incoming requests across multiple app instances
Client → Nginx / IIS → App1 (Kestrel)
→ App2 (Kestrel)
→ App3 (Kestrel)
How Nginx Does It (Simple Example)
upstream myapp {
server localhost:5000;
server localhost:5001;
}
server {
location / {
proxy_pass http://myapp;
}
}
Nginx or IIS:
- Receives request
- Sends it to one of many Kestrel instances
Analogy
- Kestrel = Engine of a car
- IIS/Nginx = Driver + security + traffic control
Key Takeaway
Kestrel is:
- The core web server in ASP.NET Core
- Fast, lightweight, and cross-platform
- Usually sits behind a reverse proxy in production
No comments:
Post a Comment