Load Balancer - System Design Interview Question

Last Updated : 31 Jul, 2026

As the number of users grows, a single server may not be able to handle all incoming requests efficiently, leading to slower response times. To improve performance and reliability, the workload is distributed across multiple servers.

  • Distributes incoming requests across multiple servers to prevent overloading a single server.
  • Improves performance, scalability, and availability by handling high traffic efficiently.

1. What is a Load Balancer?

A load balancer is a hardware device or software application that distributes incoming client requests across multiple servers. It ensures that no single server becomes overloaded, improving application performance, scalability, and availability.

  • Distributes incoming traffic evenly across multiple servers.
  • Improves performance, fault tolerance, and high availability by preventing server overload.

Example: A popular e-commerce website like Amazon uses load balancers to distribute millions of user requests across multiple web servers during sales events. If one server becomes busy or fails, the load balancer automatically redirects traffic to healthy servers, ensuring uninterrupted service.

2. What will happen if there is No Load Balancer?

Before understanding how a load balancer works, let's first see the problems that occur when an application runs on a single server. As the number of users grows, a single server may become overloaded or unavailable, affecting the application's performance and reliability.

Consider a scenario where an application is running on a single server and the client connects to that server directly without load balancing.
 

lb1

There are two major problems in this approach:

  • Single Point of Failure: If the only server crashes or becomes unavailable, the entire application goes offline, making the service inaccessible to users until the server is restored.
  • Server Overload: A single server can handle only a limited number of requests. As user traffic increases, the server may become overloaded, resulting in slow response times or request failures.
  • Solution: To handle increasing traffic, multiple servers are added, and a load balancer distributes incoming requests among them. This improves performance, scalability, and availability, ensuring that no single server becomes a bottleneck.

3. How Load Balancer Works?

A load balancer sits between clients and backend servers, receiving all incoming requests and distributing them across multiple servers based on a load balancing algorithm. This prevents any single server from becoming overloaded and ensures efficient request processing.

The working of a load balancer can be summarized as follows:

  • Receives client requests and distributes them evenly across multiple servers.
  • Performs continuous health checks and forwards requests only to healthy, available servers.
  • If a server fails, requests are automatically redirected to other active servers, ensuring uninterrupted service.
  • Supports horizontal scaling by adding or removing servers based on traffic demand.
  • Improves response time, throughput, and overall application availability by preventing server bottlenecks.

lb2

Example: Consider an online streaming platform like Netflix. During peak hours, millions of users request videos simultaneously. The load balancer distributes these requests across multiple streaming servers. If one server goes down, user requests are automatically routed to healthy servers, allowing video streaming to continue without interruption.

4. Where Are Load Balancers Typically Placed?

A load balancer can be placed at different layers of a system architecture to distribute traffic efficiently and prevent individual components from becoming overloaded. Its placement depends on the system's design and traffic requirements.

Common locations where load balancers are deployed include:

Where-are-Load-Balancer-placed-copy-(1)

  • Between clients and web servers to distribute incoming user requests.
  • Between web servers and application servers to balance application processing requests.
  • Between application servers and cache servers to distribute cache access requests.
  • Between cache servers and database servers to balance database queries and improve performance.

Example: In an e-commerce application, one load balancer distributes user requests across web servers, while another balances requests among application servers to ensure smooth order processing during high-traffic events.

5. Types of Load Balancers

5.1 Types of Load Balancers Based on Configuration

Load balancers can be categorized based on how they are deployed and managed. The three main types are Software Load Balancers, Hardware Load Balancers, and Virtual Load Balancers.

1. Software Load Balancer

A software load balancer is an application that runs on standard servers or virtual machines to distribute incoming traffic across multiple backend servers. It is flexible, scalable, and widely used in cloud and microservices environments.

  • Runs as software on general-purpose servers or virtual machines.
  • Offers high flexibility, scalability, and cost-effectiveness.

Example: NGINX and HAProxy are popular software load balancers used to distribute traffic across web servers in cloud-based applications.

2. Hardware Load Balancer

A hardware load balancer is a dedicated physical appliance designed to distribute network traffic efficiently. It provides high performance and supports protocols such as HTTP, HTTPS, TCP, and UDP, making it suitable for enterprise and data center environments.

  • Uses a dedicated physical device to handle and distribute network traffic.
  • Provides high performance and reliability but is more expensive than software-based solutions.

