惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 【当耐特】
S
Schneier on Security
Blog — PlanetScale
Blog — PlanetScale
MyScale Blog
MyScale Blog
Apple Machine Learning Research
Apple Machine Learning Research
Google DeepMind News
Google DeepMind News
aimingoo的专栏
aimingoo的专栏
The GitHub Blog
The GitHub Blog
腾讯CDC
A
About on SuperTechFans
H
Help Net Security
The Register - Security
The Register - Security
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 三生石上(FineUI控件)
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Vercel News
Vercel News
V
Visual Studio Blog
T
Tailwind CSS Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - Franky
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
D
DataBreaches.Net
I
InfoQ
L
Lohrmann on Cybersecurity
M
MIT News - Artificial intelligence
I
Intezer
博客园 - 聂微东
Webroot Blog
Webroot Blog
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
Microsoft Security Blog
Microsoft Security Blog
SecWiki News
SecWiki News
Hacker News: Ask HN
Hacker News: Ask HN
T
Troy Hunt's Blog
S
Security @ Cisco Blogs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
D
Docker
N
Netflix TechBlog - Medium
小众软件
小众软件
The Cloudflare Blog
WordPress大学
WordPress大学
N
News | PayPal Newsroom
C
Check Point Blog
Google Online Security Blog
Google Online Security Blog
月光博客
月光博客
C
Cisco Blogs
阮一峰的网络日志
阮一峰的网络日志
W
WeLiveSecurity
Schneier on Security
Schneier on Security

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
The Thread Battle: Go Concurrency vs. Node.js Event Loop from First Principles
Manoj Khatri · 2026-06-16 · via DEV Community

When building high-concurrency backend services, two ecosystems dominate the conversation: Node.js and Go (Golang).

If you ask the internet how they handle concurrency, you’ll get the standard textbook answers:

  • "Node.js is asynchronous and single-threaded, using an Event Loop."
  • "Go is synchronous and multi-threaded, using lightweight Goroutines."

But what do these statements actually mean under the hood? How do they look to your computer's CPU and RAM? To build bulletproof systems, we must stop memorizing these taglines and look at the low-level mechanical reality of how these two runtimes schedule execution.


1. The Origin: Why Google Invented Go

To truly appreciate Go's concurrency model, we have to look at the exact historical problems its creators (Rob Pike, Ken Thompson, and Robert Griesemer) were trying to solve at Google around 2007. They didn't just wake up and decide to invent a new language for fun; they were fundamentally frustrated by C++ and Java in the era of modern infrastructure.

They designed Go to attack three specific engineering nightmares:

  1. The Hardware Shift (Multi-core Revolution): C++ was designed in 1983, and Java in 1995. They were built for an era of single-core CPUs. By 2006, the hardware industry hit a wall and started expanding sideways by adding multiple physical cores (Dual-core, Quad-core). C++ and Java struggled to utilize these cores efficiently because their primary unit of concurrency,the OS Thread,was too heavy and expensive to spin up by the thousands.
  2. The C++ Build Time Nightmare: Google possesses one of the largest codebases in the world. At the time, compiling a large C++ binary at Google would take 45 minutes to over an hour. The creators famously joked that they designed Go while sitting around waiting for a C++ project to compile. They wanted a language that compiled directly to machine code like C++, but blazingly fast (in milliseconds).
  3. The Scale of Engineering Teams: Google was hiring hundreds of software engineers every month. Complex languages with massive feature sets (like C++ template metaprogramming or Java's deep object-oriented boilerplates) meant onboarding took months. Go's creators deliberately threw out classes, inheritance, and complex pointer arithmetic, keeping only 25 keywords so that any engineer could master the language in a week.

With these constraints, they built a runtime that could utilize every single core of Google's massive server farms cheaply, leading directly to the birth of the M:N Goroutine Scheduler.


2. The Low-Level Foundation: What is an OS Thread?

Before comparing Node and Go, we must understand the currency of execution in modern operating systems: the OS Thread (Kernel Thread).

A thread is the smallest sequence of programmed instructions that an Operating System scheduler can manage independently. When your CPU runs code, it executes it inside an OS Thread.

However, OS Threads are expensive.

  • Memory Cost: Every time an OS thread is created, the kernel allocates a massive chunk of fixed memory (typically 1MB to 8MB) just for its execution stack.
  • Context Switching Cost: When a CPU core switches from running Thread A to Thread B, it must save the current CPU registers, flush caches, and load the state of the new thread. This operation, handled by the OS Kernel, takes valuable CPU cycles.

If you try to handle 10,000 simultaneous user connections by creating 10,000 traditional OS threads, your server will instantly run out of gigabytes of RAM and choke to death just from context-switching overhead. This is the exact bottleneck that Node.js and Go set out to solve—but they took completely opposite engineering paths.


3. A Crucial Mental Model: Process vs. Thread

Before we look at the runtimes, let's establish a bulletproof hardware baseline. A common interview trap is confusing a Process with a Thread.

Think of it this way:

  • The Process (The House): A process is an isolated container provided by the OS. It has its own dedicated memory space (RAM), environment variables, and security boundaries. Both Node.js (node server.js) and Go (./main) run inside exactly one OS Process.
  • The Thread (The Workers inside the House): Threads are the actual workers living inside that house. They run the code on the physical CPU cores. Crucially, all threads living inside the same process share the exact same house memory (Shared Memory Space).

While both Node and Go run as a single process, the way they deploy workers (threads) inside that house to handle requests is completely different.


4. The Node.js Approach: One Thread to Rule Them All

Node.js looked at the expensive nature of OS Threads and made a radical choice: "What if we use exactly ONE main OS Thread inside our process to run all user JavaScript code?"

How it works mechanically:

When 10,000 users hit a Node.js server, they don't get their own threads. They all share the exact same main thread.

  • If User 1 requests a file from the disk, Node.js doesn't sit and wait. It registers the request, hands it over to the Operating System Kernel (or Node's internal libuv C++ thread pool), and the single main thread immediately moves to handle User 2.
  • When the OS finishes reading the file for User 1, it alerts Node, and the Event Loop schedules the callback to run on that same main thread when it becomes free.

