How do you make a Spring Boot service production-ready with Actuator and observability?
Actuator endpoints
/actuator/health (with liveness and readiness groups for Kubernetes), /info (build and git info), /metrics, /prometheus, /loggers (change log levels at runtime), /threaddump, /heapdump, /env, /configprops, /conditions, /startup.
Securing Actuator
Expose only what you need (management.endpoints.web.exposure.include=health,info,prometheus), serve management on a separate internal port (management.server.port=8081) not routed through the public ingress, require authentication for sensitive endpoints, and sanitise values in /env and /configprops.
Metrics (Micrometer)
- Built-in: HTTP server requests (latency histograms by URI, method, status), JVM (heap, GC, threads), HikariCP, executors, caches, Kafka clients.
- Custom business metrics:
Counter(orders placed),Timer(payment latency),Gauge(queue depth),DistributionSummary(order value). Keep tag cardinality low: never tag with user ids or order ids. - Export to Prometheus (scraped) or push to Datadog, CloudWatch, OTLP.
Tracing and logs
- Micrometer Tracing with an OpenTelemetry bridge propagates W3C
traceparentheaders throughRestClient,WebClient, Kafka and@Asyncand exports spans to Tempo, Jaeger or Zipkin. traceIdandspanIdare added to the MDC, so every log line can be correlated. Use structured JSON logs (Boot 3.4+ supportslogging.structured.format.console=ecsorlogstash).
Health
Health indicators for DB, Redis, Kafka and disk are added automatically. Keep liveness free of external dependencies; put dependencies in readiness only if the instance genuinely cannot serve without them.
Example
@Component
class PaymentGatewayHealth implements HealthIndicator {
private final GatewayClient client;
PaymentGatewayHealth(GatewayClient client) { this.client = client; }
@Override public Health health() {
return client.ping(Duration.ofMillis(300))
? Health.up().build()
: Health.down().withDetail("gateway", "unreachable").build();
}
}Follow-up questions interviewers ask
Try answering each one before you open it.
Why should liveness probes not check the database?
If the database has an outage, every pod's liveness check fails and Kubernetes restarts all of them, which does not fix the database, adds a restart storm and cold caches, and prolongs the incident. Liveness should only answer "is this process broken beyond self-recovery" (deadlocked, corrupted state). Dependency problems should, at most, mark the pod not ready.
What are the four golden signals and RED/USE?
Golden signals (Google SRE): latency, traffic, errors, saturation. RED for request-driven services: Rate, Errors, Duration. USE for resources: Utilisation, Saturation, Errors (CPU, memory, connection pools, thread pools). Alert on symptoms users feel (error rate and p99 latency against SLOs), not on every cause.