Book 1 · Lesson 1.11
Rust async and Tokio
- Contrast JS microtasks with Rust async tasks
- Trace a webhook handler through yield points
- Identify .await as cooperative scheduling
Prerequisites: 1.10
Lesson 1.3 previewed this — now we go deep.
One thread, many tasks
Tokio multiplexes thousands of async tasks on a small thread pool. When code hits .await, the task yields so other webhooks can run.
TokioFutureMachine walks: idle → poll → await Kafka → resume → HTTP response.
Not the browser event loop
| Browser JS | Rust Tokio | |
|---|---|---|
| Scheduler | Single thread + microtasks | Thread pool + cooperative tasks |
| Blocking | Blocks the tab | spawn_blocking for CPU/sync I/O |
| Example | TanStack refetch | ingestion Kafka publish |
Read the real handler
Open services/ingestion/src/main.rs — find github_webhook and mark every .await.
Teach-back prompt
What happens to other requests while one handler awaits Kafka?
Trace one handler
Lab complete — nice work.