I have API GATEWAY, user, role, mailer, user-role microservices.
I have a question which type of development use more in production code:
API GATEWAY - Dummy Code:
user = await userMicroservice - create user
if (OK) await roleMicroservice - get role for user
if (OK) await userRoleMicroservice - assign role to user (create relation)
if (OK) await mailerMicroservice - send mail to user
OR
API GATEWAY:
user = await userMicroservice - create user
return user
User Microservice:
- create user
- get role (inject role microservice)
- assign role to user (inject user role microservice)
- send mail (inject mailer service)
return response
I understand what it's depends on project/requirements (tried chatGPT, and searched on internet) but i don't have much experiance with it and maybe one approach it's totally shit. Question for good backend developers.
Thanks:)
Normally user/role/user-role are good to have in one microservice as they represent entities of same domain (authentication / authorization). This service will create user and associate role with it. Once user is created an event can be sent which can be consumed by mailer service to send mails. There would be some edge cases with this approach as well where if while sending event message broker has some issues and you are not able to send message. In such a scenario you would still like to create user but send mail after some time when message broker comes back. For such issues we can have different approaches.