Pagination, Filtering, and Bulk Access
Core Concepts (5)
- 1.Unbounded lists are an outage waiting to happen
- 2.Cursor pagination stays stable while data changes
- 3.Offset pagination is simple but drifts and slows down
- 4.Filters and sort orders must be indexed to be affordable
- 5.Bulk endpoints trade round trips for partial-failure complexity
Map to Your Experience
Have you ever paged through a feed and seen the same item twice or missed one? Describe what likely happened.
Design Brief: Paginate an Activity Feed
Learn
Any endpoint that returns a list must have an upper bound on its response. Without one, a single request from a large customer can exhaust memory, saturate the network, and slow everyone else. Set a default page size, a hard maximum, and document both.
There are two main styles. Offset pagination uses a page number or skip count. It is easy to understand and allows jumping to page twenty, but it has two weaknesses. When rows are inserted or deleted between requests, items shift and clients see duplicates or gaps. And the database must still walk past all skipped rows, so deep pages get slower.
Cursor pagination returns an opaque token that marks the position after the last item delivered. The next request resumes from that position. It stays consistent under concurrent writes and its cost does not grow with depth. The price is that clients cannot jump to arbitrary pages and the sort order must be deterministic, usually by adding a unique tiebreaker such as the identifier.
Filtering and sorting look innocent but drive your storage design. Every filter combination you allow is a query you must serve within the latency budget, so offer a small, indexed set rather than a free-form query language. Reject unsupported combinations with a clear error instead of running a slow scan.
For large exports, a paged list is the wrong tool. Offer a bulk mechanism instead: an asynchronous export job that returns a download location when ready, or a batch endpoint that accepts many items in one request. Batch requests need a clear rule for partial failure, such as returning a per-item result so clients can retry only what failed.
Map
Choose a list in a product you know. Decide whether offset or cursor fits, which filters it needs, and which of them would require a new index. Write down what a client sees if a new item arrives mid-scroll.
Design
Specify the activity feed list endpoint: parameters, default and maximum page size, cursor format, and sort rule with its tiebreaker. Then sketch the asynchronous export flow in four steps and state its size limit. Keep your answer concrete: name real numbers, owners, and examples wherever you can, and note any assumption you had to make so a reviewer can challenge it.
Requirements
- •Choose a pagination style and justify it
- •Define allowed filters and sort orders
- •Describe the bulk option and its limits
Constraints
- •Feed grows by millions of rows per day
- •Items can be inserted at any time
Must Cover
Trade-off Axis
flexibility vs cost
Referenced Patterns
Competencies Advanced
Ready to Design?
Open this day in the Design Studio. The studio follows this track: its days, concepts, patterns and trade-offs are loaded, and you keep one design across the whole track.
Open in Studio →