04
Product
16
Backend
09
Auth
12
iOS
07
Infra
02
Real-Time

Use PostgreSQL advisory locks for coordination

ADR-0022 ACCEPTED · 2025-07-24
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_lock fails 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.