Filters logic should be on frontend or backend?

Alex Belke :

I’m creating a web application

Frontend - reactjs and backend java.

Frontend and backend communicate with each other via rest.

On UI I show a list of items. And I need to filter them for some params.

Option 1: filter logic is on front end

In this case I just need to make a get call to backend and get all items. After user choose some filter option filtering is happening on ui.

Pros: for that I don’t need to send data to back end and wait for response. Speed of refreshing the list should be faster.

Cons: If I will need multiple frontend clients. Let’s say a mobile app. Than I need to create filters again on this app too.

Option 2: filter logic is on back end

In this case I get all list items when app is loading. After user changes the filter options I need to send a get request with filters params and wait for response. After that update a list of items on UI.

Pros: filter logic is written only once.

Cons: Speed probably will be much slower. Because it takes time to send request and get a result back.

Question: Where the filter logic should be? In frontend or in backend? Or maybe what is a best practice?

Matt Carlotta :

Filter and limit on the back end. If you had a million records, and a hundred thousand users trying to access those records at the same time. Would you really want to send a million records to EVERY user? It'd kill your server and user experience (waiting for a million records to propagate from the back end for every user AND then propagate on the front end would take ages when compared to just getting 20-100 records and then clicking a button to retrieve the next 20-100). On top of that, then to filter a million records on the front-end would, again, take a very long time and ultimately not be very practical.

From a real world stand point, most websites have some sort of record limit. Ebay = 50-200 records, Amazon = ~20, Target = ~20... etc. This ensures quick server responses and a smooth user experience for every user.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=35812&siteId=1