Engineering Decisions · Middle · Question 9 of 14
An activity log has 50M rows, and OFFSET gets slower on deep pages. The UI only has "Older" and "Newer" buttons. How do you paginate?
- 1Keep
OFFSET, but cache each page - 2Cap the depth at the first 1,000 pages
- 3Keyset pagination on
(created_at, id)
Show the answer
Correct answer: Keyset pagination on (created_at, id)
Explanation
Keyset pagination seeks through an index, so depth doesn't affect speed, and next/previous buttons are all it needs. Caching fits a list that rarely changes, but a log grows constantly, so cached pages shift. A depth cap fits search results, where nobody goes deep, while here it would hide old records that people may need.