> For the complete documentation index, see [llms.txt](https://nodeboot.gitbook.io/node-boot-framework/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nodeboot.gitbook.io/node-boot-framework/fundamentals/core-features/transactions/transactions-vs-concurrency.md).

# Transactions vs Concurrency

Concurrency issues arise only when multiple transactions operate on the same data item. If transactions work on different data items, concurrency is not a problem. However, when multiple transactions are executed concurrently in an unpredictable manner, several issues can occur. Database transactions primarily involve two major operations: "Read" and "Write." Effectively managing these operations during concurrent transaction execution on the same data item is crucial to maintaining data consistency in the database.

<figure><img src="https://3259457181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuOvZq23odcftFts6HH89%2Fuploads%2FHT8VSJnWrvtUfnreN7rH%2FScreenshot%202024-05-17%20at%2015.26.50.png?alt=media&amp;token=2fc6e0d0-73b9-4371-8b6b-4a58e12805f0" alt=""><figcaption><p>Transactions Concurrency.</p></figcaption></figure>

#### Dirty Read

A transaction reads shared data that has been modified by another transaction but that transaction is not yet committed (*Uncommitted data is read*).

<figure><img src="https://3259457181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuOvZq23odcftFts6HH89%2Fuploads%2F3Utyi2MZg3NVHIjgs0cN%2F1_QRjm5ARtcm3E8lTO5Co5-w.png?alt=media&amp;token=6e1c91a5-ffb3-4441-ae47-bdfb8320ee2a" alt=""><figcaption><p>Dirty Read</p></figcaption></figure>

#### Phantom Read

When a user reads a set of records, and then another transaction inserts or deletes rows in the dataset being read. When the user reads the same set of records again, they may find new "*phantom*" rows that were not present during the initial read.

<figure><img src="https://3259457181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuOvZq23odcftFts6HH89%2Fuploads%2F9GnvV9VDaNhF5gBWHgrV%2Fphantom.webp?alt=media&amp;token=ed83da38-3d04-4571-a557-cf60ffe6a863" alt=""><figcaption><p>Phantom Read</p></figcaption></figure>

#### **Non**-**repeatable read** <a href="#c267" id="c267"></a>

Before transaction A is over, another transaction B also accesses the same data. Then, due to the modification caused by transaction B, the data read twice from transaction A may be different.

The difference between Phantom read and Non-repeatable read：

The key to non-repeatable reading is to **modify**:\
In the same conditions, the data you have read, read it again, and find that the **value is different.**\
The key point of the phantom reading is to **add** or **delete**:\
Under the same conditions, the **number of records** read out for the first time and the second time is different.

{% hint style="info" %}
Isolation levels are used to solve various problems related with transactions concurrency. Check Node-Boot isolation levels for more details.
{% endhint %}
