What is Anycast routing and when to use it
· Category: Networking
Short answer
Anycast routes traffic to the nearest server sharing the same IP address. Multiple servers in different locations all advertise the same IP, and the network's routing protocols direct each user to the closest one. This is how major DNS providers and CDNs achieve low latency globally. For how CDNs leverage this, see how CDNs speed up content delivery.
How it works
- Multiple servers in different data centers configure the same IP address
- Each server announces this IP via BGP (Border Gateway Protocol) to its local routers
- Routers choose the shortest path to that IP based on AS-path length and routing metrics
- A user in Tokyo reaches the Tokyo server; a user in London reaches the London server
- If one server goes down, routers automatically reroute to the next-nearest
Anycast vs Unicast vs Multicast
| Type | One IP → | Use case |
|---|---|---|
| Unicast | One specific server | Standard web hosting |
| Anycast | Nearest of many servers | DNS, CDN, DDoS mitigation |
| Multicast | All subscribed servers | Streaming, but rarely used on public internet |
When to use Anycast
- DNS resolvers: Cloudflare (1.1.1.1), Google (8.8.8.8) use Anycast for sub-10ms resolution worldwide
- CDN edge servers: Serve static content from the nearest point of presence
- DDoS mitigation: An attack hitting one IP gets distributed across many locations, diluting its impact
Tips
- Anycast requires BGP access and your own AS number — not feasible for small deployments
- For most web applications, a CDN provides Anycast benefits without the infrastructure complexity
- To understand the DNS layer that works alongside Anycast, see how to configure DNS records