0 day streak
Anonymous · shared experience20 Oct 2026 · 6 views

MongoDB: Read-write lock that does not starve writers

Interview question #MongoDB Phone screen

Problem. Write a read-write lock by hand. Many readers may hold it at once, but a writer needs exclusive access. Once the basic version works, change it so a steady stream of readers cannot block a waiting writer forever.

Hint from the post. Keep a flag or counter for pending writers. While a writer is waiting, new readers are not let in, so the active readers drain and the writer gets its turn.

Follow-on. In the same session the interviewers moved to database internals: the steps a query goes through, how the buffer cache works and how the query optimizer works.

What mattered. Correct use of a mutex with condition variables, clean wake-up logic, and being able to explain the fairness trade-off between readers and writers.

0 comments

Comments 0

No comments yet. Ask the author something, or add what happened in your own round.