The Trade-off: The CPU-Bound Achilles' Heel

Because there is only one main thread, Node.js is mathematically perfect for I/O-bound applications (like chat apps, streaming, or standard REST APIs) where the server spends most of its time waiting for databases or networks.

But look at what happens if User 1 triggers a heavy CPU calculation (like image processing or parsing a massive JSON string):

// Node.js Main Thread
app.get('/heavy-computation', (req, res) => {
  // This infinite loop freezes the single main thread!
  while(true) {} 
  res.send("Done");
});

app.get('/simple-ping', (req, res) => {
  res.send("Pong"); // This will NEVER respond for any other user now!
});

Because the single main thread is hijacked by the infinite loop, the entire Event Loop stops dead in its tracks. It cannot move to the next phase. It cannot accept new network packets. The entire server freezes for every single user globally.


5. The Go Approach: The M:N Green Thread Scheduler

Go looked at the same problem and said: "Single-threaded architectures are too limiting for multi-core CPUs. We want multi-threading, but we want it to be incredibly cheap."

Instead of spinning up a heavy OS thread for every incoming HTTP request, Go leaves a pool of several real OS threads running in the background (typically matching your machine's physical CPU core count). When a new request arrives, Go instantiates a Goroutine (G).

A Goroutine is a "Green Thread" or a virtual thread. The Operating System Kernel has absolutely no idea that Goroutines exist. The Go Runtime takes a massive number of virtual Goroutines (N) and multiplexes them onto a smaller number of real background OS Threads (M).

The Magic of the M:N Scheduler:

The Go scheduler uses three entities to achieve high concurrency:

  • G (Goroutine): The lightweight virtual thread. Its starting stack size is incredibly tiny—only 2KB (compared to an OS thread's fixed 1MB–8MB). You can easily spin up 100,000 Goroutines on a standard laptop without sweating.
  • M (Machine): A real, concrete Operating System Thread managed by the kernel.
  • P (Processor): A logical context or resource representing a virtual CPU core.

Mechanical Reality: What happens during Blocking?

In traditional programming, if an OS Thread makes a synchronous database call, that thread blocks and sits idle. Go solves this beautifully through Asynchronous Interception.

When a Goroutine (G1) makes a blocking system call (like reading a file or waiting for a slow DB query), the Go Runtime instantly intercepts it. It detaches the real OS Thread (M1) to handle the heavy blocking call at the kernel level.

Simultaneously, the Go Scheduler takes the remaining queue of waiting Goroutines and shifts them to a brand new or idle OS Thread (M2) on the fly.

Traditional Blocking:
[OS Thread] ──► Blocks on File Read ──► Entire Thread is Frozen

Go Scheduler Bypass:
[G1 (Blocks)] ──► Moved out with [M1 (Dedicated OS Thread)]
[G2, G3, G4]   ──► Instantly shifted to [M2 (Fresh OS Thread)] ──► Zero Downtime!

When G1 finishes its file read, it quietly slips back into the active runner queue. The execution never stops, and the CPU cores are constantly utilized at maximum capacity.


6. Work Stealing: Keeping All CPU Cores Alive

In Node.js, utilizing multiple CPU cores requires running entirely separate instances of your app via cluster modules or PM2. Each instance runs its own isolated process and Event Loop.

Go handles multi-core CPUs natively out of the box using an algorithm called Work Stealing.

Every logical Processor (P) has its own Local Run Queue of Goroutines. If Processor 1 finishes executing all its Goroutines and its queue goes empty, it doesn't sit idle. It looks over at Processor 2's queue, "steals" half of its waiting Goroutines, and starts executing them on its own CPU core.

This guarantees that as long as there is work to be done, every single hardware core of your multi-thousand-dollar server is actively crunching numbers.


7. Direct Comparison Cheat Sheet

Architectural Feature Node.js Event Loop Go Concurrency Runtime
OS Process Level Runs as 1 single OS Process. Runs as 1 single OS Process.
OS Thread Level Exactly 1 main OS Thread for execution. Multiple background OS Threads (scales with CPU cores).
Concurrency Unit Macro/Micro Callbacks inside queues. Goroutines (G) managed by the Go runtime.
Memory Footprint Low, but JavaScript objects carry runtime overhead. Extremely low initial footprint (~2KB per Goroutine).
CPU Core Utilization Single-core by default. Requires clustering/worker threads for multi-core. Multi-core by default. Automatically spans all available hardware cores.
Heavy CPU Work Impact Fatal. Freezes the entire server for all users if unmanaged. Safe. The scheduler preempts the heavy Goroutine and keeps running others.

Conclusion: When to Choose Which?

Stop arguing about which runtime is "faster" and look at the nature of your workload:

  • Choose Node.js when your system is overwhelmingly I/O bound, dealing with millions of lightweight data pipelines, JSON conversions, and standard web routing. It gives you massive throughput with highly predictable single-threaded simplicity.
  • Choose Go when your system requires high-throughput parallelism, heavy compute pipelines, distributed microservices, or low-latency system-level networking. Go's M:N scheduler will squeeze every drop of mechanical power out of your multi-core server architecture without the mental overhead of complex asynchronous callback chains.