I'm trying to create project siteWeb and mobile app with clean Architecture and Microservices.
create identity service with separate database A and make another api service with other database B.
for example i have table Competence
from DB(B) has relationship many to many with Table AspNetUser
from DB(A).
how to link between him?
Would the save two competence for user be required to store data from the User database (user_id, competence_Id) without relationship?
its a good idea to create table profile
in DB(B) has column Id
Profile
-Id
-FullName
-Email
and each inscription user be required to save user_id
to Profile ("user_id","john doe","[email protected]") after that i link profile
with others table in DB(B)?
or i can to Make profile as
Profile
-Id
-FullName
-Email
CONSTRAINT [FK_Profile_ToAspNetUsers] FOREIGN KEY ([Id]) REFERENCES [dbo].[AspNetUsers]([Id])
Do we need that?
2 Answers 2
The user information can travel in a token, see https://jwt.io and https://auth0.com/docs/protocols/oauth2 for more information
Depends on how the information is intended. As Martin pointed out, you can provide some identity information as tokens (sid (subject id, users unique id usually), email, name, birthday).
If you have information completely unrelated to identity of the user (like authorization - identity is just about authentication), you keep separate databases. If its more or less same information in both servers, you project it to the consuming one.
When you have such kind of shared information that needs to be synchronized among multiple microservices, you use pub/sub or message bus infrastructure, i.e. everytime a user changes data in ServiceA, a message is sent to the message bus and all consumers (such as ServiceB, ServiceC) read that and update their tables.
This assumes ServiceB and ServiceC don't alter this data and just need it for reading. The single source of truth remains your ServiceA which is the only one allowed to modify this data.
This can be used to sync stuff like persons names or emails in other microservices (i.e. to be able to display the creator of an data row when you display the list such as "last modified by John Doe") and keep them strictly separated.
Explore related questions
See similar questions with these tags.