0Pricing
SQL Academy · Lesson

Cross-Shard Queries: The Hard Problem

Understand why cross-shard joins and transactions are the hardest problem in distributed databases, and the patterns that minimise them.

The Sharding Tax

Sharding scales writes and capacity but makes queries that span shards painful: every cross-shard query is a fan-out.

Single-Shard Queries Are Easy

If your shard key is in the WHERE clause, the router sends one query to one shard:

-- shard_id = hash(user_id) % N
SELECT * FROM orders WHERE user_id = 42;
-- Router computes shard, sends one query, gets one result.

All lessons in this course

  1. Sharding Strategies: Range, Hash, Directory
  2. Cross-Shard Queries: The Hard Problem
  3. Citus and Distributed Postgres
  4. When NOT to Shard
← Back to SQL Academy