Lockgate is a distributed locking library for Go that supports file-based locks on a single host, Kubernetes-backed distributed locks, and HTTP-based locks across multiple hosts.
The library addresses the need to synchronize access to shared resources across multiple processes running on single or multiple hosts. It provides a classical locking interface with two lock types (shared and exclusive) and two modes (blocking and non-blocking). For Kubernetes-based locking, the tool stores locks in annotations of an arbitrary Kubernetes resource and uses native Kubernetes optimistic locking to handle concurrent access. The HTTP locker approach allows clients to connect to a lockgate lock server, which can run as a standalone process or multiple Kubernetes-backed instances, with support for in-memory or Kubernetes key-value storage. Clients waiting on locks can be placed in a FIFO queue to ensure fairness, with an "Acquirer Id" mechanism to serialize access for long-held locks.
Developers should choose this library when they need to coordinate multiple processes across hosts and have an existing Kubernetes cluster or can deploy an HTTP lock server. The file locker suits single-host scenarios where multiple processes share a filesystem. The Kubernetes locker is appropriate for teams already running Kubernetes and wanting to avoid additional infrastructure. The HTTP locker provides flexibility for deployments that need a dedicated locking service, with the option to run it standalone or backed by Kubernetes. The library is actively used in the werf CI/CD tool for synchronizing build and deploy processes.
The project maintains active development with regular updates to its core locking implementations. The codebase shows consistent refinement of the Kubernetes locker's optimistic locking behavior and HTTP server functionality. Documentation is comprehensive, covering installation, usage patterns for each locker type, and practical examples. The project welcomes community contributions and maintains a feedback channel for users.