Bounded Blocking Queue for Photo Upload Worker Threads
Last updated: November 29, 2026
Quick Overview
Implement a fixed-capacity queue where producers block when it is full and consumers block when it is empty, with a put timeout and a clean shutdown that lets workers drain remaining items.
Meta
November 29, 20260
0
0 solved
Implement a fixed-capacity queue where producers block when it is full and consumers block when it is empty, with a put timeout and a clean shutdown that lets workers drain remaining items.
Upload paths for Instagram and Facebook photos hand work from request threads to resize and transcode workers, and a bounded buffer between them is how you get backpressure instead of unbounded memory growth. Meta phone screens sometimes use this to check condition-variable fluency and whether you think about shutdown and timeouts, not only the happy path.
What the Interviewer Expects
- Uses two conditions on one lock (not full, not empty) and loops on the predicate
- Signals the opposite condition after each put and take
- Implements a deadline-based timeout that survives spurious wakeups
- Provides close semantics: producers fail fast, consumers drain then exit
- Explains why bounding the queue gives backpressure to the request tier
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
- What should a request thread do when put times out: drop, retry, or return 503 to the client?
- How would you add priorities so profile photos jump ahead of bulk album uploads?
- How does this compare with Python's queue.Queue, and when would you pick a lock-free ring buffer?
- How would you size the capacity given worker throughput and latency targets?
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
put(item, timeout=None): blocks while full; returnsFalseon timeout; raisesClosedafter shutdown.take(): blocks while empty; returnsNoneonce the queue is closed and drained, which i...
High-Level Design
A deque and one mutex shared by two Condition objects, not_full and not_empty. Sharing the mutex keeps the size check and the append or pop atomic.
put waits on not_full while the deque i...