File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 1+ // Package infra provides distributed locking for infrastructure provisioning.
2+ //
3+ // This implementation uses a naive "single instance" Redis distributed locking algorithm
4+ // as described in https://redis.io/docs/latest/develop/use/patterns/distributed-locks/
5+ //
6+ // We use the simple SET NX PX pattern which has edge cases where multiple nodes may
7+ // acquire the lock under extreme circumstances (see the Redis documentation for details).
8+ // We accept these edge cases because:
9+ //
10+ // 1. Infrastructure provisioning is infrequent and can tolerate occasional race conditions
11+ // 2. Cloud providers (AWS, GCP, Azure) handle concurrent provisioning attempts gracefully
12+ // 3. In the worst case, if provisioning fails due to a conflict, the node won't be able
13+ // to start and will fail its health check, allowing another node to take over
14+ //
15+ // This locking mechanism is primarily needed during the initial infrastructure setup.
16+ // Once infrastructure is provisioned on first startup, subsequent nodes will detect it
17+ // already exists and skip provisioning entirely.
18+
119package infra
220
321import (
You can’t perform that action at this time.
0 commit comments