accesspatterns.dev

Writing data · Lesson 11 of 20

No silent clobbers

A version check lets an update land only if nobody changed the item since you read it.

Next · Modelling relationshipsModel a one-to-many with one partition

Why

Two people open the same itinerary. Without a guard, the second to save silently overwrites the first. A version attribute fixes that: every write carries the version it expects and bumps it atomically with ADD.

Update with the version you read and it lands, taking version from 3 to 4. Run the stale update and the condition version = 3 no longer holds, so the engine rejects it with a ConditionalCheckFailedException. The stale writer must re-read and retry. No update is ever lost.

A version attribute plus a condition gives optimistic concurrency: a stale write bounces instead of silently overwriting a newer one.

Itineraries
Try an example

The Kyoto itinerary is at version 3. You must know the version before you can lock on it.

pk(pk)
sk(sk)
title
days
version

Run an operation to see the raw engine response.

table Itinerarieskeys pk / skitems 5