Implement a Bounded Blocking Queue for a Log Shipping Agent
Last updated: November 29, 2026
Quick Overview
Implement a thread-safe bounded queue with blocking put and get (each with an optional timeout) for an on-host agent that ships service logs to ByteDance's log pipeline, so producers slow down instead of exhausting memory when the pipeline lags.
ByteDance
November 29, 20260
0
0 solved
Implement a thread-safe bounded queue with blocking put and get (each with an optional timeout) for an on-host agent that ships service logs to ByteDance's log pipeline, so producers slow down instead of exhausting memory when the pipeline lags.
ByteDance backend interviews often include a concurrency coding question, and backpressure in log agents is a realistic setting. The interviewer checks correct use of a lock with condition variables, waiting in a loop on a predicate, and clean timeout semantics.
What the Interviewer Expects
- Protect shared state with one lock and two conditions
- Wait on a predicate, not a bare wait, to handle spurious wakeups
- Notify the opposite condition after each put or get
- Return or raise clearly on timeout
- Explain why busy waiting or sleep loops are wrong
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- Add a close() method so blocked producers and consumers exit cleanly.
- Support batch get of up to n items to cut lock overhead.
- What would you change for a single-producer single-consumer ring buffer without locks?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Requirements: put(item, timeout) blocks while full and returns False on timeout; get(timeout) blocks while empty and raises TimeoutError on timeout. Multiple producers and consumers. No lost or duplic...
High-Level Design
A deque holds items. One mutex guards it, and two Condition objects share that mutex: not_full for producers and not_empty for consumers. Sharing the lock means checking the size and mutating the dequ...