Most Common Problems in Database Transactions

Alok Ratnaparkhi
3 min readJan 20, 2024

Introduction: Database transactions are a fundamental aspect of ensuring data integrity, consistency, and reliability. However, they come with their own set of challenges that developers must navigate. In this article, we will delve into some of the most common problems encountered in database transactions, including dirty reads, dirty writes, read skew, non-repeatable reads, lost updates, write skew, and phantom reads. Understanding these issues is crucial for designing robust and scalable database systems.

1. Dirty Read:

  • Problem: Dirty reads occur when a transaction reads uncommitted changes made by another transaction.
  • Minimum Isolation Level Guarantee: Read Committed Isolation

2. Dirty Write:

  • Problem: Dirty writes happen when one transaction overwrites uncommitted changes made by another transaction.
  • Minimum Isolation Level Guarantee: Read Committed Isolation

3. Read Skew and Non-Repeatable Read:

  • Problem: Non-repeatable read(fuzzy read) occurs when a transaction reads the same row at least twice but the same row’s data is different between the 1st and 2nd read because other transaction update the same row’s data and commit at the same time(concurrently).
  • Read skew happens between two different read queries where a transaction reads inconsistent data between the 1st and 2nd read query because other transactions insert, update or delete data and commit between those reads. Finally, an inconsistent result is produced by the inconsistent data.
  • In summary, non-repeatable read is specifically about the inconsistency of a single read operation (reading same object twice) when the data is modified by another transaction between consecutive reads. On the other hand, read skew is a broader concept or generalization of NRR that involves inconsistencies in multiple reads (same object rows or different rows) within a transaction, especially when the transaction is making decisions based on those reads.
  • Minimum Isolation Level Guarantee: Snapshot aka Read Repeatable Isolation

4. Lost Updates:

  • Problem: Lost updates occur when one transaction overwrites changes made by another transaction without taking those changes into account.
  • Minimum Isolation Level Guarantee: Snapshot aka Read Repeatable Isolation

5. Write Skew:

  • Problem: Two transactions read from same objects at the same time, based on the information provided by the reads, they update same or different objects. If it is same object then you can get dirty write or lost update anomaly. But, if objects are different then it may lead to write skew anomaly.
  • Minimum Isolation Level Guarantee: Serializable isolation

6. Phantom Reads:

  • Problem: Phantom reads involve changes to the number of rows returned by a query due to concurrent transactions inserting or deleting data.
  • Minimum Isolation Level Guarantee: Serializable isolation

Important notes:

Difference between Phantom read and non-repeatable read is that, Non-repeatable read: The A row that user A has queried has a different value the second time. All the rows in the query have the same value before and after, but different rows are being selected (because B has deleted or inserted some).

Phantom read happens when second transaction insert new row or delete existing row which transaction one has no idea about while executing concurrently. That is why it is called as phantom/ghostly read as new row appears like a ghost. In contrast, non-repeatable read talks about reading same row twice give different result as opposed to new row.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Alok Ratnaparkhi
Alok Ratnaparkhi

Written by Alok Ratnaparkhi

Algorithms |AI | Machine learning

No responses yet

Write a response