Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

How do you write and register a health check in Dropwizard, and where does it appear? Why does Dropwizard warn at start if you have none?

We extend com.codahale.metrics.health.HealthCheck, implement check() to return Result.healthy() or Result.unhealthy(message), and register it with environment.healthChecks().register("database", new DatabaseHealthCheck(db)). The results appear on the admin port at /healthcheck, which answers 500 if any check is unhealthy. Dropwizard warns loudly at start when no checks are registered, because a service that cannot test its own dependencies cannot report whether it really works.

Why this question is asked

Health checks are how the outside world, load balancers, orchestrators and people on call, learns whether a service can do its job. Dropwizard treats them as a first-class part of every application, to the point of complaining when they are missing. Interviewers ask this to see whether we know the API and, more importantly, what a good check actually tests. In this answer, we will recap what a health check is in Dropwizard, write and register one, see where its result appears, understand the startup warning, and look at what makes a check useful.

1A Quick Recap of Health Checks in Dropwizard

A health check is a small piece of code that tests one thing the service depends on and reports healthy or unhealthy, with a message. Dropwizard uses the health check API from the Metrics library (the com.codahale.metrics.health package), and keeps all checks in a HealthCheckRegistry that the Environment gives us.

Dropwizard runs two HTTP connectors. The application port, 8080 by default, serves our resources. The admin port, 8081 by default, serves operational endpoints: /ping, /metrics, /threads and /healthcheck. Keeping them apart means we can expose the admin port only to internal tooling.

2Writing a Health Check

Here is a check that verifies the database really answers a query. It receives its dependency through the constructor, like any other class.

Java
public class DatabaseHealthCheck extends HealthCheck {
private final Jdbi jdbi;
public DatabaseHealthCheck(Jdbi jdbi) { this.jdbi = jdbi; }
@Override
protected Result check() {
try {
jdbi.withHandle(h -> h.createQuery("SELECT 1").mapTo(Integer.class).one());
return Result.healthy(); // database answered
} catch (Exception e) {
return Result.unhealthy("cannot query database: " + e.getMessage());
}
}
}

Notice that check() returns a Result instead of throwing. If it does throw, the registry catches the exception and reports the check as unhealthy with that exception, so a forgotten catch does not break the endpoint. Result also has a builder, Result.builder().healthy().withDetail("pool", 12).build(), for adding details such as pool sizes to the output.

3Registering It and Seeing the Result

We register the check in run(), under a name that will appear in the output.

Java
@Override
public void run(AppConfig config, Environment environment) {
Jdbi jdbi = new JdbiFactory().build(environment, config.getDataSourceFactory(), "postgresql");
environment.healthChecks().register("database", new DatabaseHealthCheck(jdbi));
}
// curl -i http://localhost:8081/healthcheck
// HTTP/1.1 200 OK
// {"database":{"healthy":true,...},"deadlocks":{"healthy":true,...}}
//
// with the database stopped:
// HTTP/1.1 500 Server Error
// {"database":{"healthy":false,"message":"cannot query database: ..."},...}
Step throughWhat GET /healthcheck does
  1. Request on the admin portGET :8081/healthcheck
  2. Run every registered checkdatabase, deadlocks, ...
  3. All results healthy?
    Yes200 OK with JSON detailsNo500 with the failing messages

3 steps in order. Play them, or step through them one at a time.

One unhealthy check turns the whole answer into 500.

The /healthcheck endpoint runs every registered check and returns a JSON object with one entry per name. If all are healthy it answers 200; if any one is unhealthy it answers 500. That single status code is what load balancers and monitoring tools look at, while the JSON body tells a person which check failed and why.

Notice the deadlocks entry: Dropwizard registers a thread deadlock check by itself. Also, JdbiFactory and the Hibernate bundle register a database check of their own, based on the validation query in the data source configuration, so in a real service we may get a database check without writing one. Check your version for the exact built-in checks.

4Why Dropwizard Warns When There Are None

If an application registers no health checks of its own, Dropwizard prints a large warning in capital letters at startup. The message says, in effect, that without health checks we will never find out when the service has stopped working in production.

The reason is that a running process is not the same as a working service. The JVM can be up, Jetty can answer /ping, and yet every request fails because the database password expired or a queue is unreachable. Without checks, /healthcheck has nothing to say about that. Dropwizard's authors chose to make the omission impossible to miss, so that every service at least considers what it depends on. With no checks at all, the endpoint answers 501 Not Implemented rather than pretending everything is fine.

5What Makes a Good Check

A good check tests a real dependency the way the service uses it. A SELECT 1 through the same connection pool proves the network, credentials and pool all work, while a TCP ping to the database port proves much less. For a message broker, sending a metadata request is better than checking that a client object exists.

A good check is also fast and bounded. /healthcheck may be called every few seconds, and if a check waits 30 seconds on a hung database, the endpoint hangs too, and the tool calling it may give up and decide the whole service is dead. So checks use short timeouts, for example a 1 second query timeout, and expensive checks can run on a schedule using the @Async annotation from the health check library, so the endpoint returns the last result immediately. Finally, a check should report only what it can prove; leave optional dependencies out, or mark them clearly, so that a minor feature failing does not fail the whole service.

6Follow-up questions

What is the difference between /ping and /healthcheck?

/ping on the admin port simply answers pong if the process and its admin connector are up. It tests no dependencies. /healthcheck runs every registered check. So /ping tells us the process is alive, and /healthcheck tells us whether it can reach what it depends on, which is why they suit different purposes such as liveness and readiness probes.

Can a health check use the same thread pool as requests?

It runs on the admin connector's threads, not on the application's request threads, so a busy application port does not block it directly. But it does share resources such as the database connection pool, which is the point: if the pool is exhausted, a check that borrows a connection with a short timeout will notice. That is useful information, as long as the timeout keeps the check fast.

Should a health check fail when a downstream API is slow?

Only if the service truly cannot do its main job without that API. Otherwise the check should stay healthy, perhaps with a detail field, and alerting should come from metrics on the API calls. Failing health because of a slow optional partner can make load balancers remove every instance at once, which turns a partial problem into a full outage.

7Conclusion

In this answer, we wrote a Dropwizard health check by extending HealthCheck and returning Result.healthy() or Result.unhealthy(message), registered it with environment.healthChecks().register(), and saw its result on the admin port at /healthcheck, which answers 500 when any check fails. Dropwizard warns at startup without checks because a live process is not proof of a working service, and good checks exercise real dependencies quickly and with timeouts.

What to say in the interviewAbout 80 seconds aloud

Open with

In Dropwizard I write a class that extends HealthCheck from the Metrics health package and implement check, which returns Result.healthy or Result.unhealthy with a message. For a database I'd run a cheap query like SELECT 1 through the same pool the service uses, so it proves network, credentials and pool all work.

Then, if they want more

In the application's run method I register it with environment.healthChecks().register with a name such as database. The results show up on the admin port, 8081 by default, at /healthcheck: a JSON object with one entry per check, and the status is 200 if everything is healthy and 500 if any check fails, which is what load balancers and monitoring read.

Dropwizard also adds a deadlock check itself, and the JDBI and Hibernate integrations register a database check from the validation query. If I register no checks, Dropwizard prints a big warning at startup, because a process that's running isn't the same as a service that works, and without checks there's no way to tell.

Good checks are fast and bounded, with short timeouts or scheduled execution, and they only test dependencies the service really can't work without.

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 official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
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 "How do you write and register a health check in Dropwizard, and where does it appear?...": https://scrivio-interview-library.netlify.app/java/dropwizard/cfae574bf9/