Quick revision
The short answer
We implement HealthIndicator, or extend AbstractHealthIndicator, call the pricing service with a client whose timeout is 2 seconds, and report Health.up() or Health.down() with details. A bean named pricingHealthIndicator appears in /actuator/health as the component pricing, because Boot drops the HealthIndicator suffix; the overall status is aggregated from all components by the StatusAggregator, and details are shown only if management.endpoint.health.show-details allows it.
What to remember
In this answer, we wrote a health indicator for the pricing service by extending AbstractHealthIndicator, or implementing HealthIndicator, with a client timeout of 2 seconds so the health call never blocks for long. The bean name without the HealthIndicator suffix became the component name pricing, the StatusAggregator combined all components into the overall status, and show-details, never by default, decided who sees the details.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
We implement HealthIndicator, or extend AbstractHealthIndicator, call the pricing service with a client whose timeout is 2 seconds, and report Health.up() or Health.down() with details. A bean named pricingHealthIndicator appears in /actuator/health as the component pricing, because Boot drops the HealthIndicator suffix; the overall status is aggregated from all components by the StatusAggregator, and details are shown only if management.endpoint.health.show-details allows it.
Why this question is asked
Spring Boot ships health indicators for databases, Redis, disk space and many other things, but not for the services our own application depends on. Writing one is a small piece of code with a few traps: a health check that blocks for 30 seconds, a name that does not appear where we expect, or details that leak internal host names. Interviewers ask this coding question to see whether we get those details right. In this answer, we will recap how /actuator/health is built, write the indicator with a strict timeout, see how its name and status appear, and control what details are shown.
1A Quick Recap of How /actuator/health Is Built
The health endpoint collects contributions from every HealthIndicator bean in the application. Each indicator returns a Health object, a status such as UP or DOWN plus optional details. Boot then combines all of the component statuses into one overall status, and maps that status to an HTTP code: UP gives 200, and DOWN or OUT_OF_SERVICE give 503 by default.
So adding a check is as simple as adding a bean. The two things we must get right are how long the check takes, because the endpoint waits for every indicator, and what it reports.
2Writing the Indicator With a 2-Second Timeout
AbstractHealthIndicator is the convenient base class. We put the check in doHealthCheck and call up() on the builder when it succeeds; if the method throws, the base class reports DOWN with the exception as a detail, so we do not need our own try and catch.
The timeout is the important part. Without it, the default client could wait far longer than 2 seconds for a hung service, and every call to /actuator/health would hang too, including probes and load balancer checks, which then treat our own service as broken. A short timeout keeps the health call fast and turns a slow dependency into a clear DOWN. In Boot 3 these classes are in org.springframework.boot.actuate.health; Boot 4 moved health support into its own module and package, so check your version for the imports.
3The Same Check With Explicit Health Objects
If we prefer to control the details of the failure ourselves, we implement HealthIndicator directly and build the Health in both branches.
Notice the friendlier detail. The base class puts the exception message into the details, which can include internal host names and ports; writing our own message gives operators what they need without exposing more.
4How the Name and Status Appear
Boot names each component after its bean, with the suffix HealthIndicator removed if it is there. So pricingHealthIndicator becomes pricing, and a bean already named pricing stays pricing. The overall status comes from the StatusAggregator, which by default orders statuses as DOWN, OUT_OF_SERVICE, UP, UNKNOWN and picks the most severe one present.
- Call every HealthIndicatordb,
diskSpace, pricing ... - Name each componentbean name minus the
HealthIndicatorsuffix - StatusAggregator picks the overall statusDOWN >
OUT_OF_SERVICE> UP > UNKNOWN - Map status to HTTPUP 200, DOWN 503
- show-details allows this caller?YesInclude components and detailsNoStatus only
5 steps in order. Play them, or step through them one at a time.
This last line is a design warning. If this endpoint is used as a Kubernetes liveness probe, a pricing outage would make Kubernetes restart our healthy pods. Checks on downstream services belong in a health group that is not used for liveness, and often not for readiness either if we have a fallback.
5Controlling What Details Are Shown
management.endpoint.health.show-details decides who sees the details. It is never by default, so anonymous callers get only {"status":"UP"}. when-authorized shows details to authenticated users, optionally limited to roles with management.endpoint.health.roles, and always shows them to everyone, which is convenient locally and too revealing in production. A separate property, show-components, can show the list of components and their statuses without their details.
For production I would use when-authorized, so probes and load balancers get a fast, minimal answer while operators logged in can see that pricing is DOWN and why.
6Follow-up questions
Why not call the pricing service on every health request?
If the health endpoint is probed every few seconds by several systems, the pricing service receives a steady stream of checks. For expensive checks, we can cache the result for a short time or run the check on a schedule and have the indicator return the last result, so health stays fast and the downstream is not hammered.
How do we make pricing not affect the overall status?
Put it in a health group that only operators look at, and leave it out of the liveness and readiness groups with management.endpoint.health.group.<name>.include. The component still appears in its own group, so we can see and alert on it without restarting or removing pods.
Can a health indicator be reactive?
Yes. In a WebFlux application we implement ReactiveHealthIndicator and return a Mono<Health>, using the timeout operator on the call so a slow pricing service still produces DOWN within 2 seconds.
7Conclusion
In this answer, we wrote a health indicator for the pricing service by extending AbstractHealthIndicator, or implementing HealthIndicator, with a client timeout of 2 seconds so the health call never blocks for long. The bean name without the HealthIndicator suffix became the component name pricing, the StatusAggregator combined all components into the overall status, and show-details, never by default, decided who sees the details.
Open with
I would extend AbstractHealthIndicator, or implement HealthIndicator directly, and register it as a bean. Inside, I call a cheap endpoint on the pricing service with a RestClient whose request factory has a one second connect timeout and a two second read timeout, so if pricing does not answer within two seconds the call throws.
Then, if they want more
With AbstractHealthIndicator, a thrown exception is reported as DOWN with the error as a detail, and on success I call builder.up() and maybe add the latency as a detail. If I implement HealthIndicator myself, I return Health.up() or Health.down() with a detail I choose, which avoids leaking host names from exception messages.
The short timeout matters because the health endpoint waits for every indicator, so a hung check would hang probes too. For the name, Boot uses the bean name and drops the HealthIndicator suffix, so pricingHealthIndicator appears as pricing under components.
The overall status is aggregated by the StatusAggregator, which picks the most severe status, so one DOWN component gives DOWN and HTTP 503. Details only appear if management.endpoint.health.show-details allows it; the default is never, and in production I would use when-authorized. I would also keep this check out of the liveness group, so a pricing outage never restarts our pods.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Boot reference, Actuator
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Write a custom HealthIndicator that reports DOWN when a downstream pricing service does...": https://scrivio-interview-library.netlify.app/spring-boot/actuator/7e2e4d7f27/