In single page applications, is sorting and filtering standard on the server?

I was developing a new app with ReactJS and doing client side sorting / filtering. However, after looking at the larger open source SPA programs, I see many doing this on the server side through the API. Are there any downsides to doing this on the client side besides performance?

+3


source to share


2 answers


It depends mainly on the total potential size of the data.

Client side

If this is where you will never have more than, say, 50 items and it doesn't take a lot of data to represent the list, then you can just send the whole thing to the client.

An example of this is a sublist with a limited size. For example, if your site is a store and you can only have 50 items to sell, you can just submit them right away. The downside here is that if you later change this to a larger number, you need to rewrite it with pagination on a server side page.

Server side

Often in an application, you can have thousands or millions of items in a list. An example of this would be questions / no answers , where each item takes a significant amount of data to represent, and at the time of writing it has over 2 million items.



Attempting to download 2 million stacking questions at once per client is not feasible and much more expensive for your server and database even with 1000 items.

By default, sort / filter should be done in the database, because it is often necessary to allow scaling even for a single user. In specific cases, you can download everything to the client as optimization.

Client side database

This is especially useful when the network is your bottleneck and users will be using this application for a long time, possibly offline.

When the app starts, you load a large amount of data and store it in IndexedDB (or simple objects, depending on the amount). Then you can interact with that data without any apis server side limitation or network performance and reliability.

You will probably never need this, but I think it is worth mentioning. I've heard this has been deployed in web based logger software and other office work where long startup times don't matter (and only the first startup will be very long). Facebook Ads uses this in their "power editor", which essentially loads the entire configuration and then you load everything again when you're done.

+2


source


It really depends. If you are paginating the results and don't get the whole set, you will need to go back to the server to get an updated list if the user clicks to sort the data.

For example, you get a list of fruits and vegetables. Since the result size is limited to 3, it displays the table below.

Name
--------------------
Apple

Banana

Carrot
--------------------
1 | 2 | 3 | Next >

      

If the user is sorting by name, you will need to go back to the server to get an updated list, since the client is unaware of other fruits and vegetables. The server will then return something like:



Name
--------------------
Zucchini

Yams

Xigua
--------------------
1 | 2 | 3 | Next >

      

Also, I can't really think of another reason to sort on the server side (excluding the performance from what you mentioned)

Hope that makes sense

0


source







All Articles