Z
Z
Zomdies2020-10-04 17:59:00
Node.js
Zomdies, 2020-10-04 17:59:00

How can you save session data so that if you accidentally disconnect, the data is saved?

The task is that, it is necessary to make so that the person could pass tests. That is, there is a test that contains multiple choice questions. When a person starts doing a test, it is necessary to save his questions for as long as he is doing it, so that if he exits the test and enters it after a while, then his answers are saved. Hence the question of how this can be done well, otherwise I have only two ideas to save his answers in the database, but I think this is a bad idea, because if there are a lot of people, then the selection from the database will take a long time. You will also need to save the answer to a specific question. The second option I thought was to create rooms through socket io, and already store the test progress there. But the problem arises, how optimal is this and how I believe if the server falls and all the data along with it. What can be done ? Perhaps there are some good ideas for implementing this functionality?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hzzzzl, 2020-10-04
@hzzzzl

save his answers in the database, but I think this is a bad idea, because if there are a lot of people, then the selection from the database will take a long time

probably won't be long

R
Robur, 2020-10-04
@Robur

Saving in the database is normal, if the database is not made by the left heel, then on a scale of up to thousands of users who are online at the same time, everything will be fast. Even very fast.
the easiest option is to save the user in localStorage. for 90% of cases this will be enough.
option with sockets is some kind of perversion. You will store the same amount of data as with the database option, only in a very crooked, slow and unreliable way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question