contents
Front matter
preface
acknowledgments
about this book
about the author
about the cover illustration
Part 1. gRPC and microservices architecture
1 Introduction to Go gRPC microservices
1.1 Benefits of gRPC microservices
Performance
Code generation and interoperability
Fault tolerance
Security
Streaming
1.2 REST vs. RPC
1.3 When to use gRPC
Who is this book for?
1.4 Production-grade use cases
Microservices
Container runtime
CI/CD pipeline
Monitoring and observability
Public access
2 gRPC meets microservices
2.1 Monolithic architecture
Development
Deployment
Scaling
2.2 Scale cube
X-axis scaling
Z-axis scaling
Y-axis scaling
2.3 Microservice architecture
Handling data consistency
Saga pattern
Choreography-based saga
Orchestrator-based saga
2.4 Service discovery
2.5 Using gRPC for interservice communication
Working with protocol buffers
Generating Go source code
Connecting wires
Part 2. Developing, testing, and deploying a gRPC microservice application
3 Getting up and running with gRPC and Golang
3.1 Protocol buffers
Defining message type
Protocol buffer encoding
3.2 Generating stubs
Protocol buffer compiler installation
Using the protocol buffer compiler
3.3 Maintaining .proto files
Proto project structure
Automation for source code generation
3.4 Backward and forward compatibility
Adding new fields
Upgrading the server but not the client
Upgrading the client but not the server
Adding/removing oneof fields
Moving fields out of or into oneof fields
4 Microservice project setup
4.1 Hexagonal architecture
Application
Actors
Ports
Adapters
4.2 Order service implementation
Project folders
Initializing a Go project
Implementing the application core
Implementing ports
Implementing adapters
Implementing a gRPC adapter
Dependency injection and running the application
Calling a gRPC endpoint
5 Interservice communication
5.1 gRPC service-to-service communication
Server-side load balancing
Client-side load balancing
5.2 Depending on a module and implementing ports and adapters
Payment port
Payment adapter
Implementing the payment port
Implementing the payment adapter
Client configuration for a payment stub
Using a payment adapter in gRPC
5.3 Error handling
Status codes
Returning an error code and message
Errors with details
Handling errors on the client side
Running the Payment service
6 Resilient communication
6.1 Resiliency patterns
Timeout pattern
Retry pattern
Circuit breaker pattern
6.2 Error handling
gRPC error model
gRPC error response
6.3 Securing gRPC communication
TLS handshake
Certificate generation
gRPC TLS credentials
7 Testing microservices
7.1 Testing pyramid
7.2 Testing with a unit test
System under test
Test workflow
Working with mocks
Implementing a mock
Automatic mock generation
7.3 Integration testing
Test suite preparation
Working with Testcontainers
7.4 End-to-end tests
Specifications
Understanding Docker Compose service definitions
End-to-end test folder structure
Database layer
The Payment service layer
The Order service layer
Running tests against the stack
7.5 Test coverage
Coverage information
Testing in a CI pipeline
8 Deployment
8.1 Docker
Building images
8.2 Kubernetes
Kubernetes architecture
Kubernetes resources
Eagle view of microservices deployment
Pod
Deployment
Service
NGINX Ingress controller
8.3 Certificate management
Installation
ClusterIssuer
Certificate usage in Ingress
Certificates on the client side
8.4 Deployment strategies
RollingUpdate
Blue-Green Deployment
Canary deployment
Final thoughts on deployment
Part 3. gRPC and microservices architecture
9 Observability
9.1 Observability
Traces
Metrics
Logs
9.2 OpenTelemetry
Instrumentation locations
Instrumentation
Metric backend
Service performance monitoring
9.3 Observability in Kubernetes
Jaeger All in One
OpenTelemetry Collector
Prometheus
Jaeger installation
OpenTelemetry interceptor for the Order service
Understanding the metrics of the Order service
Application logging
Logs collection
Elasticsearch as a logging backend
Kibana as a logging dashboard
index