🧵 "Node.js is single threaded" everyone says that. But this is only half of the truth. Yes, Node.js is single threaded in its main execution the Event Loop and your code run on one thread. But using many other things, we can make it behave like a multiprocess or multithreaded system that performs perfectly even for CPU intensive tasks: 1-libuv (the underlying engine) It is the underlying C++ library in Node. Through it we can handle: A)Network I/Os : by dealing with the OS kernel directly So the kernel handles it asynchronously and notifies Node when done, so the main thread never blocks. B)File I/Os and DNS operations : through a thread pool that abstracts our main thread from that heavy load. 2-Event Loop Partitioning: But if the load is heavier than we thought, we need to handle it differently. -We can do partitioning making heavy operations done in multiple phases of the Event Loop so we don't starve any phase. -Using setImmediate(), I can distribute my work across different check phase iterations, so other phases keep running alongside the heavy operation without being starved. 3-Worker Threads & Child Processes Okay but what if the task is even heavier CPU intensive work? -Then we have Node Workers I can make my main thread do some work and offload intensive CPU tasks to other threads. (Yes, other threads just like a multithreading system.) Or we can even use Child Processes to offload work onto entirely different processes, each with their own memory and dedicated everything. So now we get it Node.js is single threaded in its code execution, but we can still make it behave like any concurrent parallel system. It's not a limitation. It's a deliberate design choice. #nodejs #backend #javascript #SoftwareEngineering
Node.js: Debunking the Single-Threaded Myth
More Relevant Posts
-
🚀 What I Learned About Worker Threads in Node.js (Real Experiment) Today I explored how Node.js handles heavy CPU tasks — and the results were interesting 👇 🧠 What I Did Created 3 files (a.js, b.js, c.js) Each file had a heavy loop Ran them using Worker Threads ❓ My Doubt “Node.js is single-threaded… so how can multiple tasks run together?” 💥 What I Observed Logs from all 3 loops were interleaved (mixed output) Multiple threads were visible in system monitor CPU usage increased 👉 This clearly showed parallel execution ❌ Mistake I Made new worker = ("./a.js") ❌ ✅ Solution const { Worker } = require("worker_threads"); new Worker("./a.js"); new Worker("./b.js"); new Worker("./c.js"); 💡 Key Learnings Node.js is single-threaded by default Heavy CPU tasks block the event loop worker_threads enable true parallel execution Each worker runs in a separate thread 🔥 Big Realization “JavaScript is single-threaded, but Node.js can achieve multi-threading using worker_threads” #NodeJS #JavaScript #BackendDevelopment #Multithreading #WebDevelopment #LearningInPublic
To view or add a comment, sign in
-
-
TypeScript 6.0 dropped. Here's what actually matters for your project 🧵 🆕 What's new: • Temporal API types (finally Stage 4!) • Map.getOrInsert() — upsert in one line • RegExp.escape() — safe regex from user input • dom.iterable is now included in dom automatically • Subpath imports with #/ prefix ⚠️ New defaults that will break things: • strict is now TRUE by default • types defaults to [] — add "node" explicitly or things will go missing • rootDir defaults to "." • module defaults to esnext ❌ Start removing these now (gone in TS 7.0): • baseUrl • moduleResolution: node • target: es5 • module: amd/umd/systemjs • outFile TS 6.0 is a transition release — the real target is 7.0 with parallel type checking and a native compiler port. If you're seeing deprecation warnings after upgrading: fix them now, not later. What's your migration plan? Drop it in the comments 👇 #TypeScript #JavaScript #WebDevelopment #Frontend
To view or add a comment, sign in
-
One bad loop can freeze your entire server. Not slow it down. Freeze it. That’s the part most Node/NestJS devs underestimate 👇 We love saying “Node is non-blocking.” But that’s only true until you block it. The event loop can only move forward when your code lets it. If one task takes too long, everything else waits behind it. What actually blocks the event loop? • Synchronous operations • Heavy CPU work (large loops, calculations) • Huge JSON parsing or stringifying • Anything that keeps the call stack busy for too long Here’s the real problem: One heavy request doesn’t just slow itself down. It blocks every other user at the same time. One user clicks → everyone waits. Think of Node like a single cashier. If one customer takes 5 minutes, the whole line stops moving. No matter how many users you have — everything is stuck behind that one task. The event loop isn’t magic. It’s just fast… until you block it. #NodeJS #NestJS #BackendDevelopment #JavaScript #WebDevelopment #SoftwareEngineering #EventLoop #Performance #Scalability #Programming #CodingTips
To view or add a comment, sign in
-
-
Do you actually know what version you're installing? Most developers write ^, ~, or just a number in package.json without thinking twice — but they behave very differently. Here's a quick breakdown: ^ (Caret) — ^4.19.1 Allows minor + patch updates. Stays on major version 4. Range: ≥4.19.1 <5.0.0 ~ (Tilde) — ~4.18.7 Allows patch updates only. Minor version locked to 18. Range: ≥4.18.7 <4.19.0 Exact — 4.12.4 Pins to this exact version. No updates ever. Range: = 4.12.4 only ✅ Use ^ when you trust the library follows semver and want latest features. 🔒 Use ~ when you want stability but still need bug fixes. 📌 Use exact version when you need 100% reproducibility — CI/CD pipelines, production lockdowns. Pro tip: Always commit your package-lock.json or yarn.lock. The ranges in package.json are intentions — the lock file is what actually gets installed. Which one do you use most? Drop a comment 👇 #javascript #nodejs #npm #webdevelopment #softwareengineering #100daysofcode #devtips
To view or add a comment, sign in
-
Node.js: Single-Threaded Logic, Multi-Threaded Power "If Node.js is single-threaded, how does it handle heavy tasks without freezing?" The answer lies not just in the Event Loop, but also in the Libuv Thread Pool. The Invisible Backbone While JavaScript runs on a single "Main Thread," Node.js delegates expensive, blocking tasks to a background pool of worker threads. This keeps the main thread free to handle new incoming requests. What gets offloaded? - I/O Intensive: Complex File System (fs) operations. - CPU Intensive: Cryptography (hashing passwords) and Compression (zlib). - Networking: DNS lookups. The Workflow 1. Request: A heavy task (like crypto.pbkdf2) enters the Event Loop. 2. Delegate: The Event Loop hands the task to an available worker in the Libuv Thread Pool. 3. Execute: The worker finishes the task in the background without touching your JS execution. 4. Callback: Once done, the worker notifies the Event Loop, which then executes your callback. Pro-Tip: Scaling the Pool By default, the thread pool size is 4. On a modern 16-core server, this can be a bottleneck. You can double your throughput by increasing this limit before the application boots: ```javascript // Increase pool size to match your hardware process.env.UV_THREADPOOL_SIZE = 8; ``` Key Takeaway Node.js isn't just a single thread; it's a smart orchestrator. It uses a single thread for your code, but a team of workers for the heavy lifting. Are you monitoring your thread pool, or is your app waiting in line? #NodeJS #BackendDevelopment #JavaScript #SystemDesign #WebDevelopment #LearningInPublic
To view or add a comment, sign in
-
-
𝗡𝗼𝗱𝗲.𝗷𝘀 𝐓𝐨𝐩𝐢𝐜 𝟐: 𝐓𝐡𝐞 𝐓𝐡𝐫𝐞𝐚𝐝 𝐏𝐨𝐨𝐥 Under the hood, libuv maintains a pool of 4 threads (by default) that runs in parallel with your JavaScript. Every time you call certain Node.js APIs, the work is offloaded to this pool - silently, invisibly. 📂 What goes to the thread pool: ➡️ fs.readFile / fs.writeFile — all file system operations ➡️ crypto.pbkdf2, crypto.randomBytes, crypto.scrypt ➡️ dns.lookup (not dns.resolve — that uses the network directly) ➡️ zlib compression and decompression What goes directly to the OS kernel, bypassing the pool entirely: ➡️ TCP / UDP sockets ➡️ HTTP / HTTPS requests ➡️ Unix pipes ❗𝘛𝘩𝘦 𝘱𝘳𝘰𝘥𝘶𝘤𝘵𝘪𝘰𝘯 𝘣𝘶𝘨 Default pool size: 4 threads. If your server receives 8 simultaneous requests that each call crypto.pbkdf2 (common in authentication flows), 4 of them will wait - blocked - until a thread is free. Your Event Loop stays responsive. But your response times double. This is invisible in development. It surfaces under load in production. 💡𝐓𝐡𝐞 𝐅𝐢𝐱: Set this before your process starts: UV_THREADPOOL_SIZE=8 The maximum is 1024. The right value depends on your workload - profile before guessing. Node.js is single-threaded where it matters - your JavaScript. But the infrastructure running beneath it is not. Knowing the boundary between the two is what separates application developers from systems developers. #nodejs #javascript #backend #performance #softwaredevelopment #systemdesign
To view or add a comment, sign in
-
-
Ever wonder what's actually happening under the hood when Promise.all executes your parallel API calls? Here's the magic: libuv. Node.js doesn't run requests in parallel on a single thread. Instead: 1. Thread Pool — libuv queues your requests to worker threads (default 4). 2. OS Multiplexing — epoll/kqueue monitors network sockets simultaneously. 3. Event Loop — The main thread stays responsive, orchestrating callbacks. When you fire 3 API calls with Promise.all, libuv: - Registers them with the OS. - Worker threads handle DNS/I/O in parallel. - The event loop waits for responses (non-blocking). - Callbacks fire when data arrives. The result? True concurrency without blocking the main thread. This is why JavaScript can handle thousands of concurrent connections despite being single-threaded. Understanding libuv is key to understanding modern Node.js. #NodeJS #JavaScript #SystemArchitecture #Backend
To view or add a comment, sign in
-
The Oxc Angular Compiler: up to 20x faster Angular builds. We re-built the Angular compiler on top of Oxc, the Rust-based JavaScript Compiler that also powers Rolldown and Vite 8+. → 6.4x faster than Angular CLI on Super Productivity → 20.7x faster than Webpack + @ngtools/webpack on Bitwarden Coming with a first-class Vite plugin with full HMR and a programmatic API. We implemented the template compiler natively in Rust instead of driving compilation through TypeScript's semantic checker. That's where the speed comes from. We built the compiler in just 2 months with the help of Claude Code and Codex, but this is not just another slop fork. Nevertheless, the Oxc Angular Compiler was an experiment. We skipped cross-file optimizations and template type-checking and not plan to maintain it beyond its current state. The good news: the Angular team is already looking into integrating Oxc as well. Read the full write-up https://lnkd.in/gaWhMEJM
To view or add a comment, sign in
-
-
Every framework deserves fast tooling. As an experiment, Yinan Long rebuilt the Angular compiler in Rust on top of Oxc 👀 The results are amazing, but see for yourself!
The Oxc Angular Compiler: up to 20x faster Angular builds. We re-built the Angular compiler on top of Oxc, the Rust-based JavaScript Compiler that also powers Rolldown and Vite 8+. → 6.4x faster than Angular CLI on Super Productivity → 20.7x faster than Webpack + @ngtools/webpack on Bitwarden Coming with a first-class Vite plugin with full HMR and a programmatic API. We implemented the template compiler natively in Rust instead of driving compilation through TypeScript's semantic checker. That's where the speed comes from. We built the compiler in just 2 months with the help of Claude Code and Codex, but this is not just another slop fork. Nevertheless, the Oxc Angular Compiler was an experiment. We skipped cross-file optimizations and template type-checking and not plan to maintain it beyond its current state. The good news: the Angular team is already looking into integrating Oxc as well. Read the full write-up https://lnkd.in/gaWhMEJM
To view or add a comment, sign in
-
-
Why being a "Framework Expert" keeps you from getting promoted. Knowing every annotation in Spring Boot or every hook in React is great for your first few years. But it won't get you to the Senior level. At a certain point, the problems stop being about syntax and start being about physics. Network latency, memory allocation, thread exhaustion, and database locks don't care what framework you use. To move up, you have to look under the hood. Understand how your code interacts with the JVM heap. Understand how your framework manages OS threads. Shift your focus from the tool to the architecture. When did you realize that framework knowledge wasn't enough? 👇 #SoftwareEngineering #SystemArchitecture #CareerGrowth #BackendEngineering #SystemDesign #JVM #SpringBoot #ReactJS #SeniorDeveloper
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development