Looking for top Golang Developers? They are just a few clicks away.

Building a Microservice in Go/Golang: Business Guide

Mar 2, 202213 min read

Dawid Karczewski

Senior full stack developer and CTO at Ideamotive.

Building microservices in Go in 2023

Reflecting back from 2023, the Microservices Adoption report published by O'Reilly in 2020 underscored the increasing popularity of microservices and the triumphs experienced by companies that incorporated this architecture. This comprehensive study, which surveyed 1,500 individuals comprising software engineers, technical architects, and decision-makers, revealed that 77% of enterprises had embraced microservices. Furthermore, an impressive 92% of these reported a high degree of satisfaction with their decision to adopt this architectural style, highlighting its potential in enhancing software development and deployment processes.

 

In addition, microservices are becoming one of the leading software architectures due to their scalable framework. According to this report, almost 85% of senior engineers and managers believe that microservices will become the standard for back-end development and complex systems.

 

In 2023, the microservices trend is booming. But are microservices right for your project? Should you turn to Go/Golang developers for this purpose?

 

These questions can be answered by explaining what microservices are, how they differ from a monolithic architecture, and how Google’s programming language can assist you in this matter.

 

Let’s finally plunge into it!

Microservice: basics

What is microservice architecture?

Microservices architecture is a development methodology where you can break a single application into a number of smaller services, each running in its own process and interacting with lightweight mechanisms. 

 

Microservices are designed with business capabilities in mind, which can be deployed independently using an automated deployment mechanism. The architecture of microservices requires minimal management of these services built in different programming languages ​​and using different data storage technologies.

Microservices vs Monolithic architecture

Building a Microservice in Go Business Guide - Microservice Architecture

 

Microservices or microservices architecture is a software development approach that allows you to structure an application as a collection of small services within a business domain. In other words, the software is made up of small, independent services that communicate through well-defined application programming interfaces (APIs).

 

Building a Microservice in Go Business Guide - Monolithic Architecture

 

Monolithic architecture is the exact opposite of microservices. With this method, the entire software is a single piece designed as standalone. All components of a monolithic program are interconnected and interdependent.

 

 

Monolithic architecture is a common method for building applications. It makes it relatively easy to implement, develop, and test software. Thus, if you choose this method, you will receive the final product faster and at a better price. 

 

Monolithic architecture is a good choice for creating an experimental concept or for companies at the founding stage.

 

However, when your application needs increased scalability, it is better to use a microservices architecture. If you choose a monolithic application, you will need to modify the entire stack to make a small change. This is time-consuming, difficult, and risky as one point of failure can cause the entire program to fail. 

 

Microservices architecture means being able to change any function yourself - and avoid all the risks and additional costs.

What makes them so popular?

Netflix uses microservices to provide its popular video streaming service worldwide. Microservices are also used by global companies such as Amazon, Apple, and Uber. So it’s hard to say that this architecture type is mentioned only in narrow circles.

 

Let's see what business opportunities make microservices solutions so popular:

Compatibility

Microservices can be developed using different programming languages, frameworks, and even hardware without compromising interoperability.

Flexibility

The microservices architecture provides software flexibility, which means that you can always extend a microservices solution with new features and deploy new services independently of existing ones.

Simplicity

Microservices are simple because they are organized around business opportunities. Since each service is a separate block of code with its own database, testing and development become easier and take less time.

Reliability

In the event that one service stops working (due to maintenance or failures), its temporary unavailability will not affect the operation of the rest of the system.

Choosing the right tech stack

Once you have chosen microservices for your project, the next step is to choose the technology that will allow you to get the most out of this architecture.

Criteria for choosing a microservices technology

As we already mentioned, various frameworks and programming languages can be used to develop microservices. However, the actual development process depends entirely on your requirements, which determine what works best for your solution. Choosing a programming language is one of the most important steps in the development process. 

 

In theory, any programming language will do. However, to avoid certain issues and maximize the benefits of microservices, the technology you use must meet the following requirements:

High processing performance

The microservices solution has to be as fast as possible with databases and routing.

The minimum number of third-party libraries. Most third-party libraries use licenses that are not suitable for enterprise solutions. In addition, although these libraries provide robust functionality, their use may not be safe from a cybersecurity point of view.

