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.
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.
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.
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.
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.
Assume an organization serves its customer on four continents (North America, Europe, Asia, and Australia).
Organization custom name servers resolve the domain to servers
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 organization and accordingly tune DNS settings.