Writer-Preferring Read-Write Lock for a Hot Config Store

Last updated: November 29, 2026

Quick Overview

Implement a read-write lock where many readers can hold it together, a writer gets exclusive access, and a waiting writer blocks new readers so it cannot be starved. Explain why a plain reader-preferring lock fails under constant read traffic.

Meta
Software Engineering Fundamentals
Software Engineer
Meta
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 together, a writer gets exclusive access, and a waiting writer blocks new readers so it cannot be starved. Explain why a plain reader-preferring lock fails under constant read traffic.

Services at Meta read configuration (think Configerator-backed feature gates and sitevars) on nearly every request but update it rarely, which is the textbook case for a read-write lock and also the textbook case for writer starvation. Interviewers use this in onsite fundamentals rounds to see whether you can build a correct primitive on a condition variable and argue about fairness, not just mutual exclusion.

What the Interviewer Expects
  • Builds on one condition variable or mutex with clearly stated state (active readers, active writer, waiting writers)
  • Always waits in a while loop to handle spurious wakeups and stolen wakeups
  • Explains writer starvation with a reader-preferring design and shows how the waiting-writer count fixes it
  • Decrements the waiting count even if the wait is interrupted
  • Discusses the opposite risk, reader starvation under a stream of writers, and the tradeoff
  • Mentions alternatives such as RCU or copy-on-write snapshots for read-mostly data
Key Topics to Cover
read-write locks
condition variables
starvation and fairness
spurious wakeups
RCU and 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 without deadlock?
  • How would you make the lock fair in strict arrival order instead of writer-first?
  • For a config that changes once a minute, would you use a lock at all, or an atomic pointer swap to an immutable snapshot?
  • How would you test this for starvation and deadlock?
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: any number of readers at once, never while a writer holds the lock.
  • acquire_write / release_write: exclusive.
  • Writer preference: once a writer is waiting, ne...
High-Level Design

State guarded by one Condition: readers (active count), writer (bool) and waiting_writers (count).

  • A reader may enter only if no writer is active and no writer is waiting. The second ch...

Submit Your Answer
Markdown supported