External Publication
Visit Post

TTL

Sahil Kapoor's Playbook May 12, 2026
Source

TTL (Time To Live) is the duration for which a cached value, DNS record, or other transient piece of data remains valid. After the TTL expires, the entry is considered stale and either evicted, refreshed, or revalidated. TTL is one of the simplest knobs in cache design with outsized impact on hit rate and freshness.

How it appears in different systems

  • Caches: per-key TTL on Redis or Memcached entries; sets the lifetime independent of the eviction policy.
  • HTTP: Cache-Control: max-age=3600 tells browsers and CDNs how long to cache a response.
  • DNS: each record has a TTL; resolvers and clients cache it for that long before re-querying the authoritative server.
  • Tokens: the exp claim in a JWT is effectively a TTL on the token's validity.
  • Databases: some stores support TTL indexes (MongoDB, DynamoDB) that auto-delete documents after a duration.

Choosing a TTL

  • Shorter TTL. Fresher data, lower hit rate, more origin load.
  • Longer TTL. Higher hit rate, lower origin load, staler data and slower invalidation if something changes.
  • Stale-while-revalidate. Serve stale content immediately and refresh asynchronously, getting both speed and eventual freshness.

๐Ÿ”—

Related Terms Caching, CDN, Redis, Eviction Policy, JWT

๐Ÿ“–

Further Reading Synchronized Expiration in Distributed Systems

Discussion in the ATmosphere

Loading comments...