ASP.NET Core Interview Question #224

What should be considered when deploying ASP.NET Core behind a load balancer?

Testing, Deployment & Hosting Senior Advanced

Quick Interview Answer

Multiple application instances should avoid keeping critical shared state only in local memory. Shared sessions, caches, files, and job coordination may require external stores or an architecture that removes the need for shared mutable state.

Detailed Explanation

Multiple application instances should avoid keeping critical shared state only in local memory. Shared sessions, caches, files, and job coordination may require external stores or an architecture that removes the need for shared mutable state.

Forwarded headers, HTTPS termination, health checks, data-protection keys, authentication behavior, and client IP handling must be configured for the topology.

Sticky sessions can sometimes preserve per-instance state, but stateless application design is generally easier to scale and recover.

Code Example

builder.Services.AddDataProtection()
    .PersistKeysToFileSystem(
        new DirectoryInfo("/shared/dataprotection-keys"));

// The shared location must itself be secured
// and appropriate for the hosting environment.