Example: A large bank may use an F5 BIG-IP hardware load balancer to distribute millions of secure HTTPS requests across multiple application servers.

3. Virtual Load Balancer

A virtual load balancer is deployed as a virtual machine (VM) or software instance within a virtualized environment. It combines the flexibility of software load balancers with the benefits of virtualization, making it ideal for modern cloud and virtual data centers.

  • Deployed as a virtual machine or virtual appliance in a virtualized environment.
  • Improves resource utilization, scalability, and traffic distribution across virtual servers.

Example: An organization using VMware can deploy a virtual load balancer to distribute traffic among multiple virtual web servers running in the same data center.

5.2 Types of Load Balancers Based on Function

Based on how they inspect and distribute incoming traffic, load balancers are classified into Layer 4 (L4), Layer 7 (L7), and Global Server Load Balancing (GSLB).

1. Layer 4 (L4) Load Balancer

A Layer 4 Load Balancer operates at the Transport Layer of the OSI model. It distributes traffic based on network information such as IP addresses, TCP/UDP ports, and protocols, without inspecting the actual request content.

  • Routes traffic using IP addresses, port numbers, and transport protocols.
  • Provides high performance and low latency due to minimal packet inspection.

Example: A gaming application uses an L4 load balancer to distribute TCP connections among multiple game servers based on IP addresses and port numbers.

2. Layer 7 (L7) Load Balancer

A Layer 7 Load Balancer operates at the Application Layer of the OSI model. It makes routing decisions by inspecting application-level data such as URLs, HTTP headers, cookies, or request methods.

  • Routes requests based on application-level information like URLs, headers, or cookies.
  • Supports content-based routing, SSL termination, and advanced traffic management.

Example: An e-commerce website routes requests for /images to image servers and /payments to payment servers using an L7 load balancer.

3. Global Server Load Balancing (GSLB)

Global Server Load Balancing (GSLB) distributes user traffic across multiple geographically distributed data centers. It considers factors such as server health, network latency, and user location to route requests to the most appropriate server.

  • Distributes traffic across multiple data centers or geographic regions.
  • Improves availability, disaster recovery, and user experience by routing users to the nearest healthy server.

Example: A global streaming platform like Netflix directs users in Asia to an Asian data center and users in Europe to a European data center, reducing latency and improving streaming performance.

6. Load Balancing Algorithms

A load balancing algorithm determines how incoming client requests are distributed among the available backend servers. The choice of algorithm depends on factors such as server capacity, current load, and application requirements.

1. Round Robin

The Round Robin algorithm distributes requests to servers in a sequential, circular order. It is simple to implement and works well when all servers have similar configurations.

  • Distributes requests equally in a fixed rotation among all servers.
  • Best suited for servers with similar hardware and workloads.

Example: If there are three servers (S1, S2, S3), the requests are assigned as S1 → S2 → S3 → S1 → S2 → S3.

2. Weighted Round Robin

The Weighted Round Robin algorithm assigns a weight to each server based on its processing capacity. Servers with higher weights receive more requests than those with lower weights.

  • Assigns more requests to higher-capacity servers.
  • Ideal when backend servers have different hardware configurations.

Example: If S1, S2, and S3 have weights 5, 3, and 2, then S1 receives the highest number of requests, followed by S2 and S3.

3. Source IP Hash

The Source IP Hash algorithm uses the client's IP address to calculate a hash value, ensuring that requests from the same client are always routed to the same server.

  • Routes requests based on the hash of the client's IP address.
  • Maintains session persistence (sticky sessions).

Example: A user logging into an online banking application is consistently routed to the same server throughout the session.

4. Least Connections

The Least Connections algorithm sends each new request to the server with the fewest active connections, helping distribute the workload dynamically.

  • Selects the server with the lowest number of active connections.
  • Suitable for applications where request processing times vary.

Example: If Server A has 20 active connections and Server B has 8, the next request is routed to Server B.

5. Least Response Time

The Least Response Time algorithm routes requests to the server that currently has the fastest response time, providing better performance during varying workloads.

  • Chooses the server with the lowest response time.
  • Helps reduce latency and improve user experience.

Example: If three servers respond in 15 ms, 30 ms, and 45 ms, the load balancer forwards the next request to the 15 ms server.

