Cursor-based pagination with stable ordering

11116
0

Offset pagination falls apart as soon as rows are inserted or deleted between page fetches—users see duplicates or missing items. Cursor pagination fixes that with stable ordering and ‘seek’ queries. I use a compound cursor that includes both the primary sort key (like created_at) and a tiebreaker (id) so ordering is deterministic. Another practical trick is making the cursor an opaque token (e.g. base64-encoded JSON) so clients don’t couple themselves to your internal identifiers. It’s not about security; it’s about keeping the API contract flexible. This approach has been rock solid for feeds and admin lists where data changes constantly.