Embrace the culture of automation

Development and testing processes should be automated as much as possible to reduce the time required to implement software and reduce the risk of human error.

Decentralization of components

Each service should be decentralized to speed up software development and simplify maintenance.

Easiness to find support

The system should be designed in such a way that it is easy to find people who can support it.

Maintain a culture of continuous integration and deployment

This allows you to deploy and update the product as quickly as possible at a minimal cost. The CI/CD culture also makes development faster and easier. 

 

Verdict: Python, Java, JavaScript, .NET and Go fit the bill as they each boast a good level of readability and interoperability, and offer frameworks for developing microservice architectures. However, more and more companies are choosing Golang web development over other options ​​for developing microservices.

 

For instance, The Economist chose the Go language for developing microservices when moving from a monolith to a microservice architecture (primarily due to its excellent consistency with the platform architecture). In addition, Go's syntax is relatively simple, so it was easy to get started writing functional code right away. A quick victory for the team during the transition period.

Golang and microservices - a match made in heaven

There is no better union than Go and microservices. The Golang language meets and exceeds all the requirements outlined in the previous section. Here are a few more reasons why your business would benefit from building Golang microservices:

High readability and maintainability

Go is a simple language that is easy to learn, and this is perhaps the best feature of a programming language in terms of business processes. The syntax of Golang is relatively small and has been used for a long time without significant changes. Since there is no need to learn new paradigms or syntax, code written in Go is transparent and easy to understand.

 

This makes Go an ideal choice for backends, microservices, cloud computing systems, and more. In addition, its characteristics help mitigate the shortcomings of microservices: 

  • writing communication layers, 
  • handling service errors, 
  • working with a distributed architecture.

 

Golang's microservice architecture ensures that developers don't spend a lot of time reading other people's code and get up to speed faster. Even if you need to change the development team, you can still maintain and update your software without any problems.

Performance and speed

Golang compiles faster than most other languages, saving developers time and business owners money. Here are some of the reasons:

  • It has a faster compiler compared to other languages ​​such as C or C++.
  • Directed acyclic graphs and the absence of cycles allow packages to be compiled separately and in parallel.
  • The object file of a compiled Go package contains information about the package itself and its dependencies. To compile a package, the compiler must read the object file for each import, but it does not need to check any other files.

 

Go's performance is also excellent. Here are some tests illustrating that in many cases Golang outperforms popular programming languages

 

Building a Microservice in Go Business Guide - Python vs C#

 

Source: Benchmarks Game

Go complements the microservice architecture 

Due to the strict separation of modules. It promotes independent components to provide business logic that follows microservices design patterns. Not only that, but the effective size of the compiled Go binaries is indicative of the desired small design of the microservice itself.

Go keeps things simple

It promotes event-driven programming without the need for inheritance, callbacks, futures, promises, or strategies that can often lead to unnecessarily complex logic. Keeping it concise, Go microservices avoid being tied to each other by single job responsibilities.

Go uses the best of the world of programming

It provides:

  1. high compilation performance like C/C++, 
  2. efficient parallelization like Java, 
  3. readability like Python. 

 

It has its drawbacks, but its strengths make it a great addition to a microservice-based architecture.

Independent revision

Each microservice is independent from other microservices, it is encapsulated. Hence, you can change and update each microservice according to your requirements and revise independently. 

Polyglot development support

Developers can create each microservice using different development tools because it will not affect the development of other microservices. Similarly, each microservice can have a different database store. 

Flexibility in the release schedule

Because Golang microservices are independent of each other, they can have different release dates. As such, they are unrelated and have flexible release schedules.

Talent pool and popularity

After all, over 16,000 developers from a HackerEarth Insights survey found that Go was the most popular language to learn in 2020. Among students (29%) and experienced developers (32%), Go was the clear winner as the most in-demand programming language.

 

Moreover, the Go community boasts a huge number of Go bloggers. No wonder Go itself and Golang microservices are growing in popularity side by side. 

 

Undoubtedly, product owners won’t face Go web developers shortage in the coming years.

 

Building a Microservice in Go Business Guide - popular technologies

Golang microservices framework comparison 

Now let's discuss the frameworks we can use for microservice architecture. Frameworks that we will take into account are below:

  1. Go Micro
  2. Transition kit
  3. Gizmo
  4. Kite

