Explained step by step
A load balancer can work at 2 layers of the OSI model. The layer 4 (transport) one only looks at network data, like the IP and the port: it's fast, but it doesn't know what's being asked. The layer 7 (application) one reads the whole request, for example the URL /videos/42, and can decide based on the content. It's like a mail carrier who only reads the address on the envelope (layer 4) versus one who opens the letter to see what it's about (layer 7).
A layer 7 load balancer can split work 3 ways depending on what it looks at. Host-based: it looks at the requested name, and sends blog.example.com to some servers and shop.example.com to others. Path-based: it looks at the whole URL, and sends /api to some and /images to others. Content-based: it looks inside the message, for example the value of a parameter like country=uy. It's like a front desk that sends you to a floor based on the company, the department or the errand.
There are 3 kinds of load balancer. A software one is a program you install or rent in the cloud: cheap, flexible and easy to change, though it needs configuring. A hardware one is a physical device you own: it handles huge traffic, but it's expensive, closed, and its built-in program needs updating. A DNS one splits traffic by giving different IPs for the same domain. It's like choosing between a queue app, a ticket machine or a sign on the door.
DNS load balancing sets up a domain to return several IPs, so each user ends up on a different server. It's cheap and simple, but it has a serious problem: DNS doesn't check whether servers are alive. If 1 of 3 servers goes down, DNS keeps handing out its IP, and 1 of every 3 users reaches a dead machine. It's like a guide that keeps listing a restaurant that closed.
A single point of failure is a piece that, if it breaks, brings down the whole system. If you put 10 servers behind just 1 load balancer, that load balancer is the single point of failure: it goes down and all 10 servers become unreachable. It's like a single bridge to an island. The fix is to have 2 or more load balancers: one active and another passive waiting, which takes over if the first fails.
A health check is a question the load balancer asks each server every few seconds, like 'are you alive?'. If a server doesn't answer or takes too long, the load balancer removes it from the list and stops sending it requests. It's like a supervisor who walks past each checkout every 10 seconds and closes any without a cashier. When the server answers properly again, it goes back on the list.
Sticky sessions make the same user always go to the same server, so that server keeps their data, like the shopping cart. It's like always getting the same waiter at a restaurant: they already know what you ordered. Load balancers usually bring more features: autoscaling (turning servers on and off according to demand), encryption, compression, caching, logging each request and redirects. But careful: if that server goes down, the user loses what was stored there.