The lifecycle of a sharded Postgres query
Blog post from PlanetScale
Neki presents a sharded PostgreSQL architecture designed to make databases distributed across many servers appear to applications as a single Postgres instance, while handling authentication, wire-protocol compatibility, SQL parsing, distributed planning, failures, and connection pooling. Using a customer-and-orders join as an example, it traces how a router implements PostgreSQL SCRAM authentication and both simple and extended query protocols, parses SQL into an abstract syntax tree, consults cached schema and shard-topology metadata, and creates a distributed execution plan. When customers and orders are sharded independently by their IDs, related rows may reside on different shards, requiring scatter-gather requests and a router-side hash join that can spill to disk if memory is insufficient; individual shards still use PostgreSQL’s native planner to execute their assigned subqueries. Requests travel through sidecars that pool reusable Postgres connections and restore the correct session settings and role, while results are streamed back and, where possible, forwarded using their existing encoded values to reduce processing. For distributed aggregates such as AVG, the router rewrites calculations into shard-local sums and counts before combining them centrally. The discussion concludes that choosing compatible shard keys, such as sharding orders by customer_id alongside customers by id, colocates related data so PostgreSQL can perform joins locally, reducing router work and network requests.
No tracked trend matches for this post yet.
Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.