Skip to content

Commit 013f7d3

Browse files
committed
chore: Add comment to explain the redislock implementation
1 parent 3c26e2d commit 013f7d3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

internal/infra/redislock.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
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+
119
package infra
220

321
import (

0 commit comments

Comments
 (0)