Categories
javascript web development

Where to filter the data – backend or frontend ?

✨Where to filter the data – backend or frontend ?  

 

Hey everyone,

In this article, let us discuss about a very important question regarding filtering the data that we get from the database or API. So the question is : 

Where exactly should we filter the data ? 

🤔 Backend … ? 

🤔 Frontend … ? 

Well, the answer is : 

It depends. 

Let us discuss now : 

So if you have a a large amount of data, it is better to implement the filtering logic on the backend and let the database handle all the heavy lifting for us. Contrary to this, if you are dealing with less amount of data, you can do the filtering logic on the frontend.

In general, if you are working with a million recordset (as an example) and there are tons of users trying to access those records at the very same, then in such cases it does not make sense to send a million recordset to every user who is currently accessing the website. It simply does not make sense because it will simply bring your website down, so what we do in such cases is that we setup a record limit (kind of we send the data in batches) by using a features like database cursors. So kind of with the cursors in place, you can fetch the data in batches in some sort of pagination etc. Consider a big ecommerce website like Amazon, this is how they handle that amount of data in a nutshell.

For less amount of data, you could retrieve the data from the backend and then use the filtering logic on the frontend.

So this is it for this article. Thanks for reading.
Don’t forget to leave a like if you loved the article. Also share it with your friends and colleagues.

Alt Text