The more and more microservices we build, the more work needed around maintaining them. Need to know how are they performing, whether the service is up/down, is that service ready to serve request etc. Hence the monitoring becomes crucial and it needs to be automated. So heartbeat/ping can answer if a service is up/down but we need another endpoint which can tell if the service is healthy enough to serve a request. Not every microservice depends on each other, so sorting out the dependency tree via a healthcheck can be quite helpful too.
Healthcheck can be quite simple to build and easy to integrate with a deployment tool like Octopus, which will then give us more visibility around the state of the service and whether it’s healthy to serve request or not, as soon as deployment is done.
To add a healthcheck endpoint into the microservice, we can implement a contract as simple as this,
A simple get request to know the overall status and the status of the dependent services. The dependency tree should only include the bare minimum for the service to function. Like, in case of dataquery microservice, we need the service to be able to communicate with the underlying databases like Datawarehouse and any dependent service like Identity service or any other external service used.
So if the service failed to talk to database, the overall status will be 503 (service unavailable) or a 200 (OK), if all the underlying service call returns a success.
We can also add additional configuration details, which can help to troubleshoot some issues e.x. knowing the location of the log files can help to get more details of the error been displayed in the healthcheck response.
Then we can add a separate step in octopus deployment which fires off a healthcheck call right after the corresponding microservice deployment is done.
Based on the result, it can be either a successful deployment Or a failed one!
Not only we know the state of the service at any point of time, we can build monitoring around that and also as soon as we deploy our microservice, the first warm up call is already made