Cloud concept · Updated

Time to Live - Time to Live is a limit on how long data remains valid, reusable, or retained before expiration handling applies.

In short

Time to Live (TTL) controls the lifetime of cached responses, DNS records, and other temporary data. Engineers use it to balance freshness, latency, backend load, and storage consumption, but expiration behavior depends on the system implementing it.

Cloud Concepts Hub →

6 key aspects of Time to Live

TTL defines expiration behavior and balances freshness against efficiency, but effective results depend on cache policies, independent layers, and refresh mechanisms.

01
Explicit expiration semantics

Determine whether TTL is a duration or an expiration timestamp and what event starts the lifetime. Document whether expiration means revalidation, loss of visibility, or eventual deletion.

02
Freshness versus efficiency

Longer lifetimes reduce backend requests but increase the potential duration of stale responses. Choose values according to how quickly consumers must observe changes, not just the desired cache hit ratio.

03
Origin directives and cache policy limits

HTTP freshness headers interact with cache-specific configuration. In CloudFront, inspect minimum, default, and maximum TTL values, especially a positive minimum that can override restrictive origin caching directives.

04
Revalidation and early eviction

An expired cached response may be revalidated rather than downloaded again. An unexpired response may also be evicted early, so TTL does not guarantee cache residency.

05
Independent cache layers

Browsers, CDN edges, DNS resolvers, and application caches maintain separate lifetimes. Clearing or changing one layer does not necessarily refresh the others.

06
Operational refresh controls

Use invalidation or versioned resource names when waiting for expiration is unacceptable. Check cached errors and cache-key correctness before concluding that the freshness interval alone caused the problem.

Cloud services for Time to Live

Route 53 controls how long DNS resolvers reuse the address information that directs clients to an application. CloudFront separately controls reuse of HTTP responses, often using freshness metadata supplied by an S3 origin. An application behind the delivery layer can use ElastiCache to limit repeated backend reads, while DynamoDB TTL can clean up temporary records asynchronously. These lifetimes operate independently: DNS expiration does not refresh CDN content, CDN invalidation does not clear browser caches, and database expiration does not remove cached application results. Coordinate their settings around the application's freshness requirements and test each layer separately during troubleshooting.

Amazon CloudFrontAmazon CloudFront

CloudFront combines origin freshness headers with cache-policy minimum, default, and maximum TTL settings to control edge caching. Troubleshooting includes examining matching cache behaviors, cache keys, cached errors, and whether invalidation or versioned URLs are needed.

Amazon S3Amazon S3

S3 objects can carry Cache-Control and Expires metadata that influence downstream browser and CDN freshness. Those headers do not delete the object from S3; object retention and lifecycle expiration are separate mechanisms.

Amazon Route 53Amazon Route 53

Route 53 DNS records use TTL to tell recursive resolvers how long they may cache answers. Lowering TTL before a planned DNS change can reduce transition delays, but previously cached answers retain their earlier lifetime.

Amazon ElastiCacheAmazon ElastiCache

ElastiCache engines support expiring cache entries to limit reuse of application data. Applications must tolerate misses caused by expiration or eviction and retrieve current values from the authoritative backend.

Amazon DynamoDBAmazon DynamoDB

DynamoDB TTL uses a designated numeric attribute containing a Unix epoch expiration time in seconds. Expired items are deleted asynchronously, typically within a few days, so applications requiring immediate expiration must check timestamps rather than rely on prompt physical deletion.

Time to Live exam questions

Real practice exam questions on Time to Live, with the correct answer and its explanation. Answer them with every option in the exam simulator.

SOA-C03

A company serves a public configuration document through Amazon CloudFront. Origin request volume remains high even when users repeatedly request the same URL. The origin returns Cache-Control: public, max-age=0, must-revalidate. The CloudFront cache policy has a minimum TTL of 0 seconds, a default TTL of 3,600 seconds, and a maximum TTL of 86,400 seconds. No request attributes create different cache keys.

The company wants CloudFront to consider newly fetched responses fresh for 600 seconds to reduce origin requests. Browsers must continue to revalidate cached responses before reusing them. Which change meets both requirements?

Show answerCORRECT ANSWER

Change the origin header to Cache-Control: public, max-age=0, s-maxage=600, must-revalidate, and leave the cache policy unchanged.

The s-maxage directive gives shared caches such as CloudFront a 600-second freshness lifetime and takes precedence over max-age for those caches. This value is within the policy's TTL bounds. Browsers ignore s-maxage, so max-age=0 and must-revalidate continue to require browser revalidation before reuse.

SAP-C03

A logistics company serves a large public routing-data file through Amazon CloudFront from an HTTPS origin in its data center. All viewers receive identical content at the same URL. Requests are frequent at edge locations worldwide, and outbound data transfer from the data center is expensive. The origin returns the complete file for every origin request and does not support conditional requests.

The origin currently returns Cache-Control: public, max-age=60. The CloudFront cache policy has a minimum TTL of 0 seconds, a default TTL of 60 seconds, and a maximum TTL of 60 seconds. No other response headers specify freshness.

During normal operation, CloudFront may reuse a cached response for up to 10 minutes without checking the origin. Browsers must not consider a response fresh for more than 1 minute. The company cannot change the file URL or use scheduled invalidations. The origin headers and CloudFront cache policy can be changed.