7. How to Use Load Balancing During System Design Interviews?

In system design interviews, load balancers are commonly used to explain how a system handles high traffic, improves scalability, and ensures high availability. You should be able to describe where a load balancer is placed, how it distributes requests, and why it is essential in scalable architectures.

Key points to mention during an interview include:

  • Distributes incoming traffic across multiple servers to improve scalability and performance.
  • Ensures high availability by routing requests only to healthy servers and avoiding single points of failure.
  • Can be deployed at different layers of the architecture, such as between clients, application servers, caches, or databases.
  • Supports horizontal scaling by allowing servers to be added or removed based on traffic demand.
  • Organizations often use a combination of hardware and software load balancers depending on their infrastructure and performance requirements.

Example: If asked to design a system like Netflix or Amazon, explain that a load balancer sits in front of multiple web servers, distributing user requests evenly. As traffic increases, new servers can be added behind the load balancer without affecting users, ensuring the application remains fast and highly available.

8. What is Session Persistence (Sticky Sessions) in Load Balancing?

Session Persistence, also known as Sticky Sessions, is a load balancing technique in which all requests from the same client are routed to the same backend server throughout a session. This ensures that session-specific data stored on the server remains available during the user's interaction.

  • Routes all requests from the same client to the same backend server.
  • Commonly used for applications that store user session data locally on the server.

Example: When a user logs into an online shopping website, the load balancer continues sending all requests from that user to the same server. This allows the user's login session and shopping cart to remain available without requiring re-authentication.

9. What is Health Checking in a Load Balancer?

Health checking is a mechanism used by a load balancer to continuously monitor the status of backend servers. It periodically checks whether each server is healthy and capable of handling requests. If a server becomes unavailable or fails the health check, the load balancer automatically stops sending traffic to it until it recovers.

  • Continuously monitors the health and availability of backend servers.
  • Routes requests only to healthy servers, improving reliability and high availability.

Example: Suppose a load balancer manages three web servers (S1, S2, and S3). If S2 stops responding to health checks, the load balancer automatically removes it from the pool and forwards all incoming requests to S1 and S3 until S2 becomes healthy again.

10. What is SSL/TLS Termination?

SSL/TLS termination is the process in which a load balancer decrypts incoming HTTPS traffic before forwarding the request to backend servers. This reduces the processing overhead on application servers and simplifies SSL certificate management.

  • Decrypts HTTPS traffic at the load balancer before forwarding requests.
  • Reduces CPU usage on backend servers and simplifies certificate management.

Example: A banking website receives encrypted HTTPS requests from users. The load balancer decrypts the requests, forwards them to the web servers over the internal network, and then encrypts the responses before sending them back to users.

11. What is Reverse Proxy, and How is it Different from a Load Balancer?

A reverse proxy is a server that sits between clients and backend servers, receiving client requests and forwarding them to the appropriate server. It is commonly used for security, caching, SSL termination, and request routing. A load balancer, on the other hand, primarily distributes incoming traffic across multiple servers to improve performance, scalability, and availability.

Reverse ProxyLoad Balancer
Acts as an intermediary between clients and servers.Distributes client requests across multiple backend servers.
Focuses on security, caching, SSL termination, and request routing.Focuses on traffic distribution, scalability, and fault tolerance.
Can work with a single backend server or multiple servers.Typically requires multiple backend servers.
Hides backend server details from clients.Balances requests to prevent server overload.

Example: A company uses NGINX as a reverse proxy to terminate SSL connections and cache static content. The requests are then forwarded to an HAProxy load balancer, which distributes them across multiple application servers.

12. What is the Difference Between Horizontal Scaling and Vertical Scaling?

Horizontal scaling and vertical scaling are two approaches used to increase a system's capacity. Horizontal scaling adds more servers to distribute the workload, while vertical scaling increases the resources (CPU, RAM, or storage) of an existing server.

Horizontal ScalingVertical Scaling
Adds more servers to the system.Increases the resources of an existing server.
Also known as Scale Out.Also known as Scale Up.
Improves scalability and fault tolerance.Limited by the maximum capacity of a single server.
Commonly used with load balancers.Does not require a load balancer.
Suitable for large-scale distributed systems.Suitable for smaller applications with moderate traffic.

