Skip to main content

Routing, Load Balancing, and Congestion

1. Executive Summary​

IP routing determines which path packets take across autonomous systems — from host default gateways to BGP (Border Gateway Protocol) exchanging reachability between ISPs and data centers. Load balancers distribute traffic across backends at Layer 4 (connection) or Layer 7 (HTTP). TCP congestion control algorithms adjust send rates when the network signals overload — affecting throughput and fairness for every large transfer and many RPC workloads.

This chapter connects global routing (anycast, health-based DNS), data-center load balancing (round-robin, least connections, consistent hashing), and congestion control evolution (Reno, CUBIC, BBR) to architecture decisions for multi-region systems, failover, and capacity planning.

Key takeaway: Traffic reaches your service through routing and balancing decisions at multiple layers — each with failure modes, capacity limits, and consistency implications.


2. Why This Topic Matters​

Principal architects design:

  • Multi-region failover with BGP or DNS?
  • L4 vs L7 load balancing for gRPC?
  • Why did cross-AZ traffic spike costs?
  • How congestion control affects bulk replication lag?

Links Multi-Region Architecture, Partial Failure, and Quorum Systems.


3. Problems Being Solved​

ProblemSolution layer
ReachabilityIP routing, BGP
Scale-outLoad balancers, anycast
FailoverHealth checks, route withdrawal, DNS
OverloadCongestion control, admission control
StickinessSession affinity, consistent hashing

4. Assumptions and System Model​

  • Internet routing is policy-driven and approximate — not guaranteed optimal or stable at all times.
  • Data-center typically uses ECMP, overlay networks (VXLAN), and hardware or software LBs.
  • TCP congestion control is end-to-end; middleboxes may shape or buffer.
  • Health checks imply asynchronous failure detection — delayed failover is normal.

5. Essential Terminology​

TermDefinition
BGPInter-domain routing protocol exchanging path vectors
ASNAutonomous System Number
AnycastSame IP announced from multiple locations; route to nearest
L4 LBDistributes based on IP/port (TCP/UDP)
L7 LBRoutes based on HTTP headers, paths, cookies
ECMPEqual-cost multipath — hash flows across links
Consistent hashingMinimal key redistribution when nodes change
CWNDCongestion window — sender's allowed in-flight data
RTT fairnessFlows with longer RTT get lower throughput under some CCAs
BufferbloatExcessive queueing delay in buffers
SYN proxyLB completes handshake on behalf of backends

6. Core Mechanism​

Multi-layer traffic path:

TCP congestion window (conceptual):

Explanation: Senders increase CWND until loss or ECN indicates congestion, then decrease — probing available bandwidth. Bufferbloat inflates RTT when queues are oversized, hurting interactive traffic sharing the path.


7. Step-by-Step Walkthrough​

User request to globally distributed API:

Step 1 — DNS returns geo-proximate anycast IP or regional alias (Route 53 latency routing).

Step 2 — BGP routes packets to nearest POP announcing that prefix.

Step 3 — L7 LB terminates TLS, routes /v1/orders to order service pool by path rule.

Step 4 — L4 / kube-proxy / service mesh picks pod via consistent hash on order_id for affinity.

Step 5 — TCP flow subject to CUBIC or BBR on path; cross-region replication bulk transfer competes for bandwidth.

Step 6 — Backend failure. Health check fails; LB drains connections; BGP or DNS may shift traffic regionally — bounded by TTL and propagation delay.


8. Invariants and Guarantees​

LayerTypical guarantee
BGPConvergence to new routes after withdrawal (time varies)
LBDistributes per algorithm; not strict global fairness
TCP CCAvoids collapse; fairness properties algorithm-dependent

Not guaranteed: Instant failover; equal share across tenants without isolation; zero cross-AZ cost.


9. Failure Scenarios​

Scenario 1: BGP Misconfiguration / Hijack​

Wrong prefix announced; traffic diverted.

Mitigation: RPKI where supported, prefix monitoring, multi-homing, MANRS practices.

Scenario 2: LB Health Check Flapping​

Backends oscillate in/out of pool; connection resets.

Mitigation: Hysteresis on health checks, outlier detection, graceful drain.

Scenario 3: Thundering Herd on Cold Cache​

Failover shifts 100% traffic to standby region; overload.

Mitigation: Pre-warmed capacity, gradual shift, request shedding, cache priming.

Scenario 4: Bufferbloat During Bulk Copy​

Replication saturates link; user-facing RPC latency spikes.

