Implement a Thread-Safe Bounded Buffer for an MQ Consumer

Last updated: November 29, 2026

Quick Overview

Implement a fixed-capacity blocking queue used between a thread that reads messages from IBM MQ and a pool of worker threads, supporting put and get with optional timeouts and a clean shutdown.

IBM
Software Engineering Fundamentals
Software Engineer
IBM
November 29, 2026
Software Engineer
Technical Screen
Software Engineering Fundamentals
Medium

0

0

0 solved


Implement a fixed-capacity blocking queue used between a thread that reads messages from IBM MQ and a pool of worker threads, supporting put and get with optional timeouts and a clean shutdown.

IBM MQ client applications often decouple a receiving thread from worker threads with an in-memory buffer that applies backpressure. IBM integration teams ask this to check understanding of mutexes, condition variables, spurious wakeups and shutdown semantics, rather than just calling queue.Queue.

What the Interviewer Expects
  • Use one lock with two condition variables (not full, not empty)
  • Wait in a while loop to handle spurious wakeups
  • Support timeouts on put and get
  • Implement close so blocked threads wake and exit
  • Explain why backpressure protects the queue manager and the process
Key Topics to Cover
concurrency
condition variables
producer consumer
backpressure
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
  • How would you guarantee a message is not lost if a worker crashes after get?
  • How would batching gets improve throughput?
  • What changes if there are many producers as well as many consumers?
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 and returns False on timeout. get(timeout=None) blocks while empty and returns (True, item) or (False, None) on timeout or after close once drained. `...

High-Level Design

Protect a deque with one threading.Lock. Two Condition objects share that lock: not_full for producers and not_empty for consumers. Every wait happens inside a while loop that re-checks the ...


Submit Your Answer
Markdown supported

Related Questions