Load Balancing Explained: L4, L7, Health Checks, and Failover

Serdar Tekin
Serdar Tekin
Co-Founder & CTO
Updated Nov 17, 202616 min read
Written for: Developers, founders, and platform teams deciding when and how to move from one application server to a multi-node traffic-distribution architecture.
Load BalancingNetworkingHigh AvailabilityScalingCloud Architecture
Last reviewed:
Guide
Load Balancing Explained: L4, L7, Health Checks, and Failover
rafftechnologies.com/learn
On this page

Key Takeaways

Add load balancing only after backends are interchangeable. Choose L4/L7 by protocol, use readiness checks and draining, keep spare failure capacity, and verify managed product availability before depending on it.

Run your app across several servers on a private network.

  1. 1Pick a Linux imageUbuntu, Debian and more, with your SSH key added.
  2. 2Choose a sizeFrom $4.99 a month. Resize when your app grows.
  3. 3Connect over SSHYour server is up in about 55 seconds.

Ubuntu, Debian and other Linux distributions with full root and SSH access, up and running in about 55 seconds.

Load balancing distributes requests or connections across multiple backend servers so one application node does not define the workload's capacity, availability, deployment safety, or maintenance window.

Use load balancing when the application can run across interchangeable backends and one server has become an unacceptable capacity or failure boundary. Do not add it merely because a multi-server architecture looks more advanced.

For Raff Technologies workloads, the safer current design assumption is to treat load balancing as an architecture pattern, not as a dependency on a Raff-managed Load Balancer product. Raff's dedicated Load Balancer page is not currently treated as a generally available production dependency in this guide. Build the application so the traffic layer can be managed or self-operated, and verify current product availability before relying on a managed service.

Load balancing architecture diagram showing user traffic distributed through a load balancer to multiple application servers and a private database.

Load balancing: quick answer

A load-balanced application usually looks like this:

Text
Internet ↓ Traffic-distribution layer ↓ App VM 1 App VM 2 App VM 3 ↓ private network Database / cache / queue

Before adding the traffic layer, verify four things:

  1. Any healthy backend can serve the next request.
  2. Sessions, uploads, and durable state are not trapped on one VM.
  3. The remaining fleet can absorb traffic after one backend fails.
  4. Health checks can distinguish a ready backend from one that should not receive traffic.

If any of these are false, fix the application or dependency model first.

When should you add a load balancer?

A load balancer becomes useful when one application server is the wrong boundary for the workload.

Common triggers are:

  • one VM cannot safely handle expected peak traffic;
  • one VM failure creates unacceptable downtime;
  • deployments should happen without taking the whole application offline;
  • maintenance should not require a complete outage;
  • several interchangeable application nodes are already available;
  • HTTP hostnames, paths, or protocols need different backend pools.

Do not use a load balancer to hide a different bottleneck.

Measured problemBetter first move
One VM is CPU- or RAM-constrainedOptimize or resize the VM
Database latency dominatesTune or scale the database
Sessions/files are localExternalize state first
One-node failure is unacceptableAdd redundant backends + traffic distribution
Deployments interrupt usersAdd multiple backends + draining/readiness
Traffic is low and predictableKeep the simpler single-node design

Use Horizontal vs Vertical Scaling if the main question is whether to scale up or scale out. If the measured issue is wasted or insufficient capacity on an existing VM, use Right-Sizing Cloud Servers before introducing a multi-node traffic layer.

L4 vs L7 load balancing

Layer 4 load balancing distributes transport connections using information such as IP addresses, ports, and protocols. Layer 7 load balancing understands application-layer requests, usually HTTP/HTTPS, and can route using attributes such as hostname, path, headers, cookies, or methods.

CapabilityLayer 4Layer 7
Typical trafficTCP, UDP, TLS passthroughHTTP, HTTPS
Routing basisIP, port, protocol, connectionHost, path, header, method, cookie
Application awarenessLimitedHigh
Typical fitCustom TCP services, passthrough, low-level connection routingWebsites, APIs, path/host routing
TLS behaviorPassthrough or termination depending on implementationCommonly termination or re-encryption

Choose L4 when the traffic layer should distribute connections without interpreting the application request.

Choose L7 when routing depends on HTTP behavior or when the edge should terminate TLS and make application-aware decisions.

L4 vs L7 is not a performance shortcut

