---
library: "bootstrap"
slug: "MonotonicCounter"
name: "MonotonicCounter"
ref: "MonotonicCounter#d0d3"
hash: "sema:MonotonicCounter#mh:SHA-256:d0d3ce256be4bc080a29eab7fda36381a4352a280d9a12d59179c60e71cf9bd0"
type: "Protocols"
layer: "Society"
version: "0.11.0"
root: "a6a3d1ff0f982ee30430c5b42f3784c8ec901fd68482cfc1bc30899c1e5e48c5"
license: null
url: "https://semahash.org/vocabularies/bootstrap/patterns/MonotonicCounter"
---

# MonotonicCounter

Value that never decreases

Society · Protocols

## Mechanism

A distributed coordination primitive where a value (clock, version, balance) never decreases. This simplifies consensus: a node seeing a higher value knows it is seeing later state, without needing to compare histories. It is the foundation of logical clocks and CRDTs, and relies on a [StateLock](https://semahash.org/vocabularies/bootstrap/patterns/StateLock.md) (or CRDT logic) to ensure the value never regresses.

## Invariants

- [Value](https://semahash.org/vocabularies/bootstrap/patterns/Value.md)(T+1) >= [Value](https://semahash.org/vocabularies/bootstrap/patterns/Value.md)(T).
- A merge yields at least each of its inputs: Merge(A, B) >= A and >= B.

## Preconditions

- Initial value defined

## Postconditions

- Order preserved

## Failure modes

- Counter overflow (finite integer space).

## Where this came from

—

## Builds on

- [StateLock](https://semahash.org/vocabularies/bootstrap/patterns/StateLock.md) (references)
- [Value](https://semahash.org/vocabularies/bootstrap/patterns/Value.md) (references)

## Used by

- [AuditTrail](https://semahash.org/vocabularies/bootstrap/patterns/AuditTrail.md) (references)
- [Ballot](https://semahash.org/vocabularies/bootstrap/patterns/Ballot.md) (references)
- [TimeWarpLog](https://semahash.org/vocabularies/bootstrap/patterns/TimeWarpLog.md) (references)

## Identity

- Library: bootstrap 0.11.0 (root a6a3d1ff0f98)
- Ref: MonotonicCounter#d0d3
- Hash: sema:MonotonicCounter#mh:SHA-256:d0d3ce256be4bc080a29eab7fda36381a4352a280d9a12d59179c60e71cf9bd0

## Links

- Page: https://semahash.org/vocabularies/bootstrap/patterns/MonotonicCounter
- JSON: https://semahash.org/vocabularies/bootstrap/patterns/MonotonicCounter.json
- Library: https://semahash.org/vocabularies/bootstrap
- Library index: https://semahash.org/vocabularies/bootstrap/index.json