Example: An e-commerce website experiencing high traffic can either add more web servers behind a load balancer (horizontal scaling) or upgrade its existing server from 8 GB RAM to 32 GB RAM (vertical scaling).

13. Can a Load Balancer Become a Single Point of Failure?

Yes, a load balancer itself can become a single point of failure if only one load balancer is deployed. If it fails, client requests cannot reach the backend servers, making the entire application unavailable. To avoid this, organizations deploy multiple load balancers with failover mechanisms.

  • A single load balancer can become a bottleneck if it fails.
  • High availability is achieved using multiple load balancers in an Active-Active or Active-Passive configuration.

Example: A banking application deploys two load balancers. If the primary load balancer fails, the secondary load balancer automatically starts handling incoming traffic, ensuring the service remains available.

14. What is Failover in Load Balancing?

Answer:
Failover is the process of automatically redirecting incoming traffic to healthy or backup servers when a primary server or service becomes unavailable. This ensures that the application remains accessible with minimal downtime and no manual intervention.

  • Automatically redirects requests to healthy servers when a server fails.
  • Improves system availability, reliability, and fault tolerance.

Example: Suppose a load balancer manages three servers: S1, S2, and S3. If S2 crashes unexpectedly, the load balancer detects the failure through health checks and immediately routes all new requests to S1 and S3, ensuring users continue to access the application without interruption.

15. What Factors Should You Consider While Choosing a Load Balancing Algorithm?

The choice of a load balancing algorithm depends on the application's traffic patterns, server capacity, and performance requirements. Selecting the right algorithm helps distribute requests efficiently, improve response times, and ensure optimal resource utilization.

  • Consider the number of active connections and the current load on each server.
  • Choose an algorithm based on server capacity, response time, and traffic patterns.
  • Use session persistence if users need to stay connected to the same server.
  • Select dynamic algorithms for varying workloads and static algorithms for uniform environments.

Example: An online gaming platform with long-lived user connections may use the Least Connections algorithm, while a website with identical web servers can use Round Robin to distribute requests evenly.

16. What Factors Should You Consider While Choosing a Load Balancing Algorithm?

The choice of a load balancing algorithm depends on the application's traffic patterns, server capacity, and performance requirements. Selecting the right algorithm helps distribute requests efficiently, improve response times, and ensure optimal resource utilization.

  • Consider the number of active connections and the current load on each server.
  • Choose an algorithm based on server capacity, response time, and traffic patterns.
  • Use session persistence if users need to stay connected to the same server.
  • Select dynamic algorithms for varying workloads and static algorithms for uniform environments.

Example: An online gaming platform with long-lived user connections may use the Least Connections algorithm, while a website with identical web servers can use Round Robin to distribute requests evenly.

17. What is Auto Scaling, and How Does It Work with Load Balancers?

Auto Scaling is a cloud feature that automatically adds or removes servers based on the application's traffic and resource usage. When used with a load balancer, newly created servers are automatically added to the load balancer, while idle or unhealthy servers are removed, ensuring efficient traffic distribution.

  • Automatically adds servers during high traffic and removes them when demand decreases.
  • Works with a load balancer to distribute requests across all available healthy servers.
  • Improves scalability, performance, and resource utilization.
  • Helps reduce infrastructure costs by running only the required number of servers.

Example: During a flash sale, an e-commerce website experiences a sudden spike in traffic. Auto Scaling launches additional web servers, and the load balancer immediately starts routing requests to them. Once the traffic decreases, the extra servers are automatically removed.

18. What are the Advantages and Disadvantages of Load Balancers?

Load balancers improve application performance by distributing incoming traffic across multiple servers. They help ensure high availability and scalability, but they also introduce additional infrastructure, configuration complexity, and cost.

Advantages

  • Distributes traffic evenly across multiple servers, preventing server overload.
  • Improves application performance and reduces response time.
  • Ensures high availability by redirecting requests to healthy servers.
  • Supports horizontal scaling by allowing new servers to be added easily.
  • Increases fault tolerance by eliminating single points of failure.

Disadvantages

  • Adds extra infrastructure and deployment costs.
  • Increases system configuration and maintenance complexity.
  • A single load balancer can become a bottleneck if redundancy is not implemented.
  • May introduce slight network latency due to request routing.
  • Some advanced hardware load balancers can be expensive to purchase and maintain.

