0

I have to implement readiness probe for every service in my spring boot app.

Every of my services in application expose liveness and readiness endpoints.

Some of my services depends on others.

The question is: How to check service A in readiness of service B?

  1. Write ServiceAHealthIndicator class, that will request service A liveness endpoint. And then include this health indicator in application.yml by property menagment.endpoint.health.group.readiness.include=ServiceA

  2. In Kubernetes configuration add endpoint serviceA/liveness to readiness. Maybe something like:

readinessProbe:
   httpGet:
    path: serviceA/health/liveness
    port: 8000
Jonas
  • 121,568
  • 97
  • 310
  • 388
David89
  • 31
  • 3

1 Answers1

0

In my opinion, liveness and readiness endpoints of service B should not be called by service A. These endpoints are there for Kubernetes to know how to handle specific containers.

So the service A should call service B business endpoints as usual. E.g. if B exposes an operation add(x, y), then that's the operation A should call.

To make sure failures (of degrade of service, like latency) of B are handled properly in A; A should use Circuit Breaker pattern (https://en.wikipedia.org/wiki/Circuit_breaker_design_pattern) - this will allow A to handle B's failures in more predictable way.

Usually, services don't check their dependencies health with a dedicated call. This is because the logic around making those checks is both complicated and slow.

AndrewR
  • 1,252
  • 8
  • 7
  • What if communication between services is made by REST API and service B doesn't expose any GET endpoints? In that case it will be okay to use liveness endpoint? – David89 Jan 16 '23 at 20:18
  • Not sure how useful that would be - liveness endpoint just tells A if B is alight. It doesn't do any "business" logic. For example, let's say A call B to get a random text. B would have an API getRandomText() and it may have a healthCheck() API for Kubernetes to decide if B container is alright. Technically, you could let A to call anything on B - but in microservices architecture B should explicitly provide some logical service. Health/liveness check is just an infrastructure thing. – AndrewR Jan 16 '23 at 21:11