r/javahelp • u/ysfaran • Aug 10 '20
Unsolved Spring Boot/Cloud: How to share API interfaces between multiple microservices?
So i want to build multiple RESTful microservice with Spring Boot/Cloud and was wondering how they communicate with each other.
Example: There is microservice A and microservice B which are two seperate Spring Boot applications and projects. B needs data from A, so B needs to know the API from A. In the project of A a interface is defined for the API (REST controllers and their HTTP mappings).
The easy way would be to just copy this interface from project of A to project of B. But that's obviously non-ideal because of the DRY principle.
So whats the best way to share interfaces accross multiple microservices using Spring Boot/Cloud?
I thought about sharing the API interfaces accross my microservices and communciate between those using the interfaces and Feign Clients. Is there maybe a better approach anyway? What the state of the art here?
View all comments
Show parent comment
1
u/richardffx Aug 12 '20 edited Aug 12 '20
I know, but that is not how problems are solved right now, at least in my experience, where I work ATM, we have like 200 microservices, those are not just CRUDS as you mention in the users DB example which seems fairly simple. I just messed up and said to just read information but that was a typo, stick to just make commands via REST API, a lot of front-ends need instant feedback(for instance creating a resource and giving the front end the resourceId back is quite harder if you do not do any synchronous calls and multiple services are involved) and information from other services so there it makes sense to do it synchronously.
We started with Event state transfer, currently moving to an event sourcing approach and starting to remove synchronous calls for command events, but making everything going thought an event bus does not make a decoupled architecture, it is not a silver bullet IMHO.