Use PostgreSQL advisory locks for coordination
ADR-0022
Use PostgreSQL advisory locks for coordination
Context
The application runs on a 3-node cluster. PASETO key rotation needs to happen on exactly one node at a time.
Decision
Use PostgreSQL advisory locks (pg_try_advisory_xact_lock) to coordinate token rotation across nodes.
Rationale
- No external dependencies: Uses existing PostgreSQL connection
- Transaction scoped: Automatic lock release on commit/rollback
- Non-blocking:
pg_try_advisory_xact_lockfails fast if another node holds the lock — the losing node logs "Another node handled maintenance" and exits
Advisory locks ensure exactly one node performs token rotation while maintaining high availability.