Pagination Patterns (Offset vs Cursor)
Pagination patterns (offset vs cursor) are techniques to split large datasets into manageable chunks: offset uses page numbers/limits, while cursor uses a pointer (token) to the last seen item.
When to Use
Use offset pagination for small or mostly static datasets where random access to any page is needed. Use cursor pagination for real-time feeds (social media, messaging apps, logs) where new data arrives often and consistency matters.
Example
Showing user messages: offset pagination = “page 2, limit 10,” while cursor pagination returns a token after the last message ID.
Want to master these concepts for interviews?
Explore Grokking System Design Fundamentals, Grokking the Coding Interview, or book Mock Interviews with ex-FAANG engineers.
Why Is It Important
Pagination prevents servers from returning huge results, improves performance, and keeps user experience smooth in large-scale apps.
Interview Tips
Explain both methods with pros/cons.
Show you understand trade-offs: offset = simpler, cursor = scalable.
Mention database indexing, ordering, and real-time data freshness.
Trade-offs
- Offset: Easy, supports random page jumps, but slow on large datasets and inconsistent with changing data.
- Cursor: Efficient and consistent for large, dynamic data, but only supports sequential navigation and adds complexity.
Pitfalls
- Avoid offset on massive tables (performance hit).
- Always use a stable sort key with cursors.
- Mishandling cursor tokens can cause missing or duplicated records.
GET YOUR FREE
Coding Questions Catalog
$197

$78
$78