Mitigation: QoS, separate networks, pacing, BBR vs CUBIC evaluation on path.

Explanation: L4 distributes connections without parsing HTTP — fast, protocol-agnostic. L7 inspects requests for path/host routing, TLS SNI, and WAF — more CPU, richer policy.

Extended Deep Dive: Anycast vs GeoDNS Tradeoff Table​

MechanismFailover speedClient precisionComplexity
AnycastFast (BGP convergence)Nearest POP to resolver pathBGP ops
GeoDNSTTL-boundResolver location proxyDNS provider
Latency routingPolicy-basedMeasured probesVendor lock-in

Hybrid common: anycast at edge, regional origins behind GeoDNS.

Extended Deep Dive: Congestion Collapse​

When retransmits flood network, effective throughput collapses — classic 1986 Internet event. Modern TCP CC prevents worst cases but retry storms at application layer recreate analogous collapse — see Partial Failure. Network and application congestion control both required.

Extended Deep Dive: Equal-Cost Multipath Hash Polarization​

ECMP hashes flow 5-tuple to link. If hash entropy low (same src/dst across flows), links underutilized. Resilient ECMP or entropy labels in MPLS/segment routing mitigate in carrier networks — awareness helps when diagnosing uneven link utilization in hybrid WAN.


10. Performance Characteristics​

Routing convergence after failure: seconds to minutes depending on BGP timers and provider — not milliseconds.

LB adds small latency (TLS termination dominates for HTTPS).

Congestion control affects goodput — useful throughput after retransmits.

Cross-AZ latency is floor-bound by physics; architect to minimize chatty cross-zone calls.


11. Scalability Limits​

  • LB connection table size and new connections/sec.
  • ECMP hash polarization if entropy poor.
  • BGP table size on routers (internet-scale concern).
  • Consistent hash ring rebalance on membership change.

12. Operational Considerations​

Runbooks: regional failover, LB misroute, DDoS absorption, path MTU issues.

Monitor: BGP session state (if applicable), LB healthy host count, SYN rate, ECN marks, inter-AZ bytes.

Game days: DNS failover drill, single-AZ withdrawal.


13. Security Considerations​

L7 WAF at edge; rate limiting against DDoS.

BGP security (RPKI) against hijack.

Internal LB segmentation — east-west policy in mesh.


14. Cost Considerations​

Cross-AZ and cross-region transfer often billed per GB — architecture dominates network tax.

Anycast and CDN reduce origin load but add service fees.

Over-provisioned standby regions cost idle capacity — weighed against RTO/RPO.


15. Production Implementations​

SystemPattern
AWS ALB/NLBL7 vs L4 tradeoffs
GCP Cloud Load BalancingGlobal anycast frontends
EnvoyL7 routing, outlier detection, retry budgets
Maglev / consistent hashGoogle LB paper — minimal disruption
CUBIC / BBRLinux default CCAs — behavior differs

Extended: DSR (Direct Server Return)​

In Direct Server Return, LB receives client traffic but backends reply directly to client — reduces LB egress bandwidth. Requires loopback on backends and L2 adjacency or tunnel tricks. Used at very high scale; operational complexity high. Contrast with NAT mode where all traffic traverses LB.

Extended: Retry and Idempotency at LB​

L7 LBs may retry failed requests to another backend — safe only for idempotent methods or with request IDs. Retrying POST without idempotency violates safety. Align with Idempotency patterns. Outlier detection ejects unhealthy backends based on consecutive failures or latency — prevents retry amplification to sick nodes.

Extended: WAN vs DC Congestion​

Datacenter networks often have shallow buffers and ECN enabled — BBR may perform well. WAN paths have variable loss and bufferbloat — CUBIC loss response may differ. Bulk cross-region replication should use paced sends and bandwidth limits to protect interactive traffic — application-level QoS when network QoS unavailable.


16. Alternatives and Tradeoffs​

ApproachProsCons
DNS failoverSimpleTTL delay
BGP anycastFast regional drawComplex ops
L4 LBFast, genericNo path routing
L7 LBRich routingCPU, latency
Client-side LBNo single pointClient complexity (gRPC xDS)
Active-active regionsLow RTOData consistency cost

17. Common Misconceptions​

  1. "BGP is fast failover like LB health check." — Convergence times differ by orders of magnitude.

  2. "Round-robin is always fair." — Unequal request costs skew load.

  3. "More bandwidth eliminates congestion." — Bottleneck moves; CC still governs share.

  4. "Anycast means active-active compute." — Anycast is routing; backends may still be regional.

  5. "Consistent hashing needs no rebalancing." — Virtual nodes help; membership changes still move keys.


