A simple and neat way to build microservices

Meet Go micro, a zero-dependency microservice framework

Eirini-Eleni Papadopoulou
© Shutterstock / forden

Making use of the Go interface for its abstractions, Go micro is a pluggable framework for microservice development that promises to make building microservices a piece of cake.

Are you ready for a simple and neat way to build microservices? Then let’s take a closer look at Go micro, a pluggable framework for microservice development.

Go micro takes advantage of the Go interface for its abstractions and provides the core requirements for distributed systems development including RPC and event-driven communication.

Time to check out the most interesting features and the framework’s architecture.

The features

Service discovery – Automatic service registration and name resolution. Service discovery is at the core of micro service development. When service A needs to speak to service B it needs the location of that service. The default discovery mechanism is multicast DNS (mdns), a zeroconf system.

Load balancing – Client-side load balancing built on service discovery.

Message encoding  Dynamic message encoding based on content-type. The client and server will use codecs along with content-type to seamlessly encode and decode Go types for you. Any variety of messages could be encoded and sent from different clients and the client and server handle this by default. This includes protobuf and json by default.

Sync streaming  RPC based request/response with support for bidirectional streaming that provides an abstraction for synchronous communication. A request made to a service will be automatically resolved, load balanced, dialed and streamed.

Async messaging  PubSub is built in as a first-class citizen for asynchronous communication and event-driven architectures. Event notifications are a core pattern in microservice development.

Pluggable interfaces  Makes use of Go interfaces for each distributed system abstraction. Because of this these interfaces are pluggable and allows Go Micro to be runtime agnostic. You can plug in any underlying technology. Find the extensive list of plugins here.

SEE ALSO: 5 open source Go tools for tuning up your Golang mastery

Taking a closer look at this tool, it is definitely worth mentioning that Go micro is composed of a number of packages. Namely:

  • Transport for sync messaging – Interface for synchronous request/response communication between services. It’s akin to the Golang net package but provides a higher level abstraction which allows you to switch out communication mechanisms. It also supports bidirectional streaming.
  • Broker for async messaging – Provides an interface to a message broker for asynchronous pub/sub communication. This is one of the fundamental requirements of an event-driven architecture and microservices.
  • Codec for message encoding – Used for encoding and decoding messages before transporting them across the wire. Where this differs from most other codecs is that we actually support the RPC format here as well.
  • Registry for service discovery – Provides a service discovery mechanism to resolve names to addresses. Services should register using the registry on startup and deregister on shutdown.
  • Selector for load balancing – Load balancing abstraction which builds on the registry. It allows services to be “filtered” using filter functions and “selected” using a choice of algorithms.
  • Server for handling requests – The building block for writing a service. The service builds on the above packages to provide a unified interface for serving requests.
  • Client for making requests – Provides an interface to make requests to services. Again like the server, it builds on the other packages to provide a unified interface for finding services by name using the registry, load balancing using the selector, making synchronous requests with the transport and asynchronous messaging using the broker.

Head over to the official documentation or Go micro’s GitHub repo to find more information on this tool.

Getting started

If you want to give Go micro a try, you can do so by running:

go get

Check out the ‘install guide‘ for all the relevant information.

Eirini-Eleni Papadopoulou
Eirini-Eleni Papadopoulou was the editor for Coming from an academic background in East Asian Studies, she decided that it was time to go back to her high-school hobby that was computer science and she dived into the development world. Other hobbies include esports and League of Legends, although she never managed to escape elo hell (yet), and she is a guest writer/analyst for competitive LoL at TGH.

Inline Feedbacks
View all comments