Concurrency interview problems
Concurrency questions test whether your code stays correct when several things happen at once. In Python interviews that usually means asyncio, though threads and concurrent.futures come up in discussion. Typical tasks are limiting in-flight work with asyncio.Semaphore, protecting a check-then-act sequence with asyncio.Lock, signalling with asyncio.Event, and coalescing duplicate requests so ten callers asking for the same key share one fetch through a shared Future. You should also know the GIL in one sentence. It serialises Python bytecode, so threads help I/O but not CPU-bound pure Python.
The classic bug is a race across an await, such as reading a counter, awaiting something, then writing the counter back. Others include holding a lock while awaiting slow I/O, acquiring two locks in different orders, and unbounded fan-out with gather over ten thousand coroutines. A strong answer names the shared state up front and says which actors touch it. It keeps critical sections short and free of unrelated awaits, and writes a test that would fail if the lock were removed, for example by inserting await asyncio.sleep(0) between the read and the write.
1 open problem
- 16Async Circuit Breakerhard
Implement an asyncio circuit breaker with closed, open and half-open states, a single recovery probe, and protection against stale in-flight calls.
9 locked
These open in order of demand. Open one and press I want this one to ask for it.
- 09Concurrent Inference Batch Lockedmedium
Run a batch of async inference calls with a concurrency cap, isolate per-request failures and return results in input order.
- 13Cancellable Inference Manager Lockedmedium
Build a manager that runs inference requests in the background with a concurrency cap, supports cancelling them, and reports each final result.
- 15Concurrent Web Crawler Lockedmedium
Crawl one hostname breadth-first with asyncio, a depth limit and a concurrency cap, fetching each URL once and returning URLs in BFS order.
- 19Bounded Worker Pool with Graceful Shutdown Lockedhard
Build an asyncio worker pool with a bounded job queue, backpressure on submit, and a graceful shutdown that drains accepted jobs and rejects new ones.
- 23Async Worker Pool with Timeouts Lockedmedium
Cap how many async jobs run at once and time out each job from when it starts, not from when it was queued.
- 28Per-Key Concurrency Limiter Lockedmedium
Limit how many async jobs run at once for each key, keep keys independent, and forget idle keys so memory stays bounded.
- 30Least-Loaded Replica Scheduler Lockedhard
Send each async request to the healthy replica with the fewest in-flight requests, wait when all are full, and react to health changes.
- 43Merge Async Streams Lockedhard
Merge several async generators into one stream that yields items as soon as any source produces them, with bounded buffering and clean shutdown.
- 49Reference-Counted Model Manager Lockedhard
Load each model once for many concurrent users, unload it when the last user releases it, and handle load failures and acquires during unload.