Send heavy data from AngularJS to backend

91 views
Skip to first unread message

SignorT

unread,
Jul 16, 2015, 11:39:32 AM7/16/15
to ang...@googlegroups.com
Hi,
  on a MEAN stack application we send from the backend a list of user's filtered products to the angular view. From this view we also have a button that communicate to backend to create and download an excel file.
Considering that the products list has got a different number of properties (for example ten properties for product), the question is: is better send from angular the entire product list to the backend avoiding to query the database but making heavy the http request or is better to send only the general request letting the backend side asking the filtered list from database?
User information to filter the products list are obviously present in the backend session.

Thanks a lot

Sander Elias

unread,
Jul 17, 2015, 12:14:57 AM7/17/15
to ang...@googlegroups.com
Hi Signor,

There is no right or wrong answer here. The only correct answer is 'it depends', which is utterly useless.  So I will give you a few pointers, that might help.
  1. Filtering through records is a prime DBMS function. In some cases you can do it more effectively then a system that's build for tasks like this. Is this such a case? are you sure you can do a better job than the MongoDB people?
  2. How large is your product list? Totaling up under 100Kb? consider keeping it in the browser. The 100Kb number is not a hard boundary, you have to decide.
  3. how violate are your search parameters?   
  4. How many different set's does 1 user make? If both 3 and 4 are high numbers, consider doing client side
That are a few of the prime considerations you have to make, there are many more. 
Did this help you a bit?

Regards
Sander

SignorT

unread,
Jul 17, 2015, 4:07:27 AM7/17/15
to ang...@googlegroups.com
Hi Sander,
  thank you for your answer.
Probably I don't give you all the useful informations but your questions are in any case interesting (maybe my bad english is complicit). I can be more specific if  you have the patience to read:
the application has got a different number of user with different role. Depending on the role le list of product change showing all the product (if you are admin) or some product that you own (if you are a different role). This is the only filter: is related to the user and saved in the DB (mongo).
When you visit the page Angular call a rest API where Express retrieve data from mongo and then respond to Angular with a json like list of object. Angular compile a table with ng-repeat directive and the user can see the correct list of product and the relative properties (name, code, weight, ...).
From this page the button to download an excel file send a request to Express that send a direct download of a file generated with a library. The information of the excel table is the same of the angular view table. So the doubt was if we have to send the object list already available in the angular controller or if from the Express side we should call again mongo and retrieve the product list already knowing user role.

If you are an admin the list of product could be about 1MB in the futur and my perception is that sending an http request with this size of data could slow down the process. From the other side it doesn't request another call to mongoDB.

Perhaps I have been clearer now? What do you think?

Thank you very much!

Sander Elias

unread,
Jul 17, 2015, 5:08:08 AM7/17/15
to ang...@googlegroups.com
Hi Signor,

If you have the data already in your angular app, you can generate the excel file directly in the browser, no server-call needed at all in that case. So that would be the best option. 
BTW, an 1Mb download isn't that bad, just make sure you don't have to repeat it a lot of times...

Regards
Sander

Marco Mazzocchi

unread,
Jul 17, 2015, 5:17:35 AM7/17/15
to ang...@googlegroups.com
Ok thanks a lot!

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/XIaMB6c7zAo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.



--
Marco Mazzocchi
Technical Project Manager and Web Developer - iBru

Sito web: 
   - www.ibru.it
Skype: marco.mazzocchi2

Erick Engelhardt

unread,
Jul 17, 2015, 10:41:26 AM7/17/15
to ang...@googlegroups.com
@SignorT
​​
As you already have 1MB file to download, in your early future, this size should increase. Your http request will get slower and you will probably paginate the results.

I would rather download excel file right from server using headers (including filesize, resume property) with an exclusive button.


Erick Engelhardt 
21 99463-1994



--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.

Marco Mazzocchi

unread,
Jul 17, 2015, 10:58:23 AM7/17/15
to ang...@googlegroups.com
Hi Erick, that was my fear... the number of products could be very various in the future so we need the safest solution.

Thanks for your comment.

Sander Elias

unread,
Jul 17, 2015, 10:52:55 PM7/17/15
to ang...@googlegroups.com, mmazz...@ibru.it
@eric @marco,

Marco said the user was selecting the data that was already on its screen. If it is in the frontside already, it makes no sense to refetch the data from the server.
If it is not fully loaded already, pick point 1 of my first answer, and do it on the server. 

@marco: You now have 1Mb, how much variation do you expect? double? triple? not really big impacts. (Unless you target mobile!) Tenfold? Ok, now you will really feel the impact of the size. Just create a really big testset of data, and run it throught your app. It will show the possible bottlenecks right away. You might be surprised.

Regards
Sander
Reply all
Reply to author
Forward
0 new messages