← Lessons

quiz vs the machine

Gold1380

Concurrency

Async IO and Non Blocking

How non blocking calls let one thread serve many connections.

5 min read · core · beat Gold to climb

Async IO and Non Blocking

Blocking IO makes the calling thread wait until data arrives. To serve many clients this way you need one thread per connection, and idle threads waste memory and scheduler time. Asynchronous non blocking IO breaks that one to one tie.

A non blocking socket returns immediately. If no data is ready it signals would block rather than parking the thread. The program then asks the operating system to notify it later when the socket becomes ready, using a readiness API such as epoll.

The payoff is concurrency without a thread per connection:

  • One thread, many sockets A single event loop multiplexes thousands of connections.
  • No idle parking Threads run only when there is real work, so cores stay busy.
  • Backpressure friendly The program controls when it reads, so it can slow down under load.

Async IO is harder to write because logic that was once a straight line of blocking calls now spreads across callbacks or awaited futures. State that lived on the stack must be captured and carried until the operation completes.

Note that non blocking and asynchronous are distinct ideas. Non blocking means the call returns at once; asynchronous means completion is reported later. Modern runtimes combine both to reach high throughput on few threads.

Key idea

Non blocking calls return immediately and report readiness later, letting one event driven thread serve many connections without parking on each one.

Check yourself

Answer to earn rating on the learn ladder.

1. What does a non blocking read do when no data is ready?

2. What is the main benefit of async non blocking IO?

3. How do non blocking and asynchronous differ?