Open In App

Node.js Web Application Architecture

Improve
Improve
Like Article
Like
Save
Share
Report

Node.js is a JavaScript-based platform that is mainly used to create I/O-intensive web applications such as chat apps, multimedia streaming sites, etc. It is built on Google Chrome’s V8 JavaScript engine. A web application is software that runs on a server and is rendered by a client browser that accesses all of the application’s resources through the internet. 

A typical web application consists of the following components:

  • Client: A client refers to the user who interacts with the server by sending out requests.
  • Server: The server is in charge of receiving client requests, performing appropriate tasks, and returning results to the clients. It serves as a bridge between the front-end and the stored data, allowing clients to perform operations on the data.
  • Database: A database is where a web application’s data is stored. Depending on the client’s request, the data can be created, modified, and deleted.

VPS servers offer base capabilities and environment to integrate Node.js apps with developer tools and APIs. Hostinger’s VPS gives you more control and flexibility over your hosting environment and offers you much more than what you are paying for. It has template build for Node.js – Ubuntu 22.04 with Node.js. This makes it super easy and swift to start. It also comes with OpenLiteSpeed server. Besides, they also offer CloudPanel template which allows Node.js applications creation, making it easier to start and manage Node.js apps. With a slick, easy-to-use interface, you can figure everything out quickly even with no experience with VPS.

It has 4 active plans tailored to meet different requirements: KVM1, KVM2, KVM4, KVM8 ranging from ₹499/mo to ₹1829/mo. Its KVM2 plan is cheapest and most popular amongst those running small applications.

Node.js Server Architecture: To manage several concurrent clients, Node.js employs a “Single Threaded Event Loop” design. The JavaScript event-based model and the JavaScript callback mechanism are employed in the Node.js Processing Model. It employs two fundamental concepts:  

  1. Asynchronous model
  2. Non-blocking of I/O operations

These features enhance the scalability, performance, and throughput of Node.js web applications.

Components of the Node.js Architecture:

  • Requests: Depending on the actions that a user needs to perform, the requests to the server can be either blocking (complex) or non-blocking (simple).
  • Node.js Server: The Node.js server accepts user requests, processes them, and returns results to the users.
  • Event Queue: The main use of Event Queue is to store the incoming client requests and pass them sequentially to the Event Loop.
  • Thread Pool: The Thread pool in a Node.js server contains the threads that are available for performing operations required to process requests.
  • Event Loop: Event Loop receives requests from the Event Queue and sends out the responses to the clients.
  • External Resources: In order to handle blocking client requests, external resources are used. They can be of any type ( computation, storage, etc).

Workflow of Nodejs Server:

  • Users send requests (blocking or non-blocking) to the server for performing operations.
  • The requests enter the Event Queue first at the server-side.
  • The Event queue passes the requests sequentially to the event loop. The event loop checks the nature of the request (blocking or non-blocking).
  • Event Loop processes the non-blocking requests which do not require external resources and returns the responses to the corresponding clients
  • For blocking requests, a single thread is assigned to the process for completing the task by using external resources.
  • After the completion of the operation, the request is redirected to the Event Loop which delivers the response back to the client.

Advantages:

  • The Node.js server can efficiently handle a high number of requests by employing the use of Event Queue and Thread Pool.
  • There is no need to establish multiple threads because Event Loop processes all requests one at a time, therefore a single thread is sufficient.
  • The entire process of serving requests to a Node.js server consumes less memory and server resources since the requests are handled one at a time.

Last Updated : 06 Sep, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads