A CDN advertises the exact same IP address, say 203.0.113.10, from data centers in Frankfurt, Singapore, and Sao Paulo simultaneously via BGP, and relies on the internet's normal routing to send each user to the nearest one. Explain how this works, and describe a failure scenario where a user's connection to that IP breaks mid-session even though all three data centers are healthy.
answer
- same IP announced from many locations via BGP
- routing decided by normal internet path selection, not by the CDN
- no central steering — proximity emerges from BGP
- long-lived connections are vulnerable to mid-session reroute
- failover = simply withdrawing the BGP route
basics
~20 sAnycast means many servers around the world share one IP address, and the internet's normal routing (BGP) automatically sends each user to whichever one is 'closest' by network path. The problem: if the network path changes mid-connection, a user can suddenly get routed to a different server than before, breaking anything that depended on talking to the same machine.
solid answer
~60 sAnycast works by having every PoP announce the same IP prefix into BGP from its own location; routers across the internet see multiple paths to that prefix and, following normal BGP best-path selection, each network converges on whichever announcement looks closest from its own vantage point — there's no central traffic-steering decision, proximity emerges from ordinary internet routing. This gives automatic proximity-based routing and cheap failover: if a PoP withdraws its route, traffic reconverges onto the next-best PoP within normal BGP convergence time, with no DNS or client-side logic involved. The failure mode is a mid-connection route change: if the network path between the client and PoP shifts — say, an ISP peering link goes down or a route gets rebalanced — a long-lived TCP connection can suddenly have its packets delivered to a different, state-blind PoP than the one it was established with, and since that new PoP has no record of the existing connection, it resets. This mainly affects long-lived connections like streaming or WebSockets; short-lived HTTP request/response traffic is rarely disrupted.
go deeper
Doesn't need this depth; general awareness that 'the CDN somehow sends you to a nearby server' is enough.
Should know anycast means the same IP is served from multiple locations and is used for proximity and failover.
Should explain the BGP mechanism precisely, contrast it with DNS-based routing, and describe the mid-connection reroute failure mode and why it mainly affects long-lived connections.
Should reason about when to choose anycast versus unicast plus GeoDNS for a given product, how to mitigate reroute risk for connection-heavy protocols, and about BGP-level operational risks like route leaks and flapping across an anycast PoP fleet.
## How anycast works **Anycast** is a routing technique in which the exact same IP address is announced from multiple physically distinct locations at the same time, and the network itself — not any single server or a DNS lookup — decides which location a given packet actually reaches. Every anycast PoP runs a **BGP (Border Gateway Protocol)** speaker that advertises reachability for the same IP prefix into the internet's global routing system. Routers all over the internet end up with several candidate paths to that one prefix — one via Frankfurt, one via Singapore, one via Sao Paulo — and BGP's normal best-path selection algorithm (which weighs factors like AS-path length, local routing policy, and other metrics, not literal geographic distance) picks one path per router. A user in Berlin, several network hops from Frankfurt but many more from Singapore or Sao Paulo, ends up with their packets naturally converging on the Frankfurt announcement, purely as an emergent property of ordinary internet routing decisions made independently by routers along the path — the CDN itself makes no per-request steering decision at all. ## Why it exists This mechanism exists because it solves two problems at once with almost no operational overhead: 1. **Automatic proximity routing** without needing a DNS layer that has to guess a client's location (a guess that can be wrong, especially when clients use a public DNS resolver far from themselves). 2. **Near-instant failover.** If a PoP goes down — or is deliberately taken out of rotation for maintenance — it simply stops announcing its BGP route for that prefix. Upstream routers detect the withdrawal and reconverge onto the next-best remaining announcement within normal BGP convergence time, typically seconds to tens of seconds, with zero visible change from the client's point of view: same IP, same DNS record, just a different physical server now answering it. This is also why large-scale DDoS mitigation providers lean heavily on anycast — an attack's traffic gets naturally spread across every PoP announcing the prefix rather than concentrating on one location, since each attacking source's packets follow the same nearest-path logic as any other client's. ## The trade-off The trade-off against this simplicity is that anycast has no concept of a session. Compare this to DNS-based geo-routing: | Approach | How the steering decision is made | |---|---| | **Anycast** | Every packet is routed independently based on whatever path currently looks best from wherever it enters the network; the anycast PoPs themselves don't share per-connection state with each other. | | **DNS-based geo-routing** | A resolver returns a specific unicast IP for a specific PoP once, at resolution time, and the client keeps using that same server (and thus the same underlying connection state) until the DNS record's TTL expires. | That is a decision made once, up front, versus anycast's continuous, per-packet, routing-layer decision that can react to network changes but is blind to what's happening at the application layer above it. ## The failure mode That blindness is exactly the failure mode in the scenario: TCP is a stateful, connection-oriented protocol, and a long-lived TCP connection is anchored to whichever PoP happened to answer the very first SYN packet. If, mid-connection, an ISP-level routing change causes that user's packets to suddenly take a different path — one that BGP now resolves to the Sao Paulo PoP instead of the Singapore PoP the connection was originally established with — the newly-receiving PoP has no record of that TCP connection's sequence numbers or state, and the connection simply resets. This is a real, if relatively rare, operational risk for connection-oriented, long-lived traffic like live video streaming or WebSockets, but it's much less of a concern for ordinary HTTP request/response traffic, where each connection typically completes in well under a second, leaving little window for a mid-flight reroute, and a dropped connection just means the client opens a fresh one. ## Where it shows up This is why teams building latency-sensitive, connection-heavy products on top of anycast infrastructure sometimes pair it with additional mitigations — protocols like QUIC carry a connection identifier independent of the underlying IP/port tuple specifically so a mid-session network change doesn't have to mean starting over, and some providers build explicit session-affinity or state-sharing layers on top of anycast for exactly this reason. Anycast is heavily used by major CDN and DNS providers — Cloudflare's and Google's public DNS resolvers (1.1.1.1 and 8.8.8.8) are classic examples, as are most large CDNs' HTTP edge IPs — precisely because the vast majority of traffic they carry is short-lived enough that the mid-connection reroute risk rarely matters in practice.
- How does anycast differ from DNS-based geo-routing, where different users get different IPs based on their resolved location?DNS geo-routing makes the steering decision once, at resolution time, based on the resolver's location (which can be inaccurate, since some clients use a public DNS resolver far from themselves), and the client keeps using that IP until the DNS TTL expires; anycast makes the steering decision continuously, per packet, at the routing layer based on actual network path cost, so it reacts to network changes automatically but has no awareness of ongoing sessions.
- Why is anycast normally fine for ordinary HTTP traffic despite the mid-connection reroute risk?Most HTTP request/response cycles complete in a single short-lived connection lasting milliseconds to a couple of seconds, so the window in which a route change could occur mid-connection is small; if a connection does drop, the client simply opens a new one, which may land on a different but still-healthy PoP with no meaningful user-visible impact.
- How does anycast provide failover when a PoP goes down?The failed (or intentionally drained) PoP stops announcing its BGP route for the shared IP prefix; upstream routers detect the withdrawal and reconverge onto the next-best remaining announcement, typically within seconds to tens of seconds, with no client-visible change to the IP address or any DNS update required.
Anycast is like every branch of a national pizza chain sharing the exact same phone number: the phone network automatically connects each caller to whichever branch is 'closest' on the network, and if a branch closes for the night, calls automatically start ringing at the next-nearest branch without the caller dialing anything different — but if you're mid-call when the network reroutes you to a different branch, that branch has no idea who you are or what you already ordered.
saying these in an interview costs you the question
- Thinks anycast means one single physical server reachable everywhere
- Believes the CDN centrally decides which PoP each user goes to under anycast, confusing it with DNS-based/GeoDNS steering
- Doesn't know BGP path selection, not literal geographic distance, determines routing
- Assumes anycast is immune to mid-session disruption
- Confuses anycast with load balancing or DNS round robin