NEW RasterizedDB 1.1.0 is out: sharding and the gateway, the message broker, roles and row-level security, compression, .NET on NuGet, and the enterprise edition. What's new ›
SHARDING · GATEWAY NEW IN 1.1.0

A router that does not run your SQL.

For each statement the gateway finds the route key, works out which shard owns it, and relays the client's bytes to a session on that shard. It does not parse whole statements or decode rows, so it adds tens of microseconds, not milliseconds.

Sharding and the gateway shipped in 1.1.0: every release server can run as a shard, and the gateway has release archives of its own. Not built yet: backup and restore of a whole cluster at one point, commit timestamps from a hybrid logical clock, and splitting a shard by cloning it.

HOW IT WORKS · ANIMATED 12 s cycle

The gateway routes; the shards guard

New in 1.1.0: a gateway sends each statement to the shard that owns its key. A shard refuses rows outside its ranges, so a stale map costs a retry and never a wrong answer.

CLIENTPostgreSQL, MySQLor SQL Server GATEWAY UPDATE orders … WHERE store_id = 7 route key: store_id = 7 map epoch 41 → shard 2 refused → map epoch 42 → shard 3 fan-out: merge count from 3 shards does not run the SQL SHARD 1SHARD 2SHARD 3 relayed over mux rastcp, mTLS SHARD 2RDB02 · range movedrefused before any effect ✓ retried on shard 3 count(*) → 41,208
  1. 1
    A keyed statement

    UPDATE orders SET status = 'paid' WHERE store_id = 7 AND id = 912 arrives at the gateway over any protocol.

  2. 2
    Find the route key

    The gateway reads store_id = 7 from a cached route template. It does not run the SQL.

  3. 3
    Look up the map

    The signed shard map, at epoch 41, says the range holding store 7 lives on shard 2.

  4. 4
    Relay to shard 2

    The client's bytes go to a session on shard 2 over multiplexed, mutually authenticated rastcp.

  5. 5
    A stale map is refused

    If the range moved, shard 2 refuses with RDB02 and a newer epoch; the gateway fetches the map and retries on shard 3.

  6. 6
    Without a key: fan out

    SELECT count(*) goes to every shard, and the gateway merges the answers.

1 / 3

What it speaks

  • PostgreSQL, MySQL and SQL Server clients on the front
  • rastcp to the shards: multiplexed, mutual TLS, optional zstd frames
  • SCRAM-SHA-256 with channel binding, checked at the gateway
  • A thread-per-core design: each client stays on one worker
2 / 3

Measured on a development build

A prepared point read by key, one client, a three-shard cluster and the gateway on one machine, profiling build. Directly to a shard it took 42-50 µs; through the gateway, 63-66 µs. The gateway spends about 17 µs of CPU per statement, two thirds of it in the kernel: two reads, two writes and two waits, the floor for any TCP proxy. Representative of the gateway's own cost, not of a multi-host cluster.

Prepared point read, one client, latency per statement (lower is better)

Directly to a shard42-50 µs
Through the gateway63-66 µs
~20 µsadded per statement, one client
~17 µsgateway CPU per statement, ⅔ kernel
~6 µsthe gateway's own code, spread flat
3 / 3

Built to be operated

  • Zero-downtime upgrades: the new process binds beside the old with SO_REUSEPORT, the old drains
  • Prometheus /metrics and SHOW GATEWAY
  • Route-template caches per core and shared
  • Limits that fail loudly: sessions, in-flight requests, message and gather sizes
shell
rasterizeddb_gateway --map cluster.map --listen 0.0.0.0:6432 --auth scram
✓ page rendered in 173 µs axum + tera + htmx · no other javascript