Node JS Architecture – Single Threaded Event Loop

Filed Under: Node.js

Today we will look into Node JS Architecture and Single Threaded Event Loop model. In our previous posts, we have discussed about Node JS Basics, Node JS Components and Node JS installation.

Node JS Architecture

Before starting some Node JS programming examples, it’s important to have an idea about Node JS architecture. We will discuss about “How Node JS works under-the-hood, what type of processing model it is following, How Node JS handles concurrent request with Single-Threaded model” etc. in this post.

Node JS Single Threaded Event Loop Model

As we have already discussed, Node JS applications uses “Single Threaded Event Loop Model” architecture to handle multiple concurrent clients.

There are many web application technologies like JSP, Spring MVC, ASP.NET, HTML, Ajax, jQuery etc. But all these technologies follow “Multi-Threaded Request-Response” architecture to handle multiple concurrent clients.

We are already familiar with “Multi-Threaded Request-Response” architecture because it’s used by most of the web application frameworks. But why Node JS Platform has chosen different architecture to develop web applications. What is the major differences between multithreaded and single threaded event loop architecture.

Any web developer can learn Node JS and develop applications very easily. However without understanding Node JS Internals, we cannot design and develop Node JS Applications very well. So before starting developing Node JS Applications, first we will learn Node JS Platform internals.

Node JS Platform

Node JS Platform uses “Single Threaded Event Loop” architecture to handle multiple concurrent clients. Then how it really handles concurrent client requests without using multiple threads. What is Event Loop model? We will discuss these concepts one by one.

Before discussing “Single Threaded Event Loop” architecture, first we will go through famous “Multi-Threaded Request-Response” architecture.

Traditional Web Application Processing Model

Any Web Application developed without Node JS, typically follows “Multi-Threaded Request-Response” model. Simply we can call this model as Request/Response Model.

Client sends request to the server, then server do some processing based on clients request, prepare response and send it back to the client.

This model uses HTTP protocol. As HTTP is a Stateless Protocol, this Request/Response model is also Stateless Model. So we can call this as Request/Response Stateless Model.

However, this model uses Multiple Threads to handle concurrent client requests. Before discussing this model internals, first go through the diagram below.

Request/Response Model Processing Steps:

  • Clients Send request to Web Server.
  • Web Server internally maintains a Limited Thread pool to provide services to the Client Requests.
  • Web Server is in infinite Loop and waiting for Client Incoming Requests
  • Web Server receives those requests.
    • Web Server pickup one Client Request
    • Pickup one Thread from Thread pool
    • Assign this Thread to Client Request
    • This Thread will take care of reading Client request, processing Client request, performing any Blocking IO Operations (if required) and preparing Response
    • This Thread sends prepared response back to the Web Server
    • Web Server in-turn sends this response to the respective Client.

Server waits in Infinite loop and performs all sub-steps as mentioned above for all n clients. That means this model creates one Thread per Client request.

If more clients requests require Blocking IO Operations, then almost all threads are busy in preparing their responses. Then remaining clients Requests should wait for longer time.

Request Response Model, Multithreaded request response architecture

