Skip to main content

Command Palette

Search for a command to run...

How Node.js Handles Multiple Requests with a Single Thread

Updated
6 min readView as Markdown
How Node.js Handles Multiple Requests with a Single Thread

This was one of those things that sounded impossible when I first heard it.

People would say:

Node is single-threaded.

And then say:

Node can handle thousands of requests.

And I remember thinking…

How can both be true?

If there is one thread…

shouldn’t everything happen one request at a time?

That seemed logical to me.

And honestly, I was confused for a while.

It felt contradictory.

But later I realized…

I was mixing up single-threaded execution with handling many requests.

Those are related.

But not the same thing.

And once I saw that difference…

this topic became much easier.


What I Thought Single-Threaded Meant

I used to think single-threaded meant:

Request 1 arrives.

Finish Request 1 completely.

Then Request 2.

Then Request 3.

Like a strict line.

Everybody waits.

That was my mental model.

And that model was incomplete.

Because it ignored waiting.

And waiting changes everything.


The Word That Cleared It Up

Concurrency.

That word fixed a lot of confusion for me.

Because I kept mixing it up with parallelism.

They sound similar.

But they are not.

Parallelism means things literally happening at the same time.

Concurrency means managing multiple things efficiently.

That’s different.

And Node is usually discussed in terms of concurrency.

That distinction matters a lot.


The Chef Analogy Helped Me

This made it click.

Imagine one chef.

Just one.

Single chef.

Orders keep coming in.

Now imagine the chef works like this:

Take one order.

Put something in oven.

While it cooks…

take another order.

Prep another dish.

Check first dish.

Handle next order.

The chef is not cloning themselves.

Still one chef.

But multiple orders are being managed.

That felt a lot like Node to me.

And honestly…

that analogy made more sense than technical definitions.


Single Thread Handling Multiple Requests


The Missing Piece For Me Was Waiting

This was huge.

A lot of requests involve waiting.

Waiting for database.

Waiting for file.

Waiting for network response.

And I used to ignore that part.

But Node doesn’t want main JavaScript execution just sitting there doing nothing while waiting.

That would waste time.

So it handles that intelligently.

That is where the magic starts making sense.


Event Loop Plays A Big Role Here

This connects directly to the event loop.

Requests come in.

Some tasks begin.

Some waiting-heavy work gets delegated.

When results are ready…

callbacks can be processed.

And the event loop keeps checking what work can run next.

That constant coordination matters.

It is not random.

There is flow.

And once I understood that…

the pieces started connecting.


Event Loop + Worker Flow


Background Workers Surprised Me

I didn’t realize this early.

I thought:

If Node is single-threaded…

it literally does everything on one thread.

Not exactly.

Certain tasks can be delegated to background workers.

That was new to me.

Things like some file operations or other waiting-heavy work can be handled outside the main JavaScript execution path.

Meanwhile main thread keeps moving.

That changes the whole picture.


This Was My “Ohhh” Moment

Single-threaded did not mean:

Only one thing can exist at a time.

It meant:

One main JavaScript thread coordinates execution.

Very different.

And that difference is the entire topic.

Once I saw that…

the contradiction disappeared.


Handling Multiple Client Requests

Imagine three users hit your server.

User A needs database data.

User B requests something too.

User C arrives.

If everything blocked…

B waits for A.

C waits for B.

Terrible.

But if waiting-heavy work is managed efficiently…

server keeps handling incoming requests.

That is why Node can handle multiple clients well.

That made it feel real to me.


Why Node Scales Well

This made more sense after that.

People say Node scales well because it can handle lots of I/O-heavy requests efficiently.

Again…

not because one thread is magically doing superhuman work.

But because time isn’t wasted sitting around waiting.

That distinction matters.

A lot.


Where This Shows Up

This clicked when I thought about things like:

  • APIs

  • Chat apps

  • Real-time systems

  • Streaming

  • Request-heavy services

Lots of waiting.

Lots of events.

That fits Node well.

And now the reputation started making sense.


Tiny Example That Helped Me Think About It

const fs = require("fs");

fs.readFile(

"data.txt",

()=>{

 console.log(
  "File finished"
 );

}

);

console.log(
"Server can keep working"
);

That last line can continue immediately.

That small example taught me a lot.


One Mistake I Made

I assumed:

Single-threaded means weak.

That was wrong.

Architecture matters more than labels.

I was judging by the word.

Not by how it works.

Big difference.


Another Thing I Got Wrong

I thought Node was good for every type of workload.

Not necessarily.

I/O-heavy work and CPU-heavy work are different conversations.

That took me time to understand.

Worth knowing early.


Thread vs Process Confused Me Too

I used those words interchangeably.

Bad habit.

They are not the same thing.

And even realizing that helped me think more clearly about this topic.

I definitely mixed them up before.


Small Thought Exercise

Ask yourself:

If one request is waiting on a database…

should server do nothing during that wait?

Or keep handling other requests?

That question alone explains much of why Node works the way it does.

Honestly.


What Finally Made It Click

I stopped thinking:

Node somehow breaks single-threading rules.

And started thinking:

Node manages waiting efficiently.

That made everything make sense.

No contradiction anymore.


Quick Recap

  • Node has one main JavaScript thread

  • It handles requests through concurrency

  • Waiting-heavy work can be delegated

  • Event loop coordinates what runs next

  • That helps Node scale for I/O-heavy workloads

That’s the foundation.


Conclusion

For a long time…

“single-threaded but handles many requests” sounded impossible to me.

Now it doesn’t.

Because they are talking about different things.

One thread for execution.

Efficient concurrency for handling many requests.

And honestly…

once I understood that distinction, this topic became much simpler.

If you remember one thing from this article, remember this:

Node handles many requests not by doing everything at once…
but by managing waiting efficiently.

That idea made it click for me.

If you like this simple learning-style explanation,
I write more notes at
devwithsahil.hashnode.dev
and share progress on LinkedIn 🙂