Explain Write Skew vs Phantom Reads.
Write skew and phantom reads are two database concurrency anomalies: write skew happens when two concurrent transactions update based on outdated reads, while phantom reads occur when re-running a query returns new rows inserted by another transaction.
When to Use
Both arise in high-concurrency systems like banking, scheduling, or inventory management, where multiple users or services modify data simultaneously.
Example
- Write skew: Two doctors each see the other as on-call and both sign off, leaving no one on duty.
- Phantom read: A transaction queries “all users older than 18,” another inserts a new user, and the first query run again shows an extra row.
To strengthen your prep, explore Grokking System Design Fundamentals, Grokking the Coding Interview, or practice with Mock Interviews with ex-FAANG engineers.
Why Is It Important
These anomalies can break business logic and consistency guarantees. That’s why databases provide stricter isolation levels (like Serializable) to avoid them.
Interview Tips
Clearly define each anomaly, give a simple example, and explain how higher isolation levels prevent them. Keep answers short but precise.
Trade-offs
Preventing them (e.g., Serializable isolation, locks) ensures correctness but reduces performance. Relaxed isolation boosts speed but risks anomalies.
Pitfalls
Common mistakes include assuming repeatable read avoids phantom reads or overlooking write skew because no direct row conflict exists. Both can still violate constraints.
GET YOUR FREE
Coding Questions Catalog
$197

$78
$78