Data Modeling medium
What is 'Optimistic Locking' in a data model?
- A Explicitly locking every row in the target table before a read operation begins to ensure that no concurrent writes can occur during the query lifecycle.
- B Utilizing a `version` column to verify that a record has not been modified by another process in between the initial read and the final commit phase.
- C Assuming that the underlying storage hardware will automatically resolve all concurrent write conflicts at the physical disk-controller level.
- D Implementing a centralized, global mutex lock within a secondary Redis cluster to strictly serialize all incoming data update requests.
Answer: B. Utilizing a `version` column to verify that a record has not been modified by another process in between the initial read and the final commit phase.
Optimistic Locking assumes conflicts are rare. It is 'stateless' and doesn't hold database-level locks, making it ideal for high-concurrency web applications. If a conflict *does* occur (e.g., two users edit the same profile simultaneously), the second update will fail because the version ID has changed, allowing the application to handle the error gracefully with a retry or a warning.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- When modeling a Distributed Transaction using the Saga Pattern (Choreography or Orchestration), what type of consistency do you achieve?
- Which practice prevents SQL Injection attacks?
- What is 'Bi-Temporal' data modeling (e.g., in SQL:2011 standard)?
- Adding an Index to a database column generally improves Read performance. What is the negative trade-off?
- Log Systems Merge (LSM) Trees (used in RocksDB, Cassandra) optimize for fast writes. What is their primary downside regarding Disk I/O?
- What is the primary objective of normalizing a relational database schema (e.g., to 3NF)?