Blocking vs Non-Blocking I/O — What's the Difference?

Blocking I/O halts the calling thread until an operation (like a file read or network call) completes; non-blocking I/O returns immediately, letting the prog...

Published October 6, 2026

Blocking I/O makes the calling thread wait until the operation finishes; non-blocking I/O returns immediately and lets the program do other work until the result is ready. Non-blocking is how Node.js and modern servers handle thousands of connections.

The concept

A blocking read on a socket parks the thread; to serve 10,000 clients you would need 10,000 threads. A non-blocking approach uses an event loop to check which sockets are ready.

Non-blocking code needs callbacks, promises or async/await to continue when data arrives.

One thread, two clients

blocking: read(A) ........ then read(B) ........
non-blocking: start A, start B, handle whichever replies first

Practical examples

Blocking in Node (avoid)

const data = require('fs').readFileSync('big.txt')  // blocks the event loop

Non-blocking

const data = await require('fs/promises').readFile('big.txt')

Blocking sleep vs async sleep

import time, asyncio
time.sleep(1)           # blocks
await asyncio.sleep(1)  # yields to others

Common mistakes

  • Using synchronous file or crypto calls in a server request handler.
  • Doing CPU-heavy loops in an event-loop language.
  • Mixing blocking calls inside async code.

Key takeaways

  • Blocking waits; non-blocking continues.
  • Event loops serve many clients on few threads.
  • Never block the event loop.

FAQ

Is non-blocking the same as async?

Related: non-blocking is the I/O style, async is the programming model on top of it.

When is blocking fine?

Scripts, CLIs and low-concurrency programs.

More General articles