Observability and service lifecycle
Explain a failure without reconstructing it by hand.
The idea
Measure request rate, errors, latency, and database pool pressure. A correlation ID ties a handler to the work it triggers. Use structured logs with stable fields and exclude secrets. On SIGTERM, stop accepting traffic, drain bounded in-flight work, and close dependencies after handlers finish.
Follow the flow
Make it concrete
This excerpt isolates the concept. Connect it to the booking API as you work through the exercise.
logger.Info("booking request completed",
"operation", "reserve",
"outcome", outcome,
"duration_ms", elapsed.Milliseconds(),
)
// On termination: app.ShutdownWithTimeout(15*time.Second)Decisions that matter
- High-cardinality labels can make metrics expensive; do not label every booking ID.
- Readiness should reflect required dependencies without exposing internals.
- Retain a previous release and verify rollback before depending on it.
Your turn
A release is active in systemd but the domain returns 502. What do you check in order?
Reveal a worked answer
Verify the process and local listener, then local readiness, proxy upstream and route, DNS, and TLS. Use the exact external route in a smoke check. A process manager’s active state does not establish end-to-end availability.