Skip to content
This repository has been archived by the owner. It is now read-only.
Deprecated: Moved to go-micro/sync
Branch: master
Clone or download
Latest commit 193f7af May 21, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
data update addr parsing May 20, 2019
event add comment Nov 11, 2018
leader add leader comment Nov 11, 2018
lock update addr parsing May 20, 2019
task Add broker task runner Feb 18, 2019
time add local time Feb 18, 2019
LICENSE First Oct 15, 2018 reorder list Nov 13, 2018
cron.go resign leadership Nov 11, 2018
db.go rework interfaces again Nov 13, 2018
go.mod Added go mod support May 7, 2019
go.sum Added go mod support May 7, 2019
options.go rename store to data and map to db Nov 13, 2018
sync.go rework interfaces again Nov 13, 2018

Go Sync License GoDoc

Go Sync is a synchronization framework for distributed systems.


Distributed systems by their very nature are decoupled and independent. In most cases they must honour 2 out of 3 letters of the CAP theorem e.g Availability and Partitional tolerance but sacrificing consistency. In the case of microservices we often offload this concern to an external database or eventing system. Go Sync provides a framework for synchronization which can be used in the application by the developer.

Getting Started

  • Data - simple distributed data storage
  • Leader - leadership election for group coordination
  • Lock - distributed locking for exclusive resource access
  • Task - distributed job execution
  • Time - provides synchronized time


The Lock interface provides distributed locking. Multiple instances attempting to lock the same id will block until available.

import ""

lock := consul.NewLock()

// acquire lock
err := lock.Acquire("id")
// handle err

// release lock
err = lock.Release("id")
// handle err


Leader provides leadership election. Useful where one node needs to coordinate some action.

import (

l := consul.NewLeader(

// elect leader
e, err := l.Elect("id")
// handle err

// operate while leader
revoked := e.Revoked()

for {
	select {
	case <-revoked:
		// re-elect
		// leader operation

// resign leadership


Data provides a simple interface for distributed data storage.

import (

keyval := consul.NewData()

err := keyval.Write(&data.Record{
	Key: "foo",
	Value: []byte(`bar`),
// handle err

v, err := keyval.Read("foo")
// handle err

err = keyval.Delete("foo")


Task provides distributed job execution. It's a simple way to distribute work across a coordinated pool of workers.

import (

t := local.NewTask(

err := t.Run(task.Command{
	Name: "atask",
	Func: func() error {
		// exec some work
		return nil

if err != nil {
	// do something


Time provides synchronized time. Local machines may have clock skew and time cannot be guaranteed to be the same everywhere. Synchronized Time allows you to decide how time is defined for your applications.

import (

t := ntp.NewTime()
time, err := t.Now()


  • Event package - strongly consistent event stream e.g kafka
You can’t perform that action at this time.