Concurrency
183 bites tagged Concurrency — interview questions with model answers, and 60-second explainers.
postMessage vs SharedArrayBuffer in worker_threads tradeoffs?
Structured cloning copies data, SharedArrayBuffer shares memory. IPC performance and memory model understanding. cloning has overhead but safety isolation, SharedArrayBuffer is zero-copy but requires atomic operations.
Dedicated vs Shared vs Service Workers compared
Dedicated worker serves one page for offloading CPU; Shared worker is one instance across same-origin contexts via ports; Service worker is a network proxy for caching and push, event-driven and killable. Browser worker types and roles.
Tearing and useSyncExternalStore in concurrent React
Tearing is inconsistent UI when an interruptible render reads a changed external store mid-pass; useSyncExternalStore subscribes and forces consistent snapshots, re-rendering synchronously on change. Concurrency consistency guarantees.
Threading of native module methods
Methods run on a dedicated native module queue, not the UI thread; long blocking work stalls other module calls; offload to a background executor or override methodQueue, returning results via promise. native module threading.
How do you move a 500ms blocking task off the JS thread?
Offload to a native module or C++ TurboModule, a worklet/worker thread, or chunk the work and yield; never block JS. concurrency strategy in RN. wrapping a synchronous loop in a Promise and assuming it stops blocking.
SQLAlchemy connection pooling across Uvicorn workers
Each worker has its own pool; total DB connections equal workers times (pool_size plus max_overflow); overflow connections are temporary; misconfiguration exhausts DB… Connection pool sizing under multi-process concurrency.
asyncio.gather vs asyncio.wait
Gather returns ordered results and propagates the first exception (or captures them); wait returns done/pending sets and never raises, you inspect each. Whether you know how each aggregates results and handles errors.
worker_threads versus cluster: when to use each
Worker_threads offloads CPU-bound compute within one process with shared-memory transfer; cluster forks processes to scale IO-bound request throughput across cores. Matching the concurrency tool to the workload.
Offloading CPU work with worker_threads
Heavy sync work blocks the single event loop and stalls all requests; move it to a Worker, message the input, await the result asynchronously, and ideally pool workers. Keeping the event loop free during CPU-bound work.
Purpose of the Node.js cluster module
Cluster forks worker processes sharing one listening port, so requests spread across CPU cores via the OS, raising throughput and adding resilience. Knowing Node is single-threaded per process and how to use all cores.
Atomic order creation with Sequelize transactions
Wrap dependent writes in sequelize.transaction, pass the transaction to each query, let managed transactions auto-commit or roll back. atomicity and transaction handling.
Promise.all vs Promise.allSettled
All rejects on the first failure; allSettled always fulfills with a status/value or reason per input. Use allSettled when partial success is acceptable. choosing fail-fast vs collect-all.
Bounded concurrency for many async requests
Chunk the array and await Promise.all per chunk, or run a fixed worker pool pulling from a shared index; cap in-flight requests. limiting concurrency, not just running parallel. firing all 1000 at once or going fully serial.
Running independent requests with Promise.all and race
Start all requests then await Promise.all to get all results or fail fast on first rejection; use Promise.race when only the fastest settled result matters. concurrent Promise combinators.
Offloading CPU-bound work with Worker Threads
Synchronous CPU work freezes the loop and all requests; offload to a Worker, communicate via messages or SharedArrayBuffer, use a pool. knowing the single thread blocks on CPU work. suggesting async I/O fixes CPU blocking.
Order of the Node.js event loop phases
Timers, pending callbacks, poll, check, close phases in order; I/O completion runs in poll. understanding of libuv's loop, not just async vibes. claiming Node is single-phase or fully multithreaded.
Why does 200ms latency drop requests? Diagnose it.
Little's Law shows added latency raises in-flight requests, exhausting the thread or connection pool; check pool saturation, timeouts, and retries. Reasoning about concurrency limits and queueing.
Little's Law for capacity planning
L equals lambda times W, concurrency equals arrival rate times time in system; rearrange to size threads or concurrency for a target throughput and latency. Queueing fundamentals.
Backpressure
Backpressure is a mechanism by which a slow consumer signals an upstream producer to slow down or stop, preventing unbounded queues and resource exhaustion. It keeps systems stable under overload by propagating capacity limits backward through a pipeline.
SQL isolation levels and the anomalies they prevent
Read Uncommitted allows dirty reads; Read Committed blocks them; Repeatable Read blocks non-repeatable reads; Serializable blocks phantoms. the isolation-anomaly mapping.
Iceberg vs Delta Lake metadata and ACID
Iceberg uses a tree of metadata and manifest files with atomic pointer swaps and optimistic concurrency; Delta uses an ordered transaction log of JSON commits with optimistic concurrency. deep table-format internals.
Unit of Work / Session pattern in ORMs
The Unit of Work tracks new, dirty, and deleted objects, then flushes them as one batched transaction at commit. ORM session mechanics.
Transaction isolation levels and their tradeoffs
Isolation levels control which concurrency anomalies (dirty/non-repeatable reads, phantoms) are allowed; higher levels mean stronger consistency but more blocking and less concurrency. isolation tradeoffs.
Connection pools and the problem they solve
A pool reuses pre-opened connections so requests skip the expensive connect handshake; without one, every request pays setup latency and may overwhelm the database. connection reuse basics.
Get Concurrency bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.