Example: An online shopping platform uses a load balancer to distribute traffic across multiple web servers during a festive sale. This prevents server overload and keeps the website responsive even when millions of users access it simultaneously

Several software, hardware, and cloud-based load balancers are available to distribute traffic, improve application performance, and ensure high availability. The choice depends on the application's requirements, infrastructure, and budget.

Some popular load balancers include:

  • NGINX: An open-source software load balancer widely used for web applications, reverse proxy, and API gateways.
  • HAProxy: A high-performance software load balancer commonly used for TCP and HTTP traffic.
  • AWS Elastic Load Balancer (ELB): A managed cloud load balancing service provided by Amazon Web Services.
  • Google Cloud Load Balancer: A fully managed global load balancer offered by Google Cloud Platform.
  • Azure Load Balancer: A cloud-based load balancer provided by Microsoft Azure for distributing network traffic.
  • F5 BIG-IP: An enterprise-grade hardware and virtual load balancer used in large-scale data centers.

Example: A company hosting its application on AWS can use Elastic Load Balancer (ELB) to automatically distribute incoming traffic across multiple EC2 instances, ensuring high availability and scalability.

20. What is the Difference Between Active-Active and Active-Passive Load Balancing?

Active-Active and Active-Passive are two high-availability deployment models used for load balancers. In an Active-Active setup, multiple load balancers handle traffic simultaneously. In an Active-Passive setup, one load balancer actively handles traffic while the backup load balancer remains on standby and takes over only if the primary one fails.

Active-ActiveActive-Passive
Multiple load balancers handle traffic simultaneously.Only one load balancer handles traffic, while the other remains on standby.
Provides better resource utilization and higher throughput.Simpler to configure and manage.
Traffic is distributed across all active load balancers.Traffic is redirected to the backup only after the primary fails.
Offers higher scalability and fault tolerance.Provides high availability with failover support.
More complex to implement and maintain.Easier to deploy but may leave backup resources idle.

Example: A global streaming platform uses an Active-Active setup where two load balancers simultaneously distribute traffic across multiple servers. In contrast, a banking application may use an Active-Passive setup, where a secondary load balancer remains idle and automatically takes over if the primary load balancer fails.

21. How does a Load Balancer know if a server is down or up?

A load balancer continuously performs health checks on all backend servers to determine whether they are healthy and capable of serving requests. If a server fails the health check, the load balancer marks it as unhealthy and stops forwarding requests to it. Once the server recovers and starts responding successfully again, the load balancer adds it back to the pool of available servers.

  • Periodically sends health check requests to each backend server.
  • Routes traffic only to servers that successfully pass the health checks.

Types of Health Checks

1. Active Health Check (Most Common)

The load balancer periodically sends requests (every few seconds) to each server.

Examples:

  • HTTP request (GET /health)
  • TCP connection check
  • HTTPS health check
  • ICMP (Ping)

If the server responds with a successful status (such as HTTP 200 OK), it is considered healthy.

Load Balancer

GET /health ───► Server A - 200 OK

GET /health ───► Server B - No Response

GET /health ───► Server C - 200 OK

The load balancer now sends traffic only to Server A and Server C.

2. Passive Health Check

Instead of sending dedicated health-check requests, the load balancer observes normal client traffic.

If it notices:

  • Too many timeouts
  • Connection failures
  • HTTP 500 errors

it marks the server as unhealthy.

Passive health checks are often used together with active health checks.

What happens when the server comes back online?

The load balancer does not immediately start sending traffic to the recovered server.

Instead, it performs health checks again.

Example:

Health Check 1

Health Check 2

Health Check 3

Health Check 4

Health Check 5

22. What happens to existing user requests when a server suddenly crashes?

If a server crashes while processing requests, those in-progress requests usually fail or time out. The load balancer detects the failure through health checks and stops sending new requests to that server. New requests are automatically routed to the remaining healthy servers.

Example: If Server B crashes while processing a payment request, that request may fail, but all new user requests will be redirected to Servers A and C.

23. Can a load balancer cache data?

A traditional load balancer's primary role is to distribute traffic, not cache data. However, some software load balancers like NGINX can also act as a reverse proxy and cache static content, reducing the load on backend servers.

Example: NGINX can cache images, CSS, and JavaScript files so repeated requests are served directly without reaching the web server.

