For a messaging app I have a database structure comparatively to:
CREATE TABLE users(
userid text,
name text,
rooms list<text>
...
PRIMARY KEY (userid)
);
CREATE TABLE rooms(
roomid text,
members list<text>,
createdat bigint,
lastmessage bigint,
...
PRIMARY KEY (roomid, createdat)
);
CREATE TABLE messages(
roomid text,
bucket int,
messageid bigint,
authorid text,
...
PRIMARY KEY ((hash, roomid), messageid)
);
On startup the client requests all rooms for a given user. I expect at some point, that a user will be member of hundreds of channels. So I only want to retrieve the last X active channels to reduce traffic.
Currently the room stores the last messageid (snowflake including timestamp) so I am capable to sort, after retrieving all rooms.
What changes are necessary to only load the last X active rooms from Cassandra? I know that I need to denormalize the structure somehow, but I do not know how.