Cassandra counts item inserts (clustering keys) with TTL

As I understand it, Cassandra counters should help avoid the cost of selecting count (*). This works great if I don't put TTLs on the items I want to count. Using TTL could result in the recalculation of items as soon as they start to expire. Is there any strategy for solving this problem? Does manually delete old entries (along with counter decree) the only way for this use case?


source to share

1 answer

If you want to use counters to keep track of the number of rows in a table, you probably don't want to use TTL to randomly expire rows.

What you can do is split your data, for example, during the day, and keep a counter for each day. Then set the TTL so that all rows for a given day expire at the same time (or you could delete the entire section with DELETE). When that day expires, you set the counter for that day back to zero. Then your total row count will be the sum of all day counters.



All Articles