Multi-tenant Architecture with Moveable Collections
On this page
New in version 8.0.
In a multi-tenant architecture, a single instance of an application serves multiple users. Multi-tenant users share resources, and generally data belonging to the same tenant is kept on a single shard.
If your multi-tenant configuration has a single tenant per database and the majority of its workload takes place on a single shard, you can move frequently-accessed collections to other shards for more even workload distribution. This reduces the number of collections on the original shard and improves performance system-wide.
Note
Non-Sharded Clusters
If your multi-tenant deployment is a replica set, you can convert it to a sharded cluster and add additional shards to more evenly distribute your workload. For more information, see either:
Modify a Cluster for MongoDB Atlas deployments
Considerations
Moving collections has operational overhead. Before you move collections, review the
sh.moveCollection()
documentation for performance considerations.The optimal multi-tenant configuration depends on your workload and application needs. Moving collections to new shards is not as scalable as multi-tenancy in a single database with shared collections. However, having each database correspond to a single tenant allows for more customizable security and access patterns.
To optimize performance for cross-collection operations (like
$lookup
or transactions that access multiple collections), place all collections for a given tenant on the same shard.