Why you shouldn't do application-level sharding
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.
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.
PlanetScale's open-source Heroku Migrator moves multi-terabyte Postgres databases off Heroku standard plans, which lack WAL access and logical replication, by using Bucardo trigger-based replication: triggers record changes in delta tables, a one-time COPY loads existing data, and a worker replays the backlog before a controlled switchover with verification.
Neki, PlanetScale's Postgres sharding system, declares a primary dead only when its control plane (Admin) cannot reach it and at least one reachable replica reports broken replication with none contradicting.
Neki performs planned Postgres primary switchovers without stopping the old primary.
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.
Postgres ON DELETE CASCADE turns a single-row delete into an unbounded transaction that can cause outages at scale.
Neki, PlanetScale's sharded Postgres, implements Postgres sequences by classifying sequence operations like nextval() as router-only, with an authoritative shard hosting all sequences so values are never duplicated across shards.
PlanetScale Postgres and Neki databases can now run in three Azure regions (centralus, eastus2, westeurope), with the same HA across three availability zones, Query Insights, backups and NVMe-backed Metal clusters as on AWS and GCP.
Postgres TOAST kicks in once a row exceeds 2,032 bytes, compressing variable-length values largest-first and moving them into chunked pg_toast tables (1,996-byte chunks, 18-byte in-row pointers) when compression isn't enough.
TIN v1.0.6, PlanetScale's Postgres full-text search index, adds Snowball-based stemming for 18 languages via the rust_stemmers crate and extends its block-max top-k plan to queries with heap-attribute tiebreakers in ORDER BY.
Leaky buckets, descended from Bronze Age water clocks, remain a cheap admission-control mechanism: a bucket stores only its last level and timestamp, so its current level can be computed lazily as max(0, level_then − drain_rate × elapsed).
Neki, PlanetScale's Postgres sharding router, cuts per-query overhead by keeping PostgreSQL wire-protocol bytes intact and decoding only as much as each query requires.