Amended by 0149: Postgres advisory
locks by default, TTL with auto-renew, fencing tokens and @WithLock.
Context
Workflows, scheduled jobs, idempotent consumers and money operations need mutual exclusion across processes. Medusa ships a locking module with providers for this. Without one package, each feature invents its own advisory-lock or cache trick. The client-side@stackra/coordinator (0084) covers tabs and processes on one device,
not servers.
Decision
@stackra/lockingprovides named, time-bound locks (acquire,release,withLock(key, ttl, fn)), ported from Medusa’s MIT locking module.- Drivers follow the instance-module pattern: Postgres advisory locks (the default, works on-prem and air-gapped), a Redis/Valkey driver and a memory driver for tests, each with a conformance suite (0076).
- Lock keys are tenant-scoped by default; a platform-wide lock is explicit.
- The scheduler’s on-prem advisory lock (0078 decision 6) uses this package.
- Package placement: runtime.
Consequences
- One place to reason about lock leaks and timeouts.
@stackra/coordinatorstays client-side; the two never share code.