Course contentsShow
← Computer Science
Lesson 1670 of 2,87238. Database Transactions and IndexingFree lesson

Repeatable Read Isolation Level

Exploring how Repeatable Read guarantees consistent reads within a transaction by preventing nonrepeatable reads.

Repeatable Read Isolation Level

You'll learn how the Repeatable Read isolation level ensures that once your transaction reads data, subsequent reads see the same values, even if other transactions modify them.

The Core Idea

In the previous lesson, you learned about nonrepeatable reads—when reading the same row twice in a transaction gives different results because another transaction modified it in between. The Repeatable Read isolation level solves this problem.

When you start a transaction at Repeatable Read, the database guarantees that if you read a row once, every subsequent read of that same row within your transaction will return the identical values. It's as if the database takes a "snapshot" of the data when your transaction begins (or at first read), and you keep seeing that consistent view throughout.

How It Works

Repeatable Read typically uses locking mechanisms that hold read locks until your transaction completes. This prevents other transactions from modifying rows you've already read:

  • Your transaction reads row X → Database places a lock
  • Another transaction tries to UPDATE row X → Must wait until your transaction commits or rolls back
  • You read row X again → Guaranteed to see the same values

The Analogy

Think of reading a book in a library reading room with a "no alterations" rule. Once you check out a page to read, nobody can edit that page until you're done with your entire reading session. You can flip back and forth, always seeing the same text—no surprise edits mid-session.

Trade-off Reminder

Repeatable Read prevents nonrepeatable reads but requires more locking than Read Committed, which can reduce concurrency and increase the chance of deadlocks. You gain consistency at the cost of some performance.

Key Takeaway: Repeatable Read isolation level guarantees that all reads of the same data within a transaction return consistent results, eliminating nonrepeatable reads through locking or snapshot techniques.