Consider an application where customers frequently check their account balances while background processes update transactions. During busy periods, users may experience slow queries because read operations are waiting for write transactions to finish.
One common response is to use NOLOCK hints to reduce blocking. However, this can introduce dirty reads, missing rows, duplicate rows, and inconsistent results. It may make a query appear faster while allowing the application to display information that was never committed.
SQL Server provides a better approach through row versioning. Two important options are Read Committed Snapshot Isolation (RCSI) and Snapshot Isolation (SI). Both allow queries to read previously committed versions of data without taking shared locks that block concurrent updates.
Although they use the same underlying row-versioning framework, they provide different consistency guarantees. RCSI gives each statement its own consistent view of committed data, while Snapshot Isolation maintains a consistent view for the entire transaction.
Understanding this difference is important when building applications that perform multiple related database operations, financial calculations, reporting, or concurrent updates.
Understanding Traditional Read Committed Isolation
READ COMMITTED is the default transaction isolation level in SQL Server.
When READ COMMITTED uses traditional locking, SQL Server takes shared locks while reading data. These locks prevent other transactions from modifying the rows while the current read operation is accessing them.
Consider an Accounts table:
CREATE TABLE Accounts
(
AccountId INT PRIMARY KEY,
AccountName VARCHAR(100),
Balance DECIMAL(12, 2)
);
INSERT INTO Accounts
VALUES
(1, 'Savings Account', 5000),
(2, 'Current Account', 3000);
Now imagine two application sessions.
Session 1 begins a transaction and updates an account balance:
BEGIN TRANSACTION;
UPDATE Accounts
SET Balance = 7000
WHERE AccountId = 1;
-- Keep the transaction open temporarily.
The update has not been committed yet.
At the same time, Session 2 executes:
SELECT *
FROM Accounts
WHERE AccountId = 1;
Under traditional READ COMMITTED locking, the SELECT statement may wait for Session 1 to commit or roll back because the updated row is protected by an exclusive lock.
This behavior protects the reader from seeing an uncommitted value. However, it can create blocking when an application performs long-running updates while other users are reading the same records.
If Session 1 commits, Session 2 can continue and read the committed value. If Session 1 rolls back, Session 2 reads the previous committed value.
The problem is not that READ COMMITTED is incorrect. It provides the required consistency guarantee. The challenge is that locking-based reads and concurrent writes can interfere with each other.
What Is Row Versioning in SQL Server?
Row versioning allows SQL Server to maintain previous committed versions of modified rows.
Instead of making a reader wait for a writer to finish, SQL Server can retrieve an appropriate committed version of the row.
For example, suppose an account balance is initially 5000. A transaction changes it to 7000 but has not committed.
A concurrent reader can access the previous committed version and return 5000 without waiting for the update transaction to complete.
When the update commits, later readers can access the new committed value.
SQL Server manages these versions automatically. Developers do not need to create separate history tables or manually copy old values.
Row versions are maintained in a version store. When Accelerated Database Recovery (ADR) is not enabled, the version store is maintained in tempdb. When ADR is enabled, the persistent version store is maintained in the user database.
SQL Server retains row versions for as long as active transactions or other features need them. Once they are no longer required, background cleanup processes can remove them.
Two database options control the row-versioning isolation behaviors discussed in this article:
- READ_COMMITTED_SNAPSHOT enables row versioning for the READ COMMITTED isolation level.
- ALLOW_SNAPSHOT_ISOLATION enables the SNAPSHOT transaction isolation level.
These options can be enabled independently.
Understanding Read Committed Snapshot Isolation (RCSI)
Read Committed Snapshot Isolation changes how SQL Server implements the existing READ COMMITTED isolation level.
When READ_COMMITTED_SNAPSHOT is enabled, queries running under READ COMMITTED use row versioning instead of traditional shared data locks for read operations.
The important characteristic is statement-level consistency.
Each statement sees the committed data that existed when that statement started.
Consider a transaction that executes two SELECT statements:
BEGIN TRANSACTION;
SELECT Balance
FROM Accounts
WHERE AccountId = 1;
WAITFOR DELAY '00:00:05';
SELECT Balance
FROM Accounts
WHERE AccountId = 1;
COMMIT TRANSACTION;
Assume the first SELECT returns 5000.
While the transaction is waiting, another session updates the account balance to 7000 and commits the change.
When the second SELECT executes, it can return 7000.
Why does this happen?
Because RCSI creates a statement-level snapshot. The first SELECT reads the committed state available when that statement started. The second SELECT starts later and therefore sees the latest committed state available at its own start time.
Both statements receive consistent results, but they are not guaranteed to see the same database state.
This behavior works well for applications where individual queries need consistent committed data but do not require an identical view across an entire transaction.
Enabling RCSI
You can enable Read Committed Snapshot Isolation at the database level:
ALTER DATABASE ApplicationDB
SET READ_COMMITTED_SNAPSHOT ON;
Replace ApplicationDB with your database name.
Once enabled, sessions using READ COMMITTED automatically use row versioning for reads.
You do not need to change every application query or add a special isolation-level statement.
For example, the following query uses RCSI when executed under READ COMMITTED:
SELECT
AccountId,
AccountName,
Balance
FROM Accounts;
There is no need to add a NOLOCK hint.
RCSI is particularly useful when many application requests read data while background processes update it.
Understanding Snapshot Isolation (SI)
Snapshot Isolation also uses row versioning, but its consistency guarantee is different.
Instead of creating a new snapshot for every statement, SQL Server provides a transaction-level snapshot.
Every data-reading statement in the transaction sees the committed data that existed when the transaction's snapshot was established.
This is useful when multiple queries must work against the same consistent database state.
Consider a banking application that calculates the total balance across multiple accounts.
SET TRANSACTION ISOLATION LEVEL SNAPSHOT;
BEGIN TRANSACTION;
SELECT SUM(Balance) AS TotalBalance
FROM Accounts;
WAITFOR DELAY '00:00:05';
SELECT
AccountId,
AccountName,
Balance
FROM Accounts;
COMMIT TRANSACTION;
Assume another transaction changes an account balance and commits while the first transaction is waiting.
Under Snapshot Isolation, the second SELECT continues to see the earlier committed version associated with the transaction's snapshot.
The first and second SELECT statements therefore work with a consistent view of the database.
This is different from RCSI, where the second statement could see the newly committed value.
Enabling Snapshot Isolation
Snapshot Isolation must first be enabled at the database level:
ALTER DATABASE ApplicationDB
SET ALLOW_SNAPSHOT_ISOLATION ON;
After enabling it, an application or SQL session must explicitly select the SNAPSHOT isolation level before starting its transaction.
For example:
SET TRANSACTION ISOLATION LEVEL SNAPSHOT;
BEGIN TRANSACTION;
SELECT *
FROM Accounts;
UPDATE Accounts
SET Balance = Balance + 500
WHERE AccountId = 1;
COMMIT TRANSACTION;
The isolation-level statement applies to the session until another isolation level is selected or the connection is reset. In application connection pools, make sure the application manages session state correctly.
Snapshot Isolation is useful when a business operation contains multiple queries that must all use the same committed view of the data.
RCSI vs Snapshot Isolation: Key Differences
Both isolation levels use row versioning, but their behavior differs in important ways.
Feature | RCSI | Snapshot Isolation |
|---|
Database option | READ_COMMITTED_SNAPSHOT | ALLOW_SNAPSHOT_ISOLATION |
Consistency level | Statement-level | Transaction-level |
Default usage | Uses READ COMMITTED | Must be explicitly selected |
Snapshot timing | At the beginning of each statement | At the beginning of the transaction's snapshot |
Read operations | Use committed row versions | Use committed row versions |
Read/write blocking | Reduces blocking between readers and writers | Reduces blocking between readers and writers |
Update conflict behavior | Does not use the same application-visible snapshot update-conflict behavior | Can terminate a transaction when a row has changed since its snapshot |
Best suited for | General application queries | Multi-statement operations requiring a consistent view |
The most important difference is the consistency boundary.
RCSI guarantees that each individual statement reads a consistent committed version of the data. Snapshot Isolation guarantees that all statements in a transaction use the same transaction-level view.
Neither option guarantees that every business operation is automatically correct. Applications still need to handle concurrent updates, transaction boundaries, and business rules.
Understanding Update Conflicts in Snapshot Isolation
One important behavior developers must understand is update conflict detection.
Snapshot Isolation allows a transaction to read an older committed version of a row. However, it does not allow the transaction to silently overwrite a row that another transaction has modified since its snapshot.
Consider this scenario:
- Session 1 starts a Snapshot Isolation transaction and reads an account balance of 5000.
- Session 2 updates the balance to 7000 and commits.
- Session 1 attempts to update the same account based on its earlier snapshot.
SQL Server detects that another transaction has modified the row since Session 1's snapshot.
The first transaction receives an update conflict, and SQL Server terminates it. The application must handle the error and decide whether the operation can safely be retried.
A simplified two-session demonstration follows.
Session 1:
SET TRANSACTION ISOLATION LEVEL SNAPSHOT;
BEGIN TRANSACTION;
SELECT Balance
FROM Accounts
WHERE AccountId = 1;
WAITFOR DELAY '00:00:10';
UPDATE Accounts
SET Balance = 6000
WHERE AccountId = 1;
COMMIT TRANSACTION;
During the delay, execute this statement in Session 2:
UPDATE Accounts
SET Balance = 7000
WHERE AccountId = 1;
If Session 2 commits before Session 1 attempts its update, Session 1 encounters an update conflict.
This behavior prevents a Snapshot Isolation transaction from overwriting a newer committed change without detecting the conflict.
The application should catch the relevant SQL Server error, commonly error 3960, and retry the entire transaction when the business operation is safe to repeat.
Do not retry only the failed UPDATE statement. The transaction's original snapshot is no longer suitable for the operation. Start a new transaction so that it receives a new snapshot.
Checking the Current Database Settings
Before enabling either isolation option, check the existing database configuration.
SELECT
name,
is_read_committed_snapshot_on,
snapshot_isolation_state_desc
FROM sys.databases
WHERE name = 'ApplicationDB';
The result shows whether RCSI is enabled and the current state of Snapshot Isolation.
The snapshot_isolation_state_desc column is useful because the database can be in transitional states while the option is being enabled or disabled.
You can also inspect the current session isolation level:
DBCC USEROPTIONS;
Look for the isolation level in the returned session settings.
This is useful when troubleshooting an application that uses connection pooling, where a connection may have retained session settings from earlier work.
Understanding Version Store and Storage Impact
Row versioning reduces some forms of blocking, but it introduces additional storage and resource requirements.
When a transaction modifies a row, SQL Server may need to preserve its previous committed version so that concurrent readers can access it.
The longer an old version is required, the longer SQL Server must retain it.
For example, consider a reporting transaction that starts under Snapshot Isolation and remains open for several minutes. Even if the report reads only a small number of records, the transaction's snapshot may require SQL Server to retain older versions of rows modified by other transactions.
Long-running transactions can therefore increase version-store usage.
Monitor version-store activity, especially after enabling row versioning on a busy database.
When ADR is not enabled, you can inspect tempdb version-store usage using:
SELECT
database_id,
reserved_page_count,
reserved_space_kb
FROM sys.dm_tran_version_store_space_usage;
This view reports version-store space usage by database in tempdb.
If ADR is enabled, row versions used by the relevant database features are maintained in the persistent version store rather than the traditional tempdb version store. Monitor the appropriate persistent version-store information for that configuration.
Version-store monitoring should be part of database capacity planning. Enabling RCSI or Snapshot Isolation without considering long-running transactions and storage requirements can create operational problems.
Choosing the Right Isolation Level for Your Application
The correct choice depends on the consistency requirements of the application.
Use RCSI for general application workloads
RCSI is a good option when individual queries need committed, consistent data but do not need to share the same snapshot across multiple statements.
Typical examples include:
- Customer profile pages.
- Product catalog searches.
- Order history screens.
- Dashboard queries.
- General transactional application reads.
For many applications, RCSI can reduce reader-writer blocking without requiring changes to every query.
However, applications that depend on traditional locking behavior should be tested carefully before enabling it.
Use Snapshot Isolation for multi-query operations
Snapshot Isolation is useful when several statements inside a transaction must observe the same committed database state.
Examples include:
- Multi-step reporting operations.
- Business calculations involving multiple related queries.
- Processes that compare data across several tables.
- Operations that need a consistent view while performing other application work.
Because Snapshot Isolation can produce update conflicts, the application must implement appropriate retry and error-handling logic.
Do not select an isolation level only to reduce blocking
A common mistake is to enable an isolation level without understanding the application's consistency requirements.
For example, an application might calculate a total balance using one query and then retrieve individual account balances using another query.
Under RCSI, another transaction can commit changes between these statements. The total and the individual balances may therefore represent different committed points in time.
If the business operation requires both queries to use the same view, Snapshot Isolation may be more appropriate.
Choosing the correct isolation level should begin with the business consistency requirement, not just the desire to make queries run faster.
Production Considerations Before Enabling Row Versioning
Before changing a production database, test the behavior with realistic application workloads.
First, review transactions that depend on locking behavior. Some applications use explicit lock hints or rely on readers blocking writers. Changing to row versioning can affect those assumptions.
Second, inspect transaction duration. Long-running transactions can prevent old row versions from being cleaned up, increasing storage pressure.
Third, test update conflict handling if you plan to use Snapshot Isolation. The application must be able to recognize conflicts and retry complete business transactions where appropriate.
Fourth, review tempdb capacity and persistent version-store usage, depending on whether ADR is enabled. Monitor storage consumption, cleanup behavior, and database growth.
Finally, plan the database configuration change carefully. Changing READ_COMMITTED_SNAPSHOT requires an exclusive database lock. Active connections and transactions can interfere with the operation, so schedule the change during a suitable maintenance window and coordinate it with application deployment.
Conclusion
SQL Server RCSI and Snapshot Isolation both use row versioning to reduce blocking between read and write operations, but they provide different consistency guarantees.
RCSI gives each statement a consistent view of committed data as it existed when that statement started. Snapshot Isolation gives all statements in a transaction a consistent view based on the transaction's snapshot.
For many general application workloads, RCSI is a practical way to reduce reader-writer blocking while retaining READ COMMITTED semantics. Snapshot Isolation is more appropriate when multiple queries within one transaction must observe the same database state, provided the application can handle update conflicts.
Before enabling either option, evaluate transaction behavior, version-store capacity, application consistency requirements, and existing locking assumptions. The best isolation level is the one that protects the application's business rules while allowing concurrent database operations to run efficiently.
Join the conversation! Your thoughts help the community grow.