09 Oct: Anycast

Most network traffic connections are made between a single sender and a single destination, unicast. You can also have connections between a single sender and many destinations (multicast or broadcast). But you can also have a connection between a single sender and a single target which is chosen from a set of targets based on some metric - Anycast:

"Anycast is a network addressing and routing method in which datagrams from a single sender are routed to any one of several destination nodes, selected on the basis of which is the nearest, lowest cost, healthiest, with the least congested route, or some other distance measure."

Imagine you have multiple DNS servers deployed across the world and you want to direct a client to the nearest one for the fastest response. You could do this in a few ways for example for returning a different IP depending on location, or using a load balancer that performs geoip lookup to balance traffic. Or you could use Anycast with a metric that directs the client to the "lowest cost" (fastest) server. This works something like this:

  1. All DNS servers have the same, Unicast IP address
  2. Different routes to the addresses are annouced through BGP
  3. The routers will use the distance metric annouced by BGP to decide where to send the packets. So they'll go to the closest (lowest cost) DNS server

This mechansim can be resilliant - if a DNS server goes down, it just need to stop publishing a BGP route and it'll no longer receive traffic. If a server is busy, it could either temporarily stop publishing, or increase its cost to reduce the number of connections to it. It's possible that the calculated shortest route could change over the life of a connection, which will cause a problem since the subsequent packets will then end up at a destination that knows nothing about the existing connection. Therefore this is mainly used for stateless protocols, or short lived stateful connections. DNS is a good example, and in fact the DNS root servers all use Anycast addressing to provide multiple real servers in multiple locations behind each IP.

© 2017