18. Principal Architect Perspective​

Document RTO/RPO per tier; match failover mechanism (DNS vs BGP vs LB) to requirements.

Capacity: standby region must absorb full traffic without violating SLO — include congestion headroom.

Align with SLO, SLI, and Error Budgets.

Extended: BGP Path Selection (Conceptual)​

BGP routers select routes using attribute policies: LOCAL_PREF (higher preferred within AS), AS_PATH length (shorter often preferred), MED (multi-exit discriminator between peers), and origin type. Route leaks — announcing routes without permission — redirect traffic globally. RPKI ROV validates origin AS against signed ROAs where deployed. Multi-homed enterprises use BGP to influence inbound and outbound paths — distinct from application load balancing.

Extended: Load Balancer Algorithms​

Round robin: simple; ignores backend load. Least connections: better for long-lived unequal-cost requests. Weighted: capacity heterogeneity. Maglev consistent hash: minimal disruption on backend set change — used at Google scale. Power of two choices: pick two random backends, route to lesser load — O(1) with good balance. Match algorithm to request duration distribution and health check granularity.

Extended: TCP Reno and Fast Recovery (Teaching Baseline)​

Reno increases CWND in slow start (exponential) until loss, then congestion avoidance (linear). On triple duplicate ACK, fast retransmit resends segment without waiting full RTO; fast recovery adjusts CWND. Modern Linux defaults differ (CUBIC), but Reno remains pedagogical baseline for understanding loss reaction. Tail loss on short flows may never trigger fast retransmit — single timeout dominates latency.

Extended: Active Queue Management​

RED and CoDel proactively drop or mark packets before buffers fill completely — signaling congestion earlier, reducing bufferbloat. ECN (Explicit Congestion Notification) marks IP headers instead of dropping — TCP reduces CWND on ECN-Echo. Datacenter TCP stacks increasingly enable ECN end-to-end where switches support it — requires coordinated enablement across path.

Extended: Multi-Region Traffic Engineering​

GeoDNS routes to nearest healthy region by resolver location — imprecise (resolver not user location). Anycast routes to nearest BGP announcement. Latency-based routing (AWS Route 53 policy) uses measured latency. Active-active requires data plane accepting writes in multiple regions with conflict handling — routing alone does not solve consistency. Pair routing decisions with RPO/RTO and CAP tradeoff articulation.


19. Architecture Review Exercise​

SaaS platform active-passive between us-east and eu-west. RTO 5 minutes required. Current DNS TTL 3600. Redesign routing, LB, data replication, and failover drill. State tradeoffs.


20. Whiteboard Explanation​

"BGP advertises which IPs are reachable through which AS paths — internet routing. In DC, load balancers spread connections or HTTP requests across backends. L4 is IP/port; L7 is URL and headers. Anycast announces same IP from multiple sites — routing picks closest. TCP congestion control slows senders when network is full — affects replication and downloads. Failover is never instant — DNS TTL, BGP convergence, health checks all add delay."


Extended Walkthrough: Regional Failover Timeline​

AZ partition → ALB sheds unhealthy backends → error budget burn → DNS failover (TTL 60s) → partial cache delay → BGP withdrawal → traffic shift. Lesson: LB, DNS, BGP operate on different timescales; RTO must account for worst case. Standby region needs warmed capacity — routing alone insufficient.


Extended Failure Scenario: Consistent Hash Hot Spot​

Popular key overloads single backend despite balanced hash. Mitigation: key splitting, edge cache, rate limits, hot-key detection. Hash balancing ≠ load balancing under power-law skew.


21. Interview Questions​

  1. BGP purpose at high level?

  2. L4 vs L7 load balancing?

  3. How does anycast work?

  4. Consistent hashing — why and how?

  5. Explain TCP congestion window behavior.

  6. CUBIC vs BBR at conceptual level?

  7. DNS failover limitations?

  8. What causes bufferbloat?

  9. Session affinity tradeoffs?

  10. ECMP and flow hashing?

  11. Cross-AZ traffic cost implications for architecture?

  12. How health checks relate to partial failure?


22. Interview Follow-Ups​

  1. After Q4: "Virtual nodes in consistent hash?" — Better balance; more memory.

  2. After Q6: "When BBR problematic?" — Fairness with loss-based CCAs; shared bottlenecks — context-dependent.

  3. Principal: "Multi-region active-active for payments?" — Consistency, conflict resolution, regulatory residency — often active-passive.


