Why interviewers love this: Actuator is the part of Spring Boot that tells you whether your app is healthy, visible, and measurable once it is running in production.
Question: Explain Spring Boot Actuator.
Answer: Spring Boot Actuator adds production-ready features to a Spring Boot app, such as health checks, metrics, environment details, and application info. It exposes these through built-in endpoints like /actuator/health and /actuator/metrics, so ops teams and monitoring tools can see what the app is doing without logging into the server.
Interview-Ready Answer: I use Spring Boot Actuator to make a Spring Boot app production-ready. It gives me built-in endpoints for health, metrics, info, environment details, and more, so I can monitor the app and wire it into tools like Kubernetes, Prometheus, or a load balancer. I like that it is very configurable: I can expose only safe endpoints, secure them, and even add custom health checks for things like a database or cache.
Spring Boot Actuator is a set of production-focused features that sit beside your business code. Think of observability as the ability to understand a running system from its outputs; Actuator gives you those outputs in a standard way. It is especially useful in production because you need answers to questions like: Is the app alive? Can it receive traffic? Is the database slow? How many requests per second are we handling?
spring-boot-starter-actuator is on the classpath, Spring Boot auto-configures a set of endpoint beans. An endpoint is a managed component that can expose a small piece of runtime information.health, info, metrics, env, and beans. Some are safe to expose; others are sensitive and stay hidden unless you opt in.management.endpoints.web.exposure.include controls which endpoints are reachable over HTTP. The base path is usually /actuator. You can also move management traffic to another port with management.server.port.health endpoint becomes /actuator/health. Spring adds a handler mapping so these endpoints behave like normal web routes, but they are not your business controllers.UP, DOWN, or OUT_OF_SERVICE. Actuator combines all indicators into one health response, so a database, cache, and disk check can all contribute to the final answer.These terms are often confused, so keep them separate. Health is the overall status. Readiness means the instance can receive traffic. Liveness means the instance is not stuck and should not be restarted. Since Spring Boot 2.3, Boot supports health groups such as readiness and liveness, which is very useful in Kubernetes.
| Probe | Meaning | Typical use |
|---|---|---|
| health | Overall status | Monitoring dashboards |
| readiness | Can take traffic | Load balancers, Kubernetes |
| liveness | Should keep running | Restart checks |
8081 while the app stays on 8080 reduces accidental exposure.Most Actuator endpoints are lightweight. A health request is roughly O(k), where k is the number of health indicators being evaluated, because it must ask each indicator for its status. Metrics collection is usually near O(1) at the point where the event is recorded, because timers and counters are updated incrementally. The expensive part is not the endpoint framework; it is the work your custom checks do. If you call a slow external service inside a health check, you can make the endpoint slow, trigger probe failures, or even cause restart loops.
One more important detail: exposing /actuator/env, /actuator/beans, or /actuator/configprops publicly can leak secrets or internal structure, so do not use * casually in production. Keep the default safe, then opt in only to endpoints you really need.
Imagine a checkout service for an e-commerce site running in Kubernetes. The team exposes /actuator/health/readiness so the cluster only sends traffic to pods that can actually charge cards. They also expose /actuator/metrics to a Prometheus dashboard so they can watch request latency, payment failure rate, and JVM memory during flash sales.
Here is the incident that Actuator helps prevent. A developer once added a slow payment-gateway ping to the liveness check instead of the readiness check. When the gateway had a brief outage, Kubernetes thought the app was broken and restarted the pods over and over. The logs filled with lines like Liveness probe failed, the pods never stayed up long enough to recover, and customers saw 502 errors at checkout. The fix was to move dependency checks to readiness and keep liveness focused on ‘is the process stuck or dead?’ That one change stopped the restart loop and let the service recover gracefully.
In the real world, Actuator is the difference between guessing and knowing. It turns a mystery outage into a measurable signal.
// Requires spring-boot-starter-web and spring-boot-starter-actuator on the classpath.
//
// application.properties example:
// management.endpoints.web.exposure.include=health,info
// management.endpoint.health.show-details=always
//
// Run with:
// java -Ddemo.cache.ready=true -jar app.jar
// java -Ddemo.cache.ready=false -jar app.jar // /actuator/health will show DOWN
package com.example.actuatordemo;
import java.util.Map;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootVersion;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
public class ActuatorDemoApplication {
public static void main(String[] args) {
SpringApplication.run(ActuatorDemoApplication.class, args);
}
@Bean
HealthIndicator cacheHealthIndicator() {
return () -> {
boolean cacheReady = Boolean.parseBoolean(System.getProperty("demo.cache.ready", "true"));
if (cacheReady) {
return Health.up()
.withDetail("cache", "ready")
.withDetail("latencyMs", 3)
.build();
}
// This failure path is intentional: a bad dependency should surface as DOWN,
// but it should not crash the whole app.
return Health.down()
.withDetail("cache", "unreachable")
.withDetail("hint", "start with -Ddemo.cache.ready=true")
.build();
};
}
@Bean
InfoContributor buildInfoContributor() {
return builder -> builder
.withDetail("app", Map.of(
"name", "actuator-demo",
"purpose", "show Spring Boot Actuator"
))
.withDetail("runtime", Map.of(
"java", System.getProperty("java.version"),
"springBoot", SpringBootVersion.getVersion()
));
}
}
@RestController
class HelloController {
@GetMapping("/hello")
String hello() {
return "Hello. Try /actuator/health and /actuator/info.";
}
}Follow-up & Tricky Questions:
management.endpoints.web.exposure.include to list only what you need, such as health, info, and metrics. Avoid * unless you are in a locked-down internal environment.management.endpoint.<id>.enabled and exposure? Enabling controls whether the endpoint bean exists at all; exposure controls whether that enabled endpoint is reachable over HTTP or JMX. You can disable an endpoint completely, or keep it enabled but not exposed.env and beans can reveal sensitive operational details.management.server.port to move management traffic to a separate port, which helps isolate admin endpoints from public traffic.HealthIndicator for blocking code or ReactiveHealthIndicator for reactive stacks. Spring Boot collects those checks and merges them into the final health response./actuator/health always mean the app is ready for traffic? No. Health is an aggregate status; readiness is the specific signal for traffic routing. A service can be alive but not ready if a dependency is still starting up.show-details=always enough to make health safe? No. That setting only changes how much detail is returned; it does not protect the endpoint. You still need authentication, authorization, and careful exposure rules.Tricky / gotcha questions:
@RestController classes.Common Mistakes:
*. Correction: expose only the endpoints you need, because env, beans, and similar endpoints can leak sensitive information.Memory Hook: Think of Actuator as your app’s dashboard: health is the warning light, readiness is the ‘ready to drive’ sign, and metrics are the speedometer and fuel gauge. If you remember one line, remember this: Actuator tells you whether the app is alive, ready, and behaving.
Cheat Sheet:
health, info, metrics, env, beans.HealthIndicator and custom data from InfoContributor.Practice Tasks:
/actuator/health.HealthIndicator for a fake cache and make it return DOWN with a system property.management.server.port=8081 and expose only health and info.