Understanding basics of real-time apps

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

In the enterprise world, we must understand everything’s moving faster than we may see and that’s why exists tools like NodeJS that help us and where we can manage concurrents connections easily through the network which based on Javascript, a programming language that runs in server side and is changing the way to see every web, changes how a server should be working and it became a powerful, essential tool if every startup want to survive in a competitive world due to javascript is able to predict client’s behaviour, thanks to a virtual machine named as V8 runtime, letting the developer to build highly and scalable apps and of course I’ll try to explain in brief, not without get to grasp its architecture’s goals in first which we can do through below graph.

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.
Let’s consider that Node came from a Javascript’s virtual machine of Google Chrome named as V8 and it has been written in C++, therefore is not a webserver like mentioned above, but it is useful to make it works with Apache together such as a load balancer or something similar, due to its great speed and process optimized is able to be a system event-oriented which it is possible to add different modules that extends its basic functionality.

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.

Leave a Reply