THN Interview Prep

Concurrency & async models

Core details

Compare models you can name in-room:

ModelStrengthPitfall
Thread-per-requestisolationpool exhaustion under load
Event loop / async I/Ohigh concurrency cheap waitsaccidental CPU block (sync FS, heavy regex)
Actor / mailboxordered per entitymailbox backlog unbounded if no backpressure
Worker pools + queuessmoothing burstsqueue growth if consumers slower than producers

Backpressure manifests as bounded queue depth shedding load, 429/503 with Retry-After, or slowing producers—pick intentionally with SLO alignment.

Problem this solves: backend services receive more concurrent work than a single CPU, thread pool, event loop, database pool, or queue can process at once.

Simple mental model: concurrency is not capacity. Capacity is the smallest saturated resource on the request path.

Understanding

Async shines when work is waiting-dominated (I/O). It fails when CPU-bound tasks monopolize cooperative schedulers—moving CPU work to pools/child processes preserves latency for I/O handlers. Unbounded queues pretend infinite capacity—real systems need visible saturation metrics.

Use this quick diagnosis:

SymptomFirst suspectMeasurement
Fast DB query, slow APIpool wait or event loop lagpool wait histogram, loop delay
CPU high, I/O lowsynchronous computationCPU profile, flame graph
Queue grows during spikesconsumers slower than producersqueue depth, age of oldest message
One tenant hurts othersmissing bulkhead/fairnessper-tenant rate, queue, and latency

Senior understanding

Demonstrate reading pool wait time and event-loop lag before blaming “the database is slow.” Mention bulkhead patterns isolating noisy neighbors (reporting vs payments). For Node specifically, cross-link /backend/nodejs/fundamentals/event-loop, but keep this page model-agnostic patterns crisp.

Decision rules

Work typeGood defaultAvoid
Waiting on network/databaseasync I/O with bounded poolsone thread per slow client without limits
CPU-heavy image/PDF/crypto workworker pool, process pool, or specialized serviceblocking request handler
Per-account ordered workactor/mailbox or keyed partitionglobal queue with accidental reordering
Burst absorptionbounded queue + backpressureunbounded queue that hides overload

Interview answer structure

“I identify whether the work is waiting-bound or CPU-bound, then choose the scheduling model. Async I/O helps with many waits, but it does not create more CPU. I bound pools and queues, expose saturation metrics, and add backpressure before the dependency becomes the failure amplifier.”

Follow-ups to expect:

  • How do you detect event-loop starvation?
  • What happens if every request starts ten parallel downstream calls?
  • How do you isolate reporting jobs from payment traffic?
  • When would you choose workers over a separate service?

Diagram

Loading diagram…

See also

Mark this page when you finish learning it.

Spotted something unclear or wrong on this page?

On this page