Stage 9 - Observability, Actuator, and Production Diagnostics

An application is not production-ready just because it starts on a developer machine. Production means somebody will have to answer practical questions under pressure: is the service alive, is it ready to receive traffic, why did requests become slow, did the database connection pool fill up, and which release introduced the problem? Observability is the set of tools and habits that helps answer those questions without guessing.

Observability and Actuator

Why Actuator exists

Spring Boot Actuator exposes operational information through special endpoints under /actuator. These endpoints are not business API endpoints. A customer does not call them to create an order. Infrastructure, monitoring tools, and developers use them to understand the state of the service. The most common endpoint is /actuator/health, which reports whether the application is alive and, if configured, whether important dependencies such as the database are available.

Without Actuator, teams often invent weak health checks like GET /api/orders and assume that a successful response means the service is fine. That is not precise enough. A service can start but fail to connect to the database. It can be alive but not ready for traffic during startup. It can answer one endpoint while a background dependency is broken. Actuator gives a standard place for these signals.

Signal Example endpoint or source What it answers
Health /actuator/health Is the service alive and are required dependencies available?
Readiness /actuator/health/readiness Can traffic be sent to this instance now?
Metrics /actuator/metrics, /actuator/prometheus How many requests, errors, memory pressure, and DB pool usage?
Logs Application logs with request id What happened inside one request?
Traces Distributed tracing system Which services participated in a slow request?

Minimal configuration

management.endpoints.web.exposure.include=health,info,metrics,prometheus
management.endpoint.health.probes.enabled=true
management.endpoint.health.show-details=when_authorized

Do not expose every actuator endpoint to the public internet. Some endpoints can reveal environment details, configuration, or operational internals. In production, actuator endpoints are usually restricted by network rules, Spring Security, or both. Public load balancers may need health and readiness, but they do not need full metric details or environment dumps.

A real diagnostic flow

Imagine users report that checkout is slow. A useful investigation has a sequence. First, check dashboards: did p95 latency increase, or is it only one user? Second, check error rate: are 5xx responses rising? Third, inspect database pool metrics: are connections exhausted? Fourth, use logs with a correlation id to follow one slow request through controller, service, repository, and external calls. If tracing is available, check whether the time is spent in this service, the database, or another service.

The important idea is that logs, metrics, and traces are not separate hobbies. Metrics show that something changed. Logs explain what happened in a concrete request. Traces show where time was spent across boundaries. Actuator and Micrometer give the Spring Boot application a standard way to publish these signals.

Common mistakes

  • Treating /actuator/health as a public debug page instead of an infrastructure signal.
  • Monitoring only CPU and memory while ignoring latency, error rate, and database pool usage.
  • Logging messages without request ids, which makes incident investigation slow.
  • Adding dashboards but no alerts, so nobody learns about the problem until users complain.
Glossary
bean
An object managed by the Spring container.
IoC
Inversion of Control, a design principle where a framework manages object creation and wiring.
dependency injection
A technique where required dependencies are provided to an object from the outside.
application context
The Spring container that stores beans, configuration, and runtime wiring.
auto-configuration
Spring Boot behavior that configures application components based on dependencies and settings.
starter
A Spring Boot dependency bundle that brings related libraries and default configuration together.
dependency management
The practice of controlling dependency versions and relationships in a project.
controller
A component that handles incoming requests and returns responses or view models.
service layer
The application layer where business logic and use-case orchestration usually live.
repository layer
The application layer responsible for data access and persistence operations.
REST controller
A controller that exposes HTTP endpoints and usually returns JSON or another response body.
endpoint
A specific API address and operation that clients can call.
request mapping
The configuration that connects an HTTP request path and method to controller code.
Spring Security
The Spring project used to implement authentication, authorization, and security filters.
authentication
The process of proving who a user or client is.
authorization
The process of deciding what an authenticated user or client is allowed to do.
filter chain
An ordered set of web filters that process a request before it reaches the application handler.
observability
The ability to understand system behavior from signals such as logs, metrics, traces, and health checks.