I am learning micro-services in java and after going through several reference on its design and patterns still not clear what is the right way to check foreign key relationship.
I have two micro-services userService and groupService.
userService has: user_id, user_name, group_id
groupService has: group_id, group_name
When adding new user through Rest POST I have to make sure group_id exist in groupService.
I went with following approaches after going through several reference:
First, userService Post calls group service with provided groupid to check if group exist and then add user but not happy as this seems to tightly coupled user service and also I have to get Group domain object in my userService to parse it.
Second way using Aggregator Pattern. I have created another service user_department_composite_service and brought common domain model in this service so on POST to composite service, call GET group and on success call POST user. This seems to separate concerns from user service but not happy as to POST user I am calling POST composite_service.
Third approach seems event sourcing (not done yet).
Could anyone guide me or provide a reference for better way to do this as this seems a common problem with micro-service. Also if anyone knows good book for microservice design pattern please let me know.
Thanks