From one machine to many, by key.
A gateway that speaks the protocols your apps already use sends each statement to the shard that owns its key. Shards are ordinary RasterizedDB servers, and every one refuses a row outside the key ranges it owns, so a stale map costs a retry, never a wrong answer.
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.
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.
- 1A keyed statement
UPDATE orders SET status = 'paid' WHERE store_id = 7 AND id = 912 arrives at the gateway over any protocol.
- 2Find the route key
The gateway reads store_id = 7 from a cached route template. It does not run the SQL.
- 3Look up the map
The signed shard map, at epoch 41, says the range holding store 7 lives on shard 2.
- 4Relay to shard 2
The client's bytes go to a session on shard 2 over multiplexed, mutually authenticated rastcp.
- 5A 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.
- 6Without a key: fan out
SELECT count(*) goes to every shard, and the gateway merges the answers.
Two ways to shard
Key sharding spreads one table's rows across shards by a route key, a customer or a store id, with fan-out for statements that span them. Per-user shards place each login on one shard at authentication and keep the session there, for isolation rather than scale.
- Key sharding: hash of a route key, a signed shard map with epochs
- Per-user shards: login role → one shard, no fan-out, no override
- Reference tables copied to every shard for local joins
- Two-phase commit for writes that span shards
Correctness does not depend on the gateway
The gateway routes; the shards guard. A read or write for a key range a shard does not own is refused there, so a gateway with an old map or a wrong template produces a retry or an error and never rows from the wrong place.
In your ORM too
The Rust client routes by itself when you would rather not run a gateway: declare the shard key on the model, and every query that carries it goes straight to its shard.
#[derive(Model)]
#[rdb(table = "orders", partition_by = "store_id, id", shard_by = "store_id")]
struct Order { store_id: i64, id: i64, total: Decimal }