|
|
|
|
|
by latch
4125 days ago
|
|
FWIW, I've found that building a robust and deep "API Gateway" is the key to making SOA/Microservices work. Otherwise, you end up with duplication and latency. Routing and authentication are obvious candidates. It's also a good place to track stats and tag each request with a unique ID so you can trace it as it flows through your services. By "deep", I mean that it should be application-aware. Caching is a good example. For many applications, url + querystring results in too many permutations. If the cache is aware, it can often use more meaningful keys. Additionally, events in the underlying services can be used to cache purge, which can result in a wicked cache hit ratio. A more complex example has to do with duplication. Say you're building an ecomm platform. You have a service for search, and one for recommendations and one for the main catalog. They all need to return the same representation of a "product". Do you duplicate the logic? Do you tie them together and pay the latency and reliability price? No. Have them all just return IDS, and let the API Gateway hydrate the actual results. It's a form of API-aware server-side include and it works well. |
|
Three useful definitions[1] for microservices are:
1) collaborating
2) independently deployable (Martin Fowler [2])
3) globally-aware
Having an API Gateway makes them follow none of these meaningfully, as:
1) the services are collaborated _upon_ rather than doing so with each other (see Clump[3], not itself a bad idea)
2) updating a microservice will many times require a redeploy of the API gateway and for everyone to update their connections to it
3) any functionality you put in the gateway becomes encapsulated in a way tailored to application-global needs, which is pretty inimical to modular components, so you'd better not talk through the gateway except where you absolutely must!
Having orchestration/aggregation services as buro9 mentions in a sibling post is one good solution, satisfying all of those three points much more cleanly.
The danger arises when you start to think of your gateway(s) as layers in front of your system rather than just more microservices in it.
[1]: (context) https://vimeo.com/118895501#t=48s
[2]: http://martinfowler.com/articles/microservices.html
[3]: http://getclump.io/