---
title: "Shard design doesn't start from your tables"
description: "Neki's shard groups co-locate related Postgres tables by hashing a shared shard key (e.g. customer_id via xxhash) into a 64-bit keyspace split across shards, so joins and transactions for one customer stay on a single shard with full Postgres semantics."
url: "https://swe.quest/articles/shard-design-doesn-t-start-from-your-tables-283c900085b220b2"
canonical: "https://planetscale.com/blog/shard-groups-the-unit-of-co-location"
source: "PlanetScale"
published: "2026-10-23"
difficulty: "medium"
kind: "How-to"
reading_minutes: 8
tags: ["distributed-databases","postgres","system-design"]
---

# Shard design doesn't start from your tables

A post on [PlanetScale](https://swe.quest/sources/planetscale.md), published 2026-10-23, 8 min read, How-to. Original: [https://planetscale.com/blog/shard-groups-the-unit-of-co-location](https://planetscale.com/blog/shard-groups-the-unit-of-co-location)

## Summary

Neki's shard groups co-locate related Postgres tables by hashing a shared shard key (e.g. customer\_id via xxhash) into a 64-bit keyspace split across shards, so joins and transactions for one customer stay on a single shard with full Postgres semantics. Cross-shard transactions get no atomic commit or shared snapshot. The design toolkit includes reference tables replicated to every shard for lookup data, separate shard groups for differently keyed data like a SKU catalog, SQL expressions in shard indexes such as lower(sku), range and modulo index types for legacy schemes, and global secondary indexes that turn non-shard-key lookups into two single-shard reads. The core advice is to design shard groups from your most important queries and transactions rather than from your tables, and to change them later with the Reshard workflow as needed.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Distributed databases](https://swe.quest/tags/distributed-databases.md) (Data & databases)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [System design](https://swe.quest/tags/system-design.md) (Architecture & design)

## Prerequisites

- PostgreSQL basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- database sharding concepts ([easy posts on Databases](https://swe.quest/tags/databases.md?difficulty=easy))
- hash partitioning

## Keywords

Neki, PlanetScale, xxhash, global secondary index, shard groups, Reshard workflow, MoveTables

## Related posts

- [Handling hot shards](https://swe.quest/articles/handling-hot-shards-713450434ac73606.md): PlanetScale · 2026-09-28 · Medium · 7 min read · Distributed databases, PostgreSQL, Scaling, Multi-tenancy
  When a shard key like tenant\_id stops matching reality because a few whale tenants dominate load or cross-tenant queries appear, Neki (PlanetScale's sharded Postgres from the Vitess maintainers) offers three escalating fixes: vertically scale the hot shard with its own configuration profile, isolate the whale by narrowing hashed key ranges in the declarative data topology, or reshard specific tables by a better key.
- [How Figma’s databases team lived to tell the scale](https://swe.quest/articles/how-figma-s-databases-team-lived-to-tell-the-scale-5117114294b188fe.md): Figma · 2024-03-14 · Medium · 19 min read · PostgreSQL, Distributed databases, Scaling, Query engines
  Figma horizontally sharded its RDS Postgres stack after vertical partitioning ran out of room.
- [You should shard your database](https://swe.quest/articles/you-should-shard-your-database-12cdc70ed1f6d2d7.md): PgDog · 2025-11-13 · Medium · 7 min read · PostgreSQL, Distributed databases, Scaling, Query engines
  Sharding Postgres early avoids the operational pain of large single instances, illustrated by an outage where stale planner statistics caused a 300 GB table to be sequentially scanned.
- [Horizontally scaling the Rails backend of Shop app with Vitess](https://swe.quest/articles/horizontally-scaling-the-rails-backend-of-shop-app-with-vitess-03c7b2da20f98ec3.md): Shopify Engineering · 2024-01-17 · Medium · 27 min read · MySQL, Distributed databases, Ruby, Scaling, Schema migrations
  Shop app outgrew a single MySQL database despite federating tables across databases, so the team moved its Rails backend to Vitess, sharding user-owned tables by user\_id into a "users" keyspace and keeping the rest in an unsharded "global" keyspace.
- [Why you shouldn't do application-level sharding](https://swe.quest/articles/why-you-shouldn-t-do-application-level-sharding-4fe6249c12df9221.md): PlanetScale · 2026-11-23 · Medium · 21 min read · Distributed databases, Scaling, Consistency models, Schema migrations, PostgreSQL
  Application-level sharding of an OLTP database looks simple on day one (a \`shard\_for(user\_id % N)\` function) but accumulates serious engineering burdens as a system grows.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
