Why is keyset pagination often preferred over offset pagination when designing REST APIs for large datasets?
easy🧠 Conceptual Q1 of Q15
Rest API - Pagination Patterns
Why is keyset pagination often preferred over offset pagination when designing REST APIs for large datasets?
ABecause it requires less complex SQL queries
BBecause it allows jumping to any page directly using page numbers
CBecause it avoids performance degradation by not scanning skipped rows
DBecause it always returns a fixed number of rows regardless of data changes
Step-by-Step Solution
Solution:
Step 1: Understand offset pagination
Offset pagination uses OFFSET and LIMIT, which causes the database to scan and skip rows before returning results, leading to slower queries on large datasets.
Step 2: Understand keyset pagination
Keyset pagination uses a cursor (like an ID or timestamp) to fetch the next set of rows without scanning skipped rows, improving performance.
Final Answer:
Because it avoids performance degradation by not scanning skipped rows -> Option C
Quick Check:
Keyset pagination uses cursor-based queries to improve speed [OK]