Stay organized with collections
Save and categorize content based on your preferences.
Simulate cell-level TTL
In Bigtable, garbage collection policies are set at the
column family level, and you cannot specify a cell-level garbage collection
policy. However, you can simulate a time to live (TTL) policy at the cell level
by changing your garbage collection settings. This page explains a few different
approaches that you can use.
In this approach, set your garbage collection rule to let data expire after one
second. Whenever you write data, set the cell's timestamp to the time you want
the value to expire. During compaction, Bigtable deletes any cells
that have a timestamp that is at least one second in the past. For example, if
you set a cell's timestamp to April 30 at 9:00:00 AM, the cell is deleted
sometime after April 30 at 9:00:01 AM. This approach enables you to set
different expiration values for different cells in the same column family.
Advantages of one-second expiration
The timestamp has a real meaning: the expiration time.
Disadvantages of one-second expiration
Every application that writes data to this Bigtable column
family needs to be configured to follow this rule. If you forget and use a
default server timestamp on a write, that data expires right away
and is deleted during the next compaction.
Because your timestamps aren't "real" you cannot use timestamps for any other
use case, such as determining when a value was written. As a workaround, you can
write the real timestamp to a separate column, but this will increase the amount
of data you store.
You cannot implement this strategy on a column family that already has data
with real timestamps. If existing data has real timestamps, or if you
accidentally write new data with real timestamps, that data is deleted
during the next compaction.
You cannot specify that multiple cells for a given row and column should
expire at the same time as each other. New data will overwrite old data with the
same timestamp.
Because garbage collection can take up to a week, you always need to use
filters when you read the data.
Default expiration
Let's say you want most of your data to have a default TTL, but you want to set
different per-cell expiration values for some of your data.
For example, you might store click events for ten customers in one table. Most
of the click events should expire after 2 days, but you have one customer whose
click events should expire after an hour, and you have another customer whose
click events should expire after 3 days.
In this approach, create your column family with an age limit for garbage
collection set to the default TTL. For data you want to expire sooner than the
default, set the timestamp to be earlier than the time the data is actually
written. For data you want to expire later, set the timestamp to be later than
the time the data is actually written.
Advantages of default expiration
A default TTL is in place for writes that do not have a custom TTL.
This approach can safely be applied to a pre-existing table.
Disadvantages of default expiration
The timestamp is not semantically meaningful because a cell's timestamp
might be real or artificial. This means you cannot use the cells'
timestamps for any other use case, such as determining when a value was written.
As a workaround, you can write the real timestamp to a separate column, but
this will increase the amount of data you store.
You can inadvertently write a custom timestamp that clashes with a real
timestamp in a given column.
Because garbage collection is asynchronous, you still need to always use
filters when you read the data when you use this strategy.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-25 UTC."],[[["\u003cp\u003eThis page details methods to simulate cell-level time-to-live (TTL) policies in Bigtable, which natively only supports garbage collection at the column family level.\u003c/p\u003e\n"],["\u003cp\u003eThe "one-second expiration" approach involves setting a column family's garbage collection rule to expire data after one second, with the cell's timestamp set to the desired expiration time.\u003c/p\u003e\n"],["\u003cp\u003eThe "default expiration" strategy involves setting a default TTL at the column family level, while allowing for per-cell adjustments by manipulating the cell's timestamp.\u003c/p\u003e\n"],["\u003cp\u003eBoth expiration approaches use timestamps that may not be semantically meaningful for data creation time and require filters when reading data due to asynchronous garbage collection.\u003c/p\u003e\n"],["\u003cp\u003eBoth approaches have some advantages, such as how default expiration can be safely applied to pre-existing table, but also disadvantages such as the data write process needing to be configured correctly in the one-second approach.\u003c/p\u003e\n"]]],[],null,["# Simulate cell-level TTL\n=======================\n\nIn Bigtable, garbage collection policies are set at the\ncolumn family level, and you cannot specify a cell-level garbage collection\npolicy. However, you can simulate a time to live (TTL) policy at the cell level\nby changing your garbage collection settings. This page explains a few different\napproaches that you can use.\n\nBefore you read this page, you should read the [garbage collection overview](/bigtable/docs/garbage-collection). To learn how to send write requests, which\ninclude timestamps, see [Bigtable writes](/bigtable/docs/writes).\n\nOne-second expiration\n---------------------\n\nIn this approach, set your garbage collection rule to let data expire after one\nsecond. Whenever you write data, set the cell's timestamp to the time you want\nthe value to expire. During compaction, Bigtable deletes any cells\nthat have a timestamp that is at least one second in the past. For example, if\nyou set a cell's timestamp to April 30 at 9:00:00 AM, the cell is deleted\nsometime after April 30 at 9:00:01 AM. This approach enables you to set\ndifferent expiration values for different cells in the same column family.\n\n### Advantages of one-second expiration\n\n- The timestamp has a real meaning: the expiration time.\n\n### Disadvantages of one-second expiration\n\n- Every application that writes data to this Bigtable column\n family needs to be configured to follow this rule. If you forget and use a\n default server timestamp on a write, that data expires right away\n and is deleted during the next compaction.\n\n- Because your timestamps aren't \"real\" you cannot use timestamps for any other\n use case, such as determining when a value was written. As a workaround, you can\n write the real timestamp to a separate column, but this will increase the amount\n of data you store.\n\n- **You cannot implement this strategy on a column family that already has data\n with real timestamps.** If existing data has real timestamps, or if you\n accidentally write new data with real timestamps, that data is deleted\n during the next compaction.\n\n- You cannot specify that multiple cells for a given row and column should\n expire at the same time as each other. New data will overwrite old data with the\n same timestamp.\n\n- Because garbage collection can take up to a week, you always need to use\n filters when you read the data.\n\nDefault expiration\n------------------\n\nLet's say you want most of your data to have a default TTL, but you want to set\ndifferent per-cell expiration values for some of your data.\n\nFor example, you might store click events for ten customers in one table. Most\nof the click events should expire after 2 days, but you have one customer whose\nclick events should expire after an hour, and you have another customer whose\nclick events should expire after 3 days.\n\nIn this approach, create your column family with an age limit for garbage\ncollection set to the default TTL. For data you want to expire sooner than the\ndefault, set the timestamp to be earlier than the time the data is actually\nwritten. For data you want to expire later, set the timestamp to be later than\nthe time the data is actually written.\n\n### Advantages of default expiration\n\n- A default TTL is in place for writes that do not have a custom TTL.\n\n- This approach can safely be applied to a pre-existing table.\n\n### Disadvantages of default expiration\n\n- The timestamp is not semantically meaningful because a cell's timestamp\n might be real or artificial. This means you cannot use the cells'\n timestamps for any other use case, such as determining when a value was written.\n As a workaround, you can write the real timestamp to a separate column, but\n this will increase the amount of data you store.\n\n- You can inadvertently write a custom timestamp that clashes with a real\n timestamp in a given column.\n\n- Because garbage collection is asynchronous, you still need to always use\n filters when you read the data when you use this strategy.\n\nWhat's next\n-----------\n\n- Read about garbage collection with [timestamps that are sequential numbers](/bigtable/docs/gc-sequence-numbers).\n- Learn a strategy to [always read the most recent value of a column](/bigtable/docs/keep-only-latest-value).\n- Review code samples showing how to [configure garbage collection](/bigtable/docs/configuring-garbage-collection).\n- Learn more about [storage pricing](/bigtable/pricing#storage)."]]