Q25: How do you design pagination for a large dataset?
Offset pagination is simple but can become expensive at high offsets and can skip or repeat rows as data changes. Cursor/keyset pagination uses a stable ordering key, such as (createdAt, id), and requests rows after the last seen key; it scales better for sequential traversal. Use a deterministic order, opaque cursors, page-size limits, and an index matching the filter and ordering. Decide whether clients need a consistent snapshot.
Key Takeaways
- Cursor pagination is usually better for large, changing datasets.
- Stable ordering and supporting indexes are essential.