dsync is a sync library for distributed Go processes.
It works similarly to the built-in sync library, only it synchronizes across multiple processes - even on different machines.
This is achieved by storing the semaphore state and the value on a remote database.
Currently only DynamoDB is implemented. This might change in the future (Redis is considered currently).
- DB access for the chosen implementation
$ export AWS_ACCESS_KEY=access
$ export AWS_SECRET_KEY=secret
// ./main.go
package main
import "github.com/greg-szabo/dsync/ddb/sync"
func main() {
m := sync.Mutex{}
m.Lock()
defer m.Unlock()
// do important work here
return
}
$ go get github.com/greg-szabo/dsync/ddb/sync
$ go run main.go
The locking mechanism will automatically create a Locks
database in DynamoDB and stores the Mutex details.
Configuration parameters are described in the API documentation.
Shout out to Ryan Smith who created ddbsync which has a similar concept. Among others, his work inspired this library.