Engineering Manager @housing.com (https://bit.ly/2GCus2q). Love learning and teaching.
DNS resolution is the first thing that happens when a request is made to a remote server. It is a process of finding the computer-friendly address of the remote server using a human-friendly domain name.
There are few performance improvement possibilities like perfect cache invalidation time. Preferring A record over CNAME. But before all these let's understand how DNS resolution actually works.
Ahh too confusing and too much to remember. Let's keep it simple and know what is in our control and find the scope of performance improvements.
A registrar is a place where one buys a domain. The registrar provides name servers and a few other DNS management tools.
Example Registrars and DNS management tools
The main job of DNS management tools.
1. Increase cache invalidation time
Increasing cache invalidation time will ensure that the domain IP addresses will be served from the nearest cache. This will result in low latency DNS resolution.
This will be a problem in cases where domain to IP mapping is frequently changed.
To handle such cases follow these steps.
This will fix any downtime possibilities from any known changes. But what if the server crashed or something unexpected happened. For such cases keeping a static IP and assigning it to a new server will help.
Let's look at the TTL value of some popular domains.
Increasing TTL is a tradeoff between availability and performance. Controlling availability with high TTL is possible but needs extra effort and care.
2. Use A or AAAA record wherever possible in place of CNAME
CNAME or Canonical Name is like recursion where one domain resolves to another domain. The DNS resolution algorithm keeps looking until it finds the real IP address.
In most cases replacing CNAME will not be possible because of no control over the resolved IP address. This rule is only applicable for cases where IP address is known but still, CNAME is preferable due to unmanageable DNS records. DNS records if not maintained properly becomes unmanageable in most mid to large-scale organizations.
Some CDN and DNS service providers use a concept of CNAME Flattening to resolve IP directly without going through the whole chain of DNS resolution. Opt for it if your CDN or DNS service provider has support for it.
3. Use CDN which uses their own name servers.
CDN works in two ways.
Both approaches have their own Pros and Cons. The first one is good for fast DNS resolution. The second one gives more flexibility and control to the maintainer.
CDN has other limitations they are yet not equipped to serve dynamic content. There is some development in this area like using lambda on the edge(AWS) but still, there is a long path to cover.
4. Use custom name servers (only for large scale applications)
The purpose of name servers is to provide a real IP address that corresponds to a domain. Using custom logic a domain can be resolved to a different IP each time it receives a request.
CDN uses this approach to serve content from the nearest host to the user but they can’t be used for dynamic content.
Using custom name servers to resolve IP addresses based on the region can significantly reduce latency.
Now people in North America can get their content directly from servers in California and people in India get content from Mumbai. Data belongs to a region can be stored along with the region and fallbacks to other regions.
This gives a lot of flexibility for dynamic logic without any compromising on performance.
There are lots of complexities in this approach. One problem is database sharding keeping a region's data close to it but still able to serve content from other shards.
Many large scale organizations use this approach to distribute traffic and serve the request quickly.
Improving DNS resolution can have a huge impact on the performance of a site. But every possible optimization has some cost.
Figure out appetite for performance at your org and accordingly tune DNS settings.
Previously published at https://ashu.online/blogs/optimize-dns-resolution-for-fast-website
Create your free account to unlock your custom reading experience.