Writing a Client for an API
I'm continuing to read of Building Microservices by Sam Newman. The book is excellent so far. The author describes not only what's the best approach in particular situation but also what are common mistakes.
Today I learned about mistake which I made. Some time ago I was working on an internal project in our company. I was a part of a team implementing a system which groups all knowledge about our people, projects, used technologies, clients etc. This system was designed to help identify if we have appropriate skill-set and experience to tackle project requests coming from our clients.
I'm not going to describe all the details about the project. The technology stack, design and issues we had, deserves separate blog post. It's worth saying that we had several microservices (the longer I'm reading the book, the more I'm convinced that those are not microservices — just multiple monoliths) and the API of core service was supposed to be open for anyone in our company interested in the integration. So basically, if someone wanted to get some information from the system it should be easy to integrate with the core service.
The graph nature of the data (we actually used neo4j to store all the information) resulted in the API which was not the easiest to work with. My proposal was to implement a java client which would hide all the complexity of the API. Maybe more feasible approach would be to use GraphQL instead of REST but at the time we were implementing the system, we decided that REST would be easier approach for MVP.
Today I read that using the client for API is not the best approach because it's easy to increase coupling between the client and the implementation of the service. It makes sense. The team which implemented the core, knows all the quirks of the core and those details can leak to the client if we are not careful. The risk of coupling can be mitigated by delegating the implementation to a separate team which was not working on the core. This is how Amazon is creating theirs SDKs for AWS.
I see more mistakes we made the longer I read the book.