Weight records to balance traffic
Spread the answers for one name across several addresses with weighted records in Edge DNS, from Azion Console, the Azion CLI, or the API.
You can weight records to balance traffic in Edge DNS from Azion Console, the Azion CLI, or the Azion API. Several records share one name and type, and each answer carries the value of one of them, chosen in proportion to its weight. To add a record that answers with all of its values at once, refer to Add, edit, or delete a record instead.
Prerequisites
Console
- A zone for your domain. To create one, refer to Create, edit, or delete a zone.
- The Edit Edge DNS permission. It requires View Edge DNS. Refer to Teams permissions.
digon your machine, to check the answers. To install it, refer to Query a zone with dig.- Access to Azion Console. To sign in, refer to Access Azion Console.
Add the weighted records
This example adds three A records on the name lb, one per address, with weights 50, 20, and 30. Over many answers, 192.0.2.21 carries about half of them, 192.0.2.22 a fifth, and 192.0.2.23 the rest. Replace the addresses with your own, and example.com with your domain.
Each record uses a TTL of 20 seconds, so resolvers choose again sooner. A short TTL also makes resolvers ask more often, and every query counts toward your plan’s included usage.
Console
To add the first record in Azion Console:
Access Azion Console > Edge DNS.
On the Zones page, select the row of the zone, then select the Records tab.
The Create Record drawer opens.
In Name, enter lb. The Console shows your domain after the field and adds it for you, so never type the domain.
Keep Record Type set to A - IPv4 Address.
In TTL (seconds), enter 20.
In Value, enter 192.0.2.21.
In the Policy section, set Policy Type to Weighted.
In Weight, enter 50. The Console pre-fills 100.
In Description, enter up to 45 characters that tell this record apart from the others on lb, such as origin weight 50.
The Console shows Edge DNS Record has been created, and the record appears in the Records table with weighted in the Policy column.
Repeat the steps for the other two records. Keep Name lb, Record Type A, and the TTL, and change only the value and the weight: 192.0.2.22 with weight 20, then 192.0.2.23 with weight 30. The Records table then lists three lb rows.
The weighted policy works on A, AAAA, CNAME, ANAME, and MX records. A TXT or NS record with policy set to weighted is refused with 19017. For every field and its bounds, refer to Zones and records.
Check the weighted answers
Query Azion’s nameserver directly, without your resolver’s cache, to see which address it answers.
To query ns1.aziondns.net for the name, replace example.com with your domain:
The nameserver returns one address, the value of the record it chose:
Each answer carries one address, never the three. Run the query again right away and the same address returns: the nameserver answers from a cache that counts the record’s TTL down. Run it again after each 20-second TTL, over several minutes, and the other addresses appear. Over many answers, each address answers in proportion to its weight. For how the nameserver chooses, refer to How Edge DNS works.
A new name nobody queried before it existed answers within seconds. A change to an existing record can take a few minutes to reach every nameserver. For the details, refer to Caching and propagation.
Take an address out of rotation
A record with weight 0 stays in the zone and is never answered. Set a weight of 0 to stop answers for an address without deleting its record, and restore the weight to bring it back. Before you delete a weighted record, set its weight to 0 first, as Best practices for Edge DNS explains.
Console
To set a record’s weight to 0 in Azion Console:
Access Azion Console > Edge DNS.
On the Zones page, select the row of the zone, then select the Records tab.
Select the row of the record. The Edit Record drawer opens.
In Weight, enter 0.
The Console shows Edge DNS Record has been updated, and the Weight column of the row reads 0.
Resolvers that cached the address keep it until its TTL expires, and the change can take a few minutes to reach every nameserver. After that, the other records carry every answer for the name.