← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

Load Balancer Types — L4 vs L7

Cloud Intermediate
debt(d7/e7/b7/t5)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The wrong load balancer type choice manifests as subtle operational issues: unexpected latency, missing client IPs, failed WebSocket connections, or inability to route by path. No linter or SAST tool flags 'you picked L4 when you needed L7.' Detection requires load testing, production traffic analysis, or careful architecture review.

e7 Effort Remediation debt — work required to fix once spotted

Closest to 'cross-cutting refactor across the codebase' (e7). Switching from L4 to L7 (or vice versa) mid-project typically requires: changing DNS/endpoints, reconfiguring TLS termination, updating backends to parse PROXY protocol or X-Forwarded-For headers, adjusting health checks, and potentially rearchitecting how services discover each other. It's not a one-line fix—it touches infrastructure-as-code, application config, and possibly application code.

b7 Burden Structural debt — long-term weight of choosing wrong

Closest to 'strong gravitational pull' (b7). The load balancer tier choice shapes how you handle TLS, session affinity, routing, client IP preservation, and observability. Every new service must conform to the chosen pattern. The common_mistakes list shows the cascading effects: sticky sessions, PROXY protocol, re-encryption to backends—all are constrained by this architectural decision. Not quite b9 (you can change it with significant effort), but it definitely shapes every change.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap' (t5). The misconception field explicitly states that developers assume 'L7 is strictly better than L4' when in fact L4 is the right choice for raw TCP workloads. This is a documented gotcha that experienced cloud architects learn, but it's not immediately obvious to developers new to load balancing. The assumption that 'higher layer = better' contradicts the reality that each tier serves different use cases.

About DEBT scoring →

Also Known As

Transport layer vs application layer load balancing L4 vs L7 load balancing Network load balancer vs application load balancer Layer 4 vs layer 7 routing

TL;DR

Layer-4 load balancers forward raw TCP/UDP packets based on IP and port; layer-7 load balancers terminate HTTP and route based on paths, headers and cookies — different trade-offs for different traffic.

Explanation

An L4 (transport-layer) load balancer operates at TCP/UDP: it sees source IP, destination IP, and ports, and forwards connections without inspecting their contents. This makes it fast, protocol-agnostic and cheap (AWS NLB, GCP TCP/UDP LB). An L7 (application-layer) load balancer terminates the application protocol — almost always HTTP(S) — so it can read URLs, headers, cookies and body content. That lets it do path-based routing, host-based routing, header-based A/B testing, sticky sessions by cookie, and request rewriting (AWS ALB, GCP HTTPS LB, Nginx, HAProxy in HTTP mode, Envoy). L7 is slower per packet and costs more, but unlocks the routing features modern microservices need. Service meshes add L7 sidecars on every pod, which is why a mesh's data plane needs careful tuning. Choosing between them is a question of: do you need protocol-aware routing, and can you afford to terminate TLS at the LB?

Watch Out

L7 load balancers terminate TLS, so they see plaintext headers and can route on them—but this means your backend never sees the client IP unless the LB adds an X-Forwarded-For header, and you must trust that header or an attacker can spoof it. L4 load balancers preserve the true client IP in the TCP connection itself, which is why some compliance frameworks prefer them.

Common Misconception

L7 is not strictly 'better' than L4 — for a raw-TCP workload like a database proxy or a gaming server, L4 is the right choice because it preserves the client IP cleanly and introduces no protocol overhead.

Why It Matters

Picking the wrong tier causes expensive rewrites: L4 cannot route /api vs /app to different services, and L7 adds latency and cost for workloads that do not need its features. TLS termination, client-IP preservation (PROXY protocol / X-Forwarded-For), and WebSocket support all hinge on the choice.

Common Mistakes

  • Assuming L4 load balancers can read HTTP headers or route by URL path, then discovering too late that connection-level routing doesn't work for microservices.
  • Deploying L7 load balancers in front of every service in a mesh without realizing the TLS termination overhead compounds when sidecars also terminate TLS, creating double encryption cost.
  • Choosing L4 for 'performance' without measuring actual latency impact, then finding that lack of sticky-session routing by cookie causes session thrashing in stateful workloads.
  • Using L7 routing rules (path-based, header-based) without validating that backend services actually respect the Host header or X-Forwarded-For header needed for request context.

Avoid When

  • Mixing them without a clear boundary — if you need both, terminate L7 behind an L4 tier, not the other way around.

When To Use

  • L7 — HTTP-based microservices needing path/host routing, sticky sessions by cookie, or centralised TLS termination.
  • L4 — pure TCP/UDP workloads, very high throughput with minimal CPU, or preserving the exact client connection to the backend.

Added 18 Apr 2026
Edited 19 Aug 2026
Views 118
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings S 0 pings M 1 ping T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 3 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 1 ping F 2 pings S 0 pings S 0 pings M
No pings yet today
No pings yesterday
SEMrush 10 Google 9 Bing 8 PetalBot 8 Ahrefs 7 ChatGPT 6 Perplexity 4 Claude 4 Amazonbot 3 Meta AI 2 Scrapy 2 Brave Search 2 Applebot 2 Twitter/X 1
crawler 63 crawler_json 5
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
Cloud cloud The cloud refers to remote servers accessed over the internet that store data, run applications, and provide computing power instead of using your local machine.

Almost every modern application relies on cloud infrastructure. Understanding the cloud helps you deploy apps, manage costs, and build systems that can handle real-world traffic without buying physical hardware.

💡 Think of the cloud as renting computers by the hour — you pay for what you use, so always turn off what you're not using.

Ask Codex about Cloud →
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: Medium
⚡ Quick Fix
Rule of thumb: HTTPS/gRPC with routing needs → L7 (ALB, Envoy). Raw TCP/UDP or huge throughput → L4 (NLB).
🔗 Prerequisites


✓ schema.org compliant