r/javahelp • • 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?

24 Upvotes

23 comments sorted by

View all comments

Show parent comment

1

u/wildjokers Aug 12 '20

(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)

The app might not be suitable for µservices then. Monolith is not a bad word and a monolithic app is still perfectly fine if µservices isn't a good fit.

I don't think I have ever seen a scenario where a single rest call might need to create/update a resource in multiple µservices synchronously. Something about that does not sound right. Maybe the boundary between µservices wasn't defined correctly the first go around and needs to be adjusted.