Layer 7 load balancing redirects traffic more intelligently by inspecting content to gain deeper context on the application request. This additional context allows the load balancer to not only optimize load balancing but to also rewrite content, perform security inspections and to implement access controls.

Layer 7 load balancing (or application layer load balancing) gets its name from the 7 Layer OSI model which places applications in the top layer.

Figure 1 - OSI 7 layer model and load balancing

Layer 4 load balancing is not application aware and focuses on items such as the source IP address of the client and application port numbers to determine where traffic is directed.

Approaches to load balancing

When load balancing a workload, there are many different methods that can be used to determine which server will service a request. The simplest approach is to do a ‘Round Robin’ where requests are forwarded to servers in the same way as dealing cards. This approach works well in some scenarios and is often enhanced by including additional metrics, such as relative server size (weighted round-robin), in the forwarding decision. However, round-robin has limitations – especially where a client session context needs to be maintained on the same server (persistence) or where servers are optimized for different aspects of the application.

Layer 7 Load Balancing Features

Persistence with Cookies

One of the main tasks of a load balancer is to maintain persistence – i.e. sending requests from a client to the same server so that application context can be maintained. With Layer 7 load balancing, persistence may be maintained by inspecting client and server generated cookies or by the load balancer inserting cookies into the traffic stream. Sending all requests from a client to a single server avoids having to synchronize back-end context across multiple servers.

Context Switching

Context switching allows a load balancer to direct traffic based on the content and context of a client request. For example, requests for images are redirected to an optimized image server whenever the load balancer detects a request for a .png or .gif file.

Content Rewriting

A layer 7 load balancer can rewrite requests and replies – a feature that can be used to achieve a number of outcomes including hiding internal URLs and supporting applications with hardcoded URLs.