Writer-Preferring Read-Write Lock for a Shared Parameter Store

Last updated: November 29, 2026

Quick Overview

Implement a read-write lock where many readers can hold it at once, writers get exclusive access, and waiting writers are not starved by a continuous stream of readers.

Voleon
Software Engineering Fundamentals
Software Engineer
Voleon
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Hard

0

0

0 solved


Implement a read-write lock where many readers can hold it at once, writers get exclusive access, and waiting writers are not starved by a continuous stream of readers.

Model parameters and risk limits in a trading system like Voleon's are read constantly and updated occasionally, which makes read-write locking and starvation a realistic concurrency topic. The interviewer checks correctness of the invariants, starvation reasoning, and awareness of alternatives such as copy-on-write.

What the Interviewer Expects
  • State the invariants: many readers or one writer, never both
  • Implement with a condition variable and counters
  • Prevent writer starvation by blocking new readers when writers wait
  • Explain the reader starvation trade-off
  • Suggest alternatives such as copy-on-write snapshots
Key Topics to Cover
read-write lock
starvation
condition variables
concurrency invariants
copy on write
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 support upgrading a read lock to a write lock, and why is it dangerous?
  • How would you make the lock reentrant?
  • Would you use a lock at all for parameters updated once a minute?
  • How would you test this for 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

acquire_read, release_read, acquire_write, release_write. Invariant: either any number of readers or exactly one writer. A writer that is waiting must eventually get the lock even if readers k...

High-Level Design

One condition variable guards three fields: active reader count, whether a writer is active, and the number of waiting writers. Readers wait while a writer is active or any writer is waiting; that las...


Submit Your Answer
Markdown supported

Related Questions