22A. Production Low-Level Design (Interview + Game Day)​

Design L7 load balancing with maglev hashing, graceful drain, and adaptive retries. Production LLD and Game Day Standard.

Control vs data plane​

PlaneRole
ControlWeighted routing, drain flags, retry budget
DataMaglev pick backend; health-gated

API: Route(req) → backend; sticky via consistent hash on session id.

Step-by-step flow:

StepMechanismOps hook
1Accept flow—
2Consistent hash stickiness—
3Skip unhealthy—
4–5Retry with jitter budget—
  • SLO: error rate < 0.1%; drain completes in 30s
  • Congestion: RED on backend queues

22B. Game Day Playbooks​

#DrillInjectDetectMitigateVerify
GD-1Thundering herd deployFlip all weights instantError spikeGradual drain + jitterSmooth
GD-2Retry stormBackend slowLB retry amplifiesRetry budget + 503Stable
GD-3Hot keyOne hash slotSingle backend meltSplit keys / overloadSpread load
GD-4ECN lossIncastLatency tailDCTCP / bounded buffersTail stable

GD-1 — Deploy causes retry storm​

23. Strong Answer Example​

Question: "How do you avoid thundering herd during deploys and congestion collapse?"

Answer this as a 45-minute design discussion using the PRACTICE framework. Below is how a strong student sounds aloud—drain + retry budgets + ECN, not infinite retries.

Student interview script (PRACTICE)​

P — Problem framing​

"Deploys flip health checks together → all clients reconnect at once. Congestion collapse when queues infinite and retries amplify load."

R — Requirements​

TypeRequirement
AvailabilityNo error budget burn on deploy
FairnessNo incast on one backend
OpsWeighted drain automation

A — Assumptions​

AssumptionWhy it matters
Idempotent GET retries OKPOST needs budget 0
Maglev stickinessSession locality

C — Capacity (sketch)​

100 backends; drain 1%/30s; max retry 2 with jitter
Queue RED at 80% fill

T — Topology (draw this)​

Step-by-step flow:

StepClaim
1Connection draining
2Jittered health
3Retry budget

I — Invariants​

"Retries never exceed configured budget per request."

C — Constraints​

ConstraintResponse
Retry stormCircuit breaker
IncastECN + DCTCP

E — Evolution​

Automate weighted drain; game day instant kill.

Closing line​

"Drain connections before health flip. Cap retries. RED queues and ECN-aware TCP prevent collapse."

Scoring signals​

StrongWeak
Names mechanism + failure path + metricsHand-wavy scaling; buzzwords only

Compact outline (2 min)​

See closing line in script above.

24. Weak Answer Example​

Weak answer: "Use round-robin ALB; WebSockets are just HTTP."

Why weak: Ignores stickiness, drain, connection limits, state partition.


25. Hands-On Exercise​

Configure nginx upstream with ip_hash vs least_conn. Simulate backend failure with iptables DROP. Observe reconnect behavior. Use iperf3 with parallel streams to see congestion behavior on constrained link (tc netem).


26. Knowledge Check​

  1. BGP exchanges? (Path reachability between autonomous systems.)
  2. L7 LB routes on? (Application data like HTTP path/headers.)
  3. Anycast property? (Same IP, multiple sites, route to nearest.)
  4. CWND increases when? (No congestion signals — probing bandwidth.)
  5. DNS failover delay driver? (TTL and resolver caching.)

27. Flashcards​

FrontBack
BGPInter-domain routing protocol for IP prefix reachability
AnycastSame IP announced from multiple locations
L4 load balancingDistributes TCP/UDP flows by connection
L7 load balancingRoutes based on application-layer data
Consistent hashingMaps keys to nodes with minimal remapping on change
Congestion windowSender limit on unACKed data in flight
BufferbloatExcess queueing delay from oversized buffers
ECMPLoad splits flows across equal-cost paths
Session affinitySame client to same backend
SYN proxyLoad balancer completes TCP handshake
CUBICLoss-based congestion control common on Linux
BBRModel-based congestion control using bandwidth and RTT estimates

28. Cheat Sheet​

Global: BGP/anycast · DNS TTL · RTO realism

LB: L4 = connections · L7 = HTTP rules · drain on deploy

Stateful: sticky hash · connection limits · graceful failover

