Queues interview problems
Queue problems cover both the data structure and the coordination pattern. On the data structure side you use collections.deque for O(1) appends and pops at both ends, deque(maxlen=n) for a bounded buffer that drops the oldest item, and you avoid list.pop(0), which is O(n). On the coordination side asyncio.Queue(maxsize=n) connects producers to consumers. await put() blocks when the queue is full, which is backpressure for free, and task_done() with join() lets you wait until every item has been processed.
Interviewers watch for unbounded queues that let a fast producer eat memory, forgetting task_done() so join() never returns, calling get_nowait() in a loop and spinning the CPU, and shutting down consumers without draining what is already queued. A strong answer picks a bounded size and says why, decides between dropping, blocking and rejecting when full, and has a clean shutdown story. That can be a sentinel per consumer, or join() followed by cancelling the workers. Python 3.13 added Queue.shutdown(), which is worth mentioning if you know the interviewer's version.
2 open problems
- 06Sliding Window Rate Limitermedium
Build a per-user sliding window log rate limiter that allows at most N requests in any window of W seconds.
- 12Inference Worker Poolmedium
Run inference requests through a fixed pool of asyncio workers sharing one queue, isolate failures, and return results in input order.
6 locked
These open in order of demand. Open one and press I want this one to ask for it.
- 07Inference Request Queue Lockedmedium
Design a FIFO request queue with a status lifecycle: submit, start, complete and cancel, with O(1) operations and lazy removal.
- 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.
- 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.
- 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.
- 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.
- 27Async Inference Batcher Lockedhard
Group single inference requests into batches by size or wait time, with per-request timeouts, cancellation and a draining shutdown.