AlgoMaster Logo

Anycast Routing

Low Priority13 min readUpdated October 25, 2026
AI Mock Interview

Practice this topic in a realistic system design interview

Premium Video

This video is available to premium subscribers only

Unlock Full Access

Anycast routing is a technique that allows servers in different parts of the world to share the same IP address.

In this chapter, we will look at how anycast works with internet routing, what happens when a location fails, where it's used, its limitations, and how it compares with DNS load balancing.

1. The Problem with DNS-Based Routing

Suppose you run a service in three locations: Tokyo, Frankfurt, and Virginia. Ideally, users in Japan should connect to Tokyo, users in Germany to Frankfurt, and users in New York to Virginia.

One way to do this is through DNS-based routing. Your DNS provider uses the location associated with a DNS query to return the IP address of a nearby region.

This works, but it has a couple of limitations.

First, DNS responses are cached. If the Tokyo region goes down, some users might keep connecting to its old IP address until their cached response expires.

Second, DNS often sees the location of the user's recursive resolver rather than the user. If that resolver is far away, the user might end up connecting to a region that isn't actually the closest.

Anycast solves this problem differently. Instead of giving each location a separate IP address and relying on DNS to choose between them, all three locations advertise the same IP address. The internet's routing system then determines where each user's traffic goes.

To understand how this works, let's first compare anycast with other ways of routing IP packets.

2. IP Routing Models

Unicast

Most IP traffic on the internet uses unicast. With unicast, an IP address identifies a particular network endpoint, and packets sent to that address are routed toward it.

Broadcast

Broadcast works differently. It sends a packet to every device on a local network. For example, when a device first joins a network, it might use broadcast to discover a DHCP server.

Multicast

Then there's multicast, which delivers packets to a group of receivers that have joined a particular group. It's used in some video distribution systems and financial market data networks.

Anycast

Anycast takes a different approach. Multiple servers in different locations share the same IP address, but each packet is routed to just one of those locations, based on the network's routing decisions.

Think of an emergency number like 911. Everyone dials the same number, but the phone network directs each call to the emergency center responsible for that area. You don't need to know the number of your local emergency center.

Anycast works in a similar way. Users connect to the same IP address, but their traffic can reach different locations depending on where they're connecting from and how the network is routed.

ModelDelivery PatternCommon Use
UnicastOne address to one endpointMost internet traffic: web, APIs, databases
BroadcastOne sender to every device on a local networkDHCP discovery
MulticastOne sender to receivers that joined a groupVideo distribution, market data
AnycastOne address shared by many locations, each packet reaches oneDNS, CDN edges, DDoS protection, global entry points

So how does the internet decide which location receives the traffic? That's where BGP comes in.

3. BGP and Autonomous Systems

Premium Content

This content is for premium members only.