Medium System Design API Design
What are different API pagination strategies and their trade-offs?
Answer
Offset pagination: page/offset parameters - simple but slow for large offsets, inconsistent with data changes. Cursor-based: opaque cursor pointing to position - consistent, efficient, but no random access. Keyset: filter by last seen key - efficient, handles inserts well, requires sortable unique field. Time-based: filter by timestamp - good for chronological data. Response: include total_count, next_cursor, has_more. Choose based on: data characteristics, consistency needs, performance requirements. Cursor-based preferred for infinite scroll; offset for traditional pagination.
IIT Certified
Master These Concepts with IIT Certification
175+ hours of industry projects. Get placed at Bosch, Tata Motors, L&T and 500+ companies.
Relevant for Roles
Backend Developer API Developer Software Engineer