The correct choice follows protocol and routing requirements. A simpler Layer 4 design may be appropriate for raw TCP. A Layer 7 design may be necessary when /api, /admin, and different hostnames need different backends.

The layer alone does not make the architecture more available. Health checks, state handling, spare capacity, and dependency resilience still determine failure behavior.

Load balancer health checks: liveness is not readiness

A load balancer should send new traffic only to a backend that is ready to serve production requests.

A successful TCP connection only proves that a port accepted a connection. It does not prove that the application can complete useful work.

Check typeWhat it answers
LivenessIs the process running or recoverable?
ReadinessCan this instance accept new production traffic?
Dependency checkAre required downstream systems available?
Synthetic checkCan a representative workflow complete?

A good readiness endpoint should be:

  • fast;
  • deterministic;
  • inexpensive;
  • strict enough to remove a broken node;
  • not dependent on every optional external service.

A poor health check can create an outage by removing healthy nodes or keeping unusable nodes in rotation.

What should happen when all backends are unhealthy?

This is one of the most important load-balancing failure modes to test.

Depending on the traffic layer and configuration, all-unhealthy behavior may return errors, stop forwarding traffic, or fall back to implementation-specific behavior.

Do not assume the answer. Verify the behavior before production and include it in the incident runbook.

A bad health-check deployment should not be able to surprise the team with a completely unknown failure mode.

Moving clients between public endpoints with DNS is a different failure boundary. DNS for Cloud Applications explains why cached answers and existing connections make DNS failover different from removing an unhealthy backend from a load-balancer pool.

Connection draining protects in-flight requests

Connection draining stops new traffic from reaching a backend while existing requests or connections are allowed to finish before the node is stopped, updated, or removed.

A safe sequence is:

  1. Mark the backend unavailable for new traffic.
  2. Allow routing state to propagate.
  3. Let active requests or connections finish.
  4. Stop the application or worker safely.
  5. Deploy, maintain, or terminate the node.
  6. Return it only after readiness succeeds.

The drain period should match real workload behavior. A short API request, large upload, streaming response, and long-lived WebSocket connection do not have the same lifecycle.

Failover requires spare capacity

A two-node application is not automatically highly available.

If each backend is already serving close to its maximum safe load, losing one node can simply move the outage to the remaining node.

Plan headroom for:

  • one-backend failure;
  • maintenance overlap;
  • rolling deployments;
  • cache warm-up;
  • connection redistribution;
  • temporary traffic spikes.

A useful test is simple:

Remove one backend during representative load and verify that latency and error rates stay within acceptable limits.

High availability is a capacity decision as well as a routing decision.

Sticky sessions do not make an application stateless

Sticky sessions keep a user or connection tied to a particular backend.

They can help legacy applications during a transition, but they preserve dependence on that node and can create uneven traffic.

Prefer external/shared state where appropriate:

Local dependencyBetter shared pattern
In-memory sessionShared session store or suitable token design
User uploadsObject storage or approved shared storage
Durable filesExternal authoritative storage
Background jobsShared queue with retry/ownership rules
CacheShared/distributed cache with defined loss behavior
Local databaseSeparate database service or VM

Read Stateful vs Stateless Applications before adding interchangeable application replicas.

Load balancing application servers can expose the next bottleneck

Adding more application servers often increases pressure elsewhere.

Expect more:

  • database connections;
  • concurrent queries;
  • lock contention;
  • cache misses;
  • queue consumers;
  • outbound API calls;
  • object-storage operations.

A faster application tier can move the bottleneck into the database or another shared service.

Measure the entire request path rather than treating backend count as the primary performance metric.

TLS termination changes the trust boundary

Common TLS patterns include:

PatternTraffic path
TerminationHTTPS to traffic layer, HTTP to protected backend
Re-encryptionHTTPS to traffic layer, HTTPS to backend
PassthroughEncrypted connection forwarded to backend

Layer 7 routing commonly uses TLS termination so the traffic layer can inspect HTTP requests. Re-encryption protects the backend path. Passthrough keeps TLS termination at the application but limits application-aware routing at the edge.

If TLS terminates before the application, configure trusted proxy headers carefully. The backend should trust forwarding headers only from the expected proxy/traffic layer, not from arbitrary clients.

Backends should normally use private networking

The public traffic layer should not require every backend VM to expose its application port to the internet.

