TTL (Time to Live)
DNS TTL (Time to Live) is a value in DNS records that tells DNS resolvers how long to cache a query result before requesting fresh data from authoritative nameservers. Measured in seconds, TTL balances the need for up-to-date information against the efficiency of caching. A longer TTL reduces server load and improves performance, while a shorter TTL ensures changes propagate more quickly.
How it works
When a DNS resolver queries an authoritative nameserver for a record, it receives not just the answer (like an IP address) but also a TTL value specifying how many seconds that answer remains valid. The resolver caches this answer and reuses it for subsequent queries until the TTL expires. Once expired, the next query forces the resolver to fetch fresh data from the authoritative server.
example.com and receives the IP 192.0.2.1 with a TTL of 3600 seconds (1 hour)
2. **Caching**: The resolver stores this result in its cache for 3600 seconds
3. **Cache Hits**: For the next hour, any queries for example.com are answered immediately from cache without contacting the authoritative server
4. **Expiration**: After 3600 seconds, the cached record is considered stale
5. **Refresh**: The next query after expiration forces the resolver to query the authoritative server again, potentially receiving updated information
**Trade-offs:**
**Long TTL (hours or days):**
- ✓ Reduces load on authoritative servers
- ✓ Faster DNS resolution (more cache hits)
- ✓ Lower network traffic
- ✗ Changes take longer to propagate
- ✗ Outdated data served for longer periods
**Short TTL (minutes):**
- ✓ Changes propagate quickly
- ✓ More up-to-date information
- ✗ Higher server load
- ✗ More DNS queries needed
- ✗ Slightly slower resolution timesKey Points
- TTL is always measured in seconds (e.g., 300 = 5 minutes, 86400 = 24 hours)
- Shorter TTL values enable faster propagation of DNS changes but increase server load
- Longer TTL values improve performance and reduce server queries but delay change propagation
- Best practice is 1-5 days (86400-432000 seconds) for stable records
- Lower TTL to 5-15 minutes (300-900 seconds) before making planned DNS changes
Common Use Cases
- Stable Production Websites: Use long TTL values (24-48 hours) for established websites with infrastructure that rarely changes, minimizing DNS queries and improving performance
- Pre-Migration Preparation: Lower TTL to 5-15 minutes a day before server migrations or DNS changes to ensure rapid propagation when changes are made
- Development Environments: Use short TTL values (5-10 minutes) for testing and development where DNS records change frequently and quick propagation is essential
- Load Balancing and Failover: Short TTL values allow quick updates to DNS records when servers go down or traffic needs to be redirected
code Common TTL Values
| Type | Host / Name | Value / Points to | TTL |
|---|---|---|---|
| Value | 300 seconds | 5 minutes | — |
| Value | 3600 seconds | 1 hour | — |
| Value | 86400 seconds | 24 hours | — |
| Value | 172800 seconds | 48 hours | — |
* TTL values are measured in seconds. Choose based on how frequently your DNS records change and how quickly you need updates to propagate.