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...

  • Replace microgen with the maintained fork

    Replace microgen with the maintained fork

    Hi, I'm Shay from Reco - we are maintaining a fork of microgen which is more updated (the original repo is practically abandoned).

    Suggesting this update after this discussion in Slack: https://gophers.slack.com/archives/C04S3T99A/p1672303249635659?thread_ts=1672237987.314089&cid=C04S3T99A

  • [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

Create production ready microservices mono repo pattern wired with Neo4j. Microservices for other languages and front end repos to be added as well in future.
Create production ready microservices mono repo pattern wired with Neo4j. Microservices for other languages and front end repos to be added as well in future.

Create Microservices MonoRepo in GO/Python Create a new production-ready project with backend (Golang), (Python) by running one CLI command. Focus on

Oct 26, 2022
Go-kit-microservices - Example microservices implemented with Go Kit

Go Kit Microservices Example microservices implemented with go kit, a programmin

Jan 18, 2022
Go Micro: a standard library for distributed systems development

Go Micro Go Micro is a standard library for distributed systems development. Ove

Oct 4, 2022
A gateway to expose s3 standard API for any storage type.

s3-gateway this project is used to be compatible with any other storage type. there are tons of object storage services in the internat. However, many

Nov 28, 2021
Zeebe.io - Workflow Engine for Microservices Orchestration

Distributed Workflow Engine for Microservices Orchestration

Jan 2, 2023
Design-based APIs and microservices in Go
Design-based APIs and microservices in Go

Goa is a framework for building micro-services and APIs in Go using a unique design-first approach. Overview Goa takes a different approach to buildin

Jan 5, 2023
goTempM is a full stack Golang microservices sample application built on top of the Micro platform.
goTempM is a full stack Golang microservices sample application built on top of the Micro platform.

goTempM is a full stack Golang microservices sample application built on top of the Micro platform.

Sep 24, 2022
Sample cloud-native application with 10 microservices showcasing Kubernetes, Istio, gRPC and OpenCensus.
Sample cloud-native application with 10 microservices showcasing Kubernetes, Istio, gRPC and OpenCensus.

Online Boutique is a cloud-native microservices demo application. Online Boutique consists of a 10-tier microservices application. The application is

Dec 31, 2022
Microservices using Go, RabbitMQ, Docker, WebSocket, PostgreSQL, React
Microservices using Go, RabbitMQ, Docker, WebSocket, PostgreSQL, React

Microservices A basic example of microservice architecture which demonstrates communication between a few loosely coupled services. Written in Go Uses

Jan 1, 2023
Go microservices with REST, and gRPC using BFF pattern.
Go microservices with REST, and gRPC using BFF pattern.

Go microservices with REST, and gRPC using BFF pattern. This repository contains backend services. Everything is dockerized and ready to

Jan 4, 2023
TinyHat.Me: Microservices deployed with Kubernetes that enable users to propose hat pictures and try on hats from a user-curated database.
TinyHat.Me: Microservices deployed with Kubernetes that enable users to propose hat pictures and try on hats from a user-curated database.

Click here to see the "buggy" version ?? The Scenario TinyHat.Me is an up and coming startup that provides an API to allow users to try on tiny hats v

Jun 17, 2022
This is an example to demonstrate implementation golang microservices using domain driven design principles and sugestions from go-kit

go-kit DDD Domain Driven Design is prevelent and rising standard for organizing your microservice code. This design architecture emphasis on Code orga

Feb 9, 2022
Box is an incrementally adoptable tool for building scalable, cloud native, microservices.

Box is a tool for building scalable microservices from predefined templates. Box is currently in Beta so if you find any issues or have some ideas

Feb 3, 2022
Best microservices framework in Go, like alibaba Dubbo, but with more features, Scale easily.
Best microservices framework in Go, like alibaba Dubbo, but with more features, Scale easily.

Best microservices framework in Go, like alibaba Dubbo, but with more features, Scale easily.

Dec 30, 2022
Access to b2c microservices through this service
Access to b2c microservices through this service

API service Access to b2c microservices through this service Config file Create config file with services addresses. Services: vdc - get camera inform

Nov 8, 2021
This is demo / sample / example project using microservices architecture for Online Food Delivery App.

Microservices This is demo / sample / example project using microservices architecture for Online Food Delivery App. Architecture Services menu-servic

Nov 21, 2022
Goya circuit is a circuit breaker mechanism implementation in microservices.

Goya-Circuit: 类似于Hystrix的熔断器实现 Goya circuit is a circuit breaker mechanism implementation in microservices. It can prevent the whole link avalanche ca

Mar 8, 2022
Example golang microservices deployed on kubernetes.
Example golang microservices deployed on kubernetes.

Tech Stack Golang RabbitMQ Docker K8S MongoDB Services There are two services which communicate via http(sync) and rabbitmq(async). Services opened to

Sep 6, 2022
A microservices-demo service that provides catalogue/product information.

A microservices-demo service that provides catalogue/product information. This service is built, tested and released by travis.

Nov 22, 2021