A cleaner pattern is:

Text
Internet ↓ Traffic-distribution layer ↓ private network App VM 1 App VM 2 ↓ private network Database / cache / queue

Use Raff VPC for private communication between Raff workloads. Current Raff VPC traffic is private and unmetered, with no separate VPC charge.

Restrict backend ports to the sources that actually need them. Private reachability does not replace authentication or firewall policy.

Use VPC Architecture for Multi-VM Applications for the private-network design.

Reverse proxy vs load balancer

A reverse proxy is an entry point that forwards client requests to backend services. A load balancer is a traffic-distribution role that spreads traffic across multiple backends.

The same software can often perform both jobs, but the architecture question is different.

  • One backend behind Nginx can still be a reverse-proxy architecture without load balancing.
  • Several interchangeable backends behind a traffic layer is load balancing.

Use Reverse Proxy vs Load Balancer when deciding whether the workload actually needs a backend pool.

Rolling deployments depend on draining and version compatibility

A basic rolling deployment can follow this sequence:

  1. Drain one backend.
  2. Deploy the new version.
  3. Wait for readiness.
  4. Return the backend to traffic.
  5. Continue to the next node.

During the rollout, old and new application versions may run at the same time.

Keep compatibility in:

  • database schemas;
  • session formats;
  • queue messages;
  • cache keys;
  • APIs;
  • background jobs.

Use Blue-Green vs Rolling Deployments for the release-strategy decision.

Align timeouts and retries across the request path

A request may cross a client, CDN, traffic layer, reverse proxy, application server, database, and external API.

Each layer can have its own:

  • connect timeout;
  • request timeout;
  • response timeout;
  • idle timeout;
  • retry policy.

Document which layer should fail first. Avoid retries at several layers that multiply traffic during an incident.

Do not automatically retry non-idempotent actions such as payment or order creation unless the application has an idempotency design.

Monitor the traffic layer and application separately

Useful load-balancing metrics include:

  • request or connection rate;
  • p50/p95/p99 latency;
  • frontend and backend error rates;
  • healthy/unhealthy backend count;
  • health-check failure reasons;
  • active connections;
  • timeout/reset counts;
  • distribution by backend;
  • draining duration.

Also monitor:

  • backend CPU and memory;
  • database connections and latency;
  • cache hit/miss behavior;
  • queue depth;
  • external dependency errors.

A healthy traffic layer can forward requests to an application that is returning logical errors. A failed health check may be caused by routing, firewall, TLS, timeout, or application problems.

How to design a load-balanced architecture on Raff today

A current Raff architecture can use the live building blocks around the traffic layer without assuming that Raff's managed Load Balancer is generally available.

A practical growth path is:

Text
Stage 1 One Raff VM Application + reverse proxy Stage 2 Resize if CPU/RAM is the measured limit Stage 3 Multiple interchangeable Raff VMs Traffic-distribution layer Raff VPC Separate database / managed database Stage 4 Health checks + draining + monitoring Object storage/shared state Data Protection + tested recovery

Relevant live Raff products include:

Raff's managed Load Balancers product page currently says Coming Soon. It is not a production-available managed dependency for this design; use a self-operated or separately available traffic layer where needed, and recheck the product page before planning a managed rollout.

Build interchangeable application backends first, then add the traffic-distribution layer that fits your protocol, availability, and deployment requirements.

Load-balancing readiness checklist

Architecture

  • The reason for adding load balancing is documented.
  • Any healthy backend can serve the next request.
  • Sessions, uploads, and jobs are externalized where required.
  • Database/dependency headroom is measured.

Routing and security

  • L4 or L7 behavior matches the protocol.
  • TLS termination/re-encryption/passthrough is defined.
  • Backend ports are not broadly public.
  • Forwarding headers are trusted only from approved sources.

Health and lifecycle

  • Readiness checks represent real serving ability.
  • All-backends-unhealthy behavior is known.
  • Draining is tested with real request durations.
  • New-node warm-up behavior is understood.

Failure and operations

  • Remaining nodes can absorb one-backend failure.
  • Timeouts and retries are aligned.
  • Rolling deployments preserve compatibility.
  • Routing health and application health are monitored separately.
  • Database, storage, DNS, and external dependencies have their own recovery plans.

Frequently asked questions

What is load balancing?

