Search code examples
architecturemicroservicesapi-gateway

internal communication Microservices through API Gateway


In a microservice architecture, there is a common pattern called API Gateway.

I know that all communication from outside the API Gateway is used as a single entry point.

But I also would like that the internal communication from microservice to a microservice is going through the API gateway? I mean it's a lot easier to handle than establishing a point to point connection.

So what speaks against to use the API gateway also for the whole internal communication?

enter image description here


Solution

  • I have tried three flavours

    1. All communication via API gateway It makes service discovery easy, all communications can be tracked at one point, but it increases latency for services behind the gateway(Not by much but one extra hop). Also you can strip authentication and that means all services even those behind the gateway need to get the auth right (This may not be cons for some apps but for others this may very well be)
    2. External services via gateway It helps you strip auth at the gateway. You can force stricter checks on incoming request, you services talk to each other directly (but that means they need to discover the service some how, we use route53 based dns so endpoints for them to hit remains same). Services trust each other and no auth is required for these communications.
    3. External/Internal gateways We also had a scenario where we had to get two api gateways, one reason was different kind of checks that were required on two set of gateways and different set of load that each of them had to undergo.