Skip to main content
← PROBLEMS / ARCHITECTURE
An end-to-end domain learning journey

Design a Global Anycast L4/L7 Edge Load
Balancer with DSR & Zero-Drop PoP Drain.

Use BGP Anycast across 30 PoPs, eBPF/XDP Maglev L4 balancers with GRE/IPIP Direct Server Return to Envoy L7 proxies, and graceful BGP drain + QUIC CID migration.
Start the journey5 stages· Last modified Nov 26, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When designing a 20 Tbps edge ingress, pair XDP Maglev + DSR to offload L4 egress with BFD/BGP withdrawal and QUIC CID tunneling for PoP failover.

TL;DR30-second simplified summary
▾

XDP Maglev handles ~1.5 Tbps ingress with O(1) consistent hashing, Envoy replies directly via DSR to offload 20 Tbps egress, and BFD + QUIC CIDs enable <3s PoP failover.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
BGP Anycast & Maglev ECMP
Understand /24 Anycast routing and why Maglev's 65,537-slot lookup table prevents ECMP reshuffling.
Direct Server Return (DSR)
Know why asymmetric return paths (L7 proxy -> client directly) save 80–90% of L4 balancer NIC bandwidth.
Full walkthrough · 5 stages
01
L4 · FUNDAMENTALS

R & E · Requirements, Asymmetric Bandwidth & DSR Math.

HTTP traffic is heavily asymmetric: a 500-byte GET request triggers a 50 KB JSON or media response (a 100:1 egress-to-ingress ratio, ~10:1–20:1 on average across mixed API traffic).

Illustrative Sizing: Across 30 PoPs, 20 Tbps egress averages ~667 Gbps/PoP (bursting to 2 Tbps/PoP), while ingress is only ~1–2 Tbps globally (~33–67 Gbps/PoP). With DSR, L4 balancers only handle 67 Gbps ingress per PoP (2x 100GbE NICs per L4 box, 2–4 boxes/PoP) instead of 2 Tbps egress!

L4 Egress Offload

Symmetric L4 Proxy vs. Direct Server Return (DSR)

Before · Symmetric L4 NAT
  • L4 NICs carry 20 Tbps egress
  • 10x more L4 servers needed
  • Double sk_buff memory copies
After · XDP Maglev + DSR
  • L4 only handles ~1.5 Tbps ingress
  • Envoy replies directly to client
  • 10+ Mpps/core in XDP
02
L4 · FUNDAMENTALS

S · State & Conntrack Tables in eBPF Maps.

Software L4 balancers cannot acquire global mutexes at 10 Mpps; all state must live in lock-free per-CPU eBPF maps.

Each L4 node maintains: (1) maglev_table (BPF_MAP_TYPE_ARRAY, 65,537 entries -> Envoy VIP index); (2) conntrack_lru (BPF_MAP_TYPE_LRU_PERCPU_HASH, 4M entries keyed by 5-tuple -> {backend_ip, last_seen_ns}); (3) vip_backends (BPF_MAP_TYPE_ARRAY of healthy Envoy IPs + weights).

eBPF XDP Data Plane

NIC RX -> Conntrack LRU -> Maglev Array -> IPIP/GRE Encap

NIC XDP RXPer-CPU ConntrackMaglev 65537Envoy L7 DSR
03
L5 · APPLIED DESIGN

H & A · Global Anycast + L4/L7 + DSR Packet Flow.

A user sends a packet to Anycast VIP 198.51.100.1. BGP routes it to the closest PoP's border routers, which ECMP-hash the 5-tuple to one of the PoP's Maglev L4 servers.

Maglev checks conntrack_lru (or maglev_table on SYN), wraps the packet in an IPIP/GRE header addressed to the chosen Envoy L7 node's unicast IP, and transmits it. Envoy decapsulates the packet—revealing the original (client_ip -> 198.51.100.1)—terminates TLS/HTTP, and sends the response straight out the PoP gateway with source IP 198.51.100.1.

DSR Triangle Flow

Client -> Anycast Router -> Maglev L4 -> Envoy L7 -> Client (DSR)

ClientMaglev L4Envoy L7 (VIP onlo)1. SYN / Request -> 198.51.100.12. IPIP/GRE Encap (ingress only)3. TLS / HTTP Response directly(DSR)
04
L5 · APPLIED DESIGN

D · Detailed Design: <3s PoP Drain & QUIC CID Migration.

If a PoP loses upstream transit or Envoy health checks drop below threshold, its BGP daemon (ExaBGP / BIRD / GoBGP) must withdraw the Anycast prefix fast.

With BFD (Bidirectional Forwarding Detection) + 500 ms local health probes, an unhealthy PoP withdraws its BGP announcement in <2 seconds. For active QUIC/HTTP3 connections, the 8-byte QUIC Connection ID encodes (pop_id, server_id): if BGP shifts a user to PoP 2 mid-stream, PoP 2 reads pop_id=1 from the CID and tunnels those packets over the private backbone to PoP 1.

PoP Failover Lifecycle

Healthy -> Health Drop -> BGP Withdraw (<3s) -> Neighboring PoP

planned maintBFD / probe failwithdraw < 3sServing AnycastPrepend 65535:0Health < 50%Prefix Withdrawn
Engineering Decision Framework
Problem
How to drain or fail over an Anycast PoP without dropping active sessions or blackholing traffic.
Naive Solution
Kill the BGP speaker process abruptly on maintenance or rely on 60s BGP hold timers.
Why It Fails
60s hold timers blackhole traffic for a full minute; abrupt withdrawal resets every active TCP connection in flight.
Alternatives
Abrupt BGP kill vs. BFD + Graceful-Shutdown Community + QUIC CID Backbone Tunneling.
Engineering Decision
Use BFD (<2s hard-failure withdrawal), BGP 65535:0 graceful drain for maintenance, and QUIC CID routing for mid-stream PoP shifts.
Trade-Offs
Requires private inter-PoP backbone capacity for tunneled QUIC flows and strict uRPF/DSR router config.
Decision Exercise · Make the Call

During a PoP's peak 1.5 Tbps video-streaming burst, Envoy L7 proxies are healthy, but your Maglev L4 servers hit 100% NIC TX saturation. What architectural change removes the bottleneck?

05
L6 · SCALE & TRADE-OFFS

E & D · Evaluation, Assumptions, Limitations & Glossary.

DSR requires L2/L3 adjacency (or IPIP/GRE support) between L4 balancers and L7 proxies and permissive uRPF on egress border routers.

Assumptions & Limitations: Bandwidth estimates assume 10:1–20:1 egress-to-ingress asymmetry across 30 PoPs, an owned ASN with /24 IPv4 / /48 IPv6 prefixes, and private backbone tunnels for QUIC CID migration. In public cloud VPCs where raw source-IP spoofing (DSR) is blocked by SDN hypervisors, you must use cloud-native GWLB (GENEVE) or symmetric L4 proxies.

30-PoP Edge Fabric

Anycast BGP + XDP Maglev + Envoy DSR + QUIC CID Backbone

BGP Anycast + BFDingressXDP Maglev L4computeEnvoy L7 (DSR)storageQUIC CID BackbonecontrolECMP 5-tupleIPIP/GRE ingressCID tunnel fallback
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why does Direct Server Return (DSR) dramatically reduce L4 load balancer hardware requirements at a 20 Tbps edge?

Recommended Learning Flow