How to Build Low-Latency Services, Using Anycast Routing

Equinix Metal makes it as easy as 1.2.3.

David McKay
How to Build Low-Latency Services, Using Anycast Routing

Did you know that the city with the most McDonald’s restaurants per capita is Orlando, Florida? With almost 20 McDonald’s per 100k people, finding a McDonald’s depends entirely on where you are. It doesn’t matter if you’re on International Drive or Thornton Park, you’ll get your Big Mac; it’ll just be served by different staff, in a different franchise, in a different neighborhood. If there’s not a McDonald’s close enough to you, you’ll need to wait longer before you get your meal.

When we talk about Anycast, it’s pretty much the same. You can request your favorite website, and it’s within that website’s best interest to serve you from a location as close to you as possible for the best possible experience.

To dig into the fundamental advantages of Anycast before we dive into the more technical side of how it works, check out “Leverage BGP and Bare Metal To Build An Anycast Network“. Let’s start with a quick example of how the internet traditionally works with unicast routing. With unicast, every public IP address maps to zero or one machine. The machines that have these addresses have their IP address advertised by an autonomous system (AS). There are many autonomous systems on the internet, and they all share information with each other about the IP addresses they advertise.

When you request from your laptop, you’re routed through a local AS. It’s unlikely the local AS is advertising, so it needs to route you through another AS. In our diagram above, it’s possible to get to via multiple paths within the network, and your local AS will do its best to route you through the shortest, which is through the Amsterdam AS to the machine.

With anycast routing, we can mix things up a little and switch from having a single machine advertising an IP address to one machine per AS advertising the IP.

Anycast with Equinix Metal

In-order to leverage the anycast pattern with Equinix Metal, we can utilize Global IPs. Global IPs are what Equinix Metal call IP addresses that can be advertised from multiple AS’s within network.

You can order Global IPs from the “IPs & Networks” page on your Equinix Metal console. They are available as 1 (/32), 2 (/31), or 4 (/30) IP blocks.

Start Your Equinix Metal Free Trial

To try this for yourself, signup for Equinix Metal and use promocode ANYCAST for $100 in free credit.

Get Started
Equinix Metal Standard RGB

Deploying Our Workload

For this example, we are going to keep things nice and simple. We will deploy nginx to two machines with Equinix Metal: one in Amsterdam (AM6) and one in Singapore (SG1). On Ubuntu, we can install nginx with the following command:

apt update && apt install -y nginx

If we ask curl to give us some performance metrics from our laptop, we will see how much the requests differ; due to the distance traveled for each request. To have curl give us performance metrics, we need to create a small helper script.

#!/usr/bin/env sh
curl -w @- -o /dev/null -s "$@" <<'EOF' 
time_namelookup:  %{time_namelookup}\n
time_connect:  %{time_connect}\n 
time_appconnect:  %{time_appconnect}\n
time_pretransfer:  %{time_pretransfer}\n 
time_redirect:  %{time_redirect}\n 
time_starttransfer: %{time_starttransfer}\n
        time_total:  %{time_total}\n

These requests are being made in Scotland. First, let us check out the timings for a curl request to Amsterdam.



Pretty quick! Not surprising, as Amsterdam is only 900km away from Scotland. Now let’s try Singapore, which is around 6800km from Scotland.



We can see that the round-trip time (RTT) for Amsterdam is 69ms, and unfortunately for our customers, the RTT for Singapore is 533ms.

We want better response times for our customers, regardless of where they are in the world; but we do not want to give our EMEA ) customers one IP address or DNS name, and other customers in other regions a different IP address or DNS

name. This would be cumbersome and confusing. We want a single-entry point to our service that can be used globally and routed efficiently and effectively.

To solve this, we’ll use the anycast pattern and advertise our Global IPs from our AS’s in as many facilities as we need to keep our customers happy.

Broadcasting Our Global IPs

First, we need to add our Global IP to each of the machines we want to route traffic to. We can add a new interface to the /etc/network/interfaces file.

# /etc/network/interfaces 
auto lo:0
iface lo:0 inet static
    address #Your Global IP 

Then we can bring up our interface with ifup lo:0

Next, we need to install bird and configure it to broadcast our IP address to the local AS via the Border Gateway Protocol (BGP).

apt -y update && apt -y install python3.6 python3-pip git bird

Equinix Metal provides some helper scripts to configure bird, which can be installed with:

cd /opt
git clone 
cd network-helpers
pip3 install jmespath 
pip3 install -e .

Now we can use these helpers to generate our bird configuration and restart the service.

./ -r bird | tee /etc/bird/bird.conf
systemctl restart bird

That is it! You need to repeat this on each of your machines that you want to advertise your Global IP. In this example, we now have two machines, geographically distributed, answering to a single IP address broadcasting to multiple AS.

Let us look at the new response times from curl. First, we will hit our Global IP from Scotland; which will be routed to Amsterdam (1000km).



As well as the response time, we can run a traceroute to ensure the IP was resolved in Amsterdam.

traceroute to (, 64 hops max, 52 byte packets

1 (  3.826 ms  6.728 ms  3.926 ms
2 (  5.452 ms  6.977 ms  7.106 ms
3  * * *
4 (  23.752 ms  19.608 ms  19.857 ms
5  * * *
6  * * *
7  * * *
8  * * *
9  * (  1206.166 ms  27.833 ms
10 (  28.407 ms  37.980 ms  34.374 ms
11 (  41.069 ms * *
12 (  54.836 ms (  40.088 ms (  34.877 ms
13 (  40.951 ms  33.051 ms  34.763 ms
14 (  35.449 ms  43.872 ms  34.326 ms
15 (  35.634 ms  46.148 ms  38.603 ms
16  * * *
17  * * *
18  am6-c3.medium.x86-01 (  35.437 ms  32.807 ms  40.736 ms

Now we can do the same from a machine in Hong Kong, which is routed to Singapore (2500km).


Finally, we can see the traceroute run from our Hong Kong machine is routed to Singapore.

traceroute to (, 30 hops max, 60 byte packets
1 (  12.815 ms  12.723 ms  12.687 ms
2 (  11.745 ms  11.707 ms  11.673 ms
3 (  7.123 ms  7.084 ms  7.093 ms
4 (  50.078 ms  50.038 ms  49.966 ms
5 (  118.265 ms  118.753 ms  118.747 ms
6 (  117.729 ms (  117.801 ms  117.751 ms
7 (  117.692 ms  117.708 ms (  117.634 ms
8  sg1-c3.medium.x86-01 (  117.588 ms  117.738 ms  117.660 ms

Building globally low-latency services that your customers will love has never been so simple.

Avatar photo
David McKay Former Senior Developer Advocate at Equinix Metal
Subscribe to the Equinix Blog