Workspace

Concurrency & async

3 day streakD
Systems syllabus
PHASE 01 · MODULE 03

Concurrency and async runtimes.

Async does not make work faster. It lets one thread wait on thousands of things.

The real design questions are what limits concurrency and what happens when producers outrun consumers. Little's Law sizes the system: at 20 agent runs per second and 30 seconds per run, you hold 600 runs open. That one multiplication sizes connection pools, memory and rate limits.

6 lessons94 minutes of reading6 illustrations
Start lesson 1
Basics
  • Blocking and non-blocking I/O
  • Threads and mutexes
  • Races and deadlock
  • Promises and microtasks
  • Event-loop phases
Depth
  • select, poll, epoll and kqueue
  • Edge and level triggering
  • Readiness versus completion
  • libuv internals and worker threads
  • SharedArrayBuffer and Atomics
  • Go's M:N scheduler and Tokio work stealing
  • AbortController and backpressure
  • Structured concurrency and Amdahl's Law
Current
  • io_uring
  • Why io_uring is often switched off in production

Lessons

  1. 01Threads, races and deadlockTwo threads touching the same memory can interleave in ways that lose updates. Learn why count++ is three steps, how a mutex fixes it, and how two mutexes can freeze a program.Basics15 min
  2. 02The event loop, tasks and microtasksJavaScript runs one piece of code at a time and picks the next piece from queues. Learn the order: synchronous code, then every microtask, then the next task.Basics14 min
  3. 03Blocking the loop and the thread poolOne slow synchronous call freezes every user on the process. Learn to spot event-loop blockers and the hidden four-thread pool behind fs, DNS and zlib.Depth15 min
  4. 04Readiness, completion and io_uringHow one thread waits on 10,000 sockets. Learn thread-per-connection, epoll's readiness model and io_uring's completion model, and why io_uring is often disabled.Depth17 min
  5. 05Little's Law and backpressureOne multiplication tells you how much the system holds open. Learn to size pools and queues with it, and what happens when producers outrun consumers.Depth15 min
  6. 06Cancellation, bounded parallelism and structured concurrencyStart work so that it can always be stopped and never outlives its owner. Then see how Go and Tokio schedule millions of tasks, and what Amdahl's Law says about speedups.Current18 min

Module lab

  1. Build a TCP echo server three ways: one thread per connection, epoll, and io_uring.
  2. Hold 10,000 idle connections and compare memory.
  3. Write a bounded-concurrency queue for tool calls, with cancellation and a full-queue policy.

Interview questions

Why can one JSON.parse hurt every user?

Show the single-threaded event loop: nothing else runs until it returns.

What is the difference between readiness and completion I/O?

epoll says you can act now; io_uring says it is done.

What happens when you ignore res.write() returning false?

Buffers grow until memory runs out.

Read

  • The libuv design overview
  • Node.js guide: the event loop, timers and process.nextTick
  • Efficient IO with io_uring, Jens Axboe
  • Notes on structured concurrency, Nathaniel Smith

A good place to start

Explore a pattern

A little guidance

Start with a pattern, read through a problem, and mark it solved when the idea clicks. Save anything you want to revisit.

New tutorials are added one at a time. Your bookmarks and solved checkmarks stay in this browser.

Explore the roadmap