A new high-transaction Deloitte application requires robust data consistency and performance under concurrent access. As a Database Administrator, how would you design the database concurrency strategy, considering isolation levels, locking mechanisms, and their impact on throughput?

DeloitteDatabase Administrator5–8 YearsConcurrency

6 min readUpdated

Designing a concurrency strategy for a high-transaction application starts with a deep understanding of its specific consistency and performance requirements. The core objective is to balance data consistency with system throughput, preventing common concurrency issues like dirty reads, non-repeatable reads, phantom reads, and lost updates, while maintaining application responsiveness. This involves selecting appropriate transaction isolation levels, implementing effective locking mechanisms, and optimizing transaction design.

Choosing Isolation Levels

SQL standards define four main isolation levels: Read Uncommitted, Read Committed, Repeatable Read, and Serializable. Read Committed is a common default, preventing dirty reads (reading uncommitted changes). Repeatable Read adds protection against non-repeatable reads (reading the same row multiple times within a transaction and getting different values due to another committed transaction). Serializable offers the highest consistency, preventing phantom reads (new rows appearing in a range query), but it incurs the highest locking overhead. The optimal choice is the lowest isolation level that precisely satisfies the application’s consistency requirements to maximize concurrency without sacrificing data integrity.

Best practice

Always design transactions to be as short-lived and fine-grained as possible to minimize the duration of locks and reduce contention. When acquiring multiple locks within a transaction, always do so in a consistent, predetermined order across all transactions to significantly reduce the likelihood of deadlocks. Implement robust indexing strategies on frequently accessed or updated columns to allow the database to locate rows quickly, thereby reducing the scope of locks to only the necessary data. Proactively monitor database performance metrics related to locks, waits, and deadlocks using tools specific to the database system. This allows for early identification and resolution of concurrency bottlenecks before they impact users.

Edge case interviewers probe for

A common edge case is phantom reads, where new rows are inserted into a range being queried by an active transaction, even under Repeatable Read isolation. Interviewers often probe how Serializable isolation or explicit range locks prevent this. Another advanced scenario involves distributed transactions across multiple databases. This requires coordinating consistency across independent systems, typically employing a two-phase commit protocol or designing the application around eventual consistency patterns for certain operations.

Common mistake

A frequent mistake is defaulting to the highest isolation level, Serializable, without fully understanding its severe performance implications. While it guarantees the strongest consistency, it often leads to excessive locking, reduced concurrency, and significant bottlenecks in high-transaction environments. Another common error is poorly designed transactions that hold locks for too long, for example, involving user interaction, which starves other transactions and degrades overall system performance.

What the interviewer is checking

The interviewer is checking your fundamental understanding of ACID properties, transaction management, and the practical trade-offs between consistency, availability, and performance in a relational database. They want to see your ability to apply theoretical knowledge to real-world system design challenges, diagnose concurrency-related issues, and propose effective, balanced solutions that consider both technical correctness and business impact.

Imagine a busy airport baggage claim where hundreds of passengers are trying to grab their luggage from several carousels. If everyone just rushed in and grabbed bags without any rules, there would be chaos: bags would get mixed up, some might be taken by the wrong person, or two people might try to grab the same bag at the same time. Concurrency control in a database is like the system that manages this baggage claim, making sure that even with many people acting simultaneously, everyone gets their correct bag and no bags are lost or wrongly assigned.

Now, think of “isolation levels” as the different sets of rules for how strictly passengers must behave at the carousel. “Read Uncommitted” is like having almost no rules, where you can grab any bag even if it’s not fully processed, leading to a lot of confusion. “Serializable” is the strictest rule: only one passenger can touch a specific bag or even a section of the carousel at any given time, ensuring perfect order but slowing down the whole process considerably. We need to find the most efficient rule that still prevents major mix-ups and ensures everyone eventually gets their luggage without unnecessary delays.

Why interviewers ask this

Interviewers ask this to gauge your fundamental understanding of how databases operate under load and how to ensure data integrity in high-traffic environments. This is a critical skill for any Database Administrator working with transactional systems.

What a strong answer signals

A strong answer demonstrates not just theoretical knowledge of isolation levels, locking mechanisms, and ACID properties, but also practical experience in diagnosing and mitigating concurrency issues. It shows an awareness of performance trade-offs and best practices for robust database design.

Common follow-ups

  • How do you detect and resolve deadlocks in a production environment?
  • Explain two-phase locking (2PL) and its role in ensuring serializability.
  • When might optimistic concurrency control be preferred over pessimistic locking, and what are its challenges?

Advanced variation

Design a concurrency strategy for a multi-region distributed database system that requires global strong consistency for critical financial transactions, discussing the underlying mechanisms and potential compromises.

A Deloitte e-commerce client experienced inconsistent inventory counts during high-volume flash sales. With the default database isolation level of “Read Committed,” two customers could simultaneously view the last item in stock, both initiating a purchase. Each transaction would read “1 in stock,” decrement the quantity to zero, resulting in an oversell where the system processed two orders for a single item. To fix this, the concurrency strategy was updated to use “Repeatable Read” isolation with explicit row-level SELECT FOR UPDATE locks on the inventory record. This ensured that the second transaction would block and wait until the first transaction committed its changes, thereby preventing oversells and maintaining accurate inventory counts.

transaction_with_locking.sql
-- Scenario: Safely transferring funds between two accounts concurrently

-- Transaction 1
START TRANSACTION;
-- Set isolation level to prevent non-repeatable reads
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;

-- Lock the source and destination rows for update (pessimistic locking)
SELECT balance FROM accounts WHERE id = 1 FOR UPDATE;
SELECT balance FROM accounts WHERE id = 2 FOR UPDATE;

-- Perform balance updates
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;

COMMIT;

-- Transaction 2 (if it tries to access rows 1 or 2 concurrently, it will wait for Transaction 1 to commit or rollback)
Transaction A Transaction B Shared Record (DB) Requests Lock Requests Lock Acquires Lock Waits for Lock
  1. 1Balance consistency requirements with performance needs when designing database concurrency strategies.
  2. 2Choose the lowest transaction isolation level that precisely meets your application’s data integrity requirements.
  3. 3Design transactions to be short, fine-grained, and acquire locks in a consistent order to minimize contention and deadlocks.
  4. 4Monitor locking, waiting, and deadlock metrics regularly to diagnose and resolve concurrency bottlenecks proactively.
  5. 5Understand phantom reads and how higher isolation levels or explicit range locks are necessary to prevent them.