Search code examples
c#.net-coreasp.net-identity

.Net Core 6 - How to relate Identity users with app entities


So, I am developing an Web Application in .Net Core 6. I have two API's, one for User authentication (using Identity), and another for executing my app services. For each API i have an separate DB, one for storing the users information, and another for storing my services information. Let's say that one of my services is uploading a file to my server. In that case i need to know witch user has uploaded the file, relating the file with the user. However, since my user is in another DB, i cannot make an relationship between them.

I thought in referencing the user Id with an Integer, getting the information in API requests, but in that case, if i delete the user, it will still reference him. Should I just make my app services tables in the DB that stores the user authentication info ?


Solution

  • For distributed systems like your describing, I recommend using a Guid/Unique Identifiers.

    It's also not uncommon to store some user information across distributed systems for that exact purpose of not losing the associated information. That said, you should be careful to always have a source of truth such as the identity server, and possible setup sync jobs that will keep the other services "eventually updated." This is often done using message bus to send updates and have listeners for your services that will pickup changes such as name, contact info, or hierarchy data.

    Hope that helps.