Software Engineering Glossary

Anycast

Also known as: Anycast Routing Anycast IP

Anycast gives one IP address to many machines in many places. Each site announces that same prefix with BGP, and routers deliver each packet to the closest announcement by their routing metrics. It is how CDNs and public DNS spread users across cities without asking the client to pick a server. Anycast chooses a location. A normal load balancer inside that location still chooses a machine.

Key Takeaways

  • Anycast announces the same IP prefix from many sites. BGP, not DNS, picks which site receives the packet.
  • Failover is a route withdrawal. Stop announcing from a bad site and new packets flow to the next closest one.
  • It is an ingress technique. A reply to a connection opened from an anycast address can land at the wrong site.
  • Anycast balances cities. You still need load balancing inside the site to balance servers.

How It Works

  1. Each site announces the same IP prefix to its upstream providers with BGP.
  2. Internet routers forward a packet along the preferred path, usually toward the nearest announcement.
  3. If a site withdraws the prefix, routers converge on the next-best announcement.
  4. Inside the chosen site, a local balancer spreads traffic across servers.

Where It Is Used

  • Cloudflare answers user traffic on anycast ranges, and uses ordinary unicast addresses when its servers open connections out to the internet.
  • Public DNS has used anycast for years, because a short UDP query has little session to pin to one machine.
  • A CDN uses anycast to land a user on a nearby edge, then a local balancer and cache take over. The same spread helps absorb a DDoS attack.

Related glossary terms