I am building a chat application using Scylla, and I am creating partitions using the chat ID and a static timestamp. For example, let’s say the chat ID is equal to 1 and the timestamp is 11/2024. I am not sure how to retrieve the partition that comes before this one if I want to perform a ‘load more’ action. Additionally, what should I do if the partition before that is empty and I need to retrieve the partition before it?
Partitions in ScyllaDB are not ordered, so it is not possible to retrieve a partition, which is just before another partition. It can maybe be made to work by generating all possible partition-keys, but this is not efficient.
I think you should instead change your schema, such that
chat_id is the partition key and
timestamp is the clustering key. Clustering rows are ordered and it is possible to select a range of them.