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.
Select your interface once. The prerequisites and every task below show only that path.
Prerequisites
- 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.
To add the three records with the Azion CLI, run one command per record. Replace <zone-id> with the ID of your zone:
Each command prints the ID of its record:
The CLI uses --weight and --description only when --policy is weighted. Never include the domain in --name: Edge DNS adds it.
To check the records, list the records of the zone:
The list shows the three records on lb, each with its own ID:
The zone holds the three weighted records. Record their IDs: a later change to a weight uses them.
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.
To set a record’s weight to 0 with the Azion CLI, replace <zone-id> and <record-id> with the IDs of the zone and the record:
The command confirms the update:
The record keeps its weighted policy, and its weight is 0. To check it, run azion describe dns-record --zone-id <zone-id> --record-id <record-id>, which prints Policy: weighted and Weight: 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.