Skip to content

Protocol facades

A facade lets an application keep its client library and talk to OliviaDB: the protocol of the system being replaced, over OliviaDB's own data and rules. OliviaDB already speaks DL/I (IMS programs), the Mem0 API, MCP and the PostgreSQL wire protocol (the read-only SQL projection, docs/sql.md). This page is about facades for the native mode: aggregates of the schema language (spec/schema.md) served by oliviadb-server (docs/network-api.md, "Native aggregates").

Principles

  • A facade is a front end, not a second data plane. Every request becomes a call of the native data plane (oliviadb_server::native::handle) as the caller: the same access profile (paths, fields, rows, masks, quota, consistency, transaction scope), the same errors, the same audit log. Nothing a profile refuses over HTTP can be done through a facade.
  • Same credentials, same transport rules. API keys and OAuth bearer tokens as for HTTP; TLS 1.3 with the server's certificate; plain connections only on a loopback address.
  • Say what differs. Where the foreign protocol promises something OliviaDB does not do the same way (a key space without types, reads inside a transaction, wildcard patterns), the facade refuses with an error that says so rather than imitating it loosely.
  • Keys are paths. A key names a node by its path in the native API (Customer/C1/Account/A1; key parts percent-encoded and joined by ,, twins by ~ordinal): ordered keys, as the engine stores them.

Candidates

Facade Clients Fit with native aggregates Cost
Redis protocol (RESP2/RESP3) every language; redis-cli a node is a hash of its fields; key = path; MULTI/EXEC = one transaction; WATCH = optimistic precondition; SCAN = a listing small: a line protocol, no schema language, auth by AUTH/HELLO
DynamoDB API (JSON over HTTP) AWS SDKs table = aggregate, partition key = root key, sort key = the path below the root; Query with begins_with = a subtree; TransactWriteItems with conditions = /v1/txn with preconditions larger: SigV4 request signing (credentials as access key pairs), typed attribute values, the condition/projection/update expression languages
MongoDB wire protocol every language a record = a document with nested children largest: BSON, the query language, cursors, aggregation pipeline

Decision: the Redis protocol first (the smallest useful subset below), DynamoDB-style second when a pilot asks for it, MongoDB not planned. The Redis protocol is small, its clients are everywhere, and its two models that matter, hashes and optimistic transactions, map one to one onto nodes and OliviaDB's optimistic transactions (oliviadb_core::otx).

The Redis-protocol facade

Code: open/crates/oliviadb-server/src/resp.rs. Configuration: "resp_listen": "127.0.0.1:6380" in the server's configuration (oliviadb_server::config), on the same TLS certificate as HTTP. The protocol is RESP as specified by Redis (redis.io/docs/latest/develop/reference/protocol-spec): commands as arrays of bulk strings (or inline), replies in RESP2, or RESP3 after HELLO 3.

Commands

