{
  "code": null,
  "collection": "architecture",
  "href": "https://banes-lab.com/ontology#architecture-optimistic-locking",
  "id": "optimistic-locking",
  "kind": "pattern",
  "layer": {
    "href": "https://banes-lab.com/ontology/schema#layer-atomic-boundary",
    "json": "https://banes-lab.com/json/records/layer/atomic-boundary",
    "label": "Atomic Boundary",
    "markdown": "https://banes-lab.com/records/layer/atomic-boundary.md",
    "ref": "layer:atomic-boundary"
  },
  "name": "Optimistic Locking",
  "ref": "architecture:optimistic-locking",
  "relations": [
    {
      "links": [
        {
          "href": "https://banes-lab.com/ontology/lexicon#lexicon-version-field",
          "json": "https://banes-lab.com/json/records/lexicon/version-field",
          "label": "Version Field",
          "markdown": "https://banes-lab.com/records/lexicon/version-field.md",
          "ref": "lexicon:version-field"
        }
      ],
      "relation": "requires"
    },
    {
      "links": [
        {
          "href": "https://banes-lab.com/ontology#architecture-concurrency-control",
          "json": "https://banes-lab.com/json/records/architecture/concurrency-control",
          "label": "Concurrency Control",
          "markdown": "https://banes-lab.com/records/architecture/concurrency-control.md",
          "ref": "architecture:concurrency-control"
        }
      ],
      "relation": "reinforces"
    },
    {
      "links": [
        {
          "href": "https://banes-lab.com/ontology/lexicon#lexicon-conflict-detection",
          "json": "https://banes-lab.com/json/records/lexicon/conflict-detection",
          "label": "Conflict Detection",
          "markdown": "https://banes-lab.com/records/lexicon/conflict-detection.md",
          "ref": "lexicon:conflict-detection"
        }
      ],
      "relation": "enables"
    },
    {
      "links": [
        {
          "href": "https://banes-lab.com/ontology/lexicon#lexicon-blind-overwrite",
          "json": "https://banes-lab.com/json/records/lexicon/blind-overwrite",
          "label": "Blind Overwrite",
          "markdown": "https://banes-lab.com/records/lexicon/blind-overwrite.md",
          "ref": "lexicon:blind-overwrite"
        }
      ],
      "relation": "conflicts-with"
    },
    {
      "links": [
        {
          "href": "https://banes-lab.com/ontology/lexicon#lexicon-retry-complexity",
          "json": "https://banes-lab.com/json/records/lexicon/retry-complexity",
          "label": "Retry Complexity",
          "markdown": "https://banes-lab.com/records/lexicon/retry-complexity.md",
          "ref": "lexicon:retry-complexity"
        }
      ],
      "relation": "tensions-with"
    },
    {
      "links": [
        {
          "href": "https://banes-lab.com/ontology/schema#tension-optimistic-locking-retry-complexity",
          "json": "https://banes-lab.com/json/records/tension/optimistic-locking-retry-complexity",
          "label": "Optimistic Locking / Retry Complexity",
          "markdown": "https://banes-lab.com/records/tension/optimistic-locking-retry-complexity.md",
          "ref": "tension:optimistic-locking-retry-complexity"
        }
      ],
      "relation": "tensions"
    },
    {
      "links": [
        {
          "href": "https://banes-lab.com/ontology#architecture-lost-update",
          "json": "https://banes-lab.com/json/records/architecture/lost-update",
          "label": "Lost Update",
          "markdown": "https://banes-lab.com/records/architecture/lost-update.md",
          "ref": "architecture:lost-update"
        }
      ],
      "relation": "violated-by"
    },
    {
      "links": [
        {
          "href": "https://banes-lab.com/ontology/schema#vocabulary-severity-contextual",
          "json": "https://banes-lab.com/json/records/vocabulary/severity-contextual",
          "label": "contextual",
          "markdown": "https://banes-lab.com/records/vocabulary/severity-contextual.md",
          "ref": "vocabulary:severity-contextual"
        }
      ],
      "relation": "severity"
    },
    {
      "links": [
        {
          "href": "https://banes-lab.com/ontology#architecture-category-transactions-state-concurrency",
          "json": "https://banes-lab.com/json/records/architecture-category/transactions-state-concurrency",
          "label": "Transactions / State / Concurrency",
          "markdown": "https://banes-lab.com/records/architecture-category/transactions-state-concurrency.md",
          "ref": "architecture-category:transactions-state-concurrency"
        }
      ],
      "relation": "category"
    },
    {
      "links": [
        {
          "href": "https://banes-lab.com/ontology#architecture-write-barrier",
          "json": "https://banes-lab.com/json/records/architecture/write-barrier",
          "label": "Write Barrier",
          "markdown": "https://banes-lab.com/records/architecture/write-barrier.md",
          "ref": "architecture:write-barrier"
        }
      ],
      "relation": "refactors"
    },
    {
      "links": [
        {
          "href": "https://banes-lab.com/ontology#architecture-write-barrier",
          "json": "https://banes-lab.com/json/records/architecture/write-barrier",
          "label": "Write Barrier",
          "markdown": "https://banes-lab.com/records/architecture/write-barrier.md",
          "ref": "architecture:write-barrier"
        }
      ],
      "relation": "reinforced-by"
    },
    {
      "links": [
        {
          "href": "https://banes-lab.com/disciplined-methodology/verify#verify-the-verifier",
          "json": "https://banes-lab.com/json/disciplined-methodology/verify/verify-the-verifier",
          "label": "Verify the verifier",
          "markdown": "https://banes-lab.com/disciplined-methodology/verify/verify-the-verifier.md",
          "ref": "chapter:/disciplined-methodology/verify#verify-the-verifier"
        },
        {
          "href": "https://banes-lab.com/disciplined-methodology/collaborate#posting-and-waiting-are-one-operation",
          "json": "https://banes-lab.com/json/disciplined-methodology/collaborate/posting-and-waiting-are-one-operation",
          "label": "Posting and waiting are one operation",
          "markdown": "https://banes-lab.com/disciplined-methodology/collaborate/posting-and-waiting-are-one-operation.md",
          "ref": "chapter:/disciplined-methodology/collaborate#posting-and-waiting-are-one-operation"
        },
        {
          "href": "https://banes-lab.com/ontology#architecture-category-anti-patterns",
          "json": "https://banes-lab.com/json/ontology/principles/architecture-category-anti-patterns",
          "label": "Anti-patterns",
          "markdown": "https://banes-lab.com/ontology/principles/architecture-category-anti-patterns.md",
          "ref": "chapter:/ontology#architecture-category-anti-patterns"
        },
        {
          "href": "https://banes-lab.com/ontology#architecture-category-coordination-surfaces",
          "json": "https://banes-lab.com/json/ontology/principles/architecture-category-coordination-surfaces",
          "label": "Coordination Surfaces",
          "markdown": "https://banes-lab.com/ontology/principles/architecture-category-coordination-surfaces.md",
          "ref": "chapter:/ontology#architecture-category-coordination-surfaces"
        },
        {
          "href": "https://banes-lab.com/ontology#architecture-category-transactions-state-concurrency",
          "json": "https://banes-lab.com/json/ontology/principles/architecture-category-transactions-state-concurrency",
          "label": "Transactions / State / Concurrency",
          "markdown": "https://banes-lab.com/ontology/principles/architecture-category-transactions-state-concurrency.md",
          "ref": "chapter:/ontology#architecture-category-transactions-state-concurrency"
        },
        {
          "href": "https://banes-lab.com/ontology/lexicon#lexicon-category-transactions-state-concurrency",
          "json": "https://banes-lab.com/json/ontology/lexicon/lexicon-category-transactions-state-concurrency",
          "label": "Transactions / State / Concurrency",
          "markdown": "https://banes-lab.com/ontology/lexicon/lexicon-category-transactions-state-concurrency.md",
          "ref": "chapter:/ontology/lexicon#lexicon-category-transactions-state-concurrency"
        },
        {
          "href": "https://banes-lab.com/ontology/schema#the-vocabulary-severity",
          "json": "https://banes-lab.com/json/ontology/schema/the-vocabulary-severity",
          "label": "Severity levels",
          "markdown": "https://banes-lab.com/ontology/schema/the-vocabulary-severity.md",
          "ref": "chapter:/ontology/schema#the-vocabulary-severity"
        },
        {
          "href": "https://banes-lab.com/ontology/schema#the-resolutions",
          "json": "https://banes-lab.com/json/ontology/schema/the-resolutions",
          "label": "The resolutions",
          "markdown": "https://banes-lab.com/ontology/schema/the-resolutions.md",
          "ref": "chapter:/ontology/schema#the-resolutions"
        }
      ],
      "relation": "linked-from"
    }
  ],
  "summary": "A design pattern that checks a record's version when it is written and rejects the write if another writer changed it first, comparing only the writer's own span where a surface is fenced per writer.",
  "siblings": {
    "next": {
      "href": "https://banes-lab.com/ontology#architecture-pessimistic-locking",
      "json": "https://banes-lab.com/json/records/architecture/pessimistic-locking",
      "label": "Pessimistic Locking",
      "markdown": "https://banes-lab.com/records/architecture/pessimistic-locking.md",
      "ref": "architecture:pessimistic-locking"
    },
    "previous": {
      "href": "https://banes-lab.com/ontology#architecture-concurrency-control",
      "json": "https://banes-lab.com/json/records/architecture/concurrency-control",
      "label": "Concurrency Control",
      "markdown": "https://banes-lab.com/records/architecture/concurrency-control.md",
      "ref": "architecture:concurrency-control"
    }
  },
  "up": {
    "href": null,
    "json": "https://banes-lab.com/json/api/records/architecture",
    "label": "Architecture principles",
    "markdown": "https://banes-lab.com/api/records/architecture.md",
    "ref": "api:records/architecture"
  },
  "aliases": [
    "Own-Span Compare-and-Swap"
  ],
  "exemplar": {
    "after": "const updated = await fooTable.update({\n  id: foo.id,\n  expectedVersion: foo.version,\n  next: { ...foo, version: foo.version + 1 },\n});\nif (!updated) throw new ConflictError(foo.id);",
    "before": "await fooTable.update({ id: foo.id, name: foo.name });",
    "lang": "ts",
    "medium": "code"
  },
  "formedBy": null,
  "scope": [
    "persistence",
    "transaction"
  ],
  "severity": "contextual"
}
