Note: this article is published on 07/14/2024.

Concurrency

In computer science, concurrency is the ability of different parts or units of a program, algorithm, or problem to be executed out-of-order or in partial order, without affecting the outcome.

Transaction

A transaction is a collection of operations that performs a single logical function in a database application. Multiple transactions execute at the same time can cause the concurrency issue.

Transaction Properties

A database management system (DBMS) is considered a relational database management system (RDBMS) if it follows the transactional properties, ACID, a set of properties of database transactions intended to guarantee data validity..

Concurrency Problem Types

The concurrency problem mostly arises when both the users try to write the same data, or when one is writing and the other is reading. Apart from this logic, there are some common types of concurrency problems:

Solve Concurrency Problems

SQL Server provides 5 different levels of transaction isolation to overcome these Concurrency problems. These 5 isolation levels work on two major concurrency models:

  1. Pessimistic model -
    • Readers can block writers, and
    • Writers can block readers.
  2. Optimistic model -
    • Readers cannot block writers, and
    • Writers cannot block readers, but
    • Writer can block another writer.

Note that readers are users are performing the SELECT operations. Writers are users are performing INSERT, ALTER, UPDATE, S.E.T. operations.

5 Isolation Level

In a SQL server, a query can have five different isolation levels:

These levels are ordered in terms of the separation of work by two different processes, from minimal separation to maximal.

Conclusion

References: