# 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&#x26;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&#x26;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&#x26;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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nodeboot.gitbook.io/node-boot-framework/fundamentals/core-features/transactions/transactions-vs-concurrency.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
