简体   繁体   中英

Best practices with multi API project using Maven and Spring Boot

I am working on a project that requires the development of two separate APIs that connect to the same database.

Management API

This is an internal, non-public API that contains endpoints to manage multiple resources. Of course, these resources are persisted in the database.

Public API

The other is a public API that contains endpoints to list some of the above resources and execute operations that do not persist in the database.

Up until now, I would just create a Maven Spring Boot project using Spring Initilizr with the dependencies needed and just start developing... As you can imagine this would result in having a big monolithic project with no separation whatsoever, increasing the technical debt overtime unnecessarily.

What would be the best solution for this case?

Something like this:

  • projectname-data : The data layer. Contains DB models and interfaces
  • projectname-management-api : The Management API, that uses projectname-data as a dependency
  • projectname-public-api : The Public API, that uses projectname-data as a dependency

Unless you really need it, I wouldn't start dividing the service in more services from the very beginning. Simply having a separate controller and different access/control requirements applied to each controller should get you started.

Things that would make you start thinking about splitting them... from what you explained, basically scaling. If the public API has to be able to scale much more than the management one, you might start thinking about making it lighter and not scaling the management along with it. Strong restrictions related to access might be an issue as well.

But unless that's the case and you have it clear from the very beginning, don't pay the price of having multiple services from the very beginning for such a simple thing. Unless you are in a nut rush, once you have the proper foundations, you should have time and a cleaner view about how to divide them in the future.

"Extra services" is not something you are given for free.

That's my 2ec;). Cheers: PD, We have plenty of such services, internal tools, and so far. no need to divide any of them, I've consulted in other places where we started dividing from the very beginning but not for internal tools. and then we would not share the same DB directly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM