gRPC Health Check: Not Responding
In this tutorial, you'll learn about grpc health check: not responding. We cover key concepts, practical examples, and best practices.
gRPC health checking -- Implement the standard gRPC health check protocol for load balancers and Kubernetes probes.
The Problem
gRPC has a standard health check protocol (grpc.health.v1.Health/Check). Without it, load balancers treat healthy instances as unhealthy.
Wrong
// No health check. Load balancer may route to dead instances.
Output:
// Or kill healthy instances that don't respond.
Right
import "google.golang.org/grpc/health/grpc_health_v1"
// Server:
health := health.NewServer()
grpc_health_v1.RegisterHealthServer(server, health)
health.SetServingStatus("myservice.Greeter", grpc_health_v1.HealthCheckResponse_SERVING)
// Client probe:
healthClient := grpc_health_v1.NewHealthClient(conn)
resp, err := healthClient.Check(ctx, &grpc_health_v1.HealthCheckRequest{Service: ""})
if resp.Status != grpc_health_v1.HealthCheckResponse_SERVING {
// Instance not ready
}
Output:
// Health check returns SERVING. Load balancer routes traffic.
Prevention
- Register grpc_health_v1.HealthServer in your gRPC server
- Set serving status per service name
- Empty string checks overall server status
- Kubernetes: use grpc_health_probe for liveness/readiness
- Mark NOT_SERVING during startup and shutdown
Common Mistakes with grpc health
- Mixing let bindings with <- bindings in do notation, producing type errors
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
These mistakes appear frequently in real-world GO code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. DodaTech tutorials help Go developers build production-ready software used by millions.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro