5-min deep dive

Load balancing in depth: session persistence, L4 vs. L7 and redundancy

A load balancer isn’t just a device that hands things out in turn. You use it with logged-in users, content-based routing, and even its own failure in mind.

Reading time: about 5 min

← Start with the 1-min version

In the game, this was a supermarket checkoutPlay “Checkout Line Captain”

In the gameIn real IT
ShoppersAccess (requests)
Checkouts 1–3Three web servers
Slow trainee’s checkoutA weaker server
“Closed” signA failure found by a health check
Flash saleTraffic spike
Line captainLoad balancer

Comparing distribution methods

MethodHow it hands outGood for
Round robinOne at a time, in turnServers with equal performance and requests of similar weight
WeightingChanges the share to match performanceA mix of new and old servers
Least connectionsTo whichever has the fewest in progressWhen processing time varies from request to request

In the game “Checkout Line Captain,” the trainee’s checkout 3 got swamped fast when it got as many shoppers as the others, because the split ignored the difference in speed.

Session persistence

On an online shop, if you’re sent to a different server after adding items to your cart, the cart can appear empty. So you use session persistence, which keeps sending requests from the same person to the same server.

It can recognize users by source IP address or by a browser cookie. But since traffic tends to pile up on particular servers, systems are often designed so that session data is shared across all servers instead.

L4 and L7 load balancers

A load balancer that routes by looking only at IP addresses and port numbers is called L4 (transport layer); one that also looks at the URL and HTTP headers is called L7 (application layer).

With L7 you can route like “send /images/ to the image servers and /api/ to the API servers.” SSL offload, where the load balancer decrypts HTTPS to lighten the load on the servers behind it, is also common.

Make the load balancer itself redundant

No matter how many servers you line up, if there’s only one load balancer, everything stops when it breaks. A place like this is called a single point of failure.

So you prepare two load balancers too, in an active-standby setup: normally one runs, and if it breaks, the other takes over.

Field note: take a server out of rotation before working on it

Before restarting or patching a server, first remove it from rotation on the load balancer and wait for in-progress requests to finish. If you stop it abruptly, users get error screens.

If the health-check interval is long, the load balancer keeps sending traffic to a broken server for the seconds to tens of seconds it takes to notice. Set the interval and how many failures before removal to suit the service.

Practice questions

Four-choice questions in the style of Japan’s IT Passport and Fundamental Information Technology Engineer exams. Tap below to see the answer.

Q1Which best describes the role of a load balancer?

  • AEncrypts traffic to prevent eavesdropping
  • BDistributes processing across several servers to spread the load
  • CAssigns IP addresses automatically
  • DConverts domain names into IP addresses
Show the answer and explanation

Answer: BA load balancer spreads requests across several servers so no single server gets overloaded.

Q2What is the purpose of a load balancer’s health check?

  • ATo check users’ health
  • BTo remove failed servers from rotation
  • CTo remove viruses from servers
  • DTo predict peak traffic hours
Show the answer and explanation

Answer: BBy finding servers that don’t answer the health check and removing them from rotation, the service keeps running.

Q3Which correctly describes scaling out?

  • ARaising capacity by adding CPU and memory to a server
  • BRaising capacity by adding more servers
  • CShutting down unused servers to save power
  • DStoring data split across several disks
Show the answer and explanation

Answer: BScaling out means adding servers; scaling up means making one server more powerful.

Summary
  • Use weighting when performance differs, least connections when processing time varies
  • Send logged-in users to the same server with session persistence
  • Make the load balancer itself redundant to remove the single point of failure