← Lessons

quiz vs the machine

Gold1450

Concurrency

The Event Loop Per Core

A shared nothing design that runs one event loop pinned to each core to avoid locking.

5 min read · core · beat Gold to climb

One loop on each core

The event loop per core design runs a separate single threaded event loop on every CPU core, with each loop pinned to its core. Instead of one shared pool of threads contending over shared state, each core owns its own slice of the work and its own data.

Shared nothing benefits

Because a core's data is touched only by that core's loop, the design is often called shared nothing:

  • No locks are needed for per core state since only one thread accesses it.
  • Cache stays warm because data lives near the core that uses it.
  • Predictable latency follows from avoiding lock contention and cross core stalls.

The cost of partitioning

The tradeoff is that work must be partitioned across cores, usually by sharding connections or keys. When one core's request needs data owned by another core, the loops must pass a message between them rather than share memory directly. Balancing the shards matters too, since one hot shard can overload a single core while others sit idle.

Key idea

Event loop per core pins one single threaded loop to each core and partitions data so per core state needs no locks, trading sharing for message passing across cores.

Check yourself

Answer to earn rating on the learn ladder.

1. Why does per core state need no locks in this design?

2. What is the main tradeoff of event loop per core?