ASP.NET Core Interview Question #198

What is the difference between vertical and horizontal scaling?

Performance, Caching & HTTP Senior Advanced

Quick Interview Answer

Vertical scaling increases the resources of one application host, such as CPU or memory. It is simple but has hardware limits and can leave one large instance as a significant failure domain.

Detailed Explanation

Vertical scaling increases the resources of one application host, such as CPU or memory. It is simple but has hardware limits and can leave one large instance as a significant failure domain.

Horizontal scaling runs multiple application instances and distributes traffic between them. It can improve capacity and resilience but requires application state to be designed for multiple instances.

For horizontal scaling, avoid relying on local process memory for shared session or critical state unless the architecture explicitly supports that behavior.

Code Example

// Stateless application services are easier to scale out.
// Shared state can be placed in appropriate external systems,
// for example a database or distributed cache.

builder.Services.AddStackExchangeRedisCache(options =>
{
    options.Configuration = "redis:6379";
});