PlanetScale

Designing Neki for performance

Oct 1, 2026Dirkjan Bussink
Designing Neki for performance
SummaryAI, from the source post

This post details performance optimizations in Neki's query router. Key contributions include: 1. Lazy decoding of PostgreSQL response messages, avoiding full row/column decoding when not necessary for routing or client presentation. 2. Preservation of original PostgreSQL wire formats for `DataRow` and `Bind` messages to minimize serialization/deserialization overhead. 3. Selective decoding of only the sharding key (`account_id`) for point lookups, leaving other columns as raw bytes. 4. Handling of `LIMIT` clauses by first counting rows and then creating a pointer slice to the relevant rows without moving data. 5. Decoding of sort keys (`created_at`) only when sorting is required for global ordering across shards. 6. Efficient handling of bind parameters by caching and reusing original protocol frames. 7. Optimization for cross-shard queries where full row decoding is not needed by streaming and combining `CommandComplete` and `DataRow` messages.

More from the Neki Query Performance trail