Skip to main content

> Term

Time to Live

A mechanism that determines how long a cached item remains valid.

Detailed Explanation

Time to Live (TTL) is an expiration mechanism that determines exactly how long a piece of data should be considered fresh or valid before it is automatically discarded or refreshed.

While most commonly associated with caching and DNS records, TTLs are heavily used in session management, distributed locks, and temporary cloud resources to prevent stale data and endless resource consumption.

Why It Matters

It forces a healthy cycle of renewal in distributed systems. Without TTLs, caches grow infinitely large, state becomes permanently corrupted, and phantom resources drain cloud budgets.

Common Failure Mode

Setting a TTL way too long, meaning users see an old version of the website for three days after a deploy; or setting it way too short, completely defeating the purpose of the cache and overwhelming the database.

Practical Example

A news website caches its homepage with a TTL of 60 seconds. For one minute, millions of users are served directly from the cache without hitting the database. On the 61st second, the cache expires and a fresh homepage is generated.

Production Manifestation

Headers in HTTP responses (`Cache-Control: max-age`), configuration properties in Redis (`EXPIRE`), and DNS zone file settings governing how long IP addresses are cached.

Frequently Asked Questions

What is Time to Live in short?

A mechanism that determines how long a cached item remains valid.

What is the most common failure mode?

Setting a TTL way too long, meaning users see an old version of the website for three days after a deploy; or setting it way too short, completely defeating the purpose of the cache and overwhelming the database.

AI Summary

A mechanism that determines how long a cached item remains valid. It forces a healthy cycle of renewal in distributed systems. Without TTLs, caches grow infinitely large, state becomes permanently corrupted, and phantom resources drain cloud budgets.