DEV Community

Aaron Goulden
Aaron Goulden

Posted on

Pagination: The cursed feature

I just wanted to start by saying: pagination isn't an easy problem. At a first naive glance from a product perspective it looks easy. Most devs who haven't implemented it before would probably give a rough estimate of 1-2 days max. In theory, if everything under the hood is implemented nicely that's probably about right.

When a dev first goes away to research how they are going to do pagination, the first thing they are going to find is stack overflow articles full of people arguing how they should be implemented. Cursor based / index based, the product owner doesn't care, they just want a nice pretty little widget that lets them scroll through multiple pages of results.

This is where tech debt rears it's ugly head. For any codebase that isn't brand new, there is going to be mounds of tech debt with regards to how data is stored in the underlying database. Even when using a framework like Laravel or Symfony, it's likely that out of the box pagination solutions aren't going to work due to the amount of crap that has been piled on top of models to make them work.

Then comes the issue of multiple consumers. The web front-end might not be the only consumer of the API. Mobile apps might also be consuming the same API. Mobile UI/UX works differently than web, they might already have come up with a solution like infinite scrolling / lazy loading which already uses the existing endpoints. They might also have a local storage which they use to the app works offline.

At this point everyone involved starts to blame the dev who is trying their best to implement this and satisfy everyone's requirements without breaking existing functionality. If the dev is lucky, they will have other devs they can bounce ideas off and try to put into words why pagination is a harder problem than it looks. It requires changes at multiple levels of the stack, as well as negotiation with multiple stakeholders. If your project has a lot of tech debt, this is where it will show.

When you asked to get implement pagination, please show this to your product owner and proceed with caution. Possibly start looking for a new job on the side just in case. More than one project i've worked on has had people quit over this cursed feature.

Top comments (0)