Streaming interview problems
Streaming questions give you more data than you should hold at once, or data that arrives over time, and ask you to process it incrementally. Expect to parse a chunked byte stream where records span chunk boundaries, merge several sorted async streams, compute running aggregates, or forward tokens from an async source with a timeout between items. The tools are async generators (async def with yield), async for, heapq.merge for sorted sync streams, and an asyncio.Queue when producers and consumers run at different speeds.
The classic bug is a record split across two chunks, handled by keeping a carry-over buffer and only emitting complete lines. Other mistakes are collecting the whole stream into a list "just to sort it", forgetting that an abandoned async generator needs aclose() to run its cleanup, and applying a timeout to the whole stream when the spec says per item. A strong answer keeps memory proportional to one chunk or one window, handles the final partial record at end of stream, and states what happens when the consumer is slower than the producer.
2 open problems
- 31Chunked File Copy with Bounded Memoryeasy
Copy a file of any size in fixed-size chunks so memory stays flat, and refuse inputs that would destroy data.
- 36Delimited Stream Parsermedium
Turn an iterator of arbitrary byte chunks into delimited messages, handling messages and multi-byte delimiters split across chunks.
13 locked
These open in order of demand. Open one and press I want this one to ask for it.
- 03Parse an SSE Token Stream Lockedmedium
Reassemble a streamed LLM response from Server-Sent Events chunks that can split anywhere, handling CRLF, junk payloads and [DONE].
- 04Reassemble Streamed Tokens Lockedeasy
Rebuild each request's output from interleaved, out-of-order and duplicated token events keyed by request id and sequence number.
- 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.
- 34Split and Merge Files Lockedmedium
Split a large file into fixed-size numbered parts and merge parts back together, streaming in chunks with bounded memory.
- 37Stream Rechunker Lockedeasy
Regroup a stream of arbitrarily sized byte chunks into fixed-size chunks, lazily and with memory bounded by the chunk size.
- 38Stream Until Stop Sequence Lockedmedium
Forward streamed LLM text until a stop sequence appears, holding back only a possible partial match even when it spans chunks.
- 39Streaming JSONL Parser Lockedmedium
Parse JSON Lines from arbitrary byte chunks into records, handling split lines and UTF-8, with a strict mode and a skip-invalid mode.
- 40Length-Prefixed Message Parser Lockedmedium
Decode a stream of 4-byte big-endian length-prefixed messages from arbitrary chunks, rejecting oversized and truncated frames.
- 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.
- 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.
- 50Streaming Response Aggregator Lockedmedium
Assemble interleaved token, done and error events into complete responses with a lazy generator that keeps only in-flight requests in memory.