TLDR Web Dev · ARTICLES & TUTORIALS

KEYSET CURSORS, NOT OFFSETS, FOR POSTGRES PAGINATION

blog.sequinstream.com8 min read

Summary from the TLDR Web Dev newsletter

Offset pagination in Postgres can decrease performance and correctness as the offset increases. Keyset pagination, using a compound cursor based on multiple columns, has much better performance and handles deletions gracefully, maintaining a stable order even with data modifications. However, keyset pagination still has subtle correctness issues related to concurrent inserts causing rows to be skipped, but there are strategies to get around this.