Problem Statement
Explain co-location strategies for multi-tenant apps to keep common queries single-shard.
Explanation
Choose tenant_id as the primary partition key so tenant-scoped reads and writes stay on one shard. Within a tenant, derive entity keys from tenant_id to keep locality for joins.
For global reports, build asynchronous aggregates or warehouse exports. If some tenants are huge, allow them multiple sub-shards with a tenant hash suffix to avoid hotspots while preserving tenant isolation.
Code Solution
SolutionRead Only
key = tenant_id + ":" + user_id // shard by tenant_id
