Anycast
Anycast Routing
A way to make one IP address live in many places at once. Each user is automatically routed to the nearest copy — the trick that makes global DNS resolvers and CDNs feel local no matter where you are.
Anycast is a routing method in which the same IP address is announced from many separate locations around the world. When you send traffic to that address, the internet's routing system delivers your packets to whichever location is closest to you — not because your device chose it, but because the routers between you and the destination naturally prefer the nearest path. One address, many doors, and you always walk through the one nearest to you.
Anycast vs the other "-cast" methods
| Method | Delivery | Typical use |
|---|---|---|
| Unicast | One sender → one specific host | Almost all normal traffic |
| Anycast | One sender → nearest of many identical hosts | DNS resolvers, CDNs, DDoS absorption |
| Multicast | One sender → many subscribers at once | IPTV, live streaming on a network |
How the routing actually happens
The mechanism lives in BGP, the internet's inter-network routing protocol. Each anycast location announces the same address block (the same prefix) to its neighbours. Other networks receive multiple announcements for that prefix and, following normal BGP route selection, each picks the one that looks closest — usually the fewest network hops away. The result is that users in Tokyo reach the Tokyo node and users in Frankfurt reach the Frankfurt node, all using one identical IP.
Why it makes things fast and resilient
Anycast delivers two big wins at once:
- Lower latency: because every user is served by a nearby node, the round trip is short. This is why public resolvers like
1.1.1.1and8.8.8.8answer so quickly from almost anywhere — they are anycast across hundreds of sites. - Built-in failover: if a location goes offline, it simply stops announcing the address, and BGP reroutes users to the next-nearest node within seconds. No DNS change, no client reconfiguration.
- DDoS absorption: a flood of attack traffic is split across all locations rather than hitting one, so the load that any single site must absorb is a fraction of the total.
Anycast and CDNs
Anycast is one of the routing techniques behind CDNs, though not the only one. A CDN is the service — a fleet of caching servers near users. Anycast can be how a CDN steers each user to the nearest cache, but some CDNs instead use DNS-based steering (returning a different IP per region), and many blend both. Think of anycast as the routing layer and the CDN as the caching product built on top.
The TCP caveat
Anycast works beautifully for short, stateless exchanges like a DNS query. For long-lived TCP connections there is a subtlety: if internet routing changes mid-connection, packets could suddenly arrive at a different location that has no record of the session, breaking it. In practice routes are stable enough that this is rare, and large anycast operators engineer their networks to keep sessions pinned to one site. It is the reason anycast first became popular for DNS — where every exchange is a single quick request and reply.