I don't necessarily disagree with Chris' assertion that the
Backend-for-Frontend pattern is an adaptation of an API Gateway. In my
opinion that stretches the definition of API Gateway toward something
very general. In my experience calling something "API Gateway" means
that you're typically a lot closer to infrastructure than business
logic. But it's all a matter of perspective and opinion.
You can definitely write an API Gateway using Go kit, be it dumb (just
routing requests) or smart (serving a composite response full of
business domain awareness) or anywhere in between. The transport layer
would likely be HTTP+JSON. Your service implementation would perform
the necessary business logic for each request, treating downstream
microservices as dependencies. I guess it would look something like
this
type APIGateway interface {
Login(...) (token string, err error)
UserRequestFoo(...) error
// ...
}
type apiGateway struct {
search searchService // implemented by a load-balanced pool of
connections
profile profileService // same
// etc.
}
Or, if you were deploying onto e.g. Kubernetes, you maybe wouldn't
need to keep a pool of connections to individual search services;
maybe you'd just forward requests to the search service DNS entry, and
let Kubernetes handle all the load balancing and etc. for you. Then
search would be a *url.URL, maybe.
With all of that said, my intuition is that you shouldn't need to do
this, in the general case. I'd instead hope that individual
microservices would implement reasonably broad bounded contexts, and
could be called directly by clients to perform complete
business-domain actions. Said another way: if every individual action
your users take in your e.g. web app requires calling multiple
microservices, this ·may· indicate that your microservices are too
granular.
>
https://groups.google.com/d/msgid/go-kit/1B736EA9-229A-4EC8-9F4D-9FA23461237A%40gmail.com.