

- Route the query to the shard holding the “primary” side of the relation and perform remote lookups for missing rows (remote key lookups).
- Fan-out (scatter) the query to multiple shards, gather results, and aggregate them; sometimes an intermediate shuffle of results is needed.
- Use distributed join algorithms (for example, a repartition/repartition-join) that repartition intermediate results across nodes; this can be expensive for high-cardinality sets.
Design strategies to avoid expensive cross-shard joins
Because cross-shard joins are expensive, a common design goal is to keep frequently-joined data on the same shard. The three primary strategies are:
- Co-location
- Denormalization
- Replicating small reference tables
- Co-location means placing related rows together on the same shard. For example, if Chris’s user profile is stored on Shard 3, store Chris’s posts and likes on Shard 3 as well. That way, rendering Chris’s profile, posts, and like counts requires only local reads and joins.
Co-locating data that’s frequently accessed together minimizes cross-shard network overhead and gives the best read performance for those access patterns.
- Denormalization copies frequently-read attributes into the table where the read happens. For example, when Leo (on shard 0) likes Chris’s post (on shard 3), you might copy Leo’s display name into the likes row stored on shard 3. Rendering the list of likers then requires no remote reads.
Denormalization improves read latency but requires a strategy for keeping duplicated copies consistent (synchronous update, asynchronous propagation, or accepting eventual consistency).

- For very small lookup tables (country codes, currency symbols, status enums), keep a full copy on every shard so queries can be answered locally without cross-shard coordination.
Replicated across shards:
This pattern works well when the table is small and relatively static.


Links and references
- [Distributed SQL databases and sharding concepts — overview articles and docs]
- For examples of distributed databases that provide partitioning and routing primitives, see CockroachDB, Google Spanner, and YugabyteDB.
- When choosing a solution, evaluate your read/write patterns, acceptable consistency model, and operational complexity.