When building a global edge ingress, pair BGP Anycast with Maglev consistent hashing and local conntrack so scale-out only shifts ~1/N new flows.
TL;DR30-second simplified summary▾
BGP Anycast eliminates stale GeoDNS caches at L3, while Maglev's prime-sized permutation table + 5-tuple conntrack limits flow disruption to ~1/N new connections during L4/L7 pool changes.
P · Problem & Why Modulo ECMP Breaks Active TCP.
Suppose a PoP runs N = 10 L4 load balancers behind an ECMP router. Every incoming packet is hashed by its 5-tuple and sent to hash % 10.
If LB #3 crashes or you scale up to N = 11, hash % 11 changes the destination for roughly 10/11 (~91%) of all active TCP connections! Packets for an established connection land on a brand-new L4/L7 box that has never seen its SYN handshake, causing immediate TCP RSTs and dropped user requests.
Naive Modulo ECMP vs. Maglev Consistent Lookup Table
- ~91% flows remap on N=10->11
- TCP RST storm on scale-out
- Stale GeoDNS TTLs on failover
- O(1) array lookup (65,537 slots)
- Only ~1/N slots move on change
- BGP withdraws dead PoP in <3s
R · Representation: BGP Anycast + Maglev Permutation Table.
At the global layer, 30+ PoPs announce the exact same /24 IPv4 prefix (the minimum routable BGP prefix on the public internet). Each user's ISP picks the shortest BGP AS-path.
Inside each PoP, Maglev builds a lookup table entry[0..M-1] where M is a prime much larger than N (e.g., M = 65,537). Each backend i generates a pseudo-random permutation of 0..M-1 using two independent hashes (offset_i, skip_i). Backends take turns claiming their next unclaimed slot in entry[] until all M slots are filled.
User -> BGP Anycast PoP -> ECMP -> Maglev L4 -> Envoy L7
I · Invariant: Deterministic Maglev Table & Conntrack.
Maglev guarantees that if backend k is removed, ~1/N of the 65,537 slots change, and all other (N-1)/N slots keep pointing to the exact same backend.
Every L4 balancer runs the identical deterministic algorithm to build the same 65,537-entry table from the healthy backend list. For existing TCP flows that happen to land in the 1/N remapped slots during a scale-up, a local LRU connection-tracking table (keyed by 5-tuple) remembers the original L7 backend for established flows.
Conntrack Cache + Maglev Table + DSR Encapsulation
M · Mechanics at Scale: BGP Route Shifts & Asymmetric Paths.
BGP is stateless: an internet router can switch a user's path from PoP A to PoP B mid-download if a peering link flaps.
When a TCP packet arrives at PoP B for a connection initiated at PoP A, PoP B has no TCP state! Two production patterns solve this: (1) QUIC with Connection IDs encoding the home PoP/server ID so PoP B forwards packets over an internal backbone tunnel to PoP A; (2) Anycast-over-tunnel where edge PoPs proxy TCP via a regional origin shield.
Healthy Announce -> Graceful Prepend -> Drain -> Withdraw
- Problem
- How to route global traffic to the nearest healthy PoP without stale DNS caches or broken TCP state.
- Naive Solution
- Use GeoDNS with 60s TTL and modulo ECMP inside each PoP.
- Why It Fails
- ISP resolvers ignore short TTLs during outages, and modulo ECMP resets ~91% of flows when scaling backends.
- Alternatives
- GeoDNS + stateful NAT vs. BGP Anycast + Maglev ECMP + DSR.
- Engineering Decision
- Announce shared
/24via BGP Anycast, run Maglev ECMP + conntrack at L4, and use QUIC CIDs or internal tunnels for PoP-flap resilience. - Trade-Offs
- Requires own ASN and
/24IPv4 block plus BGP peering, and careful graceful-drain tooling for stateful TCP.
E · Edge Cases, Assumptions & When NOT to Use Anycast.
You cannot announce a single /32 IP over public BGP—global DFZ routers filter anything more specific than /24 IPv4 (or /48 IPv6).
When NOT to use BGP Anycast directly: for multi-hour stateful WebSocket or SSH sessions where mid-stream BGP convergence could shift PoPs, terminate TCP at a stable unicast or QUIC-CID-routed edge, or tunnel straggler packets over a private backbone.
Three Independent Anycast PoPs Sharing 198.51.100.0/24
You scale your PoP's L4 load balancer pool from 8 to 9 nodes using stateless hash(5-tuple) % N ECMP. Immediately, 88% of active HTTPS downloads fail with Connection reset by peer. What fixes this?
Practice: Make the trade-off yourself.
Why does Maglev use a prime table size M (e.g., 65,537) much larger than the backend count N?