1. What is the difference between Layer 4 and Layer 7 load balancing?
Compare the two load-balancing boundaries for a cloud-hosted service. Cover the traffic unit each layer understands, available routing inputs, connection and TLS termination, health checking, protocol support, client-address visibility, connection reuse, failure behavior, and the workload characteristics that would make one layer preferable to the other.
At a high level, Layer 4 and Layer 7 load balancers make routing decisions using different information. The main challenge is choosing between simple connection-level routing and richer application-aware routing. I would compare two paths. Layer 4 routes TCP or UDP connections using transport details. Layer 7 understands HTTP or HTTPS requests and can route by host, path, headers, or cookies. Layer 7 gives more control, but it usually requires more processing.
The goal is to decide how incoming traffic should be spread across healthy backend services. The important difference is how much each load balancer understands about the traffic. Layer 4 mainly sees connection information. Layer 7 can understand application requests and make more detailed decisions. This choice affects routing, TLS handling, health checks, client IP visibility, connection reuse, and failure handling. I would explain the design by looking at Layer 4 first, then Layer 7, and finally choosing between them based on the workload.
- Does the service need TCP or UDP routing, or HTTP-aware routing?
- Do we need routing by host, URL path, headers, query values, or cookies?
- Where should TLS encryption be terminated?
- Does the backend need the original client IP address?
- Do we need application-level health checks or request retries?
Layer 4 works at the transport layer. It routes a TCP or UDP connection using information such as IP address, port, protocol, and sometimes source IP. It does not need to inspect the HTTP content inside the connection.
Layer 7 works at the application layer. It understands requests such as HTTP or HTTPS. It can route using the host, URL path, query values, headers, cookies, method, or other application content.
For Layer 4, the client creates a TCP or UDP connection. The Layer 4 Load Balancer chooses a healthy Backend Server or Service using connection information. A Layer 4 health check can test whether a TCP connection succeeds or whether a port is reachable.
TLS commonly passes through because the load balancer does not need to decrypt HTTP content. Client IP visibility depends on the implementation. Direct or transparent modes can preserve it. Proxy or NAT modes may need PROXY protocol or other metadata.
For Layer 7, the client sends an HTTP or HTTPS request. The Layer 7 Load Balancer understands the request and can make a more specific routing decision. For example, it can choose a backend using the host, path, query value, headers, or cookies.
It can terminate TLS, inspect the request, and encrypt traffic again before sending it to a backend. Its health checks can send HTTP or HTTPS requests and expect a specific status code or response. The backend socket usually sees the proxy address. The original client IP can be passed in trusted metadata such as X-Forwarded-For.
Layer 7 mainly handles application-aware protocols such as HTTP and HTTPS. Some implementations also support gRPC or WebSocket.
Layer 4 performs connection-level forwarding. It does not provide HTTP keep-alive, multiplexing, or request-pooling behavior itself. If a backend becomes unhealthy, new connections can be directed to another healthy backend. An already established connection may still fail and need the client to reconnect.
Layer 7 can reuse backend connections with keep-alive or connection pooling. It can also detect application-level failures. When configured safely, it may perform request-aware failover or retries.
Layer 4 fits simple routing, high connection volumes, non-HTTP workloads, and cases where low processing overhead matters. Layer 7 fits web applications, APIs, multi-tenant routing, content-based routing, and security policies. The main trade-off is simple connection routing versus richer application control. The choice should follow the protocol, routing needs, TLS design, client visibility, failure behavior, and workload requirements.
The benefit of Layer 4 is simplicity. It can route TCP or UDP connections without understanding the application data inside them. This usually means less processing and works well for non-HTTP traffic. The downside is limited routing control because it cannot choose a backend from a URL path, header, or cookie. Layer 7 gives richer routing and can handle TLS and application-level health checks. It can also reuse backend connections and react to application failures. The downside is more processing and more rules to manage. The right choice depends on what the workload actually needs.
Interviewers ask this question to see whether you understand where load-balancing decisions happen in the network stack. They want to know if you can connect protocol choice with routing, TLS handling, health checks, client IP visibility, connection reuse, failures, and workload needs. The important skill is not memorizing Layer 4 and Layer 7 definitions. It is explaining why one boundary fits a particular service better.






