Optimizing Filtering and Pagination: Reducing Backend Requests Efficiently
I want to implement filtering and pagination while minimizing backend requests as much as possible.
Here’s the challenge:
-I know caching can help, but if the filtering logic is complex, managing cache efficiently can also become challenging.
-How can I reduce backend requests while handling filtering and pagination efficiently?
18 Replies
this is how I did it at least:
It could've been better or refined but it might give you a rought idea about it
I have one more question, when i apply filter i am approaching this way
Whatever data i have sented at frontend i use js and apply filters there should i change my approach?
I didnt understand that but if you meant JS is okay to apply filters at the frontend then yes totally fine
In the above code as you can see I'm receiving various filters from the frontend , I check if a filter is present I apply it on the EF Query, if it doesnt I move to the next step, eventually I return the retrieved data from the database.
My current approach involves fetching data from the backend and sending it to the frontend in a structured format, making it easy to filter and display to the user. While most filtering happens on the frontend, the backend also applies filtering based on the structured view I control.
So basically you just build the result progressively based on user request and at last apply pagination and sent the data to user got it!
exactly
So I am confused right now should i change my approach or not :/
your approach sounds fine as long as it works
Issue comes in when i want to reduce backend call, how i can update strucutre effectively
You should call your backend when searching a value , applying a filter or updating the page , make sure you dont call it unnecessarily. For searching a value you can't rely on the items you have on the frontend cuz maybe the item exists in the other sections since the frontend only contains a section of the whole data. So you might always need to call backend in order to make sure that you search the whole data
So there is uncertainity and we cant rely on data that i sent on frontend got it, so I might as well change filtering part on backend, because I am doing 2 way filters right now
So instead of this i can rely on backend
So removing filtering logic from frontend is my next step
thanks
Ofc you cant, you only have a portion of data on the frontend
Another approach is that just fetch the whole data on the frontend and then apply the filters on the frontend, no need to call the backend. But the obvious problem is that what if the database has thousands of records, fetching them all would be unnecessary and too slow . So the best option imo is pagination and filtering
I was high few moment ago I only thought about first condition
Yeah this will cause backend issue, i thought about this but seems bad idea
I think its good if your db have like few hundred or thousand record?
Nah I still dont prefer it
Reason for that?
Because it'll still be too slow
The pagination approach is efficient for long term
Even for few hundred records?
Got it
Thanks alot for helping brother appreciate your time and efforts me closing this request now
Welcome $close
If you have no further questions, please use /close to mark the forum thread as answered