The future of the apps in real-time is here, now we can see everything in the tech world is managed by activities that requires by moving instantly, for example, financial operations that they need its huge data lists be available 24/7, in the worst of cases, they need to have backup servers that responds in real-time when the primary’s one will crashes.
Accordingly, we can notice that nowadays a bunch of apps within mobile apps stores or even on different websites, we perceive many of these apps were getting to use some of sort of concepts that allow to interact with the user instantly or as known as real time, so, in this post I’ll try to explain how sockets works, which it is the way where this concept is applied on any website you see out there.
Node JS and V8 Runtime
If we may see languages like Java or PHP, each connection forces cpu to make a new thread considering each thread is 2 MB for each user in a system that has 4 GB of RAM, now we can understand if we try to scale an app where there are a daily traffic about 1,000 users, we’ll feel forced to upgrade hardware of each server or just buy another and another one ’til we’ll get a huge farm of server like a datacenter, therefore it shouldn’t be so since costs were increased for each server and that’s what nodejs is for, to optimize these tasks and because creates a subprocess by itself for each process created by each user instead of cpu.
And what that V8 runtime -ish is?
Node is a server software surely, but try to not confuse with software like Apache or Tomcat.
Sockets in Nodejs
We may get to know how node connects to every client through sockets; an important module in those apps written for real-time these sockets are created automatically giving to the client a unique identifier, making a “persistent” session in order to send or receive data based on messages using a kind of point-to-point architecture.
To get understanding it well, we have our Nodejs as a main server which it is configured with a socket module and we’ll try to imagine that is a big farm that deal out their products to each clients who needs one, when a client comes to the farm (connect to the server), the farmer (in this case Nodejs) gives it a product (a unique identifier), which with this product the client will be able to interact with others clients.
Of course the farmer does not offering its product every time but only when a client asks for it, which this is the magic that Nodejs do when it says is event-oriented.