---
title: "The architecture of Neki"
description: "Neki shards unmodified PostgreSQL behind a single connection string."
url: "https://swe.quest/articles/the-architecture-of-neki-b0a20bdb70a4c3cd"
canonical: "https://planetscale.com/blog/the-architecture-of-neki"
source: "PlanetScale"
published: "2026-09-18"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 9
tags: ["postgres","distributed-databases","replication","system-design","kubernetes"]
---

# The architecture of Neki

A post on [PlanetScale](https://swe.quest/sources/planetscale.md), published 2026-09-18, 9 min read, Deep dive. Original: [https://planetscale.com/blog/the-architecture-of-neki](https://planetscale.com/blog/the-architecture-of-neki)

## Summary

Neki shards unmodified PostgreSQL behind a single connection string. A Router speaks the Postgres wire protocol, parses and plans queries against the sharding layout, and either pushes joins down to shards or runs cross-shard nested-loop, hash or merge joins itself. Each instance runs a Sidecar that pools connections by lifetime (statement, transaction, session advisory lock) and a PostgresManager. Admin handles failover, pg\_rewind and per-shard sync/async/cross-zone durability, while an authoritative shard keeps custom type OIDs consistent and etcd holds the Data Topology. A Replicator built on logical replication drives MoveTables, Reshard and shadow-table OnlineDDL, and the Router buffers retryable queries during cutovers and failovers.

Written by swe.quest, not by the author.

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

## Topics

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

## Prerequisites

- PostgreSQL replication ([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))
- Kubernetes operators ([easy posts on Kubernetes](https://swe.quest/tags/kubernetes.md?difficulty=easy))

## Keywords

Neki, PlanetScale, PostgreSQL, etcd, pg\_rewind, gRPC

## Related posts

- [Building a faster, lazier router for Postgres](https://swe.quest/articles/building-a-faster-lazier-router-for-postgres-bc9a70ce219128ed.md): PlanetScale · 2026-10-01 · Hard · 15 min read · PostgreSQL, Distributed databases, Performance engineering, Go, Query engines
  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.
- [Architecture decisions in Neon](https://swe.quest/articles/architecture-decisions-in-neon-01182afd96537274.md): Neon · 2022-07-08 · Medium · 9 min read · PostgreSQL, Storage engines, System design, Serverless, Replication
  Neon built serverless Postgres by separating storage from compute without forking Postgres.
- [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.
- [Managed Postgres on Railway](https://swe.quest/articles/managed-postgres-on-railway-38376e6923686bbc.md): Railway · 2026-11-05 · Medium · 9 min read · PostgreSQL, Replication, Cloud platforms, AI agents
  Railway's managed Postgres now covers the full database lifecycle: private-by-default services with reference-variable credentials, usage-billed vertical scaling, live volume resizing, and one-click PgBouncer pooling with a separate unpooled URL for migrations.
- [Our Approach to High Availability](https://swe.quest/articles/our-approach-to-high-availability-0ddd5899b8c18a1c.md): Neon · 2024-10-25 · Easy · 5 min read · PostgreSQL, Replication, Resilience, Cloud platforms, Databases
  Neon treats high availability as a consequence of separating stateless compute from distributed storage rather than as a paid add-on.

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)
