Apache · Configuration and operations
How does load balancing work with mod_proxy_balancer?
Short answer
Define a balancer group, add BalancerMember entries and proxy to the balancer URL. Scheduling can be by requests, traffic or busy workers, and sticky sessions keep a client on one backend when the application requires it.
A balancer is a named group of backends. Apache chooses a member for each request according to the load-balancing method. Failed members are marked and retried after a configured interval, which gives basic failover without an external load balancer.
<Proxy balancer://appcluster>
BalancerMember http://10.0.0.11:8080 route=node1
BalancerMember http://10.0.0.12:8080 route=node2
ProxySet lbmethod=byrequests
</Proxy>
ProxyPass / balancer://appcluster/
ProxyPassReverse / balancer://appcluster/
<Location "/balancer-manager">
SetHandler balancer-manager
Require ip 10.0.0.0/8
</Location>Choosing a method
- byrequests: distributes by request count, the usual default
- bytraffic: weights by bytes transferred, useful for large downloads
- bybusyness: sends to the member with the fewest active workers
- heartbeat: uses a shared heartbeat file with mod_heartbeat and mod_heartmonitor
- stickysession: pins a client using a cookie or URL parameter when state is local
Prefer stateless backends and shared session storage over sticky sessions. Sticky sessions create uneven load and complicate failover because a member failure loses the pinned sessions unless the application can recover. If stickiness is required, set a clear cookie name and a failover policy.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What is the difference between byrequests and bybusyness?
- 2When do you need sticky sessions?
- 3How does Apache detect a failed backend?
- 4How do you drain a backend for maintenance?
Say it in the interview
I define a balancer group with BalancerMember entries and choose a scheduling method that matches the workload. byrequests is a sensible default, while bybusyness helps with uneven request cost. I prefer stateless backends over sticky sessions, and I protect balancer-manager. For maintenance I mark a member as drained rather than killing it abruptly.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Apache mock interview and get scored feedback on depth, clarity and confidence.