-
Notifications
You must be signed in to change notification settings - Fork 162
Configuring sharding
From AuthP version 6 and above there are four things to setup a sharding multi-tenant application. They are:
- Set the AuthPermissionsOptions's
TenantType
- Register the DistributedFileStoreCache
- Add the
SetupMultiTenantSharding
method to register sharding - Select which mode you want to use.
The following sections details the four steps, with longer section at the end to explain about the two modes.
NOTE: There are two examples of sharding multi-tenant applications to help you understanding sharding. Example6 uses the hybrid mode and Example7 uses the sharding-only mode.
You need set the AuthPermissionsOptions's TenantType
with one of the following enums
-
TenantTypes.SingleLevel
- see this section for details how the tenant's data is stored -
TenantTypes.HierarchicalTenant
- see this section for details how the tenant's data is stored
This should be set in the first RegisterAuthPermissions
method, e.g.
builder.Services.RegisterAuthPermissions<Example7Permissions>(options =>
{
options.TenantType = TenantTypes.SingleLevel;
//... rest of code left out
The AuthP version uses the Net.DistributedFileStoreCache to hold the sharding entries which holds the information to select the correct database based on the logged-in user. There is the code for registering
builder.Services.AddDistributedFileStoreCache(options =>
{
options.WhichVersion = FileStoreCacheVersions.Class;
}, builder.Environment);
NOTE: Go to the Net.DistributedFileStoreCache's documentation for a more detailed on how to register the DistributedFileStoreCache.
You need add the SetupMultiTenantSharding
method to the registration of the AuthP features.
.SetupMultiTenantSharding(.. see mode section below ...)
Its easy to set the mode but the documentation below is long as it explains what each mode does.
From AuthP version 6 and above you have the opportunity to select how the tenant's data. In the Sharding explained document explains the two modes, hybrid or sharding-only, and information to help you to select the mode that works for your project. This document then tells you:
- a. How to select a mode
- b. The changes the mode makes to your app
- c. What is the result of being this mode?
Here is a list of what they do, and want is the result of being in each mode.
When you add the SetupMultiTenantSharding
method to the AuthP you must provide a new ShardingEntryOptions
with its hybridmode
ctor parameter to true
as shown below.
.SetupMultiTenantSharding(new ShardingEntryOptions(true))
NOTE: See the Example6's Program for a multi-tenant app using hybrid mode.
- The "DefaultConnection" connection string, which provides the database use by AuthP's to hold its data, is shown in the list of connection strings available to add sharing tenants.
- On the first deployment of your multi-tenant application to a new web server, then a default sharding entry (see the How AuthP handles sharding document on sharding entries are) is added to the sharding entries and linked to the "DefaultConnection" connection string. This default sharding entry allows you immediately add sharing tenants to the database defined by the "DefaultConnection" connection string.
When in hybrid mode the first deployment the application sets up connection strings and a sharding entry that allows a new shared tenant without need to manually set up a sharding entry. This also me to create a example of using sharding in the AuthP repo called Example6, which you can run to try it out, including demo users and tenants via AuthP's Bulk load feature.
The SetupMultiTenantSharding
method will default to sharding-only mode.
.SetupMultiTenantSharding()
NOTE: See the Example7's Program for a multi-tenant app using sharding-only mode.
- The "DefaultConnection" connection string is not listed in the connection strings available to add sharing tenants, unless the "DefaultConnection" connection string is the only connection string. This useful because:
- If you add connection strings linked to different servers, they are shown and the "DefaultConnection" connection string isn't (see Example7's appsettings.json file.
- But only want one server, found by the "DefaultConnection" connection string, then this will work without providing any other connection strings.
- On the first deployment of your multi-tenant application to a new web server the list of sharding entries is empty.
Because you have sharding-only tenants and there is Shard-only tenant service that makes it very easy to create and delete tenants. Therefore its better to NOT have pre-configured like the hybrid mode and on first deployment the application. This means you application starts there will no tenants or sharding entries (see the How AuthP handles sharding document for sharding entries), but it is very simple to add a new tenant.
- Intro to multi-tenants (ASP.NET video)
- Articles in date order:
- 0. Improved Roles/Permissions
- 1. Setting up the database
- 2. Admin: adding users and tenants
- 3. Versioning your app
- 4. Hierarchical multi-tenant
- 5. Advanced technique with claims
- 6. Sharding multi-tenant setup
- 7. Three ways to add new users
- 8. The design of the sharding data
- 9. Down for maintenance article
- 10: Three ways to refresh claims
- 11. Features of Multilingual service
- 12. Custom databases - Part1
- Videos (old)
- Authentication explained
- Permissions explained
- Roles explained
- AuthUser explained
- Multi tenant explained
- Sharding explained
- How AuthP handles sharding
- How AuthP handles errors
- Languages & cultures explained
- JWT Token refresh explained
- Setup Permissions
- Setup Authentication
- Startup code
- Setup the custom database feature
- JWT Token configuration
- Multi tenant configuration
- Using Permissions
- Using JWT Tokens
- Creating a multi-tenant app
- Supporting multiple languages
- Unit Test your AuthP app