asyncio interview problems
asyncio questions are the backbone of systems-flavoured Python interviews. You will be asked to fetch many things concurrently with a cap, build a producer and consumer pipeline, add timeouts and retries, or make a cache safe when many coroutines hit it at once. The core API is small. It covers asyncio.run, create_task, gather, TaskGroup, Semaphore, Lock, Event, Queue, wait_for, timeout and as_completed. Knowing their exception and cancellation semantics matters more than knowing every function in the module.
Interviewers see the same mistakes repeatedly. Candidates call time.sleep or other blocking code inside a coroutine, create tasks without keeping a reference (the loop holds only a weak one, so the task can be garbage collected), forget to await a coroutine, or assume that code between two awaits can be interrupted. A strong answer knows that single-threaded does not mean race-free, because state can change across any await. It also picks TaskGroup over bare gather when failure should cancel siblings, bounds concurrency explicitly, and tests with a fake clock or small sleeps rather than real network calls.
6 open problems
- 12Inference Worker Poolmedium
Run inference requests through a fixed pool of asyncio workers sharing one queue, isolate failures, and return results in input order.
- 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.
- 20Dynamic Request Batcherhard
Group concurrent inference requests into batches that flush when full or when the oldest request has waited long enough, with cancellation and drain.
- 21Async TTL Cache with Request Coalescingmedium
Build an asyncio cache whose entries expire after a TTL, where concurrent misses for the same key share one fetch that survives caller cancellation.
- 22Async Retry with Exponential Backoffmedium
Retry a failing coroutine with capped exponential backoff, re-raise the last error, and never swallow cancellation.
- 25Async Request Deduplicatorhard
Collapse concurrent fetches for the same key into one shared call, with per-caller timeouts that never cancel the shared work.
22 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.
- 10Async Inference with Retries and Timeouts Lockedhard
Run async inference calls under a concurrency cap with a per-attempt timeout, bounded retries, attempt counts and correct cancellation.
- 11Dynamic Request Batching Lockedhard
Group arriving inference requests into batches that close when full or when a wait deadline passes, using an asyncio producer and consumer.
- 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.
- 14Fair Async Token Bucket Lockedhard
Implement an asyncio token bucket rate limiter that serves waiters in strict FIFO order and handles cancelled waiters without leaking tokens.
- 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.
- 17GPU Memory Scheduler Lockedhard
Admit async jobs onto a GPU with fixed memory in strict FIFO order, so large jobs never starve, and survive cancelled waiters without leaking memory.
- 18Streaming Inference Limiter Lockedmedium
Wrap token-streaming backends in an async generator that caps concurrent streams, starts lazily, and frees its slot on every exit path.
- 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.
- 24Async Sliding Window Rate Limiter Lockedmedium
Admit at most N requests in any rolling window of T seconds, making callers await until a slot opens.
- 26Async Priority Job Scheduler Lockedhard
Run submitted async jobs on N workers in priority order, FIFO within a priority, with cancellation and a draining shutdown.
- 27Async Inference Batcher Lockedhard
Group single inference requests into batches by size or wait time, with per-request timeouts, cancellation and a draining shutdown.
- 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.
- 29Round-Robin Load Balancer Lockedeasy
Route async requests to model replicas in round-robin order, skipping replicas marked unhealthy and failing fast when none are left.
- 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.
- 41Atomic Async Download Lockedhard
Save an async byte stream to disk atomically, enforcing an expected size and cleaning up on errors, callback failures and cancellation.
- 42Chunked Upload with Retries Lockedmedium
Upload a large file in fixed-size chunks through an async send function, retrying each chunk independently and never loading the whole file.
- 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.
- 44Resumable Download Lockedmedium
Resume an interrupted file download from the bytes already on disk, append streamed chunks, report progress, and reject wrong-sized data.
- 45Stream Idle and Total Timeout Lockedmedium
Wrap an async token stream so it fails when the gap between items is too long or the whole stream runs past a deadline, closing the source.
- 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.