- In a single database instance, joins are local: the database reads both tables and performs the join in-memory or on-disk on the same machine.
- Once data is sharded, the rows to join may live on different machines. Joining them can require moving rows across the network, coordinating partial results, and merging them, which increases latency and load.
- Some databases forbid cross-shard joins, others implement them at significant cost. Therefore, designing to avoid frequent cross-shard joins is a common performance and operational goal.

Design for locality: put frequently-joined data on the same shard, replicate small static lookup tables, and apply targeted denormalization where it reduces cross-shard traffic. These patterns trade simplicity and storage for lower read latency.
- Co-location places related entities on the same shard. For example, if Chris’s user profile is stored on Shard 3, then Chris’s chirps and their likes are also stored on Shard 3.
- This enables the database to read all relevant rows from one machine and perform local joins, giving fast reads and low cross-shard traffic.
- Co-location often uses the same shard key (or a shard key derived from the primary entity) for related tables.
- Co-location reduces cross-shard joins but doesn’t eliminate them in all cases. Example: Leo (on Shard 0) likes Chris’s post (on Shard 3). When showing Chris’s post, the likes list on Shard 3 needs Leo’s display name, which is stored on Shard 0.
- Denormalization duplicates just the fields needed for reads — e.g., storing a small copy of Leo’s name alongside the like row on Shard 3 — so reads are local and fast.
- Denormalization is selective: store only the frequently-accessed attributes needed to avoid a cross-shard lookup.

Denormalization improves read performance but introduces duplication. Updates to the original record (for example, Leo changing his name) require propagating changes to all duplicated copies. Typical solutions include synchronous updates, asynchronous background jobs, or accepting eventual consistency — each approach carries trade-offs in complexity and correctness.
- Keep a full copy of small, mostly-static reference tables (for example,
country_codes) on every shard. This lets each shard answer lookups locally without network hops. - This strategy is inexpensive for small tables and avoids the complexity of denormalizing many attributes.
- It’s only appropriate for small tables that rarely change.

- Some queries inherently require data from many users or from entities spread across shards—examples include global leaderboards, wide analytical queries, or searches across non-sharded attributes.
- In these cases the application or a coordinating service must fetch rows from multiple shards and merge or join them. This is inherently slower than a local join.
- A practical approach is to accept occasional slower queries and optimize for the common fast-path reads.

- Building a full sharding stack (hash ring, bucket map, resharding/migration tools, routing layer) is complex and operationally heavy.
- Many modern distributed databases (and managed services) already implement these components and provide features that simplify co-location, routing, and migrations.
- Choose a database that aligns with your operational needs and sharding strategy: some databases offer transparent cross-shard queries, others encourage or automate co-location and denormalization patterns.

Recommendations (practical rules)
- Prefer co-location for objects with frequent joins (e.g., user → user_posts → likes).
- Denormalize only the minimal attributes needed to avoid common cross-shard reads.
- Replicate small static tables to every shard rather than denormalizing them into many rows.
- Accept and isolate expensive cross-shard queries (run them in background jobs or on dedicated analytic clusters).
- Select a database whose sharding semantics and operational properties match your consistency, latency, and resharding needs.
- Designing Data-Intensive Applications — Sharding and Partitioning
- Kubernetes Basics (for general distributed system patterns)
- Explore vendor docs for sharding support and cross-shard query guarantees when evaluating managed databases.