A standard library for microservices.

Go kit

GitHub Workflow Status GoDev codecov Go Report Card Sourcegraph

Go kit is a programming toolkit for building microservices (or elegant monoliths) in Go. We solve common problems in distributed systems and application architecture so you can focus on delivering business value.

Sponsors

Click on Sponsor, above, for more information on sponsorship.

Motivation

Go has emerged as the language of the server, but it remains underrepresented in so-called "modern enterprise" companies like Facebook, Twitter, Netflix, and SoundCloud. Many of these organizations have turned to JVM-based stacks for their business logic, owing in large part to libraries and ecosystems that directly support their microservice architectures.

To reach its next level of success, Go needs more than simple primitives and idioms. It needs a comprehensive toolkit, for coherent distributed programming in the large. Go kit is a set of packages and best practices, which provide a comprehensive, robust, and trustable way of building microservices for organizations of any size.

For more details, see the website, the motivating blog post and the video of the talk. See also the Go kit talk at GopherCon 2015.

Goals

  • Operate in a heterogeneous SOA — expect to interact with mostly non-Go-kit services
  • RPC as the primary messaging pattern
  • Pluggable serialization and transport — not just JSON over HTTP
  • Operate within existing infrastructures — no mandates for specific tools or technologies

Non-goals

  • Supporting messaging patterns other than RPC (for now) — e.g. MPI, pub/sub, CQRS, etc.
  • Re-implementing functionality that can be provided by adapting existing software
  • Having opinions on operational concerns: deployment, configuration, process supervision, orchestration, etc.

Contributing

Please see CONTRIBUTING.md. Thank you, contributors!

Dependency management

Go kit is modules aware, and we encourage users to use the standard modules tooling. But Go kit is at major version 0, so it should be compatible with non-modules environments.

Code generators

There are several third-party tools that can generate Go kit code based on different starting assumptions.

Related projects

Projects with a ★ have had particular influence on Go kit's design (or vice-versa).

Service frameworks

  • gizmo, a microservice toolkit from The New York Times ★
  • go-micro, a distributed systems development framework ★
  • gotalk, async peer communication protocol & library
  • Kite, a micro-service framework
  • gocircuit, dynamic cloud orchestration

Individual components

Web frameworks

Additional reading

Owner
Go kit
A Go toolkit for microservices.
Go kit
Comments
  • Explain why Logger.log() returns error

    Explain why Logger.log() returns error

    Hi,

    I think go-kit/kit/log reflects my personal thoughts on logging, but I am hesitant to use it directly due to Logger.log() returning an error. In my opinion errors are intended to be checked, not ignored. And it's unreasonable to ask users to check log messages. I feel a better philosophy is for the formatters/writers that eventually output messages to disk/tcp/stdout/etc to allow registering handlers for error types. Then, when I setup logging I can say "Here is a logger that logs JSON to a file. If there is an error, call this function (maybe try stdout or maybe trigger some application "debug me" state).

    Maybe something like

    type jsonLogger struct {
      io.Writer
      onError func(err error, keyvals ...interface{})
    }
    
  • Discussion: package pubsub

    Discussion: package pubsub

    I'd like to start thinking about a design for package pubsub/msgbus/...

    Important use cases:

    • An async transport for existing/typical RPC messaging
    • A foundation for event sourcing
    • A way to manage streaming
    • Others?

    Would like support for:

    • Kafka
    • RabbitMQ
    • NATS
    • NSQ
    • AWS SQS
    • GCP PubSub
    • Weave Mesh
    • Others?

    Prior art:

    Open questions:

    • What are the core abstractions and interfaces?
    • Is streaming significantly different than event sourcing and transport use cases?
    • What is the lowest common denominator for serialization?
    • Others?
  • package log, alternate take

    package log, alternate take

    Inspired by #16 and the discussion there. @ChrisHines, this isn't very far along, but I'd appreciate your feedback to the general approach, which closely mirrors package metrics...

  • Extract github.com/go-kit/kit/log to github.com/go-kit/log

    Extract github.com/go-kit/kit/log to github.com/go-kit/log

    I have several use cases, now, where it would be beneficial if projects could use Go kit's package log without pulling in anything else. I would like to extract it to it's own module and package, tentatively named kitlog to avoid the name collision. And then I would like to point the existing package at it, maybe with type aliases if they are up for the task.

    @ChrisHines — Do you think this is a reasonable idea, and is feasible? Can you identify any blockers?

  • AMQP Transport

    AMQP Transport

    Hello,

    I noticed that here had been interest in AMQP transport similiar to NATS (#681) as well as talks of pubsub support (#295) so I thought I might like to share an implementation of a simple AMQP client & server transport.

    Comments/Reviews would be appreciated.

  • log/alt_experimental_level: concept demonstration

    log/alt_experimental_level: concept demonstration

    As a foil to #357 and following up on #368, demonstrate an alternate approach to the "level" package offered via the "github.com/go-kit/kit/log/experimental_package" import path, allowing log event level filtering via instances of the (unexported) level.leveler interface, created by functions that specify the filtering threshold.

    Features not accommodated here for now:

    • Returning an error from log.Log when squelching an event
    • Returning an error from log.Log for events that lack a level
      (This feature doesn't make much sense with this approach.)
    • Squelching events that lack a level
      (This feature doesn't make much sense with this approach.)
    • Documentation
      (We could adapt much of this from the sibling package.)

    See the commit message for then benchstat comparison.

  • Example : Ensure that http connection will be re-use

    Example : Ensure that http connection will be re-use

    Hello, It will be great into example to ensure that http connection will be re-use by ensuring that Body has be completely purged. That avoid performance problem for whom that use this example as primary guide.

    For example for https://github.com/go-kit/kit/blob/master/examples/stringsvc3/transport.go#L50, add something like this :

    func decodeUppercaseResponse(_ context.Context, r *http.Response) (interface{}, error) {
        // This defer ensures to reuse the tcp connection via HTTP/1.1
        defer io.Copy(ioutil.Discard, r.Body)
    
        var response uppercaseResponse
    

    Thx.

  • kitgen implementation

    kitgen implementation

    So far what I've got is simple generation based on a basic interface definition.

    Not complete: different layout engines.

    Specific design decision here was to construct the generated AST and then format it out, as opposed to using a text/template. There's some things that are made much easier this way (i.e. the output is more likely to be correct code), but the generation code is a bit more opaque. In working with this process I've found a few things that make the process clearer, and I'm looking to implement those before this is merged. Specifically, I think many of the repeated structures could be snagged from an example codefile and then processed into target structures, rather than built out of whole cloth or partial inline parses.

  • Configuration

    Configuration

    Filing an issue so we consider unified configuration of some kind.

    Motivating example (though definitely not the only case): let's say a gokit process does want to do Dapper/Zipkin style tracing. The process will need to know where to forward the tracing information to, which won't be known at compile time.

    It would be nice if all of the gokit packages were configured in the same or similar way, so that as they are used modularly, configuration of subpackages happens automatically, with little programmer assistance.

  • Add support for Twirp as a Transport

    Add support for Twirp as a Transport

    Twirp (https://github.com/twitchtv/twirp) is an RPC system that works over HTTP/1.1 using either JSON or Protobuf. It's leverages protobuf for generating servers and clients.

    I still need to do a few things, but wanted to get initial feedback.

    Todo

    • [ ] Add tests (planning to mirror what GRPC has)
    • [ ] Add Twirp support to addsvc example
    • [ ] Add documentation
  • Go kit 0.4.0 release

    Go kit 0.4.0 release

    Edit: Due to lots of feature churn in the last few weeks/months, I've been convinced that it makes more sense to hold off on a 1.0.0 until things settle. Notes in comments below.

    Hello! I want to cut a v1.0.0 release in the near future. This issue is created per the request of @ChrisHines to serve as a notice to anyone who may be interested, for example to raise questions, concerns, or propose specific additions.

    The only thing outstanding that I'd like to get in is a promotion of log/experimental_level to log/level. I've asked @seh to weigh in on that, as he's previously commented on the package. Otherwise, let me know your thoughts. I'll leave this open until at least the weekend, so another 5 days.

    edit: outstanding issues I'd want to resolve before a 1.0.0

    • [x] #476 — Merge log/experimental_level to level; move existing levels to deprecated_levels
    • [x] #420 / #421 — use stdlib context where possible
    • [x] #432 / #437 — log: StdlibAdapter "file" key to "caller"
    • [x] Optional: #434 — log: normalize StdlibAdapter timestamp format
    • [x] Optional: #431 — transport: implement http.EncodeJSONRequest
    • [x] Evaluate breaking change: #474 — Replace log.Context with log.With/WithPrefix?

    If anyone feels strongly about either of those two Optionals, (cc: @willfaught) please get your PRs in within the next few days...

  • [NATS transport] Support for headers in EncodeJSONResponse

    [NATS transport] Support for headers in EncodeJSONResponse

    What would you like?

    Overview

    Since release v1.11.0, nats.go supports message headers. headers are very useful to transfer metadata together with messages.

    I'm proposing to add basic support for headers in the default response encoder.

    Proposed API

    The idea is to do something similar it's done for transport/http with the Headerer interface. API change proposal is backward compatible (no public API change)

    type Headerer interface {
        Headers() Header
    }
    
    func EncodeJSONResponse(_ context.Context, reply string, nc *nats.Conn, response interface{}) error {
            msg := nats.NewMessage(reply)
            if nc. HeadersSupported() {
                    if headerer, ok := response.(Headerer); ok {
                             msg.Header = headerer.Headers()  // I wrote that to make it shorter
                    }
            }
    
    	msg.Data, err := json.Marshal(response)
    	if err != nil {
    		return err
    	}
    
    	return nc.PublishMsg(msg)
    }
    

    If the proposal is accepted I can raise a PR

  • metrics/dogstatsd: always reset all metrics before writing them when calling WriteTo

    metrics/dogstatsd: always reset all metrics before writing them when calling WriteTo

    Description

    This PR fixes an issue that occurred when the Dogstatsd client could not reach the Datadog agent to send metrics. It would fail to send counters, return and never reset timings and histograms, resulting in an ever-increasing memory consumption while the client cannot reach the Datadog agent.

  • Consul Implementation of Instancer spams Consul and pushes consul agents to 100% CPU

    Consul Implementation of Instancer spams Consul and pushes consul agents to 100% CPU

    What did you do?

    Using the GoKit implementation of Instancer for Consul in GoKit 0.11 and up results in Instancer spamming Consul with hundreds of RPC requests/sec on any register/deregister event that occurs after the Instancer is created. This resulted in our Consul agent pods going to 100% CPU and overwhelming our Consul cluster.

    Steps to re-create:

    1. Start Consul

    2. Register a dummy service

    curl --location --request PUT 'http://localhost:8500/v1/agent/service/register' \ --header 'Content-Type: application/json' \ --data-raw '{ "name": "db-example", "id": "db-example", "address": "127.0.0.1", "port": 5432, "tags": [ "database" ] }'

    1. Open a terminal and run the following command to get insights into what the Consul agent is doing

    consul monitor -log-level=trace

    1. Create Instancer for db-example service (see sample code below) and run app/code

    2. Deregister the service

    curl --location --request PUT 'http://localhost:8500/v1/agent/service/deregister/db-example'

    Observe the behavior from consul monitor, the agent is getting slammed with requests and it never stops until the Instancer is stopped or application exits.

    Simple example application.

    package main
    
    import (
    	"fmt"
    	"github.com/go-kit/kit/log"
    	"github.com/go-kit/kit/sd"
    	"github.com/hashicorp/consul/api"
    	"time"
    
    	"github.com/go-kit/kit/sd/consul"
    )
    
    func main() {
    
    	apiClient, err := api.NewClient(api.DefaultConfig())
    	if err != nil {
    		panic(err)
    	}
    	client := consul.NewClient(apiClient)
    
    	instancer := consul.NewInstancer(client, log.NewNopLogger(), "db-example", []string{}, true)
    
    	events := make(chan sd.Event, 1)
    	go func() {
    		instancer.Register(events)
    	}()
    
    	go func() {
    		for event := range events {
    			fmt.Println(event.Instances)
    		}
    	}()
    
    	time.Sleep(1 * time.Hour)
    }
    

    What did you expect?

    Consul agent should not be getting spammed with hundreds of requests a second.

    What happened instead?

    Instancer spammed Consul with way too many requests and drove the CPU utilization to 100%.

    7.0.0.1:53702 latency=9.375µs 2022-02-12T18:06:20.710-0500 [DEBUG] agent.http: Request finished: method=GET url=/v1/health/service/db-example?index=155&passing=1 from=127.0.0.1:53702 latency=12.208µs 2022-02-12T18:06:20.710-0500 [DEBUG] agent.http: Request finished: method=GET url=/v1/health/service/db-example?index=155&passing=1 from=127.0.0.1:53702 latency=162.792µs 2022-02-12T18:06:20.710-0500 [DEBUG] agent.http: Request finished: method=GET url=/v1/health/service/db-example?index=155&passing=1 from=127.0.0.1:53702 latency=54.791µs

  • Mismatch of the tutorial section of stringsvc example and its full code

    Mismatch of the tutorial section of stringsvc example and its full code

    What would you like?

    I have noticed a couple of differences between the tutorial section of the stringsvc3 example and its full source code. It is worth mentioning the differences are about different imports, or different number of parameters of a particular function. I was wondering which one is the most up to date one?

a Framework for creating microservices using technologies and design patterns of Erlang/OTP in Golang
a Framework for creating microservices using technologies and design patterns of Erlang/OTP in Golang

Technologies and design patterns of Erlang/OTP have been proven over the years. Now in Golang. Up to x5 times faster than original Erlang/OTP in terms

Dec 28, 2022
Golang client library for adding support for interacting and monitoring Celery workers, tasks and events.

Celeriac Golang client library for adding support for interacting and monitoring Celery workers and tasks. It provides functionality to place tasks on

Oct 28, 2022
dht is used by anacrolix/torrent, and is intended for use as a library in other projects both torrent related and otherwise

dht Installation Install the library package with go get github.com/anacrolix/dht, or the provided cmds with go get github.com/anacrolix/dht/cmd/....

Dec 28, 2022
A feature complete and high performance multi-group Raft library in Go.
A feature complete and high performance multi-group Raft library in Go.

Dragonboat - A Multi-Group Raft library in Go / 中文版 News 2021-01-20 Dragonboat v3.3 has been released, please check CHANGELOG for all changes. 2020-03

Dec 30, 2022
Dynatomic is a library for using dynamodb as an atomic counter

Dynatomic Dynatomic is a library for using dynamodb as an atomic counter Dynatomic Motivation Usage Development Contributing Motivation The dynatomic

Sep 26, 2022
Library for enabling asynchronous health checks in your service

go-health A library that enables async dependency health checking for services running on an orchestrated container platform such as kubernetes or mes

Jan 4, 2023
Dec 27, 2022
Simple, fast and scalable golang rpc library for high load

gorpc Simple, fast and scalable golang RPC library for high load and microservices. Gorpc provides the following features useful for highly loaded pro

Dec 19, 2022
A library that implements the outboxer pattern in go

Outboxer Outboxer is a go library that implements the outbox pattern. Getting Started Outboxer was designed to simplify the tough work of orchestratin

Dec 16, 2022
🌧 BitTorrent client and library in Go
🌧 BitTorrent client and library in Go

rain BitTorrent client and library in Go. Running in production at put.io. Features Core protocol Fast extension Magnet links Multiple trackers UDP tr

Dec 28, 2022
A Go library for master-less peer-to-peer autodiscovery and RPC between HTTP services

sleuth sleuth is a Go library that provides master-less peer-to-peer autodiscovery and RPC between HTTP services that reside on the same network. It w

Dec 28, 2022
An experimental library for building clustered services in Go

Donut is a library for building clustered applications in Go. Example package main import ( "context" "log" "os" // Wait for etcd client v3.4, t

Nov 17, 2022
Go Library [DEPRECATED]

Tideland Go Library Description The Tideland Go Library contains a larger set of useful Google Go packages for different purposes. ATTENTION: The cell

Nov 15, 2022
Lockgate is a cross-platform locking library for Go with distributed locks using Kubernetes or lockgate HTTP lock server as well as the OS file locks support.

Lockgate Lockgate is a locking library for Go. Classical interface: 2 types of locks: shared and exclusive; 2 modes of locking: blocking and non-block

Dec 16, 2022
This library contains utilities that are useful for building distributed services.

Grafana Dskit This library contains utilities that are useful for building distributed services. Current state This library is still in development. D

Jan 2, 2023
A distributed systems library for Kubernetes deployments built on top of spindle and Cloud Spanner.

hedge A library built on top of spindle and Cloud Spanner that provides rudimentary distributed computing facilities to Kubernetes deployments. Featur

Nov 9, 2022
A distributed locking library built on top of Cloud Spanner and TrueTime.

A distributed locking library built on top of Cloud Spanner and TrueTime.

Sep 13, 2022
Raft library Raft is a protocol with which a cluster of nodes can maintain a replicated state machine.

Raft library Raft is a protocol with which a cluster of nodes can maintain a replicated state machine. The state machine is kept in sync through the u

Oct 15, 2021