Skip to main content

🗓️ 07082025 1049
📎

concurrency_control

Concurrency control ensures correctness and consistency when multiple transactions or threads access shared resources at the same time.

🔥 Goals:

  • Prevent conflicts (e.g., dirty reads, lost updates)
  • Ensure isolation (ACID property)
  • Maintain performance and throughput

🧱 Types of Concurrency Problems

ProblemDescriptionExample
Lost UpdateTwo writes overwrite each otherT1 and T2 read the same record and both update it
Dirty ReadRead uncommitted changesT1 writes, T2 reads before T1 commits
Non-repeatable ReadSame read returns different resultsT1 reads, T2 modifies and commits, T1 reads again
Phantom ReadRows appear/disappear in repeated queriesT1: SELECT *, T2 inserts, T1 re-queries and sees more rows

🧠 Summary Table

optimistic_lockingpessimistic_locking
AssumptionLow contentionHigh contention
ConcurrencyHighLow
RiskRetry on failureBlocking, deadlocks
OverheadLightweightHeavyweight
Common UsageWeb apps, distributed sysDatabases, legacy systems

References

  • ChatGPT