Which configuration will minimize repeated full-file transfers from the origin while meeting both freshness requirements?

Show answerCORRECT ANSWER

Return Cache-Control: public, max-age=60, s-maxage=600. Set the CloudFront minimum TTL to 0 seconds, default TTL to 60 seconds, and maximum TTL to 600 seconds.

The s-maxage directive gives shared caches such as CloudFront a 600-second freshness lifetime, while browsers use max-age=60. The CloudFront maximum TTL permits the full 600-second shared-cache lifetime. This maximizes permitted reuse at CloudFront and reduces full-file origin transfers without allowing browsers to consider responses fresh for more than 60 seconds.

DVA-C02

A developer is configuring caching for an Amazon API Gateway Regional REST API. The GET /prices method returns a public price list in the currency specified by the X-Currency request header. Each request also includes a unique X-Request-Id header for tracing. Both headers are declared as method request parameters and forwarded to the backend. No other request attributes affect the response.

The developer has provisioned an API Gateway stage cache and enabled caching for the method. Responses can be reused for 5 minutes. Requests with the same X-Currency value must reuse a cached response even when their X-Request-Id values differ, while requests for different currencies must not share cached responses.

Which configuration meets these requirements?

Show answerCORRECT ANSWER

Select X-Currency as a cache key parameter for the method, exclude X-Request-Id from the cache key, and set the cache TTL to 300 seconds.

API Gateway REST API caching can use method request headers as cache key parameters. Including X-Currency separates responses by currency, while excluding X-Request-Id allows requests for the same currency to share an entry. A 300-second TTL provides the permitted 5-minute reuse period.

Practice Time to Live in a full exam

Questions on Time to Live in each practice exam, with every answer option and an explanation for each:

Start a free practice exam

What is Time to Live

3 min read

Time to Live, usually abbreviated TTL, defines a lifetime for a piece of data. In caching, it commonly specifies how long a stored response can be reused without checking its source. Other systems express TTL as an expiration timestamp rather than a duration. Always identify what expires, when the lifetime begins, and what the system does after expiration. Expiration might trigger revalidation, make an entry unavailable, or schedule asynchronous deletion; these are different behaviors.

For cloud content delivery, TTL determines how long an edge cache can consider an object fresh. A long TTL reduces origin requests, improves response latency, and helps absorb traffic spikes. A short TTL makes updates visible sooner but increases origin traffic and can expose backend capacity problems. Content-addressed static files, such as application.a81f.js, can usually tolerate long cache lifetimes because a changed file receives a new URL. Frequently updated HTML or configuration documents generally need shorter lifetimes or explicit revalidation.

HTTP origins communicate freshness through response headers. Cache-Control: max-age=300 specifies a freshness lifetime of 300 seconds. Cache-Control: s-maxage=3600 gives shared caches, such as a CDN, a separate lifetime and takes precedence over max-age for those caches. Expires provides an absolute expiration time when an applicable Cache-Control freshness directive is absent. For example, max-age=60, s-maxage=600 allows a browser freshness lifetime of one minute while a shared cache can use ten minutes, subject to its configured policies.

Amazon CloudFront applies minimum, default, and maximum TTL settings through cache policies. The default applies when the origin supplies no applicable freshness information; the minimum and maximum constrain the lifetime CloudFront derives from origin headers. A critical troubleshooting detail is that a minimum TTL greater than zero causes CloudFront to cache content for at least that interval even when the origin sends no-cache, no-store, or private. For sensitive or user-specific responses, use a configuration that actually prevents inappropriate caching rather than assuming an origin header alone is sufficient.

Expiration does not necessarily mean that cached bytes are immediately deleted or that the next request downloads the entire object. A cache can revalidate a stale response using ETag or Last-Modified validators. If the origin returns 304 Not Modified, the existing representation can be reused with refreshed freshness information. Explicit stale-serving directives can also permit reuse after freshness expires. Conversely, a cache can evict an object before its TTL ends because of capacity management, so TTL is not a guaranteed residency period.

When troubleshooting stale content, inspect the viewer response and the origin response, including Cache-Control, Expires, Age, and CloudFront's X-Cache header. Verify which cache behavior and cache policy match the request. Check whether the cache key distinguishes required query strings, headers, or cookies: a short TTL cannot correct a key that combines different representations. Cached error responses also have expiration controls, so a fixed origin can still appear broken while an earlier error remains cached.

Updating an origin object does not automatically replace copies already cached at the edge or in browsers. For an urgent correction, use CDN invalidation or publish a new versioned URL. CloudFront invalidation does not clear browser caches, and lowering a configured TTL should not be treated as an immediate purge. Also distinguish freshness problems from connectivity failures: changing an object TTL does not repair routing, TLS, or origin access permissions.

The same lifetime principle appears in DNS caching, application caches, and database record expiration, but their guarantees differ. DNS TTL controls resolver reuse, whereas a database TTL feature may delete expired records asynchronously. The IP packet field also called TTL is different: in modern IP forwarding, it effectively limits router hops rather than defining a cache freshness duration.

Learn Time to Live in lessons

4 short lessons on Time to Live in 3 certification courses.

Open the lessons