# Pessimistic Locking

> A design pattern that locks a record before reading it for update, so other writers wait until the transaction ends.

Record: `architecture:pessimistic-locking`
Kind: pattern
Layer: [Atomic Boundary](https://banes-lab.com/records/layer/atomic-boundary.md)
Severity: contextual
Scope: persistence, critical section
Canonical: https://banes-lab.com/ontology#architecture-pessimistic-locking

Listed in [Architecture principles](https://banes-lab.com/api/records/architecture.md), after [Optimistic Locking](https://banes-lab.com/records/architecture/optimistic-locking.md) and before [State Isolation](https://banes-lab.com/records/architecture/state-isolation.md).

## Repair

- Refactored by: Add Lock, Narrow Lock Scope
- Detected by: concurrent update conflicts
- Violated by: missing lock around critical mutation
- Measured by: lock wait/deadlock rate
- Enforced by: transactional tests

## Requires

- [Lock Ownership](https://banes-lab.com/records/lexicon/lock-ownership.md)

## Reinforces

- [Isolation](https://banes-lab.com/records/architecture/isolation.md)

## Enables

- [Strong Conflict Prevention](https://banes-lab.com/records/lexicon/strong-conflict-prevention.md)

## In tension with

- [Deadlock Freedom](https://banes-lab.com/records/lexicon/deadlock-freedom.md)
- [Latency](https://banes-lab.com/records/architecture/latency.md)
- [Lock-Free Throughput](https://banes-lab.com/records/lexicon/lock-free-throughput.md)

## Tensions

- [Pessimistic Locking / Deadlock Freedom](https://banes-lab.com/records/tension/deadlock-freedom-pessimistic-locking.md)
- [Pessimistic Locking / Latency](https://banes-lab.com/records/tension/latency-pessimistic-locking.md)
- [Pessimistic Locking / Lock-Free Throughput](https://banes-lab.com/records/tension/lock-free-throughput-pessimistic-locking.md)

## Severity

- [contextual](https://banes-lab.com/records/vocabulary/severity-contextual.md)

## Category

- [Transactions / State / Concurrency](https://banes-lab.com/records/architecture-category/transactions-state-concurrency.md)

## Linked from

- [Verify the verifier](https://banes-lab.com/disciplined-methodology/verify/verify-the-verifier.md)
- [Anti-patterns](https://banes-lab.com/ontology/principles/architecture-category-anti-patterns.md)
- [Scalability / Performance / Optimization](https://banes-lab.com/ontology/principles/architecture-category-scalability-performance-optimization.md)
- [Transactions / State / Concurrency](https://banes-lab.com/ontology/principles/architecture-category-transactions-state-concurrency.md)
- [Transactions / State / Concurrency](https://banes-lab.com/ontology/lexicon/lexicon-category-transactions-state-concurrency.md)
- [Severity levels](https://banes-lab.com/ontology/schema/the-vocabulary-severity.md)
- [The resolutions](https://banes-lab.com/ontology/schema/the-resolutions.md)
