-
Notifications
You must be signed in to change notification settings - Fork 161
Sharding explained
If you want to build a multi-tenant application, then you set the options.TenantType
to define either a SingleLevel
or a HierarchicalTenant
. This defines the how the tenant's data is organised.
And, by default all the tenant's data is stored in one database, with a DataKey
to select each tenant's data. See Multi-tenant explained documentation for an overview of the multi-tenant options.
But if you want use AuthP's sharding feature, then you call the SetupMultiTenantSharding
extension method in your AuthP registering. This will add an extra TenantTypes
called AddSharding
is added, which adds the extra ability for a tenant to store its data in its own database. Adding the AddSharding
means you have two approaches to build your multi-tenant app: either Hybrid or Sharding-only (see diagram below to explain these two approaches).
The Hybrid and Sharding-Only approaches have pros and cons which I show in the table below
What | Hybrid | Sharding-Only |
---|---|---|
Summary | Good if you have a large range of small and large tenant data. Use shared db for small tenants and Sharding-Only for large tenants | Best performance and easy to use, but costly if you have lots of cloud databases (consider Azure SQL Database elastic pools ) |
Feature diffs | "Sign up now" is limited 👎 | Extra Sharding-Only services makes coding easier 👍 |
Easy of coding | Supporting both tenant types takes a bit more work | Simpler because only one tenant type to code for |
Easy for admin | It takes two steps to add a new Tenant | It takes one step to add a new Tenant (and obvious) |
Easy for tenant user | Good | Good |
Performance | Tenants sharing one database is slower | Best performance |
Backups | Tenants sharing one database is difficult | Good: each database can be backed up |
The Configuring sharding document details how to select the Hybrid or Sharding-Only approach and explains what each approach (slightly) changes to support the approach you have selected.
- 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