- Регистрация
- 9 Май 2015
- Сообщения
- 1,480
- Баллы
- 155

In modern distributed systems, multiple users or applications often access and modify the same data concurrently. Without proper control, this can lead to inconsistent data, race conditions, or system crashes. This is where Distributed Concurrency Control (DCC) comes in—a set of techniques to manage concurrent operations safely across distributed databases.
What is Distributed Concurrency Control?
Managing Bank Transactions Safely Across Systems
Imagine a customer, Alice, transferring money between her savings and checking accounts in a distributed banking system. At the same time, another transaction is trying to deduct a loan payment from her checking account.
Without proper coordination, these concurrent operations could overwrite each other, causing incorrect balances or inconsistent states. Distributed Concurrency Control ensures such conflicts are managed safely across multiple nodes.
Key Goals:
- Consistency: Database remains in a valid state after transactions.
- Isolation: Transactions behave as if executed one after another.
- Atomicity: Each transaction completes fully or not at all.
Bank Transaction Scenario
Initial State:
Account | Balance |
---|---|
Savings | 5000 |
Checking | 2000 |
Transactions:
- T1 (Savings → Checking transfer): Transfer 1000 from Savings to Checking.
- T2 (Loan Payment): Deduct 1500 from Checking.
Types of Distributed Concurrency Control
There are two main strategies for managing concurrency in distributed systems:
- Pessimistic Concurrency Control (PCC)
- Optimistic Concurrency Control (OCC)
1. Pessimistic Concurrency Control (PCC)
- PCC assumes conflicts between transactions are likely. It prevents conflicts by locking data before accessing it. If another transaction wants the same data, it must wait.
- PCC assumes conflicts are likely and prevents them upfront using locks.
Code:
// T1: Transfer Money
lock(savingsAccount, EXCLUSIVE);
lock(checkingAccount, EXCLUSIVE);
savingsAccount.balance -= 1000;
checkingAccount.balance += 1000;
commit();
unlock(savingsAccount, checkingAccount);
// T2 will wait for locks
lock(checkingAccount, EXCLUSIVE);
checkingAccount.balance -= 1500;
commit();
unlock(checkingAccount);
How it works?
Time | T1 (Transfer) | T2 (Loan Payment) |
---|---|---|
t1 | LOCK Savings (X-lock) |