ELI5 · How computers work

The event loop.

One waiter working a full restaurant by never standing still waiting, just taking the next ready task each time around.

Imagine one waiter running a busy restaurant alone. If they stood at one table waiting for the kitchen to finish that order, everyone else would starve. Instead they take an order, hand it to the kitchen, and immediately move on to the next ready table, circling back when food is up.

The event loop is that single waiter. One thread keeps looping: it grabs the next task that is ready to run, does it quickly, and moves on. Slow things like network calls are handed off, and their results are picked up on a later lap — so one thread serves many things without ever sitting idle.

  1. Just me today!
    a full room, one waiter
    1

    One waiter runs the whole restaurant — many tables, one person to serve them.

  2. You first.
    task task task next ready one
    2

    So the rule is simple: take the next order that is ready, right now.

  3. Kitchen’s got it.
    KITCHEN hand off, don't wait
    3

    Slow work like cooking is handed to the kitchen — the waiter does not stand and wait.

  4. never idle
    4

    While it cooks, the waiter keeps serving everyone else, never standing idle.

  5. Order up — I’ll grab it.
    ding! food's up picked up next lap
    5

    When the food is up, the waiter picks it up on a later trip around the room.

  6. Nobody move…
    heavy ! everything waits
    6

    The catch: one task that hogs the waiter freezes everyone — keep each task short.

One waiter, a full room: take the next ready task, hand off slow work, never sit idle.

Why one thread can feel concurrent

The trick is that most "slow" work — waiting on a network reply, a file, a timer — is really just waiting, not computing. The event loop hands that waiting to the operating system and keeps serving other tasks. When the reply lands, its callback joins the queue and runs on a later lap. So one thread handles thousands of in-flight requests by never blocking on any one of them.

The catch: do not block the loop

Because there is only one waiter, any task that does heavy work without yielding freezes everything — no other task runs until it finishes. A tight number-crunching loop will make a whole server unresponsive. The fix is to keep tasks short and push genuinely heavy CPU work to worker threads or separate processes, leaving the loop free to keep circling.

The real version Event loop simulator →
Found this useful?