24. Does every request always go through the load balancer?

In most production systems, yes. All external client requests first reach the load balancer, which then forwards them to backend servers. However, internal service-to-service communication may bypass the load balancer depending on the architecture.

Example: A user accessing Amazon.com first reaches the load balancer before the request is forwarded to a web server.

25. Why don't we put multiple load balancers in front of each other?

Using multiple load balancers in series increases latency, complexity, and cost. Instead, organizations deploy multiple load balancers in parallel using Active-Active or Active-Passive configurations for redundancy.

Example: Instead of Client → LB1 → LB2 → Server, companies deploy Client → DNS → LB1/LB2 → Servers.

26. What happens when a new server is added to the cluster?

The new server registers with the load balancer. After passing health checks, it is added to the server pool, and the load balancer starts routing requests to it.

Example: During a sale, two new servers are launched. After becoming healthy, they immediately begin handling incoming traffic.

27. How does a load balancer remove a server for maintenance without affecting users?

The load balancer marks the server as unavailable for new requests but allows existing requests to finish. Once all active connections complete, the server is safely removed for maintenance.

Example: If Server A is being updated, it finishes serving current users before stopping new connections.

28. Why is Round Robin not always the best algorithm?

Round Robin distributes requests equally without considering server load or capacity. If one server is slower or already busy, it may become overloaded while others remain underutilized.

Example: If Server A is processing long-running requests and Server B is idle, Round Robin still sends requests equally to both servers.

29. Why do we need both an API Gateway and a Load Balancer?

A load balancer distributes traffic across multiple servers, while an API Gateway manages API-specific tasks such as authentication, rate limiting, routing, and request transformation.

Example: The API Gateway authenticates the user, then forwards the request to the load balancer, which selects the appropriate backend server.

30. Why use a reverse proxy if you already have a load balancer?

A reverse proxy provides features like SSL termination, caching, compression, and security, while a load balancer focuses on distributing traffic. Many systems use both together.

Example: NGINX acts as a reverse proxy for SSL termination, while HAProxy distributes traffic across application servers.

31. Which load balancing algorithm would you choose and why?

The choice depends on the application. Round Robin is suitable for identical servers, Least Connections works well for variable workloads, Weighted Round Robin is ideal when servers have different capacities, and Source IP Hash is useful for session persistence.

Example: For an online gaming application with long-lived connections, Least Connections is often the best choice.

32. How many load balancers are typically used in a large-scale architecture like Netflix or Amazon?

Large-scale systems typically use multiple load balancers deployed across different layers and regions. They often have global load balancers that route users to the nearest data center and local load balancers that distribute traffic within each data center.

Example: Netflix uses multiple load balancers across regions to ensure scalability and high availability.

33. Can a load balancer distribute UDP traffic as well as TCP traffic?

Yes. Layer 4 load balancers can distribute both TCP and UDP traffic because they operate at the transport layer. Layer 7 load balancers mainly handle HTTP and HTTPS traffic.

Example: A multiplayer game using UDP can use a Layer 4 load balancer to distribute player connections.

34. What is Connection Draining (Graceful Shutdown), and why is it needed?

Connection Draining, also called Graceful Shutdown, allows existing client requests to complete before a server is removed from the load balancer. This prevents active user sessions from being interrupted.

Example: During deployment, Server A finishes serving current users before it is taken offline for an update.

35. What happens if one data center goes down?

A Global Load Balancer detects that the data center is unavailable and redirects traffic to another healthy data center. This ensures users continue to access the application with minimal downtime.

Example: If the Singapore data center becomes unavailable, users are automatically redirected to the Mumbai or Tokyo data center.

36. Why do we perform health checks every few seconds instead of every request?

Checking server health for every request would add unnecessary overhead and increase latency. Periodic health checks provide a balance between quickly detecting failures and maintaining high performance.

Example: A load balancer may perform health checks every 5 seconds instead of before every client request.

37. How does a load balancer avoid sending traffic to an overloaded server?

Dynamic load balancing algorithms such as Least Connections or Least Response Time monitor server load and route new requests to servers that are less busy. Some load balancers also use CPU, memory, or response time metrics.

Example: If Server A has 100 active connections and Server B has 20, the load balancer sends new requests to Server B until the load becomes balanced.

Comment

Explore