Design users table for single sign in to use across sub domains

后端 未结 1 1187
感情败类
感情败类 2021-02-15 07:28

We have a site which has sub domains like:

  1. example.com - Main Site
  2. food.example.com
  3. fashion.example.com

And each domain

1条回答
  •  眼角桃花
    2021-02-15 07:42

    The UserID you mentioned is only identical in a specific Users table in a single DB. It's actually not an identifier of any user in your domain. To identify users across multiple databases, you will need a domain-level ID for every user. A simple way is to add one more property (column) named UID or something like that to User class (table), of Global Unique Id (GUID, see https://msdn.microsoft.com/en-us/library/system.guid(v=vs.110).aspx) and use it as domain-level ID to identify users instead of UserId. This way you can freely store user information in multiple databases in your domain. So:

    • You can hold only domain-level ID in every sub-domain's database and use that ID to query full user profiles from the main domain DB. Pros: costs less memory. Trade-off: in a distributed system, it takes longer to query user information from sub-domain because the information residing in main DB.
    • You can hold full user information in all DB, including main's and subs'. Pro: faster queries. Cons: costs more memory and when a user information changes, you will have to synchronize it across all databases.

    0 讨论(0)
提交回复
热议问题