Make multiple requisitions or just one?

1

I'm doing an application in nodejs, where it is constantly 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 every time the user passes the mouse over a movie / series.

But I would like to know if it is better to make a request to the database every time the user moves the mouse, or when loading the site, save the whole database in a session and call that data when the user passes the mouse, in case I would be using socket.io to streamline the response, however I do not know if such a practice requires too much of the server. So the question remains:

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

or

  • Send miscellaneous requests whenever needed (almost always)?
asked by anonymous 07.07.2018 / 18:56

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 of placing an ajax request on every mouseover can be too costly. It may even be the ideal solution, but I suggest a middle ground:

If the mouse is going to go over something (image, or title of text), it seems to me that it would be possible to have more meta-data that could be used in the client. For example, if you are going to do hover on images and you want to have the title, you can already bring the server when the image is mounted the title too. Then when you click on the image you will need more data, then the request would come to the server to complete the specific information related to that image.

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

    
07.07.2018 / 19:49