What is Single thread model used in node js and how its eliminates the limitation of multi thread model

Node Js is event driven, handing all the request asynchronously from single thread.

Almost no function  in node directly performs I/O, so the process never blocks.

So in a single thread model whenever a user performs an activity a event is generated.

For Example.

If you click a button or fill a form in your application a new event is generated, you can take each new request as a event.

Now, once you generate an event, event emitters emits those events and then those events decides inside the event queue in the server, then these events are executed using event loops, which is a single thread mechanism.

In this mechanism a single thread takes event from the event queue and allocates the event to a worker thread present inside the thread pool.

The allocation is based on the operation performed by event so it could be I/O operation for example a network operation etc.

So based on that it will be handle to the thread and then this worker thread process those request asynchronously.

Now you can notice here that we have only one thread in this event loop so one thread in this event loop will be handling the event directly.

So no function in node.js can directly perform operations thus the process will never get blocked.

As this process are based on events and events are handled by events loop does this model is also called event driven model.

So our node.js follow this event driven model.

Related Posts

CRUD system with node.js

Express and Mongoose seeder files to Effortless import and delete bulk data in MongoDB

In this article, we are creating an Express and Mongoose seeder file that can import the JSON file data into the MongoDB database, and on one command…

CRUD system with node.js

The beginners approach to handle requests and responses in node.js application

In this article, we will understand, how we can handle requests and responses in node.js, and we will learn about the req.on() method of node.js. Let’s see…

CRUD system with node.js

Mastering Backend Development: Building a Feature-Rich CRUD System with Node.js, Express, and MongoDB

In this article, we are building a complete CRUD system with node.js, Express, and MongoDB. We are using mongoDBCompass for viewing our Mongo database and Postman to…

AXIOS-in-react-js

The Power of Axios in React 18: How Axios Simplifying HTTP Requests and Data Handling

Axios is a JavaScript library that we use to send HTTP requests from browsers or Node.js. We can handle these requests more conveniently using Axios as compared…

Difference between Multithread and single thread or event driven model

Multi thread model Request with listener worker thread | lock application. Using incoming request model. Multi threaded server might block the request which might involve multiple events….

What is Multi thread model and what are the limitations ?

In a Multi thread model the server assign incoming requests to a new thread similar as a client server architecture, the user generate a request by interaction…

Leave a Reply

Your email address will not be published. Required fields are marked *