简体   繁体   中英

Loading the tenant specific variables in a multi tenant application

I have a MVC application which is multi tenant architecture. In this, there are some global variables (common to all users of every tenant) and some are specific to the logged in user. Also, there are some settings which are common to all users of a specific tenant.

I am storing and retrieving the Global and Session variables as mentioned below.

  • Specific to the logged in user - HttpContext.Current.Session["sessionVariableName] . These variables loaded at the time login of a user.
  • Global variables - HttpContext.Current.Application["applicationVariableName"] . These variables loaded in Global.asax on application startup.

Now I have a question, how load the tenant specific variables. In which event I need load the vaiables? I do not want to load all the tenant specific variables at the time of application startup as many tenant may not be using the application. Also, it may be overhead at the time login of each user to check and load the tenant specific settings. What is the best approach ?

In your case, I would like to suggest the following approach

  1. Create a table named as "TenantSettings" that holds the tenant specific settings
  2. Create a table named as "UserSettings" that holds all the user specific settings
  3. Identify the tenant post login and then when you first time get the tenant settings, you will store the TenantSettings into a cache [Distributed or In-Memory syc'ed via pub-sub]
  4. Also, post login of a user, fetch the UserSettings and also put that in the cache [same as in 3]
  5. Do not use the application memory because the cache may be accidentally polluted and will not be scale with the load

Database Entity Details for

1. TenantSettings The following can be the columns for TenantSettings

  • TenantId
  • SettingId
  • SettingValue
  • AuditFields like CreatedBy, CreatedOn, IsActive, UpdatedBy...

2. UserSettings

  • UserId
  • TenantId
  • SettingId
  • SettingValue
  • Audit fields similar to the above

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM