DNS Caching and TTL Explained

Why DNS Relies Heavily on Caching

Repeating the full multi-step resolution process (covered in the resolution-process note) for every single request to a popular website would be incredibly wasteful. Caching stores previous answers so repeat lookups can be answered almost instantly, without redoing all that work.

TTL: How Long a Cached Answer Stays Valid

Every DNS record includes a TTL (Time To Live) value, measured in seconds, which tells any resolver caching that answer exactly how long it's allowed to keep using it before it must ask again.

example.com.   A   93.184.216.34   TTL: 3600   (valid for 1 hour)

The Trade-off Between a High and Low TTL

Long TTLShort TTL
PerformanceFaster - fewer repeat lookups neededSlightly slower - more frequent lookups
Update speedSlow - old cached answers linger longer if changedFast - changes propagate to resolvers quickly

Why Administrators Lower TTL Before a Planned Change

Before migrating a website to a new server (and therefore a new IP address), it's common practice to lower a domain's TTL well in advance. This ensures that once the actual change happens, cached resolvers worldwide will refresh their answer quickly, instead of some visitors being stuck reaching the old server for hours.

Caching Happens at Several Levels at Once

A single lookup can be cached at the operating system level, inside the web browser itself, and at the ISP's resolver - meaning a DNS change can sometimes appear to "not have taken effect yet" for some users purely because one of these several cache layers hasn't expired yet, even though the actual DNS records were updated correctly.

Written by Lorens Mishra

Software Engineer Notes Management System Administrator

Discussion

0 comments
Sign in to join the discussion.

No comments yet. Be the first to say something.