4 ms·
My company is actually going through the transition to cursor/keyset pagination. As a SaaS company starts having to support larger customers, they will likely h
by kamikaz1k 7y ago
My company is actually going through the transition to cursor/keyset pagination. As a SaaS company starts having to support larger customers, they will likely have to go through this exercise. The reason is because most pagination is usually implemented with LIMIT/OFFSET in a SQL query. Using OFFSET becomes very expensive for pagination queries because the query has gotta do a full scan till it reaches the desired offset.
Imagine a table with a 1 million rows, and you return pages in 100 item chunks. To get page 500, using the OFFSET method, you would have to scan through 100*499 records before you even get to the first record you care about.
This can lead to all sorts of cascading problems because slow queries can cause back pressure build up from other queries queuing up. So in order to scale, services push the complexity out to the client. Conceivably, you can cache the indices on the client side, and abstract a page-number based paginator on top of it.
Here's an article talking through the issue: https://www.moesif.com/blog/technical/api-design/REST-API-Design-Filtering-Sorting-and-Pagination/# https://www.moesif.com/blog/technical/api-design/REST-API-De...
- QueensGambit 7y agoSorry! I don't think this is developer friendly. You are just pushing your problem to the developers. Do you really think developers will be able to make it faster than your implementation? Take your example of caching indices. Do I cache for each search filter and where do I store them? And again, do I serially execute all pages to cache cursors to build pagination on top of them?
- bjourne 7y agoThe performance issue is easily solved by using an index. Getting page 500 would be just as fast as select * from table where 500100 <= order_num < 501100