Node.js Architecture: Understanding Node.js Architecture

Ibrahim Lanre Adedimeji
5 min readSep 17, 2023

--

Introduction:

Node.js is an extremely powerful JavaScript-based platform that’s built on Google Chrome’s JavaScript V8 Engine, used to develop I/O intensive web applications like video streaming sites, single-page applications, online chat applications, and other web apps.

Node.js is used by large, established companies and newly-minted startups alike. Open-source and completely free, the platform is used by thousands of developers around the world. It brings plenty of advantages to the table, making it a better choice than other server-side platforms like Java or PHP in many cases.

Node.js has its core part written in C and C++. Node js is based on a single-threaded event loop architecture which allows Node to handle multiple client requests. Node js uses the concept of an asynchronous model and non-blocking I/O. We will look at these terms in detail.

Node.js is one of the best options for other server-side platforms because of the architectural pattern it follows.

Table of contents:

  • Basic components of web applications
  • Node.js Architecture.
  • Work flow of Node.js Architecture
  • Advantages of Node.js Architecture

Basic components of web applications:

A web application, as you may already know, is a program that runs on a server and is rendered by a client browser, using the internet to access all the resources of that application. It usually can be easily broken down into three parts:

  1. Client
  2. Server
  3. Database

Client:

The user interacts with the front-end part of a web application. The front-end is usually developed using languages like HTML and CSS styles, along with extensive usage of JavaScript-based frameworks like ReactJS and Angular, which help with application design.

Server:

The server is responsible for taking the client requests, performing the required tasks, and sending responses back to the clients. It acts as a middleware between the front-end and stored data to enable operations on the data by a client. Node.js, PHP, and Java are the most popular technologies in use to develop and maintain a web server.

Database:

The database stores the data for a web application. The data can be created, updated, and deleted whenever the client requests. MySQL and MongoDB are among the most popular databases used to store data for web applications.

Node.js Architecture:

Node.js uses the “Single Threaded Event Loop” architecture to handle multiple concurrent clients. Node.js Processing Model is based on the JavaScript event-based model along with the JavaScript callback mechanism.

Now let’s understand each part of the Node.js architecture and the workflow of a web server developed using Node.js.

Parts of Node js Architecture:

  • Requests : Incoming requests can be blocking (complex) or non-blocking (simple), depending upon the tasks that a user wants to perform in a web application
  • Node.js server: Node.js server is a server-side platform that takes requests from users, processes those requests, and returns responses to the corresponding users
  • Event Queue: Event Queue in a Node.js server stores incoming client requests and passes those requests one-by-one into the Event Loop
  • Thread pool: Thread pool consists of all the threads available for carrying out some tasks that might be required to fulfill client requests
  • Event loop: Event Loop indefinitely receives requests and processes them, and then returns the responses to corresponding clients.
  • External Resources: External resources are required to deal with blocking client requests. These resources can be for computation, data storage, etc.

The workflow of Node js Architecture:

A web server developed using Node.js typically has a workflow that is quite similar to the diagram illustrated below. Let’s explore this flow of operations in detail.

  • Clients send requests to the webserver to interact with the web application. Requests can be non-blocking or blocking e.g Querying the data , updating the data or deleting the data .
  • Node.js retrieves the incoming requests and adds those requests to the Event Queue.
  • The requests are then passed one-by-one through the Event Loop. It checks if the requests are simple enough to not require any external resources.
  • Event Loop processes simple requests (non-blocking operations), such as I/O Polling, and returns the responses to the corresponding clients.

A single thread from the Thread Pool is assigned to a single complex request. This thread is responsible for completing a particular blocking request by accessing the external resources, such as compute, database, file system, etc.

Once, the task is carried out completely, the response is sent to the Event Loop that in turn sends that response back to the Client.

Advantages of Node.js Architecture:

Node.js Architecture comes with several advantages that give the server-side platform a distinct upper-hand when compared to other server-side languages:

  • Handling multiple concurrent client requests is fast and easy: With the use of Event Queue and Thread Pool, the Node.js server enables efficient handling of a large number of incoming requests.
  • No need for creating multiple threads: Event Loop handles all requests one-by-one, so there is no need to create multiple threads. Instead, a single thread is sufficient to handle a blocking incoming request.

All of these advantages contribute to making the servers developed using Node.js much faster and responsive when compared to those developed using other server development technologies.

In conclusion ,Node js Architecture is widely known because of its capabilities in solving real world problems with the use of technology. Node js is a very powerful tool for creating scalable web applications with variety of usage in various technological niche e.g E commerce , streaming applications etc. Thanks for Reading.

--

--