Congestion: CWND · bufferbloat · bulk vs interactive isolation

Cost: minimize cross-AZ chatter · cache at edge

Supplementary Principal Content: Load Balancer Selection Matrix​

RequirementPrefer
TLS SNI routingL7
Millions of TCP passthroughL4
Path-based canaryL7
Lowest latency overheadL4 or DSR
WAF integrationL7 edge
gRPC with retryL7 (gRPC-aware) or mesh

Global load balancing: User → Anycast edge → regional origin. Data sovereignty: route EU users to EU region — GeoDNS or geofencing policies, not only latency optimization.

Congestion and replication: Database replication lag during bulk catch-up is TCP congestion on the wire — throttle replication bandwidth to protect OLTP traffic share same NIC.

Chaos Experiments for Routing​

  • Withdraw single backend — verify drain
  • Block BGP session in lab — measure convergence
  • Set DNS TTL to 5s temporarily — observe resolver behavior
  • Saturate link with iperf — measure API p99 alongside


Final expansion: Autoscaling and LB Interaction​

HPA scales pods on CPU/custom metrics — LB must discover new endpoints via readiness. Cold pods during scale-out receive traffic before JVM warmup — latency spike. Predicative scaling or warm pools address. LB health check interval vs scale-up time — race causes 503s if traffic shifts before ready.

Connection draining duration must exceed longest in-flight request p99 — align with terminationGracePeriodSeconds and client timeouts.

Architecture Integration Notes​

Global traffic management ADRs record: primary and failover regions; DNS TTL choices; whether anycast or GeoDNS; RTO/RPO targets; data consistency model during failover; and last successful game day date. Load balancer configuration is infrastructure-as-code with peer review — manual console changes caused too many outages.

Congestion management spans network and application: TCP CC handles wire-level share; rate limits and admission control handle service overload; message queue prefetch handles consumer lag. Principal architects ensure no single layer assumes another will always protect it.

Capacity: standby region must pass load test at 100% production traffic shape — routing failover without capacity is a false sense of resilience.

Weighted Capacity and Slow Start on Load Balancers​

When adding backends after scale-out, slow start algorithms ramp connection fraction gradually — prevents overwhelming cold JVM or empty cache. Weighted routing sends more traffic to larger instances — requires homogeneous software version and health. Misconfigured weights cause effective hot spot — monitor per-backend request rate not only aggregate.

Subnet and security group design interacts with load balancing: LB subnets must route to backend subnets; NACLs must allow return traffic; health check source IPs may be LB-owned — document in IaC modules. Cross-account LB patterns in AWS require RAM sharing or centralized network account — principal architects standardize to reduce one-off misconfigurations during acquisitions or new product launches.

Closing Principal Synthesis​

Foundation chapters in computer architecture, operating systems, and networking form a single reasoning chain for production systems. A slow API is rarely one layer's fault: DNS TTL stale after failover (networking); SYN retransmit on lossy path (TCP); TLS handshake without session resumption (HTTP/TLS); epoll thread blocked on synchronous JDBC (kernel I/O + scheduling); page fault on cold JVM heap (virtual memory); false sharing on metrics counter (cache coherence); or ambiguous timeout after partial gateway success (distributed partial failure — next domain in curriculum).

Interview answers that traverse this chain — naming the layer, the mechanism, the measurement, and the tradeoff — signal principal-level systems thinking. Answers that jump to "scale horizontally" without layer discrimination signal staff-level gaps.

Hands-on reinforcement: pick one production incident from your career (or a public postmortem) and rewrite the root cause analysis tagging each contributing factor with the chapter that explains it. Link remediation to mechanism: if coherence traffic, pad or shard; if throttling, fix cgroup quota; if DNS, fix TTL; if bufferbloat, pace bulk traffic.

This synthesis intentionally avoids invented benchmark numbers. Your fleet's constants come from profiling on your hardware, your network path, and your workload shape — the curriculum teaches which counter to read, not which magic millisecond threshold to memorize.

30. References​

  • Kurose & Ross — BGP and congestion control chapters.
  • RFC 4271 — A Border Gateway Protocol 4 (BGP-4).
  • Eisenbud, D., et al. Maglev: A Fast and Reliable Software Network Load Balancer — Google.
  • Cardwell, N., et al. BBR: Congestion-Based Congestion Control — ACM Queue.
  • AWS/GCP/Azure load balancing and data transfer pricing documentation — cost modeling.
  • RIPE NCC / MANRS — BGP security operational guidance.