← All articles
4 min read

Anycast networking explained

One IP address. Multiple servers. Users around the world all connecting to the same address - but being served by whichever server is physically closest to them. This is anycast, and it's one of the most powerful techniques in modern network infrastructure.

The four routing models

To understand anycast, it helps to contrast it with the other IP routing models:

With anycast, multiple physical servers in different locations all announce the same IP address via BGP (Border Gateway Protocol). Routers across the internet direct traffic to whichever announcement is topologically closest - measured in BGP hop count and path attributes, not geographic distance per se.

User in Tokyo  →  203.0.113.1  →  Tokyo node
User in London  →  203.0.113.1  →  Amsterdam node
User in New York  →  203.0.113.1  →  New York node
Same IP - different physical destinations

How BGP makes it work

BGP is the routing protocol that holds the internet together - it's how autonomous systems (networks run by ISPs, hosting providers, and large organisations) advertise which IP prefixes they can reach. Each anycast node announces the shared IP prefix to its upstream providers. Those providers propagate the announcement to their peers, and so on across the global routing table.

When a user in Sydney sends a packet to your anycast IP, their ISP's routers consult the BGP routing table and find the path with the best attributes to that prefix. If you have nodes in Sydney, Singapore, and Los Angeles, the Sydney user will almost always hit the Sydney node - it's simply the shortest path.

Important caveat: "Nearest" in BGP terms means fewest hops and best path attributes - not literal geographic proximity. Occasionally, suboptimal peering arrangements can route traffic further than you'd expect. This is why anycast providers often have multiple nodes in the same region.

Automatic failover

One of anycast's most valuable properties is built-in resilience. If a node goes offline and withdraws its BGP announcement, traffic automatically reroutes to the next-best node. This failover happens within BGP convergence time - typically 30–180 seconds for global propagation, though pre-configured route dampening and fast withdrawal can reduce this significantly.

For file hosting, this means a node failure in one region doesn't take your service offline - users in that region experience a brief interruption as BGP reconverges, then resume service via a more distant node.

Anycast vs DNS-based load balancing

A common alternative to anycast for geographic distribution is GeoDNS - returning different IP addresses based on the user's DNS resolver location. Anycast has several advantages over this approach:

The tradeoff: anycast requires owning an IP address block (ASN and /24 minimum) and establishing BGP sessions at each node location, which has a higher operational barrier than GeoDNS.

Anycast in practice

Modern file hosting and web platforms use anycast for their edge layers - routing users to the nearest available node for application requests like authentication, lookups, and URL generation. This reduces round-trip latency before any large data transfer begins. Download and upload traffic is typically handled by separate infrastructure, purpose-built for sustained high-throughput connections rather than low-latency request handling.

← All articles