Build a Lock-Free SPSC Ring Buffer for Market Data

Last updated: November 29, 2026

Quick Overview

Implement a bounded single-producer single-consumer queue that hands decoded market data messages from a feed-handler thread to a strategy thread without locks. Explain the memory-ordering rules that make it correct on real hardware.

Hudson River Trading
Software Engineering Fundamentals
Software Engineer
Hudson River Trading
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Medium

0

0

0 solved


Implement a bounded single-producer single-consumer queue that hands decoded market data messages from a feed-handler thread to a strategy thread without locks. Explain the memory-ordering rules that make it correct on real hardware.

In Hudson River Trading's low-latency stack, a feed handler pinned to one core decodes exchange packets and passes them to strategy code on another core, and a mutex on that path costs microseconds the firm cannot afford. Interviewers use this onsite question to see whether a candidate understands ownership of indices, false sharing, and acquire/release ordering rather than just writing a queue.

What the Interviewer Expects
  • Give each index a single writer: producer owns tail, consumer owns head
  • Use monotonically increasing counters with a power-of-two mask so full and empty are distinguishable without a wasted slot
  • Write the payload before publishing the index, with release on the store and acquire on the other side's load
  • Mention false sharing and padding head and tail onto separate cache lines
  • Discuss what to do when the buffer is full (drop, spin, or fail loudly) for market data
Key Topics to Cover
lock-free queues
memory ordering
acquire/release
false sharing
low-latency concurrency
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
  • What breaks if you use relaxed ordering for the tail store?
  • How would you cut cache-coherence traffic by caching the other side's index locally?
  • How does the design change for multiple producers?
  • For a market data feed, is it better to block the producer or drop when full, and why?
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

One producer thread, one consumer thread, fixed capacity, non-blocking try_push and try_pop, FIFO order, no message lost or duplicated, and no locks on the hot path. The interviewer usually accept...

High-Level Design

A fixed array plus two counters. tail is written only by the producer, head only by the consumer, so there is never a write-write race. Counters only increase; the slot is `counter & (capacity - 1...


Submit Your Answer
Markdown supported