Storage glossary · JSON corpus · llms.txt · hesela.com

compare-and-swap · shipping · also CAS, Compare-and-set

Compare-and-swap

Compare-and-swap is an atomic conditional update that replaces a stored value only if it matches an expected value and reports the comparison outcome or observed value.

The comparison and update must be indivisible; separate GET and PUT requests leave a race. In etcd, a transaction can compare a value or modification revision before its update. A value-only comparison cannot detect an intervening change that restores the original value; this is a constructed consequence of equality testing. A timeout can leave the operation's outcome unknown. This storage-API use of CAS is not content-addressable storage.

Relations

related
linearizability, serializability

Citations

  1. etcd v3.6 documentation: Key-Value pair metadata and Transaction. (accessed 2026-10-12)
  2. etcd v3.6 API guarantees: durability, strict serializability and operation completion. (accessed 2026-10-12)
  3. Storage consistency: ordering is not a transaction or a durability promise (accessed 2026-10-12)

JSON: /data/terms/compare-and-swap.json