Get the latest tech news
Keyset cursors, not offsets, for Postgres pagination
We're building Sequin, a Postgres CDC tool to streams and queues like Kafka, SQS, HTTP endpoints, and more. Efficient, correct pagination is paramount for our backfill process, so we use keyset cursors extensively. You've probably heard about the limitations of offset/limit in Postgres. There are two primary concerns with
We're building Sequin, a Postgres CDC tool to streams and queues like Kafka, SQS, HTTP endpoints, and more. If you're doing a one-time sweep of a table and want to avoid seeing a row twice, one easy solution is to start your pagination by first grabbing a max keyset cursor: So this can work if after the initial request, you drop params like limit and order and move to using nextPage and previousPage to traverse.
Or read this on Hacker News