Microservices – User Registration Flow

microservicesuser control

Let's say I have multiple microservices like authorization service (OAuth2 with JWT), VideoService and MyApplicationService.

The VideoService provides videos for MyApplicationService. Both services save user data.

A frontend makes use of all 3 services and a user doesn't know that she's actually using multiple services.

The problem is that the user registers on the authorization service. Therefore, he still needs to be registered at the 2 other services. How should this be done?

The best solution that I've come up with so far is registering the user implicitly, so that when an unknown user makes a request, a new user is automatically created (as long as the auth is valid, of course). This seems like a decent solution but doesn't feel "clean".

Is there a better, or more standard solution?

Best Answer

This is where a central messaging component works well in a micro services environment. The Authorization service needs to publish an event (send a message to a queue) that a new user was registered, along with the minimal information the other services need. The other services listen for new messages on this queue and respond to the "user registered" message by auto creating their profile.

So basically the workflow should be:

  1. Authentication service publishes a "user registered" message to the user authentication queue

  2. The VideoService and MyApplicationService listen in on the authentication queue, and respond to the "user registered" message

  3. The other two services create the user profile as a result of responding to the "user registered" message.


To be honest, each micro service having its own "user profile" functionality breaks one of the main guidelines of micro service architecture: Each micro service should specialize in 1 and only 1 business function. A "user profile" is a business function.

I recommend extracting the "user profile" functionality of the VideoService and MyApplicationService into yet another service: the User Profile Service.

It would involve identifying a clear abstraction for user profiles in different services. If you can't reasonably create an abstraction for this concept, then I would keep the user profile in the other services.

Related Topic