MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Call Stack, Callback Queue, Microtask Queue & Libuv Workers0%
Study Materials
Node.js & Express.jsProgress 0%
1.1Node.js Architecture, V8 Engine & Single-Threaded Event Loop1.2Call Stack, Callback Queue, Microtask Queue & Libuv Workers1.3Non-Blocking Asynchronous Code with Promises and Async/Await
HomeTutorialsNode.js & Express.jsCall Stack, Callback Queue, Microtask Queue & Libuv Workers
Non-Blocking Asynchronous Code with Promises and Async/Await

Call Stack, Callback Queue, Microtask Queue & Libuv Workers

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

To master backend performance and debug tricky race conditions in Node.js, every developer must understand the exact priority mechanism governing asynchronous execution: the Call Stack, the Microtask Queue, the Callback Queue (Macrotask Queue), and the Libuv Worker Thread Pool.


1. Execution Priority Hierarchy

When multiple asynchronous operations complete simultaneously, Node.js uses a strict order of precedence:

  1. 1
    Synchronous Code on Call Stack: Runs immediately until the call stack is completely empty.
  2. 2
    Microtask Queue 1 (process.nextTick): Runs before ANY other asynchronous queue, immediately after the current operation finishes.
  3. 3
    Microtask Queue 2 (Promises / queueMicrotask): Promise .then(), .catch(), and async/await continuations.
  4. 4
    Macrotask / Timer Queue (setTimeout, setInterval): Evaluated during the Timers phase of the Event Loop.
  5. 5
    Check Queue (setImmediate): Executed during the Check phase of the Event Loop.
1[Call Stack] -> [process.nextTick queue] -> [Promise Microtasks] -> [Event Loop Phases]

2. Priority Demonstration in Code

1console.log('1. Synchronous');
2 
3setTimeout(() => {
4 console.log('5. setTimeout (Timer Macrotask)');
5}, 0);
6 
7setImmediate(() => {
8 console.log('6. setImmediate (Check Macrotask)');
9});
10 
11Promise.resolve().then(() => {
12 console.log('3. Promise.then (Microtask Queue)');
13});
14 
15process.nextTick(() => {
16 console.log('2. process.nextTick (Microtask Queue - Priority 1)');
17});
18 
19console.log('4. Synchronous end');

Actual Execution Order:

11. Synchronous
24. Synchronous end
32. process.nextTick (Microtask Queue - Priority 1)
43. Promise.then (Microtask Queue)
55. setTimeout (Timer Macrotask)
66. setImmediate (Check Macrotask)

3. The Libuv Worker Thread Pool

While network I/O (HTTP sockets, TCP) uses non-blocking OS kernel polling (epoll/kqueue), certain operations cannot be performed asynchronously by operating system kernels. Node.js sends these to the Libuv Thread Pool:

  • File System Operations: fs.readFile, fs.writeFile
  • Cryptography: crypto.pbkdf2, crypto.scrypt, crypto.randomBytes
  • Compression: zlib.deflate, zlib.gzip
  • DNS Lookups: dns.lookup

The default size of this thread pool is 4 threads, but it can be scaled for heavy workloads using the environment variable:

1# Linux / macOS
2export UV_THREADPOOL_SIZE=16
3 
4# Windows PowerShell
5$env:UV_THREADPOOL_SIZE=16

Interactive Quiz• Knowledge Check

Multiple Choice Questions

Question 1
Which asynchronous task queue has the highest priority and executes immediately after the current call stack clears, before Promise resolutions?
Question 2
What is the default number of worker threads in the Libuv thread pool in Node.js?
Question 3
Which of the following operations is offloaded to the Libuv worker thread pool rather than using OS-level non-blocking kernel sockets?
Question 4
What is the danger of recursively calling process.nextTick() inside its own callback?
Question 5
Between setTimeout(fn, 0) and setImmediate(fn), which is explicitly designed to execute immediately after the I/O polling phase completes?

Next Lesson

Non-Blocking Asynchronous Code with Promises and Async/Await

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Node.js Architecture, V8 Engine & Single-Threaded Event LoopNon-Blocking Asynchronous Code with Promises and Async/Await

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master Node.js & Express.js with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext