How Anycast Works – An Introduction to Networking

Anycast

What is Anycast?

Anycast, also known as IP Anycast, is a networking technique that allows for multiple machines to share the same IP address. Based on the location of the user request, the routers send it to the machine in the network that is closest. This is beneficial since, among other things, it reduces latency and increases redundancy. If a particular data center were to go offline, an Anycasted IP would choose the best path for users and automatically redirect them to the next closest data center. The following outlines some of the pros and cons that are associated with configuring Anycast.

Pros

  • Speed. Traffic going to an Anycast node will be routed to the nearest node thus reducing latency between the client and the node itself. This ensures that speeds will be optimized no matter where the client is requesting information from.
  • Redundancy. Anycast improves redundancy by placing multiple servers across the globe using the same IP. This allows for traffic to be rerouted to the next nearest server in the case that one server fails or goes offline.
  • DDoS mitigation. DDoS attacks are caused by botnets which can generate so much traffic they overwhelm a typical Unicast machine. The benefit of having an Anycast configuration in this situation is that each server is able to “absorb” a portion of the attack resulting in less strain on the server overall.
  • Load balancing. Load balancing can be utilized in the case that there are multiple nodes all within the same geographic distance from the request. This takes some of the resource requirements off of a singular node and disperses them across multiple nodes.

Cons

  • Difficult to Implement. Implementing IP Anycast is a complex endeavor that requires additional hardware, reliable upstream providers, and proper traffic routing.

Border Gateway Protocol and Autonomous Systems

Border Gateway Protocol (BGP) and Autonomous Systems (AS) are integral parts in the way IP Anycast functions. The BGP exchanges routing and reachability information between AS. It makes routing decisions based on paths, policies, and rule sets which is a key component of what IP Anycast offers. Within BGP routing there are multiple routes for the same IP address which are pointing to different locations.

An Autonomous System is a single or collection of networks all administered by the same administrator. Autonomous Systems each have a unique ASN, or Autonomous System Number, for use in BGP routing since each ASN identifies each network on the internet.

Tools like ExaBGP can be used to transform BGP messages into text or JSON which can then be handled by simple scripts. This allows administrators to easily detect and handle network or service failures.

How Does Anycast Work?

As previously mentioned, Anycast directs user requests to the nearest node in order to reduce page latency. It does this by following these steps.

  1. Multiple service instances announce they share the same IP address.
  2. When the user’s browser makes a request, the router receives that request and simply chooses the route with the shortest distance to the nearest server based on the AS path.

Using Unicast, which will be explained in the following section, the path would only lead to one destination no matter the distance. Using Anycast, the route is optimized due to it always selecting the best path. In the case that a server is down, the BGP will simply find the next best path and route the request there.

It should be noted however that anycast can be configured not only to route request based on distance but also other factors for example:

  • Availability of server
  • Number of connections
  • Time to response
  • etc

Other Addressing Methods

Other addressing methodologies exist as well for routing user requests to a particular network endpoint. These include unicast, multicast, broadcast, and geocast. We’ll go into further detail for each in the sections below.

Unicast

Most of the Internet today uses this method. Unicast restricts an IP address to be associated to only one particular node in a network. This is known as a one-to-one association. Although much of the internet uses this method, it is sub-optimal due to the restrictions of only being able to associate an IP address with one node.

Unicast

Multicast

Multicast uses a one-to-many-of-many or many-to-many-of-many association. Multicast allows for a request from a sender to be routed to various selected endpoints simultaneously. This allows for a client to download a file in chunks from multiple hosts at the same time (useful for streaming audio or video). Multicast is often confused with Anycast, however the main difference is that Anycast routes the sender to one specific node even though multiple nodes are available for use.

Multicast

Broadcast

Broadcast uses a one-to-all association. A datagram from a singular sender is routed to all endpoints associated with the broadbast address. The network automatically replicates the datagrams so that it is able to reach all recipients within the broadcast, which generally consists of an entire network subnet.

broadcast

Geocast

Geocast is somewhat similar to multicast in that requests from a sender are routed to multiple endpoints simultaneously, however, the difference is that the network is defined by their geographical location.

geocast

Anycast and IPv4 vs IPv6

Anycast is not officially supported in IPv4 however, this can be worked around through using BGP. Essentially, multiple hosts are given the same unicast IP and routes are announced through BGP. Therefore, routers interpret this as multiple routes to the same destination whereas in fact, they are routed to different destinations with the same address.

The drawback to this approach, however,8 is that the network may perform what is called a “PoP switch” which changes the routing packets in the event that there is congestion or changes in the network.

IPv6 on the other hand explicitly supports anycast. IPv6 routers typically won’t distinguish an anycast packet from a unicast packet through the network although special handling from the routers near the destination is required.

Moreover, the same process used in IPv4 can be used in IPv6 as well. This method does not depend on anycast-aware routers however you will run into the same problems as discussed above.

Conclusion

It is clear that Anycast is a powerful technique for, among other things, reducing page latency and mitigating attacks. Although it is a complex endeavor to implement, the payoff is vast for both the users and the service providers alike.

KeyCDN is happy to offer Anycast to help improve the overall efficiency of services to our customers.