Cassandra TTL (Time to Live) using Automatic Data Expiration

Cassandra provides functionality by which data can be automatically expired. During data insertion, you have to specify ‘ttl’ value in seconds. ‘ttl’ value is the time to live value for the data. After that particular amount of time, data will be automatically removed. For example, specify ttl value 100 seconds during insertion. Data will be automatically deleted after 100 seconds. When data is expired, that expired data is marked with a tombstone. A tombstone exists for a grace period. After data is expired, data is automatically removed after compaction process. Syntax

Insert into KeyspaceName.TableName(ColumnNames) values(ColumnValues) using ttl TimeInseconds;

Example Here is the snapshot where data is being inserted in Student table with ttl value of 100 seconds.

insert into University.Student(rollno,name,dept,semester) values(3,‘Guru99’,‘CS’,7) using ttl 100;

Here is the snapshot where data is automatically expired after 100 seconds and data is automatically removed.