Backend Architecture
Async vs blocking: multiple-choice review
Six questions that cut across the whole unit. Each one mirrors a call you make in a real incident — not a definition to recite, but a tradeoff to weigh while the loop is on fire and the tail is climbing.
Confirm you can connect the I/O model, the event-loop schedule, what freezes it, where CPU work belongs, how to bound fan-out, and why the tail explodes near saturation — the synthesis the six lessons built toward.
Service A is a thread-per-connection app holding 50,000 mostly-idle keep-alive sockets; Service B is an event-loop app doing the same. Both are nearly idle on CPU. Why does A fall over while B stays comfortable?
Inside an I/O callback you schedule setTimeout(a, 0), setImmediate(b), and Promise.resolve().then(c). What runs first, and what principle decides it?
A two-line /health endpoint starts timing out, but only when a reporting route is hit. The reporting route runs JSON.parse on a 40 MB body. Why does health suffer, and what is the right diagnosis signal?
A CPU-heavy image resize (pure JS) freezes the loop. One engineer bumps UV_THREADPOOL_SIZE 4 to 32; another moves the resize into a worker thread. Who fixed it and why?
A migration runs await Promise.all(millionIds.map(processUser)) and is OOM-killed before the first thousand finish, while the database refuses new connections. Root cause and fix?
A Node service sits at 75% CPU with a 20 ms average; a small traffic spike pushes CPU to 82% and p99 jumps from 80 ms to 1,400 ms while the average barely moves. How do you read this?
The unit’s through-line is one chain of decisions: the I/O model sets how you spend the wait (park a thread vs multiplex on a loop), the loop’s phases and microtask drain set callback ordering, any synchronous span on the loop freezes every connection at once, CPU-bound JS belongs on a worker thread (not a bigger libuv pool) while long-but-splittable work can chunk, fan-out must be bounded to what the downstream absorbs, and near saturation queueing makes the tail explode — so you watch p99 and event-loop utilization, not the average, and run with headroom.