liveBook · Manning

Conditional update

As explained in ScyllaDB in Action

A conditional update is a database write that is applied only when a specified condition on the target data holds.

A conditional update changes a database row only when a supplied condition about its current state evaluates to true. In ScyllaDB, lightweight transactions provide this coordination, avoiding a separate application read, decision, and write sequence. section 6.5

This is useful when ordinary writes could overwrite valid data or create a logically incomplete row. Timestamp-based conflict resolution cannot understand intent, so concurrent writes can produce lost updates; conditional updates add an explicit check against the row’s state. section 6.1.2 section 6.5

Use a conditional update when the write depends on information already stored in the target row:

  • Check that a row exists before changing it. section 6.5
  • Prevent an update from overwriting data changed by another operation. section 6.1.2
  • Prefer the database-side condition when an application read followed by a write could race with another user. section 6.5

Protecting an author row

In the restaurant-review application, User A reads an author’s bio while User B deletes that author. Without coordination, User A’s later bio update can recreate a row containing only the ID and bio, leaving out the author’s name. A conditional update can require that the row still exists; if the condition is false, the update does not run. section 6.5

Conditional updates improve coordination but add compute cost. They are one option alongside client-side coordination such as distributed locking, and should be chosen when the state check is worth that additional cost. section 6.4.2 section 6.1.2

How ScyllaDB in Action covers it

How deep it goes
Explains the read-check-write race, row-existence condition, and coordination cost without detailing LWT internals.
Examples
Uses concurrent author-bio editing and deletion to demonstrate how a condition prevents an incomplete row.
What it assumes
Assumes basic database writes and concurrent operations, while introducing database-side coordination beyond ordinary timestamps.
What you can do after
Apply it via lightweight transactions when a write must succeed only if a row-state condition remains true.
How it connects
Connects conditional updates with lightweight transactions, lost writes, timestamps, and distributed locking.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ScyllaDB in Action. The section links point to the parts of the book it draws on.