Design decisions

Server, protocol and security

Decisions about the wire protocol, HTTP, UDP, the catalog, schema checks, SQL planning, accounts and Studio (D19, D20, D23 to D26, D29 to D34, D36, D40).

D19 Studio: one web front end, served by the server and wrapped in a desktop shell#

Studio is one web front end, served by the server and also wrapped in a Tauri desktop shell. The key idea is that binary documents are decoded in the browser by a WebAssembly build of the document crate, so types stay exact and the server does no JSON conversion. (D26 records that this decoder was not possible on the toolchain of the time.)

D20 Schema checked by field id against the binary form; no coercion#

Schema rules are an array indexed by dictionary id, checked in one pass over the fields, with required fields tracked in one u64. An integer field rejects floats and strings. Keys and relations belong to the database layer because they need other documents.

D23 Own binary wire protocol first; portable poller baseline#

Proposed defaults for stage 2: frames of [len][kind][id][body] with request ids so replies can return out of order, documents in their stored binary form, typed errors, and I/O through one poller interface whose baseline is poll or WSAPoll. epoll, kqueue and IOCP are to be added only when measured faster. PostgreSQL and RESP front ends were left as later options.

D24 Reference server = blocking sockets, two threads per connection#

std has no poller and a poll loop needs foreign declarations, so the portable reference server uses blocking sockets with a reader and a writer thread per connection, in safe Rust and identical everywhere. It meets the throughput targets but cannot hold a million idle connections; that target moved to the later poller work. Requests are batched per shard per socket read, and replies wait for the shard's flusher.

D25 The server owns field ids; filters scan every shard and merge#

Clients never choose field ids: the server keeps one dictionary and queues each new name to every shard in the same order before any document can use it. A filter is compiled once, counted per shard and merged, and paging uses cursors that carry the shard number; paging is not snapshot-consistent until MVCC. Rejected: client-chosen ids (shards would disagree) and a dictionary per shard.

D26 One port for the binary protocol and HTTP; JSON rows until the browser decoder exists#

The server looks at the first four bytes of a connection to tell a binary frame from HTTP text, so one listener serves clients, Studio's files and the API. The query endpoint returns JSON text because the WebAssembly build was not possible on the toolchain then. A single shared bearer token and clear text were the state at that time; TLS and real users were left to the security work.

D29 A database is a directory, a table is a set of shard logs with its own registry#

The layout is dir/<db>/<table>/shard-N.log. Tables are independent (own field ids, indexes and threads), and all tables share one shard count. The older single-table layout migrates into main.documents at start. The API uses relational names (tables, columns, rows) and keeps the earlier names as aliases for one version.

D30 Accounts without dependencies: PBKDF2-HMAC-SHA-256, tokens from an OS-seeded PRF#

Because the engine crates have no dependencies, SHA-256, HMAC and PBKDF2 are written in the server and checked against published test vectors. Session tokens and salts come from a keyed hash seeded by the operating system. The log states that this suits a loopback or trusted network and is not a substitute for TLS and a vetted random generator, which are required before wider exposure. Failed logins wait 250 ms.

D31 SQL compiles to the same plan as the JSON filter#

The SQL parser builds a plan directly (recursive descent, no syntax-tree layer), so strict typing, indexes, paging and scans are shared with JSON filters. Unsupported syntax is refused with a position and never approximated.

D32 Cross-origin access is opt-in per origin and never a substitute for authentication#

CORS headers are sent only for origins listed with --cors, pre-flights are answered without credentials, and Studio's connect-src allows other servers only with --allow-remote-servers. Rejected: a wildcard origin by default, because any website could then drive a local server that has no login.

D33 Sorting = per-shard partial sort + merge; the cursor of a sorted query is a row count#

Each shard returns its first start + page rows and the connection merges them, with a total order over all types and ties broken by primary key. There is no global sorted structure and no spill to disk yet. A row-count cursor lets Studio jump to any row; deep pages are expensive. Rejected: a sort buffer per connection and keyset-only cursors.

D34 Each table owns its threads; destructive changes stop the table first and need the exact name#

Stopping a table ends its threads and closes its files, which makes drop and rename work on Windows and keeps acknowledged writes durable. A drop must repeat the exact name, the server-side counterpart of Studio's confirmation dialog. The default database and table are protected.

D36 Three cumulative roles, optionally scoped to one database#

The roles are readonly, readwrite and admin, each account has one role and optionally one database, and one check function serves both HTTP and the binary protocol. Accounts were fixed at start, so there was nothing to revoke; per-table grants waited for a catalog stored in the database.

D40 UDP transport: authenticated datagrams, sessions obtained over TCP, hybrid client#

A client logs in over TCP, obtains a UDP session with a secret, and sends requests as datagrams that carry an 8-byte HMAC tag, so forged or replayed datagrams get no reply. Per session the server keeps recent replies so a retransmitted write runs once. The hybrid client repeats any call over TCP when UDP fails or cannot carry it. Encryption is to come from a vetted QUIC library, not hand-written DTLS. The first version was measured as not faster than TCP; later fixes (hardware SHA, parallel reply lanes, large socket buffers, fragmentation of up to 16 datagrams) brought it to parity at few clients and ahead at hundreds of clients on the Linux test host, as the log reports.