0

We are going to have multiple microservices and decided to use api gateway. What we couldn't decide is if we should go for a single gateway for all of them or one for each. The reason why one for each is considered is having all api routes for all services in a single gateway feels like it's creating more coupling between gateway and services than it should.

Services are owned by one team.

What do you think? Having all routes in a single one is an acceptable coupling (like a composition layer), or do you think every microservice should have their own?

2
  • 3
    Having an API gateway for each microservice defeats the purpose of having a centralized entry point for managing and securing your APIs. Commented Jun 24, 2023 at 15:01
  • 2
    I don't see any coupling here - services behind a gateway should not have any awareness nor dependency on that gateway (That is to say, it should be possible to switch the gateway off and for all of your services to continue to work normally for internal traffic. A gateway is just an entry point for external traffic -- if the services themselves are somehow coupled to the gateway then that's a problem to be solved in itself) Commented Jun 25, 2023 at 10:06

1 Answer 1

1

What is the purpose of your gateway?, some non-exclusive choices may be to provide:

  • Authentication - resolve the user id making the request.
  • Authorization - allow/restrict access to micro-services behind the gateway.
  • Denial of service protection (i.e. you're using an external gateway on faster pipes).
  • BFF (Backend for front-end) - you have aggregation logic in the gateway which makes multiple calls to various micro-services in order to provide a better interface for a particular front end application.

It's possible to implement the first three of these in a generic way (assuming all your micro-services use a similar authentication mechanism). One concern that you may have is overlapping routes between two micro-services, however you can address that by having the Gateway re-write the URLs, for example /users/v1/... -> ... hence the external route for each service contains the micro-service name.

If want to use a BFF style of gateway then you are going to have some coupling between the BFF gateway and the service(s) it depends upon, since it will need "understand" the requests it makes in order to perform the aggregation operation.

What do you think? Having all routes in a single one is an acceptable coupling (like a composition layer), or do you think every micro-service should have their own?

If you need to aggregate multiple internal requests as a result of a single external request - then a single gateway is probably the simplest solution.

If you are just passing through requests to the micro-services (1 route to 1 route) it probably doesn't make any difference if you use one or multiple gateways - assuming you are okay with doing some URL re-writing to avoid route collisions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.