Entity-Based Sharding
You'll learn: How to shard by natural business entities (like user ID or tenant ID) to keep related data together and enable efficient transactions.
What Is Entity-Based Sharding?
Entity-based sharding means organizing your shards around natural business entities in your system—typically users, customers, tenants, or organizations. All data belonging to one entity lives on the same shard.
For example:
- All of User #12345's posts, comments, profile data, and activity logs go to Shard A
- All of User #67890's data goes to Shard B
- All data for Company XYZ (in a multi-tenant SaaS app) goes to Shard C
This is a specialized form of hash-based or range-based sharding where the shard key is an entity identifier.
Why It Works
Related data stays together. When you query a user's timeline or a tenant's orders, all that data lives on one shard—no cross-shard joins needed. Transactions within one entity remain simple and ACID-compliant because they don't span shards.
Analogy: Think of filing cabinets where each drawer contains everything for one customer—their contracts, invoices, and correspondence. You never need to open multiple drawers to handle one customer's request.
Common Entity Keys
- User ID (social networks, gaming platforms)
- Tenant ID (multi-tenant SaaS applications)
- Customer ID (e-commerce order systems)
- Organization ID (B2B collaboration tools)
This approach aligns perfectly with how most applications naturally isolate data: users don't typically query other users' data, and tenants don't access other tenants' records.
Key Takeaway: Entity-based sharding groups all related data by business entity (user, tenant, customer) onto the same shard, keeping transactions simple and queries efficient within entity boundaries.