Design: Pagination System for Large Data Sets
Design covers backend pagination API and data retrieval patterns. UI and client implementation are out of scope.
Functional Requirements
Non-Functional Requirements
Client | | HTTP Request with pagination params v API Server |-- Validate pagination params |-- Choose pagination method (offset or cursor) |-- Query DB with pagination logic |-- Return paged data + next cursor or page info v Database |-- Indexed on ordering key(s) |-- Supports LIMIT/OFFSET and key-based queries Cache (optional) |-- Stores popular pages or cursors
items = [
{"id": 101, "name": "A"},
{"id": 102, "name": "B"},
{"id": 103, "name": "C"}
]
last_cursor = 101
page_size = 2
next_page = [item for item in items if item["id"] > last_cursor][:page_size]
next_cursor = next_page[-1]["id"] if next_page else None
print(next_cursor)Pass the test and this pattern moves unknown