---
title: "Building a faster, lazier router for Postgres"
description: "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."
url: "https://swe.quest/articles/building-a-faster-lazier-router-for-postgres-bc9a70ce219128ed"
canonical: "https://planetscale.com/blog/designing-neki-for-performance"
source: "PlanetScale"
published: "2026-10-01"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 15
tags: ["postgres","distributed-databases","performance","go","query-engines"]
---

# Building a faster, lazier router for Postgres

A post on [PlanetScale](https://swe.quest/sources/planetscale.md), published 2026-10-01, 15 min read, Deep dive. Original: [https://planetscale.com/blog/designing-neki-for-performance](https://planetscale.com/blog/designing-neki-for-performance)

## Summary

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. Results pass through as a raw byte slice and are only opened further when needed. They become row views for LIMIT, pointer slices for reordering and merge-sorting, and decoded, cached sort keys only for the columns being compared. Bind parameters and join keys are copied as length-prefixed frames, text and binary formats are preserved, and dropping columns copies contiguous runs of column frames instead of re-serializing values. Full decoding into typed values happens only when the router must compute new results, such as cross-shard aggregates. This contrasts with Vitess, which eagerly converts every row at RPC boundaries.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Distributed databases](https://swe.quest/tags/distributed-databases.md) (Data & databases)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Go](https://swe.quest/tags/go.md) (Languages)
- [Query engines](https://swe.quest/tags/query-engines.md) (Data & databases)

## Prerequisites

- PostgreSQL wire protocol ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- database sharding ([easy posts on Databases](https://swe.quest/tags/databases.md?difficulty=easy))
- Go slices and allocation ([easy posts on Go](https://swe.quest/tags/go.md?difficulty=easy))

## Keywords

Neki, PlanetScale, Vitess, PostgreSQL wire protocol, DataRow, Bind, protobuf

## Related posts

- [The architecture of Neki](https://swe.quest/articles/the-architecture-of-neki-b0a20bdb70a4c3cd.md): PlanetScale · 2026-09-18 · Medium · 9 min read · PostgreSQL, Distributed databases, Replication, System design, Kubernetes
  Neki shards unmodified PostgreSQL behind a single connection string.
- [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.
- [Making large Postgres migrations practical: 1TB in 2 hours with PeerDB](https://swe.quest/articles/making-large-postgres-migrations-practical-1tb-in-2-hours-with-peerdb-cc7872fe91229eda.md): ClickHouse · 2026-02-19 · Medium · 13 min read · PostgreSQL, Replication, Schema migrations, Performance engineering, Data pipelines
  PeerDB migrated a 1TB, 3.6-billion-row Postgres table in about 1 hour 50 minutes with 8 threads, compared with 8 hours 40 minutes for native logical replication and 17 hours for pg\_dump/pg\_restore.
- [We're building Postgres in Rust. Using the LLVM of databases](https://swe.quest/articles/we-re-building-postgres-in-rust-using-the-llvm-of-databases-e44d34208278a99e.md): Turso · 2026-07-16 · Easy · 11 min read · PostgreSQL, SQLite, Rust, Query engines, Open source
  Turso, a Rust rewrite of SQLite, is adding a Postgres frontend by parsing Postgres SQL into a common AST and compiling it to Turso's VDBE bytecode, turning the engine into an "LLVM of databases" with pluggable frontends.
- [How we scale an open source, multi-tenant storage engine for Postgres written in Rust](https://swe.quest/articles/how-we-scale-an-open-source-multi-tenant-storage-engine-for-postgres-written-in-e5615307ced50afc.md): Neon · 2024-04-15 · Medium · 5 min read · Storage engines, PostgreSQL, Distributed databases, Multi-tenancy, Scaling
  Neon shards its Rust-based Pageserver storage layer by dividing each Postgres relation's 8KiB block numbers into stripes (default 256MiB) and hashing each stripe to a Pageserver.

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)
