What is the purpose of TTL (Time to Live) in Cassandra?
Last updated
TTL lets you set an expiration time (in seconds) on data so Cassandra automatically deletes it after that period, without an explicit delete. It's ideal for transient data that should self-expire, such as sessions, caches, or time-limited records.
How it's applied:
Set per write with
USING TTL <seconds>, or as a table default viadefault_time_to_live.TTL is per cell (per column value), not per row, unless every cell is written together.
What happens at expiry: The cell becomes a tombstone and the value is no longer returned; it's physically removed during compaction after
gc_grace_seconds.Caveats:
Heavy TTL use generates many tombstones, which can hurt read performance if not managed (e.g. with TWCS for time-series).
Check remaining TTL with the
TTL(column)function.
[lang:sql]
INSERT INTO sessions (id, token) VALUES ('s1', 'abc') USING TTL 3600;
- https://www.wecreateproblems.com/interview-questions/cassandra-interview-questions
- https://mindmajix.com/cassandra-interview-questions-and-answers
- https://www.whizlabs.com/blog/cassandra-interview-questions-and-answers/
- https://www.analyticsvidhya.com/blog/2023/03/top-5-interview-questions-on-cassandra/
- https://www.geeksforgeeks.org/dbms/cassandra-vs-dynamodb/
- https://www.knowi.com/blog/cassandra-vs-dynamodb-2025-complete-guide-with-pricing-performance-usecase-migration-tips/
- https://www.bytebase.com/blog/dynamodb-vs-cassandra/
- https://dzone.com/articles/cassandra-vs-dynamodb-database-comparison
- https://www.finalroundai.com/blog/cassandra-interview-questions
- https://www.edureka.co/blog/interview-questions/cassandra-interview-questions/
- https://data-flair.training/blogs/cassandra-interview-questions/
- https://www.adaface.com/blog/cassandra-interview-questions/
- https://www.careers360.com/courses-certifications/articles/apache-cassandra-interview-questions
- https://www.acte.in/cassandra-interview-questions-and-answers
- https://www.devopsschool.com/blog/top-50-interview-questions-and-answers-of-apache-cassandra/