{
  "status": "shipping",
  "advantages": [],
  "limitations": [],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-10-12",
  "slug": "compare-and-swap",
  "term": "Compare-and-swap",
  "aliases": [
    "CAS",
    "Compare-and-set"
  ],
  "definition": "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.",
  "note": "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.",
  "related": [
    "linearizability",
    "serializability",
    "conditional-write"
  ],
  "citations": [
    {
      "id": "etcd-api",
      "title": "etcd v3.6 documentation: Key-Value pair metadata and Transaction.",
      "url": "https://etcd.io/docs/v3.6/learning/api/",
      "accessed": "2026-10-12"
    },
    {
      "id": "etcd-guarantees",
      "title": "etcd v3.6 API guarantees: durability, strict serializability and operation completion.",
      "url": "https://etcd.io/docs/v3.6/learning/api_guarantees/",
      "accessed": "2026-10-12"
    },
    {
      "id": "hesela-consistency",
      "title": "Storage consistency: ordering is not a transaction or a durability promise",
      "url": "https://hesela.com/analyses/storage-consistency-ordering/",
      "accessed": "2026-10-12"
    }
  ]
}
