Kolbis Guy
3 min readNov 5, 2020

--

Writing Microservices using Go-Kit toolkit

Ahoy!

In this post, I will share my experience with building microservices in GO using Go-Kit and will introduce corego and go-kit-user-ms-example repositories.

For a long while I have been hearing and reading about GO, yet I had no opportunity to get my head around it. GO seems to be the language of the cloud, as many of the interesting projects decided to use it. It includes kubernetes, helm, flux and other cool CNCF projects.

So, if you are building software for the cloud, making it cloud native seems to be a great decision. As contrary to the great cloud native tools (like kuberbetes), my goal was to design and build, using GO, microservices to run business services.

Go-Kit is one of the popular toolkit for building microservices in GO. It does a lot of heavy lifting when you get started. It was written back in 2015 by peter bourgon. I like the fact that Go-Kit is opinionated in the way you need to structure your microservices (transport layer, endpoint layer and service layer) which ensures a common standard among the development teams.

There are a few things that Go-Kit falls short:

  • Documentation and examples are lacking. I could not find a (production) real world example for building microservices powered by Go-Kit.
  • While working with Go-Kit, I found there important concepts which are missing: Configuration management, “Context Transport” (passing context between microservices), Working with databases, Handling execution fallbacks and more.
  • Go-Kit provides many integrations. For example, it provides service discovery integrations with: consul, DNS, etcd, zoo keeper and euroka. I was looking for a more opinionated and focus integrations.
  • Go-Kit comes with a lot of boilerplate code.

I wanted to assist others that also decide to walk my road. For that, I had built two repositories:

corego

corego aims to:

  • Be more opinionated
  • Add missing important infrastructure concepts for building microservices

Be more opinionated

As explained, out of the box, you are getting different integrations. For service discovery, it integrates with: consul, DNS, etcd, zoo keeper and eurokato. This variety also exist for tracing, logging, transporting and metrics.

corego tries to be more opinionated and focus on selected integrations:

  • consul and coreDNS for service discovery
  • consul as remote KV
  • zap as logger
  • prometheos and datadog for metrics
  • zipkin for tracing
  • cassandra, elastic, mongo for databases
  • rabbit for amqp transport

Missing important infrastructure

I found there are still missing important concepts which are needed to build a real world microservices in GO. Some of these components are:

  • Configuration management
  • Transporting context between microservices (for example passing correlation-id, deadline, duration)
  • Working with databases
  • Handling execution fallbacks
  • Working with errors

go-kit-user-ms-example

GO-KIT-USER-MS-EXAMPLE repo aims to help those who are considering using GO-KIT and want to see how to build a real world microservice in GO using Go-Kit and corego.

Each microservice has three projects:

  • svc which holds the server side of the microservice. The example server hosts http endpoints and rabbitMQ endpoints
  • client which holds the client library to communicate with the service. It uses retry, service breaker, consul service discovery and more.
  • shared which holds a shared model between the client and server

I plan to add more documentation and explanation on how to run the examples. If you have any trouble, feel free to drop me a line (question) in the git repo. Also, I plan to keep working on corego and add support for additional core microservices functionality.

Let me know what you think!

--

--

Kolbis Guy

Developer, entrepreneur, CTO, Husband and father