Advertisement

Hosting Models: Kestrel, IIS & Reverse Proxies interview questions and answers

15 Hosting Models: Kestrel, IIS & Reverse Proxies interview questions for ASP.NET Core roles, each with a model answer, examples and likely follow-ups.

15 questions
Advertisement

15 questions

Q11 Advanced Save

How would you implement graceful shutdown handling in Kestrel/ASP.NET Core to ensure in-flight requests complete before a container or process terminates during a deployment or scale-down event?

ASP.NET Core listens for SIGTERM (the standard signal orchestrators like Kubernetes send before force-killing a container) and begins graceful shutdown, stopping acceptance of new connections while allowing in-flight requests up to a configurable grace period (Host.ConfigureHostOptions's ShutdownTimeout, and Kubernetes' own terminationGracePeriodSeconds) to complete before the process actually exits -- IHostApplicationLifetime's ApplicationStopping token lets application code (like a background worker) hook into this shutdown sequence to clean up gracefully rather than being abruptly killed mid-operation.
builder.Host.ConfigureHostOptions(options => {
    options.ShutdownTimeout = TimeSpan.FromSeconds(30);
});

public class GracefulWorker(IHostApplicationLifetime lifetime) : BackgroundService {
    protected override async Task ExecuteAsync(CancellationToken stoppingToken) {
        lifetime.ApplicationStopping.Register(() => Console.WriteLine("Shutdown initiated, finishing current work..."));
        while (!stoppingToken.IsCancellationRequested) { /* ... */ }
    }
}
Real-world example
A Kubernetes deployment configures a 30-second terminationGracePeriodSeconds matching the application's own ShutdownTimeout, ensuring in-flight API requests get a full 30 seconds to complete during a rolling deployment's pod termination, rather than being abruptly cut off mid-request.
Likely follow-ups
  • What happens to requests that are still in-flight when the grace period expires?
  • How does readiness probe behavior interact with graceful shutdown to stop new traffic from arriving during the shutdown window?
Background Tasks & Hosted Services Health Checks
Q12 Intermediate Save

What role does a reverse proxy play in TLS/SSL termination, and why is this pattern common in production deployments?

