Refactoring into microservices
The first thing we need to address is the multiple responsibilities of UserService. Each service should have one responsibility and UserService is providing both authentication functionality and user profile functionality. We can refactor like so:
What we have done in the preceding diagram is create two new JAR files called user-core-domain and auth-domain. We separated the common elements between UserService and AuthService into user-core-domain, placed the authentication capabilities that had previously been provided by UserService into AuthService, and moved TokenAuthenticationFilter into the auth-domain JAR file. This refactoring and repackaging provide much more flexibility than including all the code in each service – they just make use of a JAR file that provides the needed authentication.
The account microservice will now be structured as follows...