You are implementing a component inside a storage engine that is accessed concurrently (e.g., an in-memory index, metadata cache, or block map).
Discuss the trade-offs and propose an approach for concurrency control:
-
When would you use a
coarse-grained lock
(single global mutex)?
-
When do you need
fine-grained locking
(per-bucket/per-shard/per-node locks)?
-
How do lock choices affect
latency (especially p99)
and
throughput
under contention?
-
What pitfalls must be handled (deadlocks, priority inversion, convoying, starvation)?
-
When are
lock-free / wait-free
approaches feasible, and what are the engineering costs?
Assume you may have many threads, read-heavy workloads, and occasional writes (updates).