How to add a custom health check in spring boot health?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
In Spring Boot, a custom health check is usually implemented as a HealthIndicator bean that contributes to the Actuator health endpoint. This is the right approach when you need to report the status of something application-specific, such as an external API, a queue, a license check, or a custom readiness condition. The important part is to keep the health check cheap, deterministic, and operationally meaningful.
Add Actuator First
A custom health check plugs into Spring Boot Actuator, so the project needs the Actuator starter.
Maven:
Once included, Spring Boot exposes health information through the Actuator health endpoint, subject to your endpoint exposure configuration.
Implement HealthIndicator
The most common custom check is a bean that implements HealthIndicator.
Once this bean is registered, Spring Boot automatically includes it in the health report.
Example: Check a Service Dependency
An example is probing a dependency through a client.
This pattern is common for dependencies that have a lightweight ping or status call.
Keep Health Checks Lightweight
Health endpoints may be polled frequently by:
- load balancers
- orchestration platforms
- uptime monitors
- dashboards
That means the check should be:
- fast
- low-cost
- safe to call repeatedly
Do not turn a health check into a slow business workflow or a heavy full-database scan.
Distinguish Liveness from Readiness
Operationally, not every failing dependency should necessarily mark the whole service as dead. A useful mental model is:
- liveness: should this process be restarted
- readiness: should this instance receive traffic
Depending on your deployment model, a custom health check might be more appropriate for readiness than for liveness. That design choice matters more than the Java interface itself.
Expose Details Carefully
Health responses can include details:
That is useful for operators, but be careful not to leak sensitive information such as credentials, internal endpoints, or exception payloads you would not want exposed externally.
Reactive Applications
If the application stack is reactive, Spring Boot also supports reactive health contributors. For many standard synchronous apps, HealthIndicator is still the usual choice. The key point is that your health-check style should match the execution model of the app rather than blocking reactive threads with slow synchronous probes.
Configuration and Visibility
Depending on your Spring Boot version and security setup, you may need to expose the health endpoint explicitly.
Example:
Use show-details carefully in production. It is useful during development or internal operations, but not always appropriate for public exposure.
Testing the Health Indicator
A simple unit test can verify the indicator behavior.
For real dependency checks, mocking the client is usually the better test strategy.
Common Pitfalls
The biggest mistake is making the health check too slow or too expensive for frequent polling. Another is treating every dependency issue as a process-death condition when the operational semantics may really be about readiness. Developers also often expose too much detail in health responses. Finally, if the custom indicator bean is not registered or the Actuator endpoint is not exposed, the health check may be correct in code but invisible in practice.
Summary
- Implement a custom
HealthIndicatorbean to add application-specific health logic. - Keep the check fast, cheap, and safe for repeated polling.
- Use health details carefully and avoid leaking sensitive information.
- Think operationally about liveness versus readiness.
- Make sure Actuator is included and the health endpoint is actually exposed.
Related reading
- How to add additional scrape config to Prometheus
- How to add basic authentication for Tensorflow serving
- How to add flag to Kubernetes controller manager
- How to add multiple keys for elastic beanstalk instance?
- How to add a dependency to a Spring Boot Jar in another project?
- How to add a jar in External Libraries in Android Studio?
- How to add users to Docker container?
- How to analyze disk usage of a Docker container

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.