← Lessons

quiz vs the machine

Silver1100

Concurrency

Event Driven Concurrency

A single loop multiplexes many connections without one thread each.

4 min read · intro · beat Silver to climb

Event Driven Concurrency

Event driven concurrency flips the thread per request model. Instead of blocking a thread while waiting, the program registers interest in events and lets a single event loop dispatch work as those events become ready. Node and Nginx are famous examples.

At the core sits a readiness mechanism such as epoll or kqueue. The loop asks the kernel which sockets are ready to read or write, then runs short callbacks or resumes coroutines for exactly those sockets. Because no thread parks on a slow socket, one thread can juggle tens of thousands of connections.

The discipline is strict:

  • Never block Any long synchronous call freezes the whole loop and stalls every connection.
  • Offload CPU work Heavy computation must move to a worker pool so the loop stays responsive.
  • Compose carefully Logic splits across callbacks, which async await and promises tame into readable chains.

The payoff is dramatic for IO bound workloads where most time is spent waiting on the network. The risk is that a single careless blocking line, like a synchronous file read or a tight loop, degrades latency for thousands of users at once.

Key idea

One event loop multiplexes thousands of connections by reacting to readiness events, but a single blocking call can stall everything.

Check yourself

Answer to earn rating on the learn ladder.

1. What lets an event loop handle many connections with one thread?

2. Why is a long synchronous call dangerous in an event loop?