Skip to content

Architecture

Mohammad Rasoul Kazemi edited this page Nov 28, 2026 · 5 revisions

Architecture

This is the entry to the architecture documentation. It follows the arc42 structure. The authoritative design is architecture.md; that document separates sourced facts, [Recommendation] items (design decisions) and [Needs verification] items. Where an ADR or a design note contradicts it, the ADR or note wins; the document has a table of the departures.

Map of the arc42 chapters

arc42 chapter Page
1 Introduction and goals Architecture Introduction and Goals
2 Constraints Architecture Constraints
3 Context and scope (C4 level 1) Architecture System Context
4 Solution strategy The sections below, and Enterprise Architecture
5 Building block view (C4 levels 2 and 3) Architecture Containers, Architecture Components
6 Runtime view Architecture Runtime Views Sharding, Architecture Runtime Views Availability and Ledger
7 Deployment view Architecture Deployment
8 Crosscutting concepts Architecture Crosscutting Concepts, Security Model
9 Architecture decisions Architecture Decisions
10 Quality requirements Architecture Quality Requirements
11 Risks and technical debt Architecture Risks and Technical Debt
12 Glossary Glossary

Related: the platform view and the capability map of the roadmap are in Enterprise Architecture; the data model is in Data Architecture.

A thin fork with extensions

KingresDB is a fork of a stable PostgreSQL branch with a small set of core patches (ADR 0001). The patches are registered in core-patches.md. The logic of sharding and of the ledger lives in extensions, not in the executor. The name avoids the PostgreSQL marks and the repository states that KingresDB is not PostgreSQL.

There is one product branch per PostgreSQL major, with the same KingresDB code on each: kingres-18 (upstream tag REL_18_7) and kingres-19 (upstream tag REL_19_0, PostgreSQL 19.0). Every extension is one source that builds and passes its tests on both majors; version differences live only in a compatibility header (ADR 0023, releases.md). A cluster runs one major; moving a cluster between majors is not designed.

Components at a glance

Component Where Role
kingres_shard (0.9) contrib/kingres_shard Sharding: catalog, bucket mapping, planner and executor hooks, pushdown and repartitioned joins, MERGE, two-phase commit, background worker, bucket movement and split, distributed schemas, standbys. See Sharding
kingres_ledger (0.3) contrib/kingres_ledger Ledger tables, block builder, digest and verify functions, client signatures. See Ledger
kingres_sketch (1.0), kingres_timepart (0.3), kingres_columnar (0.2) contrib/ Analytics. See Analytics Extensions
kingresd, kingres-watchdog kingres/control-plane kingresd is one Go program per server: agent, manager, client router and REST API, with the web panel embedded. kingres-watchdog is the small program that stops a primary whose kingresd is gone. See Control Plane and REST API
Web console kingres/web Vue 3 and TypeScript single-page application. See Web Console
REST contract kingres/api/openapi.yaml The OpenAPI contract that the backend and the client are checked against
Verifier kingres/verifier Standalone command-line verifier that does not trust the database. See The Verifier
Packaging kingres/packaging Build recipe, Debian package (.deb) and container image per major (amd64), development cluster, release script. See Installing and Packaging

Sharding in one paragraph

A distributed table is split into a fixed number of hash buckets; buckets are assigned to shard groups; a group is one primary and optional standbys on separate servers (ADR 0006, ADR 0007). The authoritative catalog is kept on the primary of the map group and copied to the other nodes (ADR 0008). Writes can be sent to any node, which routes them (ADR 0010). Distributed transactions use two-phase commit with Read Committed in each shard and no global snapshot (ADR 0009): a statement that spans shard groups reads each group at its own snapshot, so a cross-shard read may see a partially committed distributed transaction. A transaction that touches one shard group is fully correct. Atomic visibility of covered read-only statements is phase 8, in design and not built; it is not a global snapshot. The first release, 0.1.0, was published on 2026-11-28; every phase except 8 is built (phase 15, third-party extension management, is designed and comes after 0.1.0).

The scan that moves rows to the originating node and evaluates the statement there is permanent: it answers every query shape, and faster paths (pushdown) only add to it (ADR 0022). See Sharding Query Pushdown.

Ledger in one paragraph

A ledger table keeps a hash chain and Merkle blocks. One ledger chain exists per shard group, and phase 7 adds an aggregate digest over the chains (ADR 0013). Consensus between nodes is phase 8, in design since 2026-11-28 and not built. See Ledger, Ledger Signing and Publication and Ledger Anchoring.

Control plane decisions that departed from the original design

Every server runs one kingresd and serves the panel (ADR 0014). The pattern follows the Couchbase cluster manager: a local agent, an elected manager, one REST API.

Topic Built
Manager leader The kingresd on the server that holds the primary of the map group (ADR 0018)
Cluster state A system database kingres_system on the map group (ADR 0019)
Failover Inside kingresd, fenced by leases granted by a majority of the servers; Patroni and etcd are not shipped (ADR 0021). See High Availability
Metrics No bundled store; a short in-memory history for the charts and /metrics for an external Prometheus (ADR 0020)
Panel accounts PostgreSQL roles (ADR 0015)
Panel framework Vue 3 (ADR 0017); the API is contract-first (ADR 0016, whose frontend choice was replaced by ADR 0017)
Server-to-server traffic An internal HTTP API with mutual TLS under a cluster certificate authority (control-plane-3.md)
Package and unit Package kingres, unit kingres.service, client programs with a kingres- prefix

Licence and trademark

KingresDB's own code is AGPL-3.0-only (ADR 0024); PostgreSQL's code keeps its licence (ADR 0004, root COPYRIGHT). No code from Citus is used.

Further reading

The decisions are indexed in Architecture Decisions and in the ADR index. The designs per phase are in kingres/docs/design; see Status and Roadmap for the list. The research behind the design is in kingres/docs/research.

Sources

Clone this wiki locally