1

What's an efficient way to go about paginating through a table in Cassandra via asynchronous calls in a web app?

I know that you can pull one more row than the page size and send that value on the client so that they can use it as a starting point for the next call, but that tightly couples Cassandra and the client.

Is there a better practice for this situation?

Nick
  • 11
  • 1

1 Answers1

1

TL;DR; Yes there is. Use page states.

Take a look here: Results pagination in Cassandra (CQL) and here: http://www.datastax.com/dev/blog/client-side-improvements-in-cassandra-2-0

What is worth explaining, that when using Cassandra 2.0+ autopagination, in response you will get page results + current page state + next page state. Those page states are byte arrays. To get next page you just call as always for results, but you include page state.

Note: page state isn't protected against modification. You probably don't want to expose it for client side, because modification of a page state may return data which shouldn't be accessible for particular user.

Community
  • 1
  • 1
piotrwest
  • 2,098
  • 23
  • 35
  • Thanks, but there isn't really a way around sending the next page state to the client, right? – Nick Sep 26 '15 at 19:36
  • Well, there are workarounds for that - store it in the user cache on the server side and send only id to the client or encrypt it and send it. However, I don't know any straightforward methods. BTW. I'm sure I've read somewhere that page state isn't protected against modification. But now, here: https://datastax.github.io/java-driver/features/paging/ is written "Note that the paging state can only be reused with the exact same statement (same query string, same parameters). If you try to modify its contents or reuse it with a different statement, the driver will raise an error.". – piotrwest Sep 27 '15 at 09:19
  • It would be good to ask a separate question about the page state - how does it work (what are those bytes) and if it's safe to expose it for external users. – piotrwest Sep 27 '15 at 09:45