TLS termination at the reverse proxy (nginx, a cloud load balancer, IIS) means the proxy handles the computationally expensive TLS handshake and decryption, then forwards the request to the backend application (Kestrel) as plain HTTP over the internal, typically trusted network -- this centralizes certificate management at one layer (the proxy), reduces CPU load on individual application instances, and simplifies certificate rotation/renewal to a single location rather than needing to manage TLS certificates on every application instance.
# nginx.conf -- TLS terminated here, plain HTTP forwarded to the app
server {
    listen 443 ssl;
    ssl_certificate /etc/ssl/cert.pem;
    ssl_certificate_key /etc/ssl/key.pem;
    location / {
        proxy_pass http://localhost:5000;  // plain HTTP to Kestrel
        proxy_set_header X-Forwarded-Proto https;
    }
}
Real-world example
A company managing dozens of backend service instances centralizes all TLS certificate management at their nginx reverse proxy layer, letting them renew a single certificate rather than needing to update and redeploy certificates across every individual backend Kestrel instance.
Likely follow-ups
  • What are the security trade-offs of plain HTTP between the proxy and the backend versus full end-to-end TLS?
  • How does certificate renewal automation (like Let's Encrypt) typically integrate at this proxy layer?
HTTPS Certificates & Transport Security Configuration & Options Pattern
Q13 Advanced Save

How would you configure and validate that HTTP/2 (or HTTP/3) is actually being used end-to-end through a reverse proxy, rather than silently downgrading to HTTP/1.1?

HTTP/2 and HTTP/3 support must be explicitly enabled and correctly configured at every hop in the chain (client, reverse proxy, and Kestrel itself via Protocols = HttpProtocols.Http1AndHttp2AndHttp3), and many reverse proxy configurations silently downgrade to HTTP/1.1 for the backend connection even when the client-facing connection uses HTTP/2 -- validating the actual protocol in use requires inspecting the real negotiated protocol (via browser dev tools' network tab, or a diagnostic tool like curl --http2), not just assuming your configuration is being honored throughout the whole chain.
builder.WebHost.ConfigureKestrel(options => {
    options.ListenAnyIP(5001, listenOptions => {
        listenOptions.Protocols = HttpProtocols.Http1AndHttp2AndHttp3;
        listenOptions.UseHttps();
    });
});

# Validate with curl
curl -I --http2 https://myapi.com/health
# Look for "HTTP/2 200" in the response to confirm HTTP/2 was actually negotiated
Real-world example
A team assumes their gRPC service benefits from HTTP/2 throughout, but curl-based testing reveals their reverse proxy was silently downgrading the backend connection to HTTP/1.1, negating gRPC's multiplexing benefits until the proxy's backend protocol configuration was explicitly corrected.
Likely follow-ups
  • What are the specific benefits HTTP/2 multiplexing provides that would be lost with a silent downgrade?
  • What client and infrastructure prerequisites does HTTP/3 (QUIC-based) require beyond HTTP/2?
gRPC Services Diagnostics & Performance
Q14 Intermediate Save

How do you configure request timeout behavior differently at the Kestrel level versus the reverse proxy level, and why might they need to be coordinated?

Both Kestrel (via Limits.RequestHeadersTimeout, KeepAliveTimeout, and the RequestTimeouts middleware for per-endpoint timeouts) and the reverse proxy (nginx's proxy_read_timeout, an ALB's idle timeout) can independently enforce timeout behavior -- if these are misaligned (for example, the proxy's timeout is shorter than a legitimately slow but valid backend operation), the proxy will terminate the connection prematurely with a generic error before Kestrel's own more informative timeout/error handling ever gets a chance to respond, so these values should be deliberately coordinated across the whole chain.
# nginx.conf
proxy_read_timeout 60s;

// Program.cs -- Kestrel's own timeout should be equal to or shorter than the proxy's
builder.Services.AddRequestTimeouts(options => {
    options.DefaultPolicy = new RequestTimeoutPolicy { Timeout = TimeSpan.FromSeconds(55) };
});
app.UseRequestTimeouts();
Real-world example
A slow report-generation endpoint legitimately taking 50 seconds was being terminated by nginx's default 60-second proxy_read_timeout intermittently under load, traced to nginx's timeout interacting poorly with connection queueing delays, resolved by both raising the proxy timeout and adding explicit endpoint-level timeout handling in the application itself.
Likely follow-ups
  • What error does the client see when the reverse proxy times out versus when the application itself times out?
  • How would you design a long-running operation to avoid depending on generous synchronous timeout values entirely?
Background Tasks & Hosted Services Diagnostics & Performance
Q15 Beginner Save

What is the difference between Kestrel's ListenAnyIP and Listen methods for binding to network addresses?

ListenAnyIP binds to all available network interfaces on a given port (equivalent to 0.0.0.0), commonly used in containerized deployments where the actual accessible network interface isn't known in advance -- Listen(IPAddress, port) instead binds to one specific IP address, useful when a server has multiple network interfaces and the application should only accept connections on a particular one, such as an internal-only management interface separate from a public-facing one.
builder.WebHost.ConfigureKestrel(options => {
    options.ListenAnyIP(5000);  // binds to all interfaces, e.g. 0.0.0.0:5000
    options.Listen(IPAddress.Parse("10.0.0.5"), 5001);  // binds only to this specific internal IP
});
Real-world example
A server with both a public-facing network interface and an internal management network interface uses ListenAnyIP for its public API traffic on port 5000, while explicitly binding an internal admin endpoint only to the internal-only IP address on a separate port, preventing the admin endpoint from being reachable externally at all.
Likely follow-ups
  • What's the security risk of accidentally using ListenAnyIP for an endpoint that should be internal-only?
  • How does this interact with container networking, where the container itself typically has only one relevant interface?
Configuration & Options Pattern Security Headers Antiforgery & CSRF Protection

Showing 11–15 of 15