Go micro

Go Micro is by far the most popular RPC framework we've come across. This is a pluggable RPC framework. Go Micro provides us with the following:

  • Service discovery. Applications are automatically registered in the service discovery system;
  • Load balancing. Provides client-side load balancing, which helps balance requests between service instances;
  • Synchronous communication. Provides transport layer Req/Res;
  • Asynchronous communication. Has built-in publish and subscribe capabilities;
  • Message encoding. Encoding and decoding based on the content type present in the header;
  • RPC client/server packages. Uses the above functions and provides access to the interface used when creating Golang microservices.

 

The Go Micro architecture can be represented as follows - 

 

Building a Microservice in Go Business Guide - go micro

 

This is a three-layer stack:

  1. The first level contains the abstraction of the service. 
  2. The second level is the client-server model. The server consists of blocks that are used when writing a service, while the client provides devs with an interface for the sole purpose of making requests to services written in the server model. 
  3. The third layer has plugins.

 

There are plugins of the following types:

  • Broker (provides an interface to a message broker in asynchronous communication)
  • Codec (used to encrypt or decrypt messages)
  • Registry (provides a service finder)
  • Selector (has a load balancing abstraction created in the registry)
  • Transport (channel for synchronous req/res communication between services)

It also provides a feature called Sidecar. Sidecar allows you to integrate services written in languages ​​other than Go. It also provides us with gRPC encoding/decoding, service registration, and HTTP handlers.

Go kit

Go Kit is a set of tools for building microservices. Unlike Go Micro, this is a library that can be imported as a binary package. The Go Kit rules are pretty simple:

  • No global state
  • Declarative composition
  • Explicit dependencies
  • Interface as contracts
  • Domain-Driven Design

The Go Kit provides you with packages for the following:

  • Authentication (BasicAuth and JWT)
  • Transport (HTTP, gRPC, etc.)
  • Logging (interface for structured logging in services)
  • Metrics (CloudWatch, Statsd, Graphite, and others)
  • Tracing (Zipkin and Opentracing)
  • Service discovery (Consul, Etcd, Eureka, etc.)
  • Circuit breaker (Hystrix implementation in Go)

The Go Kit service architecture looks like this - 

 

Building a Microservice in Go Business Guide - Go kit

Gizmo

Gizmo is a microservices toolkit from The New York Times. It provides packages to combine server and pubsub daemons. It provides the following packages:

  • Server (offers two server implementations: SimpleServer (via HTTP), RPCServer (via gRPC))
  • Server/Kit (experimental package based on Go Kit)
  • Configuration (contains functions for configuration from JSON files, JSON blobs in Consul k/v, or environment variables)
  • Pubsub (provides common interfaces for publishing and consuming data from queues)
  • Pubsub/pubsubtest (contains test implementations of the publisher and subscriber interfaces)
  • Web (provides functions for parsing types from requests and payloads)

 

The Pubsub package provides interfaces for working with the following queues:

  • pubsub/aws: for Amazon SNS/SQS
  • pubsub/gcp: for Google Pubsub
  • pubsub/kafka: for Kafka topics
  • pubsub/http: for publishing over HTTP

Gizmo is somewhere between Go Micro and Go Kit. It's not a complete “black box'' like Go Micro. At the same time, it is not as raw as the Go Kit. It provides higher-level assembly components such as config and pubsub packages.

Kite

Kite is a Golang microservice framework. It provides RPC client and server packages. The created services are automatically registered in Kontrol's service discovery system. Kontrol is written in Kite and is a Kite service itself. This means that Kite microservices work well in their environment. If you need to connect the Kite microservice to another service discovery system, a configuration is required. 

Why do companies use Golang?

Basically, there are two reasons why Google’s programming language is used by companies of various tiers:

Designed for multi-core processing

Golang was created with cloud computing in mind. It takes advantage of the parallelism and concurrency provided by modern hardware.

 

This approach to parallelism is very easy to work with. Compared to Python/Java, running a function in a goroutine requires minimal boilerplate code.

 

Goroutines and a channel-based approach to parallelism make it very easy to use all available CPU cores and handle parallel I/O without complicating development.

Built for big projects

