I started as a software developer in 2007, and over the years, I’ve seen the evolution of web-based projects and the shift toward enterprise applications. In 2014, I was introduced to microservices and have advocated for this modern software architecture ever since.
In my journey with microservices, I’ve used various technologies to develop and deploy microservices to production environments. A tool that caught my attention was gRPC, which is a high-performance, open-source framework developed by Google and built on top of HTTP/2. I was fascinated by gPRC’s potential regarding microservices communication. Its support for multiple languages, including Go, and its ease of building cloud-native applications made it an obvious choice for me.
However, I soon realized that there weren’t enough resources to cover all the pieces of microservices to help developers like me get started. There were individual tutorials like the Hello World program and a couple about Protobuf, but no comprehensive guides existed that explained gRPC and Protobuf with production-grade examples. Over time, I worked through the processes and learned to use gRPC to build microservices that communicate effectively with each other. gRPC has never let me down.
That’s why I decided to write this book. I wanted to provide a comprehensive resource to help developers get up to speed with the technology and put it into practice. In this book, I have drawn on my experience with microservices and gRPC to provide a complete guide to building microservices with both gRPC and Protobuf. We’ll write the code in Go, a popular programming language for building cloud-native applications and microservices. Throughout the book, we’ll use an e-commerce application, deployed on Kubernetes, as an example to guide you on your own journey into gRPC and microservices. We’ll also cover advanced topics such as error handling, testing, and security, which are vital for building product-grade applications.
I wrote this book to make it easier for developers like me to get started with gRPC, and I hope you’ll find it a valuable resource. Thank you for choosing gRPC Microservices in Go.
Writing a book is never easy, and writing gRPC Microservices in Go was no exception. I have spent countless hours working on this book both in various cafes and at home, and while traveling, to produce comprehensive content.
First and foremost, I want to thank my beautiful wife, Emel, who has supported me throughout this journey. She has always encouraged me to pursue my passion, even when I was exhausted and felt like giving up. Her unwavering support and understanding have been a constant source of inspiration for me.
Next, I want to extend my heartfelt gratitude to my editor, Doug Rudder, for his support during several months of work on this book. His feedback, suggestions, and edits have been invaluable, and I could not have completed this book without him. I also want to thank my technical editor, Bartosz Solowiej; his attention to detail and thoroughness helped me refine and polish the technical aspects of the book. My thanks to everyone else at Manning: my project editor, Deirdre Hiam; my copyeditor, Michelle Mitchell; and my proofreader, Meredith Mix.
I want to thank the reviewers who provided valuable feedback during the writing process. Your comments and suggestions helped me improve the book’s content and make it more useful for readers. Thank you to Alain Couniot, Alceu Rodrigues de Freitas Junior, Alessandro Campeis, Andrea Monacchi, Ashish Kumar Pani, Borko Djurkovic, Cameron Singe, Dr. Keith L Mannock, Dylan Guedes, Fatih Akturk, Germano Rizzo, Gowtham Sadasivam, Horaci Macias, Jeelani Shaik, Christian B. Madsen, Joel Holmes, Jonathan Reeves, Karthikeyarajan Rajendran, Kelum Prabath Senanayake, Manzur Mukhitdinov, Marco Massenzio, Michael Haller, Mikael Dautrey, Muneeb Shaikh, Neil Croll, Nolan To, George Onofrei, Peter Hampton, Rahul Modpur, Rich Yonts, Ryan Burrows, Ryan Huber, Satadru Roy, Stanley Anozie, Syed Basheeruddin Ahmed, Tim Homan, Vadim Turkov, and Walter Alexander Mata Lopez.
Finally, I want to express my sincere gratitude to the Go, gRPC, and Kubernetes communities. Your contributions, support, and enthusiasm have been a constant source of motivation and inspiration for me. I am honored to be part of such a vibrant and dynamic community.
Thank you all for your support and encouragement throughout this journey.
gRPC Microservices in Go was written for anyone who wants to apply production-grade practices from gRPC, Go, and/or Kubernetes to microservice applications that run in a live environment. It starts with microservices theory and cloud-native application development, then dives into the technical development of microservices in Kubernetes using Go and gRPC.
This book will help developers design and implement their microservices projects using Go and gRPC in the Kubernetes environment. There are some examples of Kubernetes deployment and gRPC usage online, but this book provides a step-by-step explanation of a gRPC microservice life cycle, from beginning to production. For this reason, this book will be a good reference for architects, chief technology officers, and engineering managers in applying microservice principles to development life cycles.
This book has three sections that cover nine chapters.
Part 1 contains theoretical information about microservices and gRPC:
Chapter 1 briefly introduces gRPC microservices and provides an overview of the book.
Chapter 2 discusses microservices, including their communication patterns, and explains how to use gRPC during development.
Part 2 provides step-by-step instructions for implementing gRPC microservices and deploying them to the Kubernetes environment:
Chapter 3 provides information about installing gRPC and related tools (e.g., Protobuf) for project development.
Chapter 4 explains hexagonal architecture and how to use it in microservices. It also explains how to structure a Go project with gRPC clients and servers to build a microservices project.
Chapter 5 explains how gRPC client–server interaction can be used in microservice service-to-service communication.
Chapter 6 describes how important resiliency is and how to apply resiliency patterns to gRPC service communications. The primary goals of this chapter are reader understanding of failover scenarios and recovering from them.
Chapter 7 explains how to write unit and integration tests for microservices. This is especially important for the microservices environment because many changing pieces must be maintained properly.
Chapter 8 goes deep into some of the Kubernetes resources and shows how to use them to deploy gRPC microservices to the Kubernetes environment. This chapter also covers how to expose services to the public.
Part 3 covers gRPC microservice observability in the Kubernetes environment:
Chapter 9 focuses on observability and demonstrates how to integrate observability tools into gRPC microservices for better visibility on the entire platform.
This book contains many examples of source code both in numbered listings and in line with normal text. In both cases, source code is formatted in a fixed-width
font like
this
to separate it from ordinary text. Sometimes code is also in
bold
to highlight code that has changed from previous steps in the chapter, such as when a new feature adds to an existing line of code.
In many cases, the original source code has been reformatted; we’ve added line breaks and reworked indentation to accommodate the available page space in the book. In rare cases, even this was not enough, and listings include line-continuation markers (➥). Additionally, comments in the source code have often been removed from the listings when the code is described in the text. Code annotations accompany many of the listings, highlighting important concepts.
You can get executable snippets of code from the liveBook (online) version of this book at https://livebook.manning.com/book/grpc-microservices-in-go. The complete code for the examples in the book is available for download from the Manning website at https://www.manning.com/books/grpc-microservices-in-go, and from GitHub at https://github.com/huseyinbabal/microservices.
Purchase of gRPC Microservices in Go includes free access to liveBook, Manning’s online reading platform. Using liveBook’s exclusive discussion features, you can attach comments to the book globally or to specific sections or paragraphs. It’s a snap to make notes for yourself, ask and answer technical questions, and receive help from the author and other users. To access the forum, go to https://livebook.manning.com/book/grpc-microservices-in-go/discussion. You can also learn more about Manning’s forums and the rules of conduct at https://livebook.manning.com/discussion.
Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the author can take place. It is not a commitment to any specific amount of participation on the part of the author, whose contribution to the forum remains voluntary (and unpaid). We suggest you try asking the author some challenging questions lest his interest stray! The forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.
Hüseyin Babal has been a software developer since 2007. Since 2016, he has built cloud-native applications with Kubernetes in major cloud providers. He has also worked with enterprise companies to help them with their DevOps and microservice transition projects. You can find him giving presentations at global conferences or doing live coding sessions on his Twitch channel.
The figure on the cover of gRPC Microservices in Go is “Bohemienne de Prague,” or “Bohemian woman from Prague,” taken from a collection by Jacques Grasset de Saint-Sauveur, published in 1797. Each illustration is finely drawn and colored by hand.
In those days, it was easy to identify where people lived and what their trade or station in life was just by their dress. Manning celebrates the inventiveness and initiative of the computer business with book covers based on the rich diversity of regional culture centuries ago, brought back to life by pictures from collections such as this one.