Do multiple requisitions or just one?

Asked

Viewed 203 times

1

I am making an application in nodejs, where constantly it is necessary to consult information in the database, for example: name, description of items and etc... A similar site would be Netflix, which queries such information each time the user hovers in a movie/series.

But I would like to know, if it is better to make a request to the database each time the user passes the mouse, or when loading the site, save the entire database in a Sesssion and call such data when the user passes the mouse, in case I would be using socket.io to speed up the response, but I do not know if such a practice requires much of the server. Then the question remains:

  • Make a single select in the database or store everything in a Session?

or

  • Send various requests each time needed (almost always)?

1 answer

2

The first option will not scale, it will not be possible to have the entire database in the client when it is too large.

But the second option to make an ajax request each mouseover may be too expensive. It may even be the ideal solution, but I suggest a compromise:

If the mouse is going to pass over something (image, or text title), it seems to me that it would be possible to already have this more meta-data information that could be used in the client. For example, if you’re gonna do hover about images and want to have the title, you can bring already from the server when the image is mounted the title as well. Then when there is click on the image you will need more data, then would come the request to the server to complete with specific information related to that image.

However, if at Hover you need to have all the related data that is in the database, and there is no other step where you will need more data then solution A or B is not feasible. In this case choose one and test.

  • 1

    I will try to create something in between, or at least load as little data as possible when starting without having to make so many requests.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.