YulePale
YulePale

Reputation: 7706

Is storing data on the NodeJs server reliable?

I am learning how to use socket.io and nodejs. In this answer they explain how to store users who are online in an array in nodejs. This is done without storing them in the database. How reliable is this?

  1. Is data stored in the server reliable does the data always stay the way it is intended?
  2. Is it advisable to even store data in the server? I am thinking of a scenario where there are millions of users.
  3. Is it that there is always one instance of the server running even when the app is served from different locations? If not, will storing data in the server bring up inconsistencies between the different server instances?

Upvotes: 1

Views: 3640

Answers (1)

Lemmy Figgins
Lemmy Figgins

Reputation: 95

Congrats on your learning so far! I hope you're having fun with it.

  1. Is data stored in the server reliable does the data always stay the way it is intended?

No, storing data on the server is generally not reliable enough, unless you manage your server in its entirety. With managed services, storing data on the server should never be done because it could easily be wiped by the party managing your server.

  1. Is it advisable to even store data in the server? I am thinking of a scenario where there are millions of users.

It is not advisable at all, you need a DB of some sort.

  1. Is it that there is always one instance of the server running even when the app is served from different locations? If not, will storing data in the server bring up inconsistencies between the different server instances?

The way this works typically is that the server is always running, and has some basics information regarding its configuration stored locally - when scaling, hosted services are able to increase the processing capacity automatically, and handle load balancing in the background. Whenever the server is retrieving data for you, it requests it from the database, and then it's loaded into RAM (memory). In the example of the user, you would store the user data in a table or document (relational databases vs document oriented database) and then load them into memory to manipulate the data using 'functions'.

Additionally, to learn more about your 'data inconsistency' concern, look up concurrency as it pertains to databases, and data race conditions.

Hope that helps!

Upvotes: 3

Related Questions