Load Balancer
- In Turkish
- Yük Dengeleyici
In short
A load balancer is a server or service that spreads incoming traffic across several backend servers so no single one is overloaded and the app stays available.
What is a load balancer?
A load balancer sits in front of a group of servers and decides which one should handle each incoming request. By spreading the work, it lets an application serve more users than any single server could, and it keeps the application available when one server fails or is taken down for maintenance.
Load balancers choose a server using an algorithm such as round robin (each server in turn), least connections (the least busy server), or a hash of the client's IP address, so the same user keeps reaching the same server. They also run health checks, sending regular test requests to every backend and automatically removing any server that stops responding. A layer 4 load balancer routes traffic using only IP addresses and ports, while a layer 7 load balancer understands HTTP and can route by URL path, headers, or cookies.
Picture a supermarket with several checkout lanes and an employee directing each shopper to the shortest line; if a lane closes, shoppers are simply sent to the others. Load balancers can be dedicated hardware appliances, software such as NGINX, HAProxy, and Envoy, or managed services from cloud providers. In Kubernetes, a Service of type LoadBalancer asks the platform to create one in front of your pods.
Load balancers are often confused with reverse proxies. A reverse proxy is any server that receives requests on behalf of backend servers, and spreading those requests across several backends is one job it can do, so tools like NGINX often play both roles at once. However, some load balancers work only at the network level and forward connections without reading the HTTP requests inside them.
At a glance
Key takeaways
- A load balancer distributes requests across multiple servers.
- Health checks automatically take failing servers out of rotation.
- Common algorithms include round robin, least connections, and IP hash.
- Layer 4 balancing uses IP addresses and ports; layer 7 understands HTTP.
- Load balancing enables horizontal scaling and high availability.
Example
# The pool of backend servers that share the traffic
upstream app_servers {
least_conn; # send each request to the least busy server
server 10.0.0.11:3000;
server 10.0.0.12:3000;
server 10.0.0.13:3000;
}
server {
listen 80;
location / {
proxy_pass http://app_servers;
}
}Readers ask
What is the difference between a load balancer and a reverse proxy?
A reverse proxy accepts client requests and forwards them to backend servers, often adding caching, compression, or TLS termination. A load balancer focuses on spreading traffic across several backends; many reverse proxies can load balance, and many load balancers act as reverse proxies.
What is a sticky session?
A sticky session, or session affinity, means the load balancer sends all requests from the same user to the same backend server, usually based on a cookie or the client's IP address. It helps when servers keep session data in memory, but storing sessions in a shared cache or database scales better.
What happens if the load balancer itself fails?
A single load balancer can become a single point of failure, so production setups usually run two or more of them, with a shared floating IP address or DNS records that point to the healthy ones. Managed cloud load balancers handle this redundancy automatically.
Often compared
- Reverse Proxy vs Load BalancerA reverse proxy forwards requests to the servers behind it and adds TLS, caching and security, while a load balancer spreads load so no server is overloaded.
- API Gateway vs Load BalancerA load balancer spreads traffic across copies of one service, while an API gateway is one front door that routes calls to the right service and checks auth.
See also
- Reverse ProxyDevOps & Cloud, p. 44A reverse proxy is a server that sits in front of web servers, accepts client requests on their behalf, and forwards each request to the right backend server.
- API GatewayBackend & APIs, p. 3An API gateway is a server that sits in front of a group of backend services and acts as the single entry point that receives, checks, and routes API requests.
- KubernetesDevOps & Cloud, p. 32Kubernetes is an open-source system that automates deploying, scaling, and managing containerized applications across a cluster of machines.
- MicroservicesSoftware Architecture, p. 27Microservices are an architectural style where an application is split into small, independently deployable services that communicate over a network.
- DNSDevOps & Cloud, p. 16DNS is the internet's naming system that translates human-readable domain names like example.com into the numeric IP addresses computers use to connect.
- Horizontal ScalingSoftware Architecture, p. 23Horizontal scaling (scaling out) increases a system's capacity by adding machines and spreading the work across them, rather than making one machine bigger.
- Consistent HashingSoftware Architecture, p. 9Consistent hashing spreads keys across a changing set of servers so that adding or removing a server moves only a small share of the keys.
Spotted a mistake or something missing on this page?Suggest an edit