Almost every API design question has a list endpoint in it: a feed, search results, an order history. When you sketch GET /orders, the interviewer will ask how a client gets page 2. There are two real answers, and the trade-off between them is the point.
GET /orders?limit=20&offset=40 SELECT * FROM orders WHERE user_id = ? ORDER BY created_at DESC LIMIT 20 OFFSET 40;
Good: trivial to build, clients can jump to page 37, total page count is easy to show.
Bad, part 1, performance: the database still reads and throws away the first 40 rows. At offset 200,000 that's 200,000 rows scanned per request. Deep pages get slower linearly.
Bad, part 2, correctness: if a new order is inserted while the user is on page 1, everything shifts by one. Page 2 then repeats the last item of page 1. Deletes cause the opposite: an item gets skipped.
GET /orders?limit=20&after=eyJ0IjoiMjAyNi0xMS0xMFQwOToxMjowMFoiLCJpZCI6ODgxMn0 SELECT * FROM orders WHERE user_id = ? AND (created_at, id) < (?, ?) ORDER BY created_at DESC, id DESC LIMIT 20;
The cursor encodes the sort key of the last row the client saw. The next query starts right after it, using the index, so page 10,000 costs the same as page 1. Inserts and deletes elsewhere don't shift anything.
The detail interviewers listen for: the sort key must be unique. created_at alone isn't, so two orders in the same millisecond can be skipped or duplicated. Add the primary key as a tie-breaker, and back it with a composite index on (user_id, created_at, id).
Costs: no "jump to page 37", no cheap total count, and changing the sort order means a different cursor format.
Base64-encode a small JSON blob rather than exposing raw column values. Clients treat it as a token, and you can change what's inside without breaking them. Some teams sign it so clients can't craft cursors that hit unindexed paths.
{
"data": [ ... ],
"next_cursor": "eyJ0Ijoi...",
"has_more": true
}
Return has_more so the client doesn't need an extra empty request to discover the end. Fetch limit + 1 rows internally to compute it.
Disclosure: I'm part of the team behind real-time interview help at Linkjob AI. This article is general interview preparation and stands alone.