paginationcassandracql3clustering-key

Cassandra CQL3 clustering order and pagination


I am building out a user favourites service using Cassandra. I want to be able to have the favourites sorted by latest and then be able to paginate over the track_ids i.e the front end sends back the last track_id in the 200 page.

CREATE TABLE user_favorites 
( user_id uuid, track_id int ,
favourited_date timestamp,
PRIMARY KEY ((user_id), favourited_date)) 
WITH CLUSTERING ORDER BY (favourited_date DESC);

I've tried different combinations of primary and clustering keys but to no avail. I am wondering if it is better to split this out over multiple tables also.


Solution

  • I solved it using the comment about the Java driver base64'ing the PagingState and returning it to the client.