Command Does
AUTH [user] token, HELLO [2\|3] [AUTH user token] [SETNAME n] authenticate with an API key or an OAuth access token (the user name is ignored); HELLO chooses the protocol. Before that every other command answers NOAUTH
PING, ECHO, SELECT 0, CLIENT ID\|GETNAME\|SETNAME\|SETINFO, COMMAND, QUIT connection housekeeping (one database; COMMAND answers an empty list)
GET key the node as GET /v1/aggregates/<key> gives it (path, key, fields, layout, version), as JSON text; nil when absent or hidden
JSON.GET key [$] the node with its subtree (?tree=true), as JSON text
HGETALL, HGET, HMGET, HLEN, HEXISTS, HKEYS, HVALS the node's fields as the profile shows them, as a hash (values as text: decimals at their scale, enums by name, masked values masked); an absent node is an empty hash
EXISTS key... how many of the nodes exist (and are visible)
SET key {fields} [NX\|XX] the node's fields as a JSON object: NX inserts (nil when it exists), XX updates (nil when absent), neither inserts or updates (put)
HSET key field value..., HMSET put with these fields (typed by the node type: booleans true/false or 1/0, floats as numbers, everything else as text, as the native API reads it); HSET answers the number of fields when it inserted the node, 0 when it updated it
DEL key..., UNLINK deletes the nodes with their subtrees in one transaction; answers how many existed
SCAN cursor MATCH <listing>[/*] [COUNT n] one listing (Customer/*, Customer/C1/Account/*) in key order, COUNT a page (at most 1000); cursors are numbers the connection keeps
KEYS <listing>[/*] the whole listing (at most 10 000 keys)
MULTI, EXEC, DISCARD writes queued and run as one transaction (POST /v1/txn): all or none
WATCH key..., UNWATCH EXEC fails (a nil array) when a watched node changed since WATCH

Differences from Redis

  • Keys are typed paths. A key that is not a path of a served aggregate is an error; there are no strings, lists, sets, sorted sets or streams, no expiry, no pub/sub.
  • Values are fields. SET takes and GET gives JSON; a hash's fields are the node type's fields, typed, and a write is checked as over HTTP (an insert needs every field, a value must fit its type).
  • SCAN lists one type at a time. MATCH names a listing; glob patterns across the key space are refused (ERR MATCH names one listing), and SCAN without MATCH too. Cursors are per connection (and forgotten when it closes).
  • Transactions are all or none. In Redis a command of EXEC that fails leaves the others applied; here a failing write aborts the transaction and EXEC answers EXECABORT Transaction discarded: <reason>, nothing written. Under txn scope aggregate (the default) one transaction writes one aggregate record (NOPERM otherwise). Reads cannot be queued (ERR GET is not queued, and the transaction is discarded): read before MULTI, protected by WATCH.
  • WATCH is a precondition in the transaction. WATCH records the version the server serves at that moment; EXEC sends, before the writes, an unchanged operation per watched key (/v1/txn: the node's stored value now equals its value at that version; 412 otherwise), so the check and the writes commit together. A node absent at WATCH and still absent is unchanged. A write that stored the same bytes again is not a change (sealed data of a data subject is stored with a new nonce, so for it every write is). A watched key older than the history kept fails EXEC with an error (410).
  • Errors carry Redis's prefixes where one fits: NOAUTH, WRONGPASS, NOPERM (the access profile refused; the reason follows), TRYAGAIN (503: retryable, e.g. lock timeout or a standby), EXECABORT, ERR for the rest.

/v1/txn operations added for it

They are part of the network API (docs/network-api.md), usable over HTTP too:

  • {"op": "put", "path", "fields"}: an update when the node exists, an insert when not, each under its own grant.
  • {"op": "delete", "path", "if_exists": true}: a missing node deletes nothing (no 404).
  • {"op": "unchanged", "path", "since": <version>}: a precondition (needs get); 412 precondition-failed when the node's stored value differs from its value at since, 410 when since is older than the history kept.

Tests

open/crates/oliviadb-server/tests/resp.rs: RESP2 and RESP3 replies byte for byte, auth, hashes, GET/JSON.GET, SET NX/XX, SCAN/KEYS, DEL, transactions (all or none, the transaction scope, reads refused in MULTI), WATCH against a second connection, the teller profile of spec/schema/examples/bank.olv (its fields, rows and grants), plain text off loopback refused; then the real redis-cli of the redis:7-alpine image over TLS (RESP2 and -3), skipped with a note when Docker or the image is missing. open/crates/oliviadb-server/tests/native_more.rs (put_if_exists_and_unchanged): the new /v1/txn operations over the native handler.

DynamoDB-style facade (designed, not built)

  • Tables are aggregates; the partition key (pk) is the root's key, the sort key (sk) the path below the root (Account/A1/Txn/2026-...,1~01), so a record is an item collection and Query(pk = :c AND begins_with(sk, :p)) is a subtree or a listing in key order. Items carry the node's fields as attributes (typed: S, N, BOOL).
  • GetItem, PutItem (with attribute_not_exists / attribute_exists conditions: insert / update), UpdateItem (SET of fields only), DeleteItem, Query, TransactWriteItems (with ConditionCheck = unchanged) map onto the same calls; Scan only per type, as SCAN above.
  • Authentication: SigV4 with access key pairs configured like API keys. Needs: the expression parser (a subset), LastEvaluatedKey as the listing's next.

Open

  • The facade on the nodes of a high-availability pair (oliviadb-ha-node): only oliviadb-server serves it now.
  • Redis: change notifications (SUBSCRIBE to the change stream), HDEL (a field cannot be removed from a typed node; setting its default would be the honest form), HINCRBY (a read-modify-write: possible as one transaction), CLIENT TRACKING, INFO.
  • The DynamoDB-style facade (above), after a pilot asks for it.