New Rails health check endpoint

Rails just recently added a default /up route that will return a 200 when the application is running.

I've had to implement this in pretty much every Rails app I've ever worked on. This is a nice addition!

If you're not familiar. This is useful for load balancers which need a way to know if the application is healthy enough to receive traffic. They continuously poll the endpoint and if they get back an error code, they'll stop sending traffic to the server.

What about the database?

This new default /up endpoint does not check the database or any other resources to see if they are healthy.

Generally, when adding my own health check, I'll also have it check that it can query the primary database. Whether or not this is a good idea depends on the application. If your app can handle the database being down, then this wouldn't make sense as a load balancer health check.

Here's an example:

Quick and easy check for if we can make a query.

# health_checks_controller.rb
def index
  render(json: { time: })

The docs

This is all so fresh to Rails it hasn't landed in the docs yet. You can check out the in-progress docs PR here.