Thread-Safe Bounded Queue for Yahoo Mail Attachment Scanning Workers

Last updated: November 29, 2026

Quick Overview

Implement a bounded blocking queue used between Yahoo Mail delivery threads that enqueue attachments and a pool of virus scanning workers. Support put and get with timeouts, and a clean shutdown that lets workers drain remaining items and exit.

Yahoo
Software Engineering Fundamentals
Software Engineer
Yahoo
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Medium

0

0

0 solved


Implement a bounded blocking queue used between Yahoo Mail delivery threads that enqueue attachments and a pool of virus scanning workers. Support put and get with timeouts, and a clean shutdown that lets workers drain remaining items and exit.

Mail delivery pipelines at Yahoo scan attachments before they reach inboxes, and a slow scanner must apply backpressure instead of exhausting memory. The interviewer is checking condition variables, spurious wakeups, timeouts, and shutdown semantics.

What the Interviewer Expects
  • Use one lock with two conditions: not_full and not_empty
  • Wait in a loop or with wait_for to handle spurious wakeups
  • Return a clear result on timeout so callers can apply backpressure
  • Implement close so blocked producers fail and consumers drain then exit
  • Avoid holding the lock while doing slow work
  • Write a test with several threads to show no items are lost
Key Topics to Cover
concurrency
condition variables
producer consumer
backpressure
graceful shutdown
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • Why use notify instead of notify_all in put and get, and when is notify_all needed?
  • How would you add priorities so attachments from paid users scan first?
  • How would you implement this across processes or machines?
  • How do you test for deadlocks and races?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

put(item, timeout=None) blocks while full; returns True on success, False on timeout, raises Closed after shutdown. get(timeout=None) blocks while empty; returns an item, None on timeout, ...

High-Level Design

One Lock protects a deque. Two Condition objects share that lock: producers wait on not_full, consumers on not_empty. After a put we notify one consumer; after a get we notify one produc...


Submit Your Answer
Markdown supported

Related Questions