Thread-Safe Bounded Queue for a Market Data Handler

Last updated: November 29, 2026

Quick Overview

Implement a bounded blocking queue between a market data feed thread and a consumer thread, supporting put and get with timeouts and a clean shutdown.

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

0

0

0 solved


Implement a bounded blocking queue between a market data feed thread and a consumer thread, supporting put and get with timeouts and a clean shutdown.

Voleon's trading and data systems move streams of market events between threads, and backpressure policy is a real design choice. The interviewer checks correct use of locks and condition variables, avoiding lost wakeups and busy waiting, timeout semantics, and a shutdown path that does not hang consumers.

What the Interviewer Expects
  • Protect shared state with one lock
  • Use condition variables with predicate loops to avoid spurious wakeups
  • Support timeouts and report them clearly
  • Implement close so blocked threads wake and exit
  • Discuss backpressure: block, drop or alert when full
Key Topics to Cover
concurrency
condition variables
producer consumer
backpressure
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
  • Would you rather drop the oldest tick or block the feed when the queue is full?
  • How would you make this lock-free for a single producer and single consumer?
  • How would you measure queue latency in production?
  • What changes if multiple consumers need every message?
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

Fixed capacity. put(item, timeout) blocks while full, returns False on timeout. get(timeout) blocks while empty, raises TimeoutError on timeout, returns None once the queue is closed and drained. ...

High-Level Design

One mutex and two condition variables sharing it: not_full for producers and not_empty for consumers. wait_for(predicate, timeout) re-checks the predicate after every wakeup, which handles spuri...


Submit Your Answer
Markdown supported

Related Questions