Lesson 16 · Architecture & production
Health, reflection & graceful shutdown
The three things you need to actually operate a gRPC server.
Your win: explain the standard health service, what server reflection is (and why our repo skips it), and what graceful shutdown means — the "how do you run this in production?" round.
Health checking — the standard service
gRPC defines a standard grpc.health.v1 service with two methods —
Check (unary) and Watch (streaming) — returning a
ServingStatus (SERVING / NOT_SERVING).1
Kubernetes liveness/readiness probes call it to decide whether to route traffic or
restart the pod.
health.RegisterHealthServer(grpcserver, &healthcheck.Service{DB: pool})
/grpc.health.v1.Health/Check and /Watch are whitelisted in
every ignoreAuthEndpoint (Lesson 13) so probes don't need a JWT.
Server reflection — and why we don't use it
Server reflection lets a client discover a server's services
and methods at runtime, without having the .proto — it's what makes
tools like grpcurl and Postman "just work" against a gRPC server.
reflection.Register across the codebase finds nothing. That's a
deliberate trade: reflection is great for dev/debugging but exposes your entire API
surface, so many production services leave it off (you supply the .proto
to trusted tools instead). Knowing it exists and why you might disable it is
the complete answer.
Graceful shutdown
On SIGTERM (a deploy, a scale-down), a well-behaved server stops
accepting new RPCs, lets in-flight ones finish, then exits —
grpc.GracefulStop(). Our bootstrap wires this through the
GRPCServicer.GracefulShutdown hook, triggered by
signal.NotifyContext(SIGTERM, SIGINT) — the exact graceful-shutdown pattern
from your Go course
Lesson 18.
gRPC — Health checking guide + grpc-go health/reflection
The health protocol and how to register it; the reflection package if you want to enable it in a dev build.
→ grpc.io/docs/guides/health-checking
→ grpc_health_v1 ·
reflection
Check yourself (from memory)
Q1. The gRPC health service exposes which methods?
Check (unary) + Watch
(streaming), returning SERVING/NOT_SERVING. k8s probes call it.
Q2. Server reflection lets clients…
Q3. Graceful shutdown means the server…
GracefulStop: stop taking new RPCs, drain
in-flight ones, exit — wired via signal.NotifyContext (Go L18).
grpc.health.v1 service
(Check unary + Watch streaming, SERVING/
NOT_SERVING) that k8s probes call; our repo registers it in all three with
a DB-backed check. (2) SERVER REFLECTION — runtime API discovery for grpcurl/Postman;
our repo does NOT register it (smaller attack surface). (3) GRACEFUL SHUTDOWN — on
SIGTERM stop new RPCs, drain in-flight, then grpc.GracefulStop(); our
bootstrap wires GracefulShutdown + signal.NotifyContext (Go L18).