Use namespaces for tenant isolation
The most efficient way to implement multitenancy is to use namespaces to separate data by tenant. With this approach, each tenant has their own namespace, and queries only scan that tenant’s data, resulting in better performance and lower costs. For a complete implementation guide with examples across all SDKs, see Implement multitenancy.Why namespaces are more efficient
Why namespaces are more efficient
When you use namespaces for multitenancy:
- Lower query costs and faster performance: Query cost is based on namespace size. If you have 100 tenants with 1 GB each, querying one tenant’s namespace costs 1 RU and scans only 1 GB. With metadata filtering in a single namespace (100 GB total), the same query costs 100 RUs and scans all 100 GB, even though the filter narrows results.
- Natural isolation: Reduces the risk of application bugs that could query the wrong tenant’s data (for example, by passing an incorrect filter value).
Avoid filtering by high-cardinality IDs
A common anti-pattern is storing all data in a single namespace and using metadata filters to scope queries to specific users:- Performance degradation: Large
$infilters increase network payload size and query latency. - Hard limits: Each
$inor$ninoperator is limited to 10,000 values. Exceeding this limit will cause the request to fail. See Metadata filter limits.
Use access control groups instead of individual IDs
If data must be shared across many tenants, design your access control using the smallest number of groups that describe a user’s access:Multitenancy patterns
The following table provides general guidelines for choosing a multitenancy approach. Evaluate your specific use case, access patterns, and requirements to determine the best fit for your application.
For a complete step-by-step implementation guide, see Implement multitenancy.