Microservices with Go

Book description

Build, scale, and maintain microservices in Golang with ease.

Key Features

  • Create and organize well-structured Go microservices
  • Learn industry best practices and gain insights into Go microservice development tools, patterns, and solutions
  • Cover hands-on Golang examples in each chapter

Book Description

This book covers the key benefits and common issues of microservices, helping you understand the problems microservice architecture helps to solve, the issues it usually introduces, and the ways to tackle them.

You’ll start by learning about the importance of using the right principles and standards in order to achieve the key benefits of microservice architecture. The following chapters will explain why the Go programming language is one of the most popular languages for microservice development and lay down the foundations for the next chapters of the book. You’ll explore the foundational aspects of Go microservice development including service scaffolding, service discovery, data serialization, synchronous and asynchronous communication, deployment, and testing. After covering the development aspects, you’ll progress to maintenance and reliability topics. The last part focuses on more advanced topics of Go microservice development including system reliability, observability, maintainability, and scalability. In this part, you’ll dive into the best practices and examples which illustrate how to apply the key ideas to existing applications, using the services scaffolded in the previous part as examples.

By the end of this book, you’ll have gained hands-on experience with everything you need to develop scalable, reliable and performant microservices using Go.

What you will learn

  • Get familiar with the industry’s best practices and solutions in microservice development
  • Understand service discovery in the microservices environment
  • Explore reliability and observability principles
  • Discover best practices for asynchronous communication
  • Focus on how to write high-quality unit and integration tests in Go applications
  • Understand how to profile Go microservices

Who this book is for

This book is for all types of developers, from people interested in learning how to write microservices in Go to seasoned professionals who want to take the next step in mastering the art of writing scalable and reliable microservice-based systems. A basic understanding of Go will come in handy.

Table of contents

  1. Microservices with Go
  2. Contributors
  3. About the author
  4. About the reviewer
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
    9. Download a free PDF copy of this book
  6. Part 1: Introduction
  7. Chapter 1: Introduction to Microservices
    1. What is a microservice?
    2. Motivation to use microservices
    3. Pros and cons of microservices
      1. Benefits of microservices
      2. Common issues of microservices
    4. When to use microservice architecture
    5. Role of Go in microservice development
    6. Summary
    7. Further reading
  8. Part 2: Foundation
  9. Chapter 2: Scaffolding a Go Microservice
    1. Technical requirements
    2. Go basics
      1. Core principles
      2. Writing idiomatic Go code
      3. Interfaces
      4. Tests
      5. Context
    3. Project structure
      1. Private packages
      2. Public packages
      3. Executable packages
      4. Other commonly used directories
      5. Common files
      6. Best practices
    4. Scaffolding an example application
      1. Movie application
      2. Application code structure
      3. Movie metadata service
      4. Movie service
    5. Summary
    6. Further reading
  10. Chapter 3: Service Discovery
    1. Technical requirements
    2. Service discovery overview
      1. Registry
      2. Service discovery models
      3. Service health monitoring
    3. Service discovery solutions
      1. HashiCorp Consul
      2. Kubernetes
    4. Adopting service discovery
      1. Preparing the application
      2. Implementing the discovery logic
      3. Using the discovery logic
    5. Summary
    6. Further reading
  11. Chapter 4: Serialization
    1. Technical requirements
    2. The basics of serialization
    3. Popular serialization formats
    4. Using Protocol Buffers
    5. Best practices for serialization
    6. Summary
    7. Further reading
  12. Chapter 5: Synchronous Communication
    1. Technical requirements
    2. Introduction to synchronous communication
      1. Go RPC frameworks and libraries
    3. Defining a service API using Protocol Buffers
    4. Implementing gateways and clients
      1. Metadata service
      2. Rating service
      3. Movie service
    5. Summary
    6. Further reading
  13. Chapter 6: Asynchronous Communication
    1. Technical requirements
    2. Asynchronous communication basics
      1. Benefits and challenges of asynchronous communication
      2. Techniques and patterns of asynchronous communication
      3. Using Apache Kafka for messaging
      4. Adopting Kafka for our microservices
    3. Asynchronous communication best practices
      1. Versioning
      2. Leveraging partitioning
    4. Summary
    5. Further reading
  14. Chapter 7: Storing Service Data
    1. Technical requirements
    2. Introduction to databases
    3. Using MySQL to store our service data
    4. Summary
    5. Further reading
  15. Chapter 8: Deployment with Kubernetes
    1. Technical requirements
    2. Preparing application code for deployments
      1. Deployment basics
      2. Application configuration
    3. Deploying via Kubernetes
      1. Introduction to Kubernetes
      2. Setting up our microservices for Kubernetes deployments
    4. Deployment best practices
      1. Automated rollbacks
      2. Canary deployments
      3. Replace with Continuous Deployment (CD)
    5. Summary
    6. Further reading
  16. Chapter 9: Unit and Integration Testing
    1. Technical requirements
    2. Go testing overview
    3. Unit tests
      1. Mocking
      2. Implementing unit tests
    4. Integration tests
    5. Testing best practices
      1. Using helpful messages
      2. Avoiding the use of Fatal in your logs
      3. Making a comparison using a cmp library
    6. Summary
    7. Further reading
  17. Part 3: Maintenance
  18. Chapter 10: Reliability Overview
    1. Technical requirements
    2. Reliability basics
    3. Achieving reliability through automation
      1. Communication error handling
      2. Graceful shutdown
    4. Achieving reliability through development processes and culture
      1. On-call process
      2. Incident management
      3. Reliability drills
    5. Summary
    6. Further reading
  19. Chapter 11: Collecting Service Telemetry Data
    1. Technical requirements
    2. Telemetry overview
    3. Collecting service logs
      1. Choosing the logging library
      2. Using logging features
      3. Storing microservice logs
      4. Logging best practices
    4. Collecting service metrics
      1. Storing metrics
      2. Popular Go metrics libraries
      3. Emitting service metrics
      4. Metrics best practices
    5. Tracing
      1. Tracing tools
      2. Collecting tracing data with the OpenTelemetry SDK
    6. Summary
    7. Further reading
  20. Chapter 12: Setting Up Service Alerting
    1. Technical requirements
    2. Alerting basics
      1. Alerting use cases
    3. Introduction to Prometheus
    4. Setting up Prometheus alerting for our microservices
    5. Alerting best practices
    6. Summary
    7. Further reading
  21. Chapter 13: Advanced Topics
    1. Technical requirements
    2. Profiling Go services
    3. Creating microservice dashboards
    4. Frameworks
    5. Storing microservice ownership data
    6. Securing microservice communication with JWT
      1. JWT basics
      2. Implementing authentication and authorization with JWTs
    7. Summary
    8. Further reading
  22. Index
    1. Why subscribe?
  23. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts
    3. Download a free PDF copy of this book

Product information

  • Title: Microservices with Go
  • Author(s): Alexander Shuiskov
  • Release date: November 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781804617007