Diagram Description:

  • Here “n” number of Clients Send request to Web Server. Let us assume they are accessing our Web Application concurrently.
  • Let us assume, our Clients are Client-1, Client-2… and Client-n.
  • Web Server internally maintains a Limited Thread pool. Let us assume “m” number of Threads in Thread pool.
  • Web Server receives those requests one by one.
    • Web Server pickup Client-1 Request-1, Pickup one Thread T-1 from Thread pool and assign this request to Thread T-1
      • Thread T-1 reads Client-1 Request-1 and process it
      • Client-1 Request-1 does not require any Blocking IO Operations
      • Thread T-1 does necessary steps and prepares Response-1 and send it back to the Server
      • Web Server in-turn send this Response-1 to the Client-1
    • Web Server pickup another Client-2 Request-2, Pickup one Thread T-2 from Thread pool and assign this request to Thread T-2
      • Thread T-2 reads Client-1 Request-2 and process it
      • Client-1 Request-2 does not require any Blocking IO Operations
      • Thread T-2 does necessary steps and prepares Response-2 and send it back to the Server
      • Web Server in-turn send this Response-2 to the Client-2
    • Web Server pickup another Client-n Request-n, Pickup one Thread T-n from Thread pool and assign this request to Thread T-n
      • Thread T-n reads Client-n Request-n and process it
      • Client-n Request-n require heavy Blocking IO and computation Operations
      • Thread T-n takes more time to interact with external systems, does necessary steps and prepares Response-n and send it back to the Server
      • Web Server in-turn send this Response-n to the Client-n

    If “n” is greater than “m” (Most of the times, its true), then server assigns Threads to Client Requests up to available Threads. After all m Threads are utilized, then remaining Client’s Request should wait in the Queue until some of the busy Threads finish their Request-Processing Job and free to pick up next Request.

    If those threads are busy with Blocking IO Tasks (For example, interacting with Database, file system, JMS Queue, external services etc.) for longer time, then remaining clients should wait longer time.

  • Once Threads are free in Thread Pool and available for next tasks, Server pickup those threads and assign them to remaining Client Requests.
  • Each Thread utilizes many resources like memory etc. So before going those Threads from busy state to waiting state, they should release all acquired resources.

Drawbacks of Request/Response Stateless Model:

  • Handling more and more concurrent client’s request is bit tough.
  • When Concurrent client requests increases, then it should use more and more threads, finally they eat up more memory.
  • Sometimes, Client’s Request should wait for available threads to process their requests.
  • Wastes time in processing Blocking IO Tasks.

Node JS Architecture – Single Threaded Event Loop

Node JS Platform does not follow Request/Response Multi-Threaded Stateless Model. It follows Single Threaded with Event Loop Model. Node JS Processing model mainly based on Javascript Event based model with Javascript callback mechanism.

You should have some good knowledge about how Javascript events and callback mechanism works. If you don’t know, Please go through those posts or tutorials first and get some idea before moving to the next step in this post.

As Node JS follows this architecture, it can handle more and more concurrent client requests very easily. Before discussing this model internals, first go through the diagram below.

I tried to design this diagram to explain each and every point of Node JS Internals.

The main heart of Node JS Processing model is “Event Loop”. If we understand this, then it is very easy to understand the Node JS Internals.

Single Threaded Event Loop Model Processing Steps:

  • Clients Send request to Web Server.
  • Node JS Web Server internally maintains a Limited Thread pool to provide services to the Client Requests.
  • Node JS Web Server receives those requests and places them into a Queue. It is known as “Event Queue”.
  • Node JS Web Server internally has a Component, known as “Event Loop”. Why it got this name is that it uses indefinite loop to receive requests and process them. (See some Java Pseudo code to understand this below).
  • Event Loop uses Single Thread only. It is main heart of Node JS Platform Processing Model.
  • Even Loop checks any Client Request is placed in Event Queue. If no, then wait for incoming requests for indefinitely.
  • If yes, then pick up one Client Request from Event Queue
    • Starts process that Client Request
    • If that Client Request Does Not requires any Blocking IO Operations, then process everything, prepare response and send it back to client.
    • If that Client Request requires some Blocking IO Operations like interacting with Database, File System, External Services then it will follow different approach
      • Checks Threads availability from Internal Thread Pool
      • Picks up one Thread and assign this Client Request to that thread.
      • That Thread is responsible for taking that request, process it, perform Blocking IO operations, prepare response and send it back to the Event Loop
      • Event Loop in turn, sends that Response to the respective Client.


Diagram Description:

  • Here “n” number of Clients Send request to Web Server. Let us assume they are accessing our Web Application concurrently.
  • Let us assume, our Clients are Client-1, Client-2… and Client-n.
  • Web Server internally maintains a Limited Thread pool. Let us assume “m” number of Threads in Thread pool.
  • Node JS Web Server receives Client-1, Client-2… and Client-n Requests and places them in the Event Queue.
  • Node JS Even Loop Picks up those requests one by one.
    • Even Loop pickups Client-1 Request-1
      • Checks whether Client-1 Request-1 does require any Blocking IO Operations or takes more time for complex computation tasks.
      • As this request is simple computation and Non-Blocking IO task, it does not require separate Thread to process it.
      • Event Loop process all steps provided in that Client-1 Request-1 Operation (Here Operations means Java Script’s functions) and prepares Response-1
      • Event Loop sends Response-1 to Client-1
    • Even Loop pickups Client-2 Request-2
      • Checks whether Client-2 Request-2does require any Blocking IO Operations or takes more time for complex computation tasks.
      • As this request is simple computation and Non-Blocking IO task, it does not require separate Thread to process it.
      • Event Loop process all steps provided in that Client-2 Request-2 Operation and prepares Response-2
      • Event Loop sends Response-2 to Client-2
    • Even Loop pickups Client-n Request-n
      • Checks whether Client-n Request-n does require any Blocking IO Operations or takes more time for complex computation tasks.
      • As this request is very complex computation or Blocking IO task, Even Loop does not process this request.
      • Event Loop picks up Thread T-1 from Internal Thread pool and assigns this Client-n Request-n to Thread T-1
      • Thread T-1 reads and process Request-n, perform necessary Blocking IO or Computation task, and finally prepares Response-n
      • Thread T-1 sends this Response-n to Event Loop
      • Event Loop in turn, sends this Response-n to Client-n

Here Client Request is a call to one or more Java Script Functions. Java Script Functions may call other functions or may utilize its Callback functions nature.

So Each Client Request looks like as shown below:

Node JS Architecture, Single Threaded Event Loop

For Example:



  • If you don’t understand how these functions are executed, then I feel you are not familiar with Java Script Functions and Callback mechanism.
  • We should have some idea about Java Script functions and Callback mechanisms. Please go through some online tutorial before starting our Node JS Application development.

Node JS Architecture – Single Threaded Event Loop Advantages

  1. Handling more and more concurrent client’s request is very easy.
  2. Even though our Node JS Application receives more and more Concurrent client requests, there is no need of creating more and more threads, because of Event loop.
  3. Node JS application uses less Threads so that it can utilize only less resources or memory

Event Loop Pseudo Code

As I’m a Java Developer, I will try to explain “How Event Loop works” in Java terminology. It is not in pure Java code, I guess everyone can understand this. If you face any issues in understanding this, please drop me a comment.

public class EventLoop {
        	if(Event Queue receives a JavaScript Function Call){
        		ClientRequest request = EventQueue.getClientRequest();
                            If(request requires BlokingIO or takes more computation time)
                                    Assign request to Thread T1
                                  Process and Prepare response

That’s all for Node JS Architecture and Node JS single threaded event loop.


  1. Neelesh says:

    Please explain that what if an another request arises to event loop with blocking I/O operation and thread t1 is busy in executing earlier blocking I/O request. The in the case what will event loop decide to perform?
    Thank You

  2. Josh says:

    This is one of the best articles on Node.js single-thread architecture. So helpful specially for a newbie like me.

  3. Shuvo Khalid says:

    That means the only deference between multi thread request response and single thread (node.js) is before handling request node js check if the request is blocking operation or not if blocking then it will apply thread otherwise not
    Am I right?
    And another thing is though node js is single thread it internally use multi thread to handle request right?

    1. Ajeet Kumar Maurya says:

      Yes @Shuvo, My understanding is also the same. but I didn’t understand how node.js will handle multiple I/O blocking request concurrently because in this case, it will also require multiple threads to handle requests.

      1. Saurabh Kumar says:

        the number of internal worker threads is limited to 4 for node js. if 5th request come than it has to wait

    2. Atolagbe Elisha says:

      Same question in mind… Lol.

      If all request operations are blocking and all the internally maintained pool of thread is busy, what happens?

  4. Rabeesh V says:

    In the native model, if there is no free thread pool then request should be wait right as per ur blog.

    But u didnt emntion this case for the nodejs single threaded.

    1. Atolagbe Elisha says:


      I’m also very confused.

  5. Maruthi says:

    Great Explanation.
    I have a question i.e
    When Blocking code/file processing is taking care of Thread, who is taking care of simple code/ task which involves calculations/ etc . I mean processer/threads ?

  6. abdullatif jamous says:

    thank you very much, it is the best Node.js architecture explanation I have ever read

  7. Sonal Agarwal says:

    Very well explained. This my first time in Node JS and read many articles on the architecture, but your article made the concept so clear. Thanks.

  8. Saranya says:

    Good article. I should have read earlier. There is a clear clarification on the high level


  9. Jatin says:

    Hi All,
    I am confused about how event loop decide which request is blocking or nonblocking?

    Jatin Raghv

    1. Vamshidhar Reddy says:

      So, if the client request is a heavy computational task like writing some data into local file system or any db connection then it can be considered as blocking operation.

      1. Vijay Kholiya says:

        If I need to do heavy computational tasks which is processing the audio and it can take upto 5 minutes to process a single request. So should I create worker threads for this implementation?

        1. Reev Ranj says:

          See this article is not completely correct. I have explained about this in the comments below. Please scroll down and check for my comments.
          And about your question on whether to use worker threads, yes you can use worker threads for doing things that things like audio processing. But worker threads are limited, when there are many audio processing requests it would be better if you can implement these using message brokers like RabbitMQ or amazon SQS, where there is a separate nodeJs application waiting for job/messages to the queue and does the job. This is more reliable as queue is persistent and durable.

        2. Reev Ranj says:

          Also, I have written a worker-threads utility library called ‘vblaze’ for easier implementations. You can check it here:

  10. Abhishek says:

    beautiful explanation. everyone can understand this. so clear. thank you so much.

    1. David says:

      Excellent explanation. Really appreciate for your effort to create this blog.

  11. vitthal mahale says:

    How does the Event loop know the request requires any Blocking IO Operations or takes more time for complex computation tasks?

    1. Reev Ranj says:

      You can read very next comment of yours below , to understand whats happening.

  12. Reev Ranj says:

    This article is not completely correct, this gives very brief information in layman terms.
    The internal thread pool mentioned here just has 4 threads by default. and its not like the whole request is attached to a new thread from the thread pool the whole execution of request happens just like any normal request (without any blocking task) , just that whenever a request has any long running or a heavy operation like db call ,a file operation or a http request the task is queued to the internal thread pool which is provided by libuv. And as nodeJs provides 4 threads in internal thread pool by default every 5th or next concurrent request waits until a thread is free and once these operations are over the callback is pushed to the callback queue. and is picked up by event loop and sends back the response.

    Now here comes another information that its not once single callback queue, there are many queues.
    1) NextTick queue
    2) Micro task queue
    3) Timers Queue
    4) IO callback queue (Requests, File ops, db ops)
    5) IO Poll queue
    6) Check Phase queue or SetImmediate queue
    7) close handlers queue

    Whenever a request comes the code gets executing in this order of callbacks queued.

    It is not like when there is a blocking request it is attached to a new thread. There are only 4 threads by default. So there is another queueing happening there.

    Whenever in a code a blocking process like file read occurs , then calls a function which utilises thread from thread pool and then once the operation is done , the callback is passed to the respective queue and then executed in the order.

    Everything gets queued based on the the type of callback and processed in the order mentioned above.

    1. mrinal verma says:

      nice explanation man

  13. john says:

    Great info.
    Where have sourced the info : ‘Node JS Web Server internally maintains a Limited Thread pool to provide services to the Client Requests.’?
    I’ve never heard of this thread pool?

  14. ravindra says:

    it is a nice tutorial. thanks a lots

  15. Benaya Paul says:

    Thanks, Rambabu really nice content about Nodejs event loop and event queue.

  16. Rajesh says:

    Sir please help me understand this. I am not able to move forward without knowing that.
    1. When the request need blocking call then the event is given to a thread pool. After that event loop will start processing another client request meanwhile Am I correct?

    2. It may be a blunt question if the request is placed in event queue how the browser waits for the response. I think the browser also makes the call asynchronous?

  17. Elumalai says:

    very good article for Multithread vs single thread

  18. prabhat says:

    its very interesting topic and you explain very well.. thanks a lot…

  19. shiva says:

    Nice and clean article. Thanks, Kep it up.

  20. Hai Nguyen says:

    Great article, thanks!

  21. Harsh Verma says:

    It was great one.keep it up

  22. Pooja Gupta says:

    very nicely explained the basic concept of event loop in node js

  23. pushpender says:

    thanks very clear and easily understood.

  24. jyothi says:

    It’s a very nice article. I read it two weeks back and from then I was searching for this to re-read. Got it again today (28/12/2018). It is of so much value.

    Thanks a ton for uploading 🙂

  25. syed parveen says:

    Hi, could you please provide the brief expalnation of event loop phases how it will work

  26. Pawan Sasanka says:

    This is a great article with plenty of simple examples which anyone can understand. Simple language added a more value to this. Describing difference of Nodejs architecture with the aid of multi-threaded architecture is a great way to enhance the understandability. Than you

    1. Rajesh says:

      very useful article actully.

  27. Anand H says:

    Very helpful. Thanks!

  28. Juhi says:

    Thanks for this artical it is wonderful But it left me with some doubts.
    1. What will happen if all the requests demands for blocking I/O? means if the requests increases than the internal thread pool?
    2. What will event loop execute first ? Taking the request or sending the respons to the client?

    1. says:

      same Question.

    2. Apurva Singh says:

      Yeah same q. Author got confused with that part. He has not bought up non blocking calls with MongoDB either. That will have a different model. Request will go to Mongo, and since it is Non Blocking, so no additional thread is needed. When a response comes, a interrupt will be raised and interrupt handler will put the response in event loop again to be processed.

  29. Sadik says:

    Really!!! Great Article for NodeJS Developer.

  30. Raju Gupta says:

    Very good explanation.

    Thank you.

  31. Techno tish says:

    Detailed article with good explanation

  32. Junaid Ansari says:

    Great article.It nicely explained everything i needed for Node JS. As you rightly mentioned in the starting that one has to understand the the Javascript callback mechanism to grasp of Node js concurrent request handling without waiting or blocking.
    I see lot of comments where people has asked that if event loop is single thread then how can it still process concurrent requests (which are not I/O bound,IO request will be assigned to node thread pool as shown in above diagram) ,without waiting.I feel this is achieved with Javascript asynchronous and callback mechanism and node provides lot of asynchronous function to achieve the same or developer has to write their code in with asynchronous way and provide callback handling.Kindly correct my understanding.
    Junaid Ansari

  33. Rishabh says:

    Thanks for wonderful work.

    I have one question , if event loop picks request one by one then on user side it has to wait for longer time to get that o/p in case of multiple requests.
    Suppose n clients send their request to one server and each request require 15 seconds then if go by logic of event loop then if will take first request from event queue and process it and then send response to client , then it will fetch 2nd one and send response so by this logic first client will get data in 15 seconds and then 2nd will get data in 30 and so on.. So how node is handling these things as i know i m interpreting something wrong,

    1. Nikhil Salwe says:

      hi rishabh , I’ll try to answer your question.
      Node js is single threaded but internally it uses child thread which are not expose to users.
      In node js callback and async operation are two very important thing and heavily use. what every request make by user is run asynchronously (so that is why it is called as non-blocking) and in the end we get response.

      1. Vivek says:

        As you mentioned “every request make by user runs asynchronously”, so keeping that in mind, event loop takes request-1 from event queue and process it asynchronously then takes request-2 and process it and so on, once for request-1 callback happens, event loop takes it and returns it to the client. Please clarify if I am missing something.

  34. Gajanan Thate says:


  35. Oh man. Got asked about Node architecture in a JS dev interview. Got rejected because didn’t know all that much at the time. I wish I had come across this article a few days ago. This stuff is very helpful; especially the whole step by step explanation of the event loop model.

    1. Salman says:

      same here…

  36. Holiest says:

    **How does nodeJs know a request need heavy computation or blocking IO operations when he has not yet execute it?

    **When we have a response, the event loop first transmits the response or first processes a request?

    *** thanks a lot for your post, it’s a good abstract view.

  37. Alok Deshwal says:

    It really helps a lot

  38. Abdulla says:

    I just would like to say, this article has a lot of beautiful amazing tasty info

    God & Allah bless you bro

  39. sameer says:

    Are the [Event Loop Processing] and the [Incoming Request Insertion In Queue] handled in same thread?

  40. monika says:

    very helpful.. thnku.. 🙂

  41. Hemanth kumar V says:

    Really Amazing. what a article!!. Great Explanation and cleared all my doubts. Thanks

  42. Srimal says:

    Thank You. Well explained.

  43. Mylara says:

    Good Explanation !!!!!!!!

  44. Shagun Pruthi says:

    Great Explanation by the author. I understood each word of it and now I can explain well the Internal Architecture of Node Js. Thanks .

  45. Allaudhin says:

    To good article! Excellent !!!!!!

  46. Rafael says:

    This is the absolutely the best answer I’ve found! Congrats Rambabu, great job man. You’ve literally improved my day 😀

  47. qwdqd says:

    Great Job!
    Just a minor suggestion; please include some nodeJS codes and explain there execution. It would help some people who are a little bit familiar with node.

  48. Harsha Vardhan says:

    It is easily can understand by any person . It is very useful for me . Thank you for your post.

  49. Rajesh S says:

    Just simply explained. Great article 🙂

  50. Rahul Kumar Saini says:

    I’m MEAN stack Developer, this article helps to me a lot and I was get stuck this kind of problem. and read about many articles ,tutorials and watch many videos.
    But this tutorial remove all doubts. Thanks !
    But I have got confused in some point(Single thread in nodeJS) when client make a request to server then this server enters into event queue then event loop start execution on this and check this request will take blocking or non blocking it means take more time or not. If it takes then thread come to picture and this request assigned with a thread.And Now this thread start task on this request.
    But I want to discuss here, Request come into first event loop or thread. On the other hand this request first handled by thread and then event loop.

    Please help me
    Email Id –

    1. arpit says:

      request comes to queue , from queue if event loop is not processing any request goes to loop , if I/O blocking operation is present , it goes to thread , thread performs all the operations and sends back the data to event loop and from event loop it again goes back to the client

      1. Dilesh says:

        hey what’s that t-1,t-2,t-3…….t-n in node js architecture as Node js Internal Thread Pool ?

  51. Anantha Rambabu Gunakala says:

    Nicely Explained

  52. Jitendra kumar rajput says:

    Great article very good explanation 🙂 thank you so much.

  53. Nilesh Patil says:

    Awesome explanation 🙂 thank you so much.

  54. Umesh says:

    great article ..i understood very well

  55. micky says:

    Awesome explanation !! thanks

  56. Arularasan says:

    I am understanding the event loop concepts, thanks

  57. Juhi says:

    Awesome explanation !! Thanks a ton for writing this one.

  58. Sam says:

    How does node.js know that the function requires IO operations?

  59. Rishabh says:

    nice article but i will be awesome if we find all the above andwers

  60. Nikhil says:

    Great article!!!! In very simple language very clean and point to point description. I have one question as in normal web server also the thread pool(M) and if request number N > M then request(Client ) need to wait but in Node.js also there is a internal thread pool and event loop pick thread form thread pool if IO blocking is required. If Node.js also using thread from internal thread pool then it is possible that the thread count is less than the number of incoming request.

  61. Texas Racher says:

    Nice reading… to know internals of Node JS.

    Concept of Cloud computing Architecture is not mentioned and why NodeJS is better in cloud based apps. most of questions about n > m will be answered with cloud.

    1. Saranya says:

      I do have this question in my mind. I hope u know the answer now. Could you please explain me?

  62. Bhanu K says:

    This article brings where NodeJS surpasses other web-servers. It’s basically the IO intensive operations where NodeJS benefits.
    While when it comes to data crunching etc., NodeJS is not the best solution out there.

  63. abhishek says:

    Here we are calling separate threads as a event queue . I don’t understand, event queue will consume memory as well then how it take less memory in comparison to threads.

    1. Dariusz says:

      In a single thread (event loop) will consume memory needed to handle a one request at time. In multithreaded system it will need the memory that is a sum of the memory required for each request running parallelly in separate threads.

  64. vikas bansal says:

    this article let me with some questions like what will happen if Node.Js connection pool is totally consumed and How does node know that the request is going to take some time so assign it a thread?

    1. Bidisha says:

      Node never knows about request time. This is asynchronous process of NodeJs is totally done by the developers with the help of callbacks and event emitters only,

      Note: This article have given a high level view of the NodeJS architecture. To understand it clearly, one have to go through the basic concept of call backs and events.

      1. lakshay says:

        Hi Bidisha!

        You are right by saying the “asynchronous process of NodeJs is totally done by the developers with the help of callbacks and event emitters only”.

        Say we as a developers,made the request async but the internal thread pool is all consumed.What will happen in that scenarios?

  65. abby says:

    it seems the only difference between “Traditional Web Application Processing Model” and node.js is that node.js can determine whether a request is blocking or not.

    – they both have a thread pool
    – they both handle blocking IO by picking up a idle thread
    – they both have a manager thread

    what different is: node.js has a event queue.

    am I right?

    1. Rambabu says:

      Yes right. If you are familiar with Non-Blocking/Asynchronous servers like JBoss Netty server or languages like Scala/Akka/Play, you can understand it well. Please refer them to get in-depth knowledge.

    2. Atolagbe Elisha says:

      Although this article is great, a good question.

      What’s the actual difference between traditional servers and. Node.js servers

  66. Lalit Kumar says:

    As far as event loop is concerned it is explained well…

    But ……. connection of thread performing blocking i/o to libuv calling the callback once event received is not explained which is the heart of node.js

    1. ashutosh.ningot says:


  67. Jithendranath Gupta Y says:

    if node js has internally m threads and if i get n blocking io requests what will happen when n>m?

    1. abby says:

      I have the same question…

  68. Vineesh says:

    The article is very helpful and thank you for sharing this.

    I have a doubt, when multiple requests come which all need Blocking IO task the server uses multiple threads right? then how we can say Node is single threaded?

  69. Rakesh says:

    Hi Rambabu,

    The post is very well explained. I have one question on the thread pool of the webserver itself not the NodeJS internal threadpool that kicks in when the type of the operation is blocking.

    “Node JS Web Server internally maintains a Limited Thread pool to provide services to the Client Requests.”

    Can you please let me know where to change the thread pool setting of the webserver? What’s the default pool size? Because I think this is so crucial in handling multiple concurrent client requests and placing them on the Event Queue. I tried looking up I cannot find anything on the threadpool of the webserver and how to change and tune them? Please throw some light on this if you can.

  70. rachna says:

    thanks for all your node.js articles, really has helped me get started. one question i have is how does event loop find if the request is blocking or non-blocking, and send it to thread accordingly?

  71. Crystal A. says:

    Thank you! I am very new to Node and did not understand the logic behind a single thread…thanks again!

  72. HooRang says:

    Thanks you

    very helpful

  73. Paddy says:

    Thanks a lot. The pictorial depiction does explain things clearly.

  74. Jai says:

    Very helpful article. But I have one doubt.

    Let suppose we have n concurrent requests coming to our web server. m out of n is non blocking so event loop will process them smoothly. But n-m requests are blocking. And as mentioned it will also maintain a thread pool. Let suppose thread pool contains T threads.

    Suppose T=n-m
    Now a new request is coming to web server and it is blocking request.
    So in this scenario how event loop will be non blocking? Wouldn’t new request have to wait till one of threads to be free?

    Is this rare case?

    1. Jimmy George Thomas says:

      Yes, the new request would have to wait till a thread becomes available.

      1. Ayo Alfonso says:

        Is it a rare case ? Because Node.js then feels like a multi-thread environement with a layer of the event loop mechanism built ontop.

  75. Tat Sean says:

    I am still very confusing on NodeJs event loop as different articles seem to explain things differently. The confusion is when the thread that serves the request finishes processing the request, does it send the response back to the Event loop or to the Event queue instead? If we take a look at the JS event loop, it seems to indeed send the callback to the Task queue and Event loop then picks up the task (callback) from the Task queue.

    1. Jimmy George Thomas says:

      Yes, you are correct. The thread queues the callback in the task queue from which the event loop picks it up and proceeds.

  76. Vinod Kumar Marupu says:

    Very Helpfull :-).

  77. Raju says:

    Good article. Thanks for sharing this.
    It will be nice if you add ode related to how threads (blocking IO) responds back to event queue in your pseudo code

  78. vivek says:

    Nice Article,but i need more knowledge of how to build application using node js in PHP or any language … pls help

  79. vivek says:

    Nice Article, thanks , for sharing your knowledge we us. i need more knowledge of how to build application using node js in PHP or any language … pls help

  80. Bron1010 says:

    Its an indeed a great article,
    But I would like to know –
    1.the answer of above comment by Abdallah Al-Barmawi
    2.Can you explain how does clusters work with respect to above explain single threaded model of nodejs.

    1. Rambabu says:

      Hi, I will update this post soon by answering your questions

  81. Abdallah Al-Barmawi says:

    Thank you for this article and this explanation of how node works,

    but still i’m some how confused abut this,

    let’s say that our web server do this operation (none IO operation),
    for example (loop statement that needs 3 seconds to finish or complex validation on data(MVC model))

    what will happened if i have let’s say 1000 concurrent requests?
    does the first request will block the remaining requests until it’s finished.

    and how node determain that this operation(none IO operation) is complex or not?


    and i hope if we can chat using Skype to discuss it.

    1. Sushant says:

      Good question. Did you find a response to this? If yes please share. Thanks,S

    2. Rambabu says:

      Hi, I will update this post soon by answering your questions.

    3. Jimmy George Thomas says:

      Yes, the remaining requests will have to wait till the first request is finished. The way in which the calls are implemented is what decides if it is going to be executed on the main thread or not. You yourself can implement a module that maps internally to non-blocking OS calls and then listen for its completion. Then you would have to queue the corresponding callback in the queue for the event loop to handle.

  82. Avishek Biswas says:

    Great article, thanks , for sharing your knowledge.

  83. Johnny says:

    Great article, thanks!

  84. Kittu says:

    Nice article.. It is clearly explained.. Comparison with Muti-threaded model helped me to understand node.js very well.. Thank your very much..

  85. Balavignesh says:

    Great article!! I am a full stack developer(fresher) and I did not know this node architecture before. I got rejected in an important interview because I didn’t know this. Now I understand everything. Thank you for your awesome job Pankaj 🙂

Comments are closed.

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors