We have multiple API microservices where we want to implement healthchecks. We also want to include the dependencies of each API when asking for the current health conditions of one (for example the database and used API-s). The problem is that these API-s use each other, thus a health check can lead to an infinite loop due to circular dependency. There are multiple ways to solve this. Ideally what I would want is that:
- One API microservice has 1 health check endpoint.
- The health check also gives back the health of the API-s outside dependencies.
- The endpoint is as minimal as possible. No overengineering something as simple as a healthcheck and ideally with no additional parameters.
An example:
API A: Dependencies are: API B and API C
API B: Dependencies are: API A and API C
API C: Dependencies are: API A and API B
There are two arguments I have found. One is that dependencies should never be included as they are irrelevant. This one is argued here. The other one is that since an API can't perform their tasks without a dependency breaking, that they should definitely be included, argued here. So far I have seen the following solutions/arguments, none of them provide an easy solution for all the points above to happen together.
- Don't include the dependencies. This one is valid to some sense and if you monitor all the microservices anyway, why see them also as dependencies in one another. My reasoning is that there can many reasons why access or connection can break between applications. After that the whole API will be unhealthy because it can't perform it's tasks.
- Have two endpoints: One which includes the dependencies, and one which not. When you are calling one API from the other, use the one without the dependencies. I can understand this one, however this can overcomplicate something that should be a very simple endpoint. People can also make the main mistake of circular dependency here if they are unfamiliar with the system.
- Same as the previous one, but with 1 endpoint and an optional query parameter, like
&includeDependencies
which isfalse
by default. This seems to be the most reasonable but it can still lead to circular dependency by human error. - Have the endpoints send the already checked endpoints when calling for the health of another one. With this one, I definitely see that it is either overcomplicating, or overengineering.
How would one solve the issue described above?