---
title: Row-level concurrency
description: Row-level concurrency reduces write conflicts on Delta Lake tables by detecting changes at the row level, so concurrent writes to different rows don't conflict.
canonical_url: https://docs.databricks.com/aws/en/optimizations/isolation/row-level-concurrency
---

# Row-level concurrency

Row-level concurrency reduces conflicts between concurrent write operations by detecting changes at the row level and automatically resolving conflicts that occur when concurrent writes update or delete different rows in the same data file.

Without row-level concurrency, two concurrent operations can conflict when they modify the same data files, even if they change different rows. This causes failures in workloads such as concurrent `MERGE`, `UPDATE`, or `DELETE` jobs against the same table. See [Write conflicts without row-level concurrency](https://docs.databricks.com/aws/en/optimizations/isolation/row-level-concurrency.md#write-conflicts).

## <a id="rlc-requirements" />Requirements for row-level concurrency

Row-level concurrency is automatically enabled when all of these requirements are met:

* Using Databricks Runtime 14.3 LTS and above.
* The source table doesn't use partitions.
* The source table has deletion vectors enabled. See [Deletion vectors in Databricks](https://docs.databricks.com/aws/en/tables/features/deletion-vectors.md).

Partitioned tables don't allow row-level concurrency. However, when deletion vectors are enabled, partitioned tables can still avoid conflicts between `OPTIMIZE` and write operations. See [Limitations for row-level concurrency](https://docs.databricks.com/aws/en/optimizations/isolation/row-level-concurrency.md#rlc-limitations).

## <a id="rlc-conflict-table" />Conflict matrix with row-level concurrency

For source tables with row-level concurrency, the following table shows how each pair of concurrent write operations behaves in each isolation level.

Concurrent metadata changes are an exception to every result in the table. A metadata change, such as an `ALTER TABLE` command or a write that updates the table schema, might cause all concurrent write operations to fail, including `INSERT`. See [Metadata change conflicts](https://docs.databricks.com/aws/en/optimizations/isolation/index.md#metadata-conflicts).

| Operation pair                                                                                                | WriteSerializable (default)                                       | Serializable                                                                                                    |
| ------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| INSERT [(1)](https://docs.databricks.com/aws/en/optimizations/isolation/row-level-concurrency.md#f1) + INSERT | Cannot conflict                                                   | Cannot conflict                                                                                                 |
| INSERT + UPDATE, DELETE, MERGE INTO                                                                           | Cannot conflict                                                   | Can conflict when modifying the same row. The `UPDATE`, `DELETE`, or `MERGE` operation fails, not the `INSERT`. |
| INSERT + OPTIMIZE                                                                                             | Cannot conflict                                                   | Cannot conflict                                                                                                 |
| UPDATE, DELETE, MERGE INTO + UPDATE, DELETE, MERGE INTO                                                       | Can conflict when modifying the same row                          | Can conflict when modifying the same row                                                                        |
| UPDATE, DELETE, MERGE INTO + OPTIMIZE                                                                         | Can conflict when `ZORDER BY` is used. Cannot conflict otherwise. | Can conflict when `ZORDER BY` is used. Cannot conflict otherwise.                                               |
| OPTIMIZE + OPTIMIZE                                                                                           | Can conflict when `ZORDER BY` is used. Cannot conflict otherwise. | Can conflict when `ZORDER BY` is used. Cannot conflict otherwise.                                               |

<a id="f1" />**(1)** All `INSERT` operations in this table describe append operations that don't contain subqueries that read data from the same table. `INSERT` operations containing subqueries that read from the same table support the same concurrency as `MERGE`.

> [!NOTE]
>
> * When a pair can conflict, only the operation that reads the affected data fails. An `INSERT` that appends data without reading the table isn't the operation that fails, so retry logic belongs on the concurrent `UPDATE`, `DELETE`, or `MERGE`.
> * Tables with identity columns don't support concurrent transactions. See [Identity columns](https://docs.databricks.com/aws/en/tables/features/generated-columns.md#identity).
> * `REORG` operations have isolation semantics identical to `OPTIMIZE` when rewriting data files. When you use `REORG` to apply an upgrade, table protocols change, which conflicts with all ongoing operations.

### <a id="no-rlc-conflict-table" /><a id="write-conflicts" />Write conflicts without row-level concurrency

For source tables without row-level concurrency, the following table shows how each pair of concurrent write operations behaves in each isolation level.

Concurrent metadata changes are an exception to every result in the table. A metadata change, such as an `ALTER TABLE` command or a write that updates the table schema, might cause all concurrent write operations to fail, including `INSERT`. See [Metadata change conflicts](https://docs.databricks.com/aws/en/optimizations/isolation/index.md#metadata-conflicts).

| Operation pair                                                                                                | WriteSerializable (default)                                                                                                                            | Serializable                                                                                                                                                                                                                 |
| ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| INSERT [(1)](https://docs.databricks.com/aws/en/optimizations/isolation/row-level-concurrency.md#f2) + INSERT | Cannot conflict                                                                                                                                        | Cannot conflict                                                                                                                                                                                                              |
| INSERT + UPDATE, DELETE, MERGE INTO                                                                           | Cannot conflict                                                                                                                                        | Can conflict. The `UPDATE`, `DELETE`, or `MERGE` operation fails, not the `INSERT`. See [Avoid conflicts using partitioning](https://docs.databricks.com/aws/en/optimizations/isolation/row-level-concurrency.md#conflicts). |
| INSERT + OPTIMIZE                                                                                             | Cannot conflict                                                                                                                                        | Cannot conflict                                                                                                                                                                                                              |
| UPDATE, DELETE, MERGE INTO + UPDATE, DELETE, MERGE INTO                                                       | Can conflict. See [Avoid conflicts using partitioning](https://docs.databricks.com/aws/en/optimizations/isolation/row-level-concurrency.md#conflicts). | Can conflict. See [Avoid conflicts using partitioning](https://docs.databricks.com/aws/en/optimizations/isolation/row-level-concurrency.md#conflicts).                                                                       |
| UPDATE, DELETE, MERGE INTO + OPTIMIZE                                                                         | Cannot conflict in tables with deletion vectors enabled, unless `ZORDER BY` is used. Can conflict otherwise.                                           | Cannot conflict in tables with deletion vectors enabled, unless `ZORDER BY` is used. Can conflict otherwise.                                                                                                                 |
| OPTIMIZE + OPTIMIZE                                                                                           | Cannot conflict in tables with deletion vectors enabled, unless `ZORDER BY` is used. Can conflict otherwise.                                           | Cannot conflict in tables with deletion vectors enabled, unless `ZORDER BY` is used. Can conflict otherwise.                                                                                                                 |

<a id="f2" />**(1)** All `INSERT` operations in this table describe append operations that don't contain subqueries that read data from the same table. `INSERT` operations containing subqueries that read from the same table support the same concurrency as `MERGE`.

> [!NOTE]
>
> * When a pair can conflict, only the operation that reads the affected data fails. An `INSERT` that appends data without reading the table isn't the operation that fails, so retry logic belongs on the concurrent `UPDATE`, `DELETE`, or `MERGE`.
> * Tables with identity columns don't support concurrent transactions. See [Identity columns](https://docs.databricks.com/aws/en/tables/features/generated-columns.md#identity).
> * `REORG` operations have isolation semantics identical to `OPTIMIZE` when rewriting data files. When you use `REORG` to apply an upgrade, table protocols change and conflict with all ongoing operations.

## <a id="rlc-limitations" />Limitations for row-level concurrency

Limitations apply for row-level concurrency. For these operations, conflict resolution follows normal concurrency for write conflicts. See [Write conflicts without row-level concurrency](https://docs.databricks.com/aws/en/optimizations/isolation/row-level-concurrency.md#write-conflicts).

| Limitation                    | Description                                                                                                                                                |
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Complex conditional clauses   | Conditions on complex data types (structs, arrays, maps), non-deterministic expressions, subqueries, and correlated subqueries                             |
| `MERGE` predicate requirement | In Databricks Runtime 14.2, `MERGE` commands must use an explicit predicate on the target table to filter rows matching the source table                   |
| Performance tradeoff          | Row-level conflict detection can increase total execution time. With many concurrent transactions, the writer prioritizes latency over conflict resolution |

All limitations for deletion vectors also apply. See [Limitations](https://docs.databricks.com/aws/en/tables/features/deletion-vectors.md#limitations).

## <a id="conflicts" />Avoid conflicts using partitioning

For all cases marked "can conflict" in the conflict matrices, a conflict occurs only if the two operations affect the same set of files. To make two sets of files disjoint, partition the table by the same columns used in operation conditions.

**Example:**

The commands `UPDATE table WHERE date > '2010-01-01' ...` and `DELETE table WHERE date < '2010-01-01'` conflict if the table is not partitioned by date, because both can attempt to modify the same files. Partitioning the table by `date` avoids the conflict.

> [!NOTE]
>
> Partitioning a table by a column with high cardinality can lead to performance issues due to the large number of subdirectories.

### <a id="partition-example" />Avoid conflicts with explicit partition filters

This exception is often raised during concurrent `DELETE`, `UPDATE`, or `MERGE` operations that might read the same partition even when updating different partitions. Make the separation explicit in the operation condition:

```scala
// Problem: Condition can scan the entire table
deltaTable.as("t").merge(
    source.as("s"),
    "s.user_id = t.user_id AND s.date = t.date AND s.country = t.country")
  .whenMatched().updateAll()
  .whenNotMatched().insertAll()
  .execute()

// Solution: Add explicit partition filters
deltaTable.as("t").merge(
    source.as("s"),
    "s.user_id = t.user_id AND s.date = t.date AND s.country = t.country AND t.date = '" + date + "' AND t.country = '" + country + "'")
  .whenMatched().updateAll()
  .whenNotMatched().insertAll()
  .execute()
```

## <a id="conflict-exceptions" />Conflict exceptions

When a transaction conflict occurs, you observe one of these exceptions:

### ConcurrentAppendException

This exception occurs when a concurrent operation adds files in the same partition (or anywhere in an unpartitioned table) that your operation reads. The file additions might be caused by `INSERT`, `DELETE`, `UPDATE`, or `MERGE` operations.

With the default WriteSerializable isolation level, files added by `INSERT` operations that append data without reading any data don't conflict with any operation. If the isolation level is Serializable, any appends may conflict.

> [!IMPORTANT]
>
> A conflict can still occur in WriteSerializable mode if multiple concurrent `DELETE`, `UPDATE`, or `MERGE` operations might reference values appended by an `INSERT` operation. The `DELETE`, `UPDATE`, or `MERGE` operation is the one that fails, because it reads the appended data. To avoid this:
>
> * Ensure concurrent `DELETE`, `UPDATE`, or `MERGE` operations don't read the appended data
> * Have at most one `DELETE`, `UPDATE`, or `MERGE` operation that can read the appended data

### ConcurrentDeleteReadException

This exception occurs when a concurrent operation deletes a file that your operation read. Common causes are `DELETE`, `UPDATE`, or `MERGE` operations that rewrite files.

### ConcurrentDeleteDeleteException

This exception occurs when a concurrent operation deletes a file that your operation also deletes. This could be caused by two concurrent compaction operations rewriting the same files.

### MetadataChangedException

This exception occurs when a concurrent transaction updates the metadata of a Delta Lake table. Common causes are `ALTER TABLE` operations or writes that update the table schema.

### ConcurrentTransactionException

This exception occurs if a streaming query using the same checkpoint location is started multiple times concurrently and tries to write to the Delta Lake table at the same time. Never run two streaming queries with the same checkpoint location concurrently.

### ProtocolChangedException

This exception can occur when:

* Your Delta Lake table is upgraded to a new protocol version (you might need to upgrade your Databricks Runtime)
* Multiple writers are creating or replacing a table at the same time
* Multiple writers are writing to an empty path at the same time

See [Delta Lake feature compatibility and protocols](https://docs.databricks.com/aws/en/tables/features/feature-compatibility.md).

## <a id="additional-resources" /> Additional resources

* [Isolation levels (WriteSerializable and Serializable)](https://docs.databricks.com/aws/en/optimizations/isolation/isolation-levels.md)
* [Transactions](https://docs.databricks.com/aws/en/transactions/index.md)
* [Deletion vectors in Databricks](https://docs.databricks.com/aws/en/tables/features/deletion-vectors.md)
* [Delta Lake feature compatibility and protocols](https://docs.databricks.com/aws/en/tables/features/feature-compatibility.md)