Load balancing distributes requests or connections across multiple backend servers so one node does not define the application's capacity, availability, deployment, or maintenance behavior.

When should a small team add a load balancer?

Add one when a single server is an unacceptable capacity or failure boundary and the application can run safely across multiple interchangeable backends.

What is the difference between L4 and L7 load balancing?

Layer 4 routes transport connections using IP, port, and protocol information. Layer 7 understands HTTP/HTTPS requests and can route by hostnames, paths, headers, cookies, and other application attributes.

What should a load balancer health check test?

It should confirm that a backend is ready to receive meaningful production traffic, not merely that a process or port is open.

What is connection draining?

Connection draining stops new traffic from reaching a backend while existing requests or connections are allowed to finish before deployment, maintenance, scale-in, or removal.

Does load balancing automatically provide high availability?

No. The remaining backends must have spare capacity after a failure, application state must be portable, and shared dependencies such as databases, storage, DNS, and networking must also remain available.

What is load balancer failover?

Load balancer failover is the process of routing traffic away from an unhealthy backend to remaining healthy capacity. It works only when health detection is accurate and the surviving fleet has enough capacity.

Do sticky sessions make an application stateless?

No. Sticky sessions preserve backend affinity and can help legacy systems temporarily, but the user still depends on the selected backend.

Should load-balanced backend VMs be public?

Usually not. Put backend application nodes on private paths and expose only the traffic layer or required public edge. Restrict backend ports to approved sources.

Does Raff currently provide a managed Load Balancer I should depend on?

This guide does not assume general availability of Raff's managed Load Balancer. Verify the current product status before using it as a production dependency; Raff VM, VPC, Security, Object Storage, Managed Databases, and Data Protection remain available building blocks around the traffic layer.

Conclusion

Load balancing is useful when one application server should no longer define capacity, failure behavior, deployment safety, or maintenance.

Choose L4 or L7 according to protocol and routing requirements. Build meaningful readiness checks, externalize state, preserve spare failure capacity, drain nodes safely, align retries and timeouts, and keep backend traffic private where practical.

Most importantly, make the application ready for multiple interchangeable nodes before adding the traffic-distribution layer.

Sources

Was this article helpful?
Serdar Tekin
Serdar Tekin
Co-Founder & CTO

Co-Founder & CTO at Raff, focused on cloud infrastructure, systems architecture, security, reliability, and production operations.

Run your app across several servers on a private network.

Ubuntu, Debian and other Linux distributions with full root and SSH access, up and running in about 55 seconds.

14-day money-back guarantee

Frequently asked questions

What is load balancing?
Load balancing distributes requests or connections across multiple backend servers so one node does not define the application's capacity, availability, deployment, or maintenance behavior.
When should a small team add a load balancer?
Add one when a single server is an unacceptable capacity or failure boundary and the application can run safely across multiple interchangeable backends.
What is the difference between L4 and L7 load balancing?
Layer 4 routes transport connections using IP, port, and protocol information. Layer 7 understands HTTP/HTTPS requests and can route by hostnames, paths, headers, cookies, and other application attributes.
What should a load balancer health check test?
It should confirm that a backend is ready to receive meaningful production traffic, not merely that a process or port is open.
What is connection draining?
Connection draining stops new traffic from reaching a backend while existing requests or connections are allowed to finish before deployment, maintenance, scale-in, or removal.
Does load balancing automatically provide high availability?
No. The remaining backends must have spare capacity after a failure, application state must be portable, and shared dependencies such as databases, storage, DNS, and networking must also remain available.
What is load balancer failover?
Load balancer failover is the process of routing traffic away from an unhealthy backend to remaining healthy capacity. It works only when health detection is accurate and the surviving fleet has enough capacity.
Do sticky sessions make an application stateless?
No. Sticky sessions preserve backend affinity and can help legacy systems temporarily, but the user still depends on the selected backend.
Should load-balanced backend VMs be public?
Usually not. Put backend application nodes on private paths and expose only the traffic layer or required public edge. Restrict backend ports to approved sources.
Does Raff currently provide a managed Load Balancer I should depend on?
This guide does not assume general availability of Raff's managed Load Balancer. Verify the current product status before using it as a production dependency; Raff VM, VPC, Security, Object Storage, Managed Databases, and Data Protection remain available building blocks around the traffic layer.