Time to Live (TTL) Value

TTL Value Definition

Time-to-live (TTL) is a numerical value used for data validity and expiration. A TTL stands for the amount of time data should remain valid and available before a computing system discards it. For example, it could represent the number of seconds certain data, or a certain data record, is retained or is considered valid. TTLs are used all across the computing industry, from databases and event streaming systems, to content delivery networks (CDNs), to networking devices such as routers. Each TTL implementation will vary depending on its design goals, pragmatic purpose, and use case.

A TTL differs from an explicit timeout setting in that it is relative. For instance, a TTL could be set to “86400,” representing the number of seconds in a day. This would be very different than setting a specific date and time timeout of “2022-12-03 17:00:00.000+0500.” Consider TTL more of a countdown timer. As a relative value, it also is easier to reset. For example, a trigger could reset a TTL to a specific value rather than having to compute at that moment the new exact date and time for expiration.

Here are a range of examples to show the wide variations possible:

  • In Domain Name System (DNS) servers, TTL sets the length of time a DNS cache server can serve a DNS record before getting new data from the authoritative DNS server. Content Delivery Networks (CDNs) use TTL values to determine how long to cache data and serve it from a CDN edge server before retrieving updated information from an origin server. Ensuring an optimal amount of time between pulls from the origin server enables a CDN to reduce required bandwidth from the origin while efficiently serving content closer to users.
  • Content Delivery Networks (CDNs) use TTL values to determine how long to cache data and serve it from a CDN edge server before retrieving updated information from an origin server. Ensuring an optimal amount of time between pulls from the origin server enables a CDN to reduce required bandwidth from the origin while efficiently serving content closer to users.
  • In the World Wide Web’s hypertext transfer protocol (HTTP), TTL value represents how many seconds the web server can return cached content before it must check again to ensure the content is fresh. Web server settings define a default TTL value.
  • In data networking, TTLs are applied to packets so that the packet is discarded entirely if it exists too long in a network without reaching its destination. TTL in IPv4 was supposed to represent the number of seconds remaining in the valid lifespan of a packet. However, due to the high speed of networking equipment these days, it is often used as a simple “hop count,” decremented by one for each router the packet passes through.
  • In databases, TTLs provide the functionality to automatically delete expired data. The TTL can be set when defining a Table, or when using the INSERT and UPDATE queries. It’s measured in seconds. If the field is not updated within the TTL, it is deleted. The expiration works at the individual column level, while a default for an entire table or row can also be used. This provides a lot of flexibility.
This image depicts TTL Value (time to live), showing that as TTL Value expires, the router must retrieve the information and its updates again.

TTL Value FAQs

How are TTLs used in databases?

In databases, TTLs are used to expire database records or data elements automatically. Functioning like an expiration date, TTL is the length of time data may remain in the database. Data can no longer be retrieved after it reaches its expiration timeout value, and it no longer appears in database statistics.

Documents stored in a database remain active by default unless a removal operation explicitly deletes them. For most scenarios, this is the desired behavior. However, for some use cases, it is more desirable to automatically dispose of older records or data elements and retain only the most recent data.

[Learn about database TTL in this free training course]

What databases support TTL?

Many databases support TTLs, including NoSQL databases such as ScyllaDB, Cassandra, and DynamoDB, or SQL RDBMS such as MySQL, Oracle, PostgreSQL, and SQL Server. TTLs are also frequently deployed in cache and storage systems such as RocksDB, Redis, and MyRocks.

Does ScyllaDB offer options for setting TTL value?

TTL values are features of both ScyllaDB and Apache Cassandra, but implementation varies across both of these databases.

In ScyllaDB, TTL for its Cassandra Query Language (CQL) interface can be set based on a number of seconds. It can be set for an entire row — deleting it entirely — or for a specific value per column for a non-primary key column.

The default TTL value is null, so the data will not expire — just define the TTL value when creating the table using the default_time_to_live feature. This behavior is similar to Apache Cassandra’s use of TTLs.

In addition, TTL can be set in ScyllaDB for data stored in Change Data Capture (CDC) log tables by using the cdc$ttl setting. This prevents the CDC tables from filling up your storage. Apache Cassandra manages CDC very differently and lacks this TTL feature for its CDC implementation.

Aside from this, the DynamoDB-compatible interface for ScyllaDB, known as Alternator, uses a different form of TTL. These TTLs are set at the attribute name level. Expirations in Alternator also have a deletion delay of up to 48 hours; by default, it is set to 24 hours. Since the Alternator interface is unique to ScyllaDB, Apache Cassandra has no comparable setting.

Learn more about how TTL value works in the ScyllaDB documentation and the ScyllaDB University lesson on expiring data with TTL.

Trending NoSQL Resources

ScyllaDB University Mascot

ScyllaDB University

Get started on your path to becoming a ScyllaDB expert.