Row Expiration
Ordinarily, rows in a table are not deleted until a client explicitly deletes them. In some situations however, the data in the rows might only remain valid or relevant for a short span of time. Leaving these rows in the table indefinitely consumes disk space and in some situations can slow down your queries. The row expiration feature is designed to remove outdated rows.
An application developer can override the default TTL by setting TTL on a specific row before it is inserted in a table. Developers can use the C or Java API to override the TTL set for a table. For more information, see Overriding the Default TTL for a Single Row.
When a row is expired, it becomes available for deletion from the table. Note that becoming available for deletion does not mean it gets deleted immediately. Deletion takes place only after the table is scanned for expired rows. For more details, see Deletion of Expired Rows.
- Defining a Table with Row Expiration
When defining a table, you can set the default_ttl property to a non-zero value to enable row expiration. The time interval is specified in seconds. Unless a different TTL was set on a particular row, rows inserted in a table inherits the default TTL value set on the table and expires after their TTL interval has elapsed. If the default_ttl is not set or is set to 0 (zero), the rows of the table never expire. - Overriding the Default TTL for a Single Row
When building applications, developers can use the client APIs to override the default TTL set on a table. Remember to set the default TTL for a row before inserting the row into the table. - Deletion of Expired Rows
When a row expires, it is available for deletion, but it is not deleted immediately. Deletion is a background process that scans the tables for expired rows and then deletes them. Therefore, application can retrieve rows that have expired but not deleted.