Over time, new complex systems have been built on top of these foundational systems/libraries and languages. Too often people don't think about the hidden costs of complexity. The truth is that code is read much more often than it is written. The team's speed is greatly burdened by complexity.

 

The Go code is very simple and easy to read. This simplicity allows teams to collaborate in ways that were previously impossible.

Where to use Golang microservices

Technology platforms

Technology platforms provide a common set of features that accelerate application development, so solutions can be deployed to businesses faster. They often require high scalability and reliability, which Golang 100% provides.

Online booking systems

The online booking system allows you to order services and pay for them through web applications or mobile applications, which allows businesses to scale their operations. As part of daily operations, these systems require the highest reliability, scalability, and integration with other systems. Given Golang's microservices opportunities, why not write your code in it?

E-commerce

E-commerce startups, SMBs, and large enterprises face challenges with page load times, scalability issues, and website availability, such as during major promotions. Golang is widely used to solve these problems.

Golang in payment processing systems

With 24/7 global operations and tight SLAs, stability and automatic recovery are a must as each step in the payment processing pipeline requires the lowest possible latency that Golang provides.

Streaming music and video

Protocols such as Golang's HLS make it easy to build a streaming service that is easy to install and provides the most efficient performance. It supports the most commonly used file formats and encodings. The big advantage of language streaming is speed, especially when it comes to live streaming. Without a smooth transition when encoding, decoding, and packaging video and audio, live streaming is not possible. Go handles all of these processes seamlessly, which can provide the viewer with a high-quality experience with minimal interruptions.

Real-life examples of building microservices in Go

Building a Microservice in Go Business Guide - Dropbox

 

Dropbox owes a lot of its success to Python, a language that has allowed the company to iterate and develop quickly. However, as the user base grew, they began to look for ways to scale systems more efficiently. This led to the transfer of performance-critical backends from Python to Go in order to take advantage of better concurrency support and faster execution speed.

 

It was a huge amount of work - about 200,000 lines of Go code - done by a small team of engineers. They have successfully migrated major parts of our infrastructure to Go. Zviad Metreveli pre-set the details of this effort in the Go microservice at Dropbox.

People are getting very productive in Go very quickly, our infrastructure is built on Go today, and we build all new things on Go.

Zviad Metreveli, Senior Lead Engineer, Dropbox.

In addition, Dropbox has open-sourced several Golang libraries that help improve caching, the standard error interface, and more.

 

In 2022, Dropbox will continue to break apart the monolithic Python codebase and turn it into a serverless managed platform that will reduce code obfuscation and free services and their underlying engineering teams from intertwining with each other. To do this, they update the architecture, for example, gRPC standardization and the use of Envoy's gRPC-HTTP transcoding. See their blog post.

 

Building a Microservice in Go Business Guide - Uber

While Uber has historically been primarily a Node.js and Python result, Go is becoming the language of choice for building many new Uber Engineering services.

 

Uber has written over a hundred services in Golang. Geobase is one of the latest Uber services written in it. It matches riders with drivers, breaking down matches by car. In fact, Golang powers most of Uber's high RPS services.

Looking back, we are very happy with our decision to go for it and write our service in a new language.

— Kai Wei.

Basic moments:

  • High developer productivity. It usually only takes a few days for a C++, Java, or Node.js developer to learn Go, and the code is easy to maintain. (Thanks to static typing, no more guesswork or nasty surprises.)
  • High throughput and latency performance. In our main non-Chinese-only datacenter, this service handled a peak load of 170k requests per second, with 40 machines running at 35% CPU utilization in NY 2015. Response times were < 5ms at 95- m percentile and < 50 ms at 99th percentile.
  • Super reliable. This service has 99.99% uptime since inception. The only downtime was caused by novice programming errors and a file descriptor leak error in a third-party library. It's important to note that we haven't seen any issues with the Go runtime."

 

Source: How we created the highest request per second Uber Engineering service with Go.

 

Building a Microservice in Go Business Guide - Alibaba

Alibaba Group's PouchContainer (container engine) is written in Golang. It can package, deliver and run any application. It provides applications with a lightweight runtime environment with strong isolation and minimal overhead.

 

PouchContainer ran stably across tens of thousands of nodes in Alibaba and helped seamlessly process all online transactions during Alibaba's Singles Day 2017 on millions of containers.

 

Building a Microservice in Go Business Guide - American Express

 

American Express is primarily known for its credit cards and payment processing.

 

In 2016, their payments and rewards platform teams were among the first to start evaluating Go. Their main focus was on microservices, transaction routing, and load balancing use cases, and they needed to modernize their architecture.

After working in Go, most of our developers don't want to go back to other languages. 

— Benjamin Cain, Vice President, and Chief Engineer, American Express

To help other businesses determine if Go is right for them, they have published a Go example: American Express Uses Go for Payments & Rewards.

 

Source: Choosing Go at American Express

 

Building a Microservice in Go Business Guide - PayPal

PayPal was the pioneer of online payments and remains the leading payment processor for online merchants, auction sites, and many other commercial users around the world.

 

PayPal currently employs over 100 Go developers. While Go may never replace Node.js for some applications, Go is the top-notch language at PayPal.

Go provides channels and subroutines to solve complex problems, we were able to structure the code according to our requirements.

— Bala Natarajan, Senior CTO, Developer Experience at PayPal.

Source: PayPal Taps Go to Modernize and Scale

 

Building a Microservice in Go Business Guide - Soundcloud

SoundCloud is a consumer website that is the internet's leading audio platform and that means anything from home DJs uploading their mixes to professional interviewers uploading interviews and podcasts.

SoundCloud maintains about half a dozen services and over a dozen repositories written entirely in Go. And we are increasingly turning to Go when we launch new server projects. 

Peter Bourgon.

Sources: Go at SoundCloud, Peter Bourgon on CRDTs, Go at SoundCloud

 

Building a Microservice in Go Business Guide - Twitch

It is a live video streaming platform that focuses on the live streaming of video games, music broadcasts, creative content, esports competitions, and more.

Twitch uses Go for many of our busiest systems. Its simplicity, security, performance, and readability make it a good tool to solve the problems we face in providing live video and chat to our millions of users. Go is an important part of scaling Twitch, especially when combined with AWS Lambda. 

Spencer Nelson, Engineer at Twitch.

In 2018, Twitch released the RPC framework they use to communicate between internal servers written in Go - Twirp: a sweet new RPC framework for Go

 

Source: Twitch Engineering: An Introduction and Overview

Wrap up

Microservices may not be the fastest way to build software, but they are a smart choice in the long run. More cost-effective and flexible than monolithic architectures, microservices can be developed and tested simultaneously and almost independently by small teams. The microservices architecture also simplifies deployment and troubleshooting. Not to mention that microservices are the right choice for scalable projects.

 

If at least part of the mentioned above applies to your project, go ahead, just remember that you will need the right technology stack to get the most out of this type of architecture. The Go language is an excellent choice for this purpose. Not only does it meet all the criteria for a microservices stack, but it also offers huge business benefits.

 

Golang differs from other languages ​​in its young age and the ability to develop interesting projects from the very beginning of its release.

 

Golang provides high performance like C/C++, highly efficient parallel processing like Java, and crisp readability like Python, Perl, and Erlang. It is designed to run highly loaded systems using the 100 percent multiprocessor architecture. For these reasons, many companies are moving to Go from other languages ​​and developing efficient software using a microservices architecture.

 

Golang microservices are easy to read and therefore easy to maintain. If over time you need to make changes to the team, this will not jeopardize the entire business. 

 

At Ideamotive, we have been using Golang for a long time therefore our vast Talent Network can supplement your team with great experts. Otherwise, we can come up with an experienced fully autonomous dedicated team of outsourced developers, PMs, and designers matched with your project’s idea.


Contact us to discuss which architecture and language are best for your idea and project!

Dawid Karczewski

Dawid is a full stack developer experienced in creating Ruby on Rails and React Native apps from naught to implementation. Technological superhero, delivering amazing solutions for our clients and helping them grow.

View all author posts
Newsletter 9-1
Ideamotive Newsletter
Your bi-weekly collection of hottest tech news

Frame 29
Interested in Hiring Dawid?
If you're interested in learning more about David's availability, let's hop on a call. David is a skilled full-stack developer with a wealth of experience in Golang Development.
Schedule a consultation

Looking for Go development experts to join your team?

There are dozens of vetted Golang professionals in our talent network.