What is Reactor Pattern in Node.js ? Last Updated : 22 Jun, 2020 Comments Improve Suggest changes Like Article Like Report Reactor Pattern is used to avoid the blocking of the Input/Output operations. It provides us with a handler that is associated with I/O operations. When the I/O requests are to be generated, they get submitted to a demultiplexer, which handles concurrency in avoiding the blocking of the I/O mode and collects the requests in form of an event and queues those events. There are two ways in which I/O operations are performed: Blocking I/O: Application will make a function call and pause its execution at a point until the data is received. It is called as ‘Synchronous’. Non-Blocking I/O: Application will make a function call, and, without waiting for the results it continues its execution. It is called as ‘Asynchronous’. Note: Node.js is Asynchronous in nature. Reactor Pattern comprises of: Resources: They are shared by multiple applications for I/O operations, generally slower in executions. Synchronous Event De-multiplexer/Event Notifier: This uses Event Loop for blocking on all resources. When a set of I/O operations completes, the Event De-multiplexer pushes the new events into the Event Queue. Event Loop and Event Queue: Event Queue queues up the new events that occurred along with its event-handler, pair. Request Handler/Application: This is, generally, the application that provides the handler to be executed for registered events on resources. How Reactor Pattern works? Everything starts with the application. It makes a request and the event demultiplexer gathers those requests and then it forms queues know as Event Queues. Event demultiplexer is run by libuv which is a library that allows JavaScript code (via V8) to perform I/O, in-network, file, etc. It is an asynchronous IO library that allows Node.js to perform I/O. In the diagram above, there is only one event queue and there are 7 basics queues. Those queues have ascending priorities, the queue that has the highest priority is checked first by the event loop. The Timers queue has the highest priority. setTimeout and setInterval functions are queued here. Once the events are done in this queue, or time is up, the event loop passes those functions to call stack, named as executing handler. When one of the event queues is complete, instead of jumping to the next queue, the event loop firstly will check the other two queues which queue other micro tasks and process called nextTick functions. Then it will jump to the upcoming queue. Callback queue is an event queue and call stack is execute handler. Comment More infoAdvertise with us Next Article What is Reactor Pattern in Node.js ? S sharmaanushka Follow Improve Article Tags : Web Technologies Node.js Node.js-Misc Similar Reads What is spawn in Node JS ? Node JS is a cross-platform, open-source back-end JavaScript runtime environment that uses the V8 engine to execute JavaScript code outside of an internet browser. In this article, we will learn about the Spawn in NodeJs. PrerequisitesNodeJS fundamentalsAsynchronous ProgrammingChild ProcessesSpawn i 3 min read What is Piping in Node.js ? Piping in NodeJS is the process by which byte data from one stream is sent to another stream. It is a powerful feature in Node.js that allows data to be transferred from one stream to another seamlessly. Streams are an integral part of Node.js, providing a mechanism for handling data that is too lar 6 min read Top 8 Node.js Design Patterns in 2025 Node.js, the popular JavaScript runtime, helps developers build complex backend systems. With so many capabilities, it can get quite challenging to work with, and hence, design patterns are used.Design patterns help developers write high-quality, testable, and maintainable code. Some of the design p 10 min read What is the purpose of process object in Node.js ? A process object is a global object available in the Node.js environment. It is globally available. We do not have to use the require() to import the module of the process object. The "process" object use to get current Node.js process details & also give control over that process. Properties of 2 min read What is the purpose of the process object in Node JS ? In NodeJS, the process object is a global object that provides access to information and control over the current NodeJS process. It offers various properties and methods to interact with the underlying operating system environment and manage the NodeJS process effectively. Let's explore the primary 2 min read Like