SEEK blog
Published in

SEEK blog

Microservices in Go

Photo by Simon Abrams on Unsplash

Introduction to the frameworks

Go Micro

  • Service discovery - applications automatically registered with service discovery system.
  • Load balancing - client side load balancing used to balance requests between instances of a service.
  • Synchronous communication - request/response transport layer provided.
  • Asynchronous communication - built in publish/subscribe capabilities.
  • Message encoding - encoding/decoding based on Content-Type header of a message.
  • RPC Client/Server packages - leverage the above features and expose interface to build microservices.
Figure 1. Go Micro architecture
  • Broker - provides an interface to a message broker for asynchronous pub/sub communication.
  • Codec - used for encoding/decoding messages. Supported formats include json, bson, protobuf, msgpack, etc.
  • Registry - provides a service discovery mechanism (default is Consul).
  • Selector - load balancing abstraction which builds on the registry. It allows services to be “selected” using such algorithms as random, roundrobin, leastconn, etc.
  • Transport - interface for synchronous request/response communication between services.

Go Kit

  • No global state
  • Declarative composition
  • Explicit dependencies
  • Interfaces as contracts
  • Domain driven design
  • Authentication - basic and JWT.
  • Transport - HTTP, Nats, gRPC, and others.
  • Logging - generic interface for structured logging in services.
  • Metrics - CloudWatch, Statsd, Graphite, and others.
  • Tracing - Zipkin and Opentracing.
  • Service discovery - Consul, Etcd, Eureka, and others.
  • Circuitbreaker - Hystrix implementation in Go.
Figure 2. Example of the service architecture built with Go Kit (original image is in “Go + microservices” slides)


  • server - offers two server implementations: SimpleServer (over HTTP), RPCServer (over gRPC).
  • server/kit - experimental package based on Go Kit.
  • config - contains functions to configuration from JSON files, JSON blobs in Consul k/v, or environment variables.
  • pubsub - provides generic interfaces for publishing and consuming data from the queues.
  • pubsub/pubsubtest - contains test implementations of the publisher and subscriber interfaces.
  • web - exposes functions for parsing types from request queries and payloads.


Comparing the frameworks

  • Objective comparison - GitHub statistics
  • Documentation and examples
  • Users and community
  • Code quality.

GitHub statistics

Table 1. Go microservices frameworks statistics (collected in April 2018)

Documentation and examples

Users and community

Code quality

Coding microservices

Figure 3. Practical example architecture
  • Service should self register with the Service Discovery system.
  • Service should have health check endpoint.
  • Service should support at least HTTP and gRPC transports.

Go Micro greeter

Greeter service protobuf definition
gRPC service implementation in Go Micro
Web service implementation in Go Micro

Go Kit greeter

  • Service logic implementation.
  • Transport agnostic Service endpoints.
  • Transport specific endpoints (gRPC, HTTP)
  • Service discovery registrar.
Service logic implementation in Go Kit
Go Kit service endpoints definition (transport agnostic)
Go Kit service HTTP endpoints
Service interface generator from protobuf definition
Go Kit service gRPC endpoints
Go Kit service discovery registrar
Go Kit service starter
Service level logging middleware
Endpoints level logging middleware

Gizmo greeter

Gizmo greeter endpoints
Gizmo greeter HTTP endpoints
GIzmo greeter gRPC




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store