Skip to content

docs(rfc): draft Valkey storage backend RFC - #1396

Draft
rlunar wants to merge 2 commits into
ExtendDB:mainfrom
rlunar:backend/valkey
Draft

rlunar wants to merge 2 commits into
ExtendDB:mainfrom
rlunar:backend/valkey

Conversation

@rlunar

@rlunar rlunar commented Nov 23, 2026

Copy link
Copy Markdown

What

Adds a draft RFC proposing a Valkey storage backend (crates/storage-valkey):
docs/rfcs/draft-valkey-backend.md. Documentation only. No code, trait, config
or CI changes.

The RFC covers:

  • Two modes of one backend, chosen at runtime by probing the server. Core mode
    uses only built-in Valkey types and Functions. Search mode adds vector
    indexes and SearchVectors when the valkey-search module is loaded.
  • Data layout, key and sort-key encoding, one-FCALL atomic writes, optimistic
    reads for conditions and UpdateItem, transactions, GSI/LSI, Streams, TTL,
    catalog/IAM, and durability profiles.
  • A mapping to the RFC-0003 acceptance criteria, behavioral differences from
    DynamoDB, and a phased plan that starts with a go/no-go spike.
  • A benchmark methodology against the PostgreSQL, SQLite, MongoDB and Cassandra
    backends, with workloads, durability-matched comparison classes and
    proposed gates for the sub-millisecond goal.

Why

ExtendDB's backends are all disk-oriented databases. This RFC proposes a backend
aimed at sub-millisecond point-operation latency for users who already run
Valkey. It also asks reviewers whether the benchmark gates are the right bar for
carrying such a backend at all.

Refs #1394

Testing done

Documentation-only change. Nothing was built or benchmarked, so the latency
figures in the RFC are proposed targets, not measurements.

  • Read RFC-0002, RFC-0003, the Cassandra and MongoDB RFCs, the Backend
    descriptor, and the StorageEngine and CatalogStore traits in
    crates/storage, and checked the design against them.
  • Checked the Valkey claims against valkey.io and the valkey-search docs
    (FT.SEARCH options, vector HNSW/FLAT, hash field expiration in Valkey 9).
    Claims that could not be verified are listed under "Unresolved questions".

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace) (n/a, no code changed)
  • Code is formatted (cargo fmt --check) (n/a, no code changed)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic) (n/a, no code changed)
  • I have added or updated tests for new functionality (n/a, RFC only)
  • I have updated documentation if behavior changed (this PR is the documentation)
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, or public CLI surface, an RFC has been accepted or is linked
    below. Otherwise, an ADR captures the decision (link below).

ADR / RFC: this PR is the RFC (docs/rfcs/draft-valkey-backend.md), tracked in
#1394. It builds on RFC-0002 and RFC-0003 and proposes no change to the
Storage trait.

Breaking changes

None.


By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.

rberoj and others added 2 commits November 23, 2026 20:00
Signed-off-by: Roberto Luna-Rojas <rberoj@amazon.com>
Propose a Valkey backend (crates/storage-valkey) for sub-millisecond
DynamoDB-compatible point operations. One backend, two modes chosen at
startup by probing the server: core mode (hashes, sorted sets, streams
and Functions) and search mode (adds vector indexes and SearchVectors
when valkey-search is loaded).

The RFC covers the data layout, atomic one-FCALL writes, durability
profiles, an RFC-0003 conformance mapping, and a benchmark methodology
with go/no-go gates against the PostgreSQL, SQLite, MongoDB and
Cassandra backends. Documentation only; no code or trait changes.

Refs ExtendDB#1394

Signed-off-by: Roberto Luna-Rojas <rberoj@amazon.com>
Signed-off-by: Roberto Luna-Rojas <roberto.luna.rojas@gmail.com>

@LeeroyHannigan LeeroyHannigan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Roberto,

This is an awesome contribution, and I can't wait to see it land.

I went through it closely against main at 018715e. I checked the storage traits, the engine and server paths the design relies on, and the README tier rules. I also checked RFC-0002, RFC-0003 and ADR-0004, ADR-0005, ADR-0006, ADR-0010 and ADR-0023. I tested the Valkey behaviour that the design depends on with Valkey 9.0.8 (valkey/valkey:9.0) and valkey/valkey-bundle:9.0 in local containers. The bundle runs Valkey 9.0.8 with valkey-search module version 10003, which is 1.0.3. The DynamoDB results come from Amazon DynamoDB in us-east-1 on 2026-11-24, on an on-demand table that the test run deleted afterwards. The measurements are at the end.

Most items end with a suggested fix. The items under Blocking need a design change before the RFC can be accepted. They cover the token check in TransactWriteItems, the stream shard model, and writes that stay behind when a Function fails. They also cover the durability profiles and the benchmark gate. Items under Major need a decision or a change to the text, and Minor items are corrections.

Blocking

B1. A replayed TransactWriteItems fails where DynamoDB returns success

The RFC evaluates every condition in Rust from the snapshot read and only then calls txn_write, which checks the ClientRequestToken. Take a transaction that succeeded and whose own write made its condition false. Its replay returns TransactionCanceledException from the Rust evaluation and never reaches the token check.

Measured on DynamoDB (D1 to D5 below): a TransactWriteItems with a token and one Put conditioned on attribute_not_exists(pk) succeeded. The identical request succeeded again at once and 570 s later. The same request without a token returned TransactionCanceledException with ConditionalCheckFailed. The same token with a different item returned IdempotentParameterMismatchException. At 660 s the token was no longer honoured, and the request failed its condition.

The PostgreSQL backend checks the token before it evaluates any condition (crates/storage-postgres/src/data/transactions.rs:142-148). It returns StorageError::IdempotentReplay, which the engine answers as success (crates/engine/src/transact_write_items.rs:204).

The 540 s expiry matches the MongoDB backend. There it compensates for the 60 s cadence of the TTL monitor (crates/storage-mongodb/src/migrations/m0001_baseline.rs:122-124). MongoDB also filters out rows older than 10 minutes on read (crates/storage-mongodb/src/data_engine.rs:2422). Valkey never returns a key past its expiry, so 540 s gives a 9-minute window. The 570 s replay above would execute again.

Suggested fix: read the token in snapshot_read, and return IdempotentReplay or IdempotentMismatch before Rust evaluates any condition. Keep the SET NX in txn_write so that concurrent duplicates still execute once. Set the expiry to 600 s.

B2. Streams use the shard model that the stream lineage replaced

The RFC gives each table four shards with ids shardId-{table_id}-{i:012}. It also says that enabling an already-enabled stream reuses the shards and label. Both contradict crates/storage/src/stream_lineage.rs:

  • Disabling a stream closes it, and enabling it again creates a new stream with a new label and new shards. Shard ids are shardId-{table_id}-{label_millis:013}{view_type:1}{index:02} (lines 4 to 22). The RFC's format is the pre-lineage form, which that module reads as the table's current stream.
  • stream_change refuses to enable an enabled stream with "Table already has an enabled stream: TableName: ..." (lines 75 to 85). DynamoDB returned the same message (D4).
  • get_stream_records must resolve the shard against the stream label in the ARN. A shard of another stream of the same table yields no records. A closed stream stays readable under its own ARN (crates/storage/src/lib.rs:646-656). With one Valkey stream key per pre-lineage shard id, a disabled stream and its successor write to the same keys.

On retention, RFC-0003 5.5 requires the backend to delete records after the configured retention, default 24 hours. It also forbids a TRIM_HORIZON iterator from replaying older records. PostgreSQL, SQLite and MongoDB use 24 hours (crates/storage-postgres/src/workers.rs:220, crates/storage-sqlite/src/workers.rs:105, crates/storage-mongodb/src/ttl_worker.rs:24). The 30 hours the RFC cites from Cassandra is a record TTL (crates/storage-cassandra/src/engine.rs:166). Its comment says spawn_workers overrides it, but no code assigns it. Cassandra's cleanup_expired_stream_records also ignores retention_hours (crates/storage-cassandra/src/stream_engine.rs:316-321). The Cassandra backend therefore keeps records longer than 5.5 allows.

For sequence numbers, the RFC renders the Valkey id as 21 digits, the milliseconds plus a 6-digit counter. The counter has no such bound. Measured (V6): XADD accepts the id 5-1000000. After an entry whose id was one hour ahead of the clock, two XADD * calls returned 1795515474000-1 and 1795515474000-2. The millisecond part stays at the last id, and the counter climbs. A backward clock step produces that state. So does a failover to a replica whose clock is behind the old primary's. Once the counter passes 999,999, the 21-digit form no longer sorts in commit order (RFC-0003 5.2). A failover also drops the records that the old primary acknowledged and did not replicate. If the new primary's clock is behind the ids that a consumer has already read, new records get lower ids. A consumer that resumes after its last sequence number then skips them.

For AT_TIMESTAMP iterators, #468 merged on main after you wrote the RFC. It added a required method, StreamEngine::first_sequence_number_at_or_after (crates/storage/src/lib.rs:726-737). The method compares against a creation time that the backend stores from the same clock read as ApproximateCreationDateTime. With XADD *, the millisecond part of the id comes from the Valkey server's clock, and after the V6 case it stops following the clock.

Suggested fix: build shard ids with stream_lineage::shard_id, follow stream_change, and key each Valkey stream by the lineage shard id. Trim at the retention_hours that the worker passes in. Override sequence_number_width() with a width that holds the full 64-bit counter. Store each record's creation time from the clock behind ApproximateCreationDateTime, and seek AT_TIMESTAMP on it. State the failover behaviour in the differences list.

B3. A Function is not rolled back when it fails after its first write

The RFC rests RFC-0003 3.1, 3.2 and 5.1 on one FCALL per write. In its words, "the stream record becomes visible if and only if the data write did". Valkey runs a Function without interleaving other clients, but it does not undo the Function's writes when a later command in it fails.

Measured on Valkey 9.0.8 (V1, V2): a Function that runs SET and then HSET on a string key returned WRONGTYPE, and the SET stayed. A Function that runs SET and then hits a Lua error on a nil value returned the error, and the SET stayed.

The Functions take keys and side-effect lists from Rust, and put deletes the index entries listed in the stored ix field. An argument can be malformed, or a key under the prefix can have an unexpected type. A failure part way through put or txn_write then leaves an item without its stream record, or index entries without their item. The design has no step that detects this.

A Function that wrote a key also cannot be stopped. Measured (V11): during a Function that wrote one key and then looped for 4 s, PING returned BUSY and FUNCTION KILL returned UNKILLABLE. The server can then only wait for the Function to end, or stop with SHUTDOWN NOSAVE. That command drops every write since the last fsync or snapshot. The kill succeeded on the same loop without the write.

Suggested fix: make it a rule that every Function checks its arguments and the types of its keys before its first write. After the first write, a Function issues no command that can fail. Add Function tests that inject a failure after the first write. Cap the work per Function so that no Function reaches busy-reply-threshold.

B4. The durability profiles do not deliver the loss windows in the table

durable adds WAIT 1 after each write. Measured (V3, V4): inside a Function, WAIT 1 5000 after a SET returned at once. It returned 0 with no replica, 1 with a replica online, and 1 again with the replica frozen by docker pause. In both runs with a replica, INFO replication on the primary right after the Function showed the replica's acknowledged offset below the primary's. The offsets were 15 against 67 with the replica online, and 96 against 162 with it frozen. A WAIT inside the Function therefore counted a replica that had not acknowledged the write. As a separate command, WAIT 1 1500 returned 1 in 46 ms with the replica online, and 0 after 1,536 ms with it frozen. The WAIT documentation says that WAIT does not block inside a script. It also says that WAIT does not make Valkey strongly consistent, because a failover can still lose a write that replicas acknowledged. WAIT counts the replicas that received the write. WAITAOF waits for the fsync on the primary and on replicas.

So WAIT has to be a second command after the FCALL, which the design does not say. On the default pool of multiplexed connections, a blocked WAIT delays the requests queued behind it on that connection. WAIT 1 0 blocks forever while the replica is down. With a timeout, the write is already applied and visible on the primary when the request fails. The RFC defines neither the timeout nor the response.

latency lists "AOF appendfsync everysec, or RDB" with "up to about 1 s" of loss, and the startup check accepts an RDB schedule. An RDB-only setup loses every write since the last snapshot. The valkey-bundle 9.0 image runs with save 3600 1 300 100 60 10000, which on a lightly written instance means up to an hour. The catalog, with its access keys and passwords, shares that window.

The RFC names failover ("replicas for failover") but does not design it. It does not say how the backend finds the new primary, through Sentinel or a managed endpoint. In latency, a failover loses the acknowledged writes that the replica had not received, and in durable WAIT lowers that risk without removing it. A ConsistentRead=true read on the new primary then returns the item without those writes, which RFC-0003 4.5 forbids. The RFC also does not mention min-replicas-to-write, which makes a primary that has lost its replicas refuse writes that a failover would discard.

Suggested fix: send WAIT or WAITAOF after the FCALL, on a connection that carries no other requests. Give it a bounded timeout, and define the response when it times out. Give RDB its own row in the table, or refuse RDB-only persistence outside ephemeral. Specify failover, its loss window and the min-replicas-to-write setting.

B5. The go/no-go gate cannot be evaluated as written

  • Phase 0 builds get_item and put_item in a throwaway crate and must exit with "G1 and G2 evidence". G1 is an L1 figure from the server's metrics. The server cannot run on a backend without the full StorageEngine and the CatalogStore. SigV4 verification reads access keys from the catalog, and both traits arrive in Phase 1. Phase 0 can produce L0 numbers only.
  • G2 compares against "the best of PostgreSQL, SQLite-file and MongoDB", and Phase 0 does not run MongoDB. G2 does not name the layer either. At L2 every backend also pays for the server stack, which the RFC budgets at about 250 µs. A 3x gain in storage time then appears as less than 3x.
  • The SQLite D1 row (synchronous=FULL) needs a change to the SQLite backend. That backend sets synchronous = NORMAL on every connection (crates/storage-sqlite/src/sqlite_util.rs:27). The MongoDB backend refuses w=1 and journal=false in the connection string (crates/storage-mongodb/src/lib.rs:516-554). Its D0 row therefore has to come from the server's default write concern, and its catalog and backup writes stay at majority. The RFC's implementation summary lists neither change.
  • The classes differ in kind. Valkey D1 waits for a replica. PostgreSQL, SQLite and Cassandra D1 are a local fsync, and w:majority on a one-node replica set is a local journal write.
  • The gates are "ratified after Phase 0 from measured data", and the reference host is an open question. So the RFC can set the thresholds after it sees the results.

Suggested fix: say that Phase 0 measures L0 only, and move G1 to the end of Phase 1. Fix the G2 margin, layer and host before Phase 0 runs, and add MongoDB to Phase 0. Define durability classes that the backends can run today. Otherwise, list the changes to other backends that the matrix needs, and check them against G5.

Major

Latency model

M1. The round-trip table does not match the engine.

  • BatchGetItem calls get_item once per key in a sequential loop (crates/engine/src/batch_get_item.rs:183-190), so 100 keys are 100 round trips. BatchWriteItem calls put_item or delete_item once per request in a loop (crates/engine/src/batch_write_item.rs:212-250), so 25 requests are 25 round trips.
  • Batch and transaction requests read each table's key info from storage during authorization, without the cache (crates/server/src/request_helpers.rs:405-415). That adds one catalog read per table to BatchGetItem, BatchWriteItem, TransactGetItems and TransactWriteItems. The Motivation says that the auth cache leaves one storage call on the data path. That is true for single-table operations only.
  • The engine reads a page in chunks and asks for 128 items first (crates/engine/src/read_helpers.rs:78). A full page of small items therefore takes at least two storage calls.
  • One FCALL per batch needs a batch method on DataEngine, a trait change that the RFC leaves to a separate RFC. Fix the table, or propose the trait change in this RFC.

M2. Long Functions delay the requests queued behind them by more than the latency target. The RFC has no Function code, so V12 timed stand-ins written from its description, on Valkey 9.0.8 on a shared development host. One Function that read 1,000 items of 1 KB took 1,833 µs of server time, and one that read 100 items took 261 µs. Both used ZRANGEBYLEX and HGET. A Function that made 100 writes took 1,067 µs, and one write took 69 µs. Each write had an item hash, a sort-key entry, a registry entry, two index entries and an XADD. The figures are medians of 7 runs. The engine asks storage for up to 1,024 items per chunk (crates/engine/src/read_helpers.rs:85-86). Default Query and Scan pages therefore produce Functions of this size. The RFC's own bound, "a few milliseconds" per Function, is above the 1 ms p99 target. G1 covers W1, W2 and W4 only, and the RFC reports the interference measurement without gating on it. The gate therefore never runs the load that the design creates. The RFC also does not say whether runs include RDB snapshots and AOF rewrites. Their fork() pauses the server thread for a time that grows with the dataset (latest_fork_usec in INFO). With the default save rules, a run that writes more than 10,000 keys a minute starts a snapshot every 60 s. Gate G1 on W15 and on the interference test with persistence on. Size the per-Function cap from the measured cost, and report latency with the fork events of each run.

M3. The L1 metrics do not measure what the RFC says. No backend records PoolAcquireLatency: record_pool_acquire_latency (crates/core/src/metrics/collector_record.rs:288) has no caller outside the metrics module. StorageQueryLatency times the whole extenddb_engine::dispatch call, engine work included (crates/server/src/handler.rs:277-305). Its dimensions are source and category (Catalog, Auth, Data), with no operation (crates/core/src/metrics/collector_record.rs:236-262). SuccessfulRequestLatency stops when the handler builds the response, before the server writes it (crates/server/src/handler.rs:386-397). The collector computes percentiles per query window (crates/core/src/metrics/collector_query.rs:76-88). The difference between two reads of /metrics therefore gives counts and sums, and no p99 for the run. Add per-operation storage timing in the backend crate, or measure storage time at L0 and drop the attribution claim.

M4. The RFC does not measure the existing backends. The Motivation says that existing backends sit "in the low milliseconds" for point writes. The PR description says that nothing was measured, and docs/ has no point-operation latency record for any backend. SQLite runs WAL with synchronous = NORMAL (crates/storage-sqlite/src/sqlite_util.rs:24-27), so its commits do not wait for an fsync. The RFC does not show where that backend sits against the target. Before Phase 0, measure L1 and L2 for GetItem, PutItem and UpdateItem on the existing server. Use SQLite file, sqlite-memory and PostgreSQL, and set the G2 margin from those numbers. That needs no Valkey code, and its result decides whether to build the rest.

Data model and write paths

M5. The write path needs the TTL attribute and has no source for it. put_item receives TableKeyInfo (crates/core/src/types/key_schema.rs:75), which has no TTL attribute. PostgreSQL, SQLite and MongoDB never need it on writes. They find expired items through an index over the stored item (create_ttl_index and find_expired_items_indexed, crates/storage/src/lib.rs:590-614). The Valkey put needs a TTL score on every write. The backend must then read the attribute per write, at the cost of one more round trip, or cache it. A cache that still says "TTL off" during UpdateTimeToLive lets writes skip the zset after the enable backfill passed them, and those items never expire. Cassandra met the same problem, and ADR-0010 handles it with a 5 s configuration cache and write quiescence during enable. Name the source of the attribute on writes, its invalidation, and the enable and disable transitions. Otherwise, propose adding it to TableKeyInfo, which is a core change that the RFC currently excludes.

M6. Secondary indexes.

  • SQLite GSIs follow index_propagation_delay_ms (default 10 ms) and are synchronous only at delay 0. The sources are crates/storage-sqlite/src/data/index.rs:202-232 and the "GSI update propagation" row of docs/differences-from-dynamodb.md. Of the existing backends, only MongoDB is synchronous (design 13, section 5.4). The text and the differences entry say that SQLite is synchronous. Say also whether this backend honours that setting and the per-GSI propagation_delay_ms.
  • The conformance table relies on a "GSI-presence cache with short TTL". The write path already receives the index list in TableKeyInfo from the server's key-info cache. The DDL handlers invalidate that cache (crates/server/src/key_info_cache.rs:19-22). A second cache with a TTL can hide a CREATING index from a write. If the backfill cursor is already past that item, the index never gets it (RFC-0003 2.4). Use the list in TableKeyInfo.
  • Lua never decodes the blob, so the backfill reads an item in Rust and writes its index entry in a later call. A write in between makes that entry stale. Unless the backfill also records the entry in ix, the next write cannot delete it (RFC-0003 2.2). The backfill write needs the item's expected version and must update ix.
  • ExtendDB serves GSIs with several HASH or RANGE attributes. tests/test_gsi_multi_range_query.py covers one HASH with four RANGE attributes, and a two-HASH index. The layout has one {ipk} and one enc(index sk). Specify the encoding for those keys and the key-condition rule. The rule is equality on a leading run of RANGE attributes, with any operator on the last.

M7. Delete paths and destroy are not specified.

  • The Writes section covers put. DeleteItem must also delete the sort-key entry, the registry entry when the partition becomes empty, the index entries and the TTL entry. It also appends the REMOVE record. Without the registry step, every partition ever written stays registered. The session stores and TTL workloads in the Motivation create short-lived partitions. Scan time and memory then grow with history.
  • DeleteTable on a large table cannot be one Function. A Function that reads 1,000 items takes about 1.8 ms (M2), and deleting a table visits every item key. It needs a background delete under the retired tid, and the memory stays in use until that finishes. DynamoDB puts the stream of a deleted table into the DISABLED state and deletes it after 24 hours (DeleteTable). ExtendDB keeps a deleted table's stream readable for that period (crates/storage-postgres/src/stream_engine.rs:346-351). The delete therefore has to leave the table's stream keys in place until the retention sweep deletes them.
  • destroy "deletes only keys under its prefix", and several prefixes may share one instance. A SCAN MATCH xdb:* also matches the keys of a deployment whose prefix is xdb:i. A *, ? or [ in a prefix also changes the pattern. Forbid : and the glob characters in a prefix, so that {p}:* matches only that deployment's keys. Delete by walking the deployment's own registries.

M8. The item version v is under-specified. put receives "new version" from Rust, but an unconditional put reads nothing. Rust cannot compute the old version plus one, so the Function has to assign it. If v counts writes per item, a delete resets it. A conditional writer that read v=5 can then match a re-created item that is back at v=5. It then applies a write that it evaluated against the old item. Phase 3 compares v with a table-wide counter E ("any item with v <= E"). That works only if v comes from that counter. Assign v inside the Function from one counter per table that never resets. The Phase 3 design has two more gaps. The reader pages the registry, so it misses an item deleted after the snapshot started, unless it also reads the undo hash. Every write of every table must also check snap:{tid}, including writes to tables with no snapshot.

M9. Catalog migrations conflict with ADR-0023, and Functions are global to the instance. ADR-0023 requires one numbered MigrationId list with an exhaustive entry per backend (decision 1). It requires an extenddb_migrations ledger with checksums in every store (decision 2). It also requires a migration lock and a serving registration that keep migrate --yes and serve apart (decision 5). A {p}:cat:schema_version key has none of these. The step "an upgrade loads the new library before the binary starts serving" also puts a store change in serve. Measured (V7): loading a second library that defines put fails with "Function put already exists". FUNCTION LOAD REPLACE replaces a library for every client of the instance. Two deployments on one instance cannot run different releases. An upgrade also replaces Functions that an older server is still calling, and that server keeps calling them with its own argument layout. Implement the ADR-0023 runner over {p}:cat:*. Name the library and its functions after the prefix and a layout version, and load them in migrate --yes. Unload a version only when no registered server runs it.

M10. A full instance cannot free memory through the API. Measured (V9) with used_memory 200 KB above maxmemory under noeviction: an FCALL of a Function with only DEL failed. The error was "OOM command not allowed when used memory > 'maxmemory'". The same DEL as a plain command, or in a Function flagged allow-oom, succeeded. Every write path in the RFC is a Function. On a full instance, DeleteItem, DeleteTable and the TTL worker therefore cannot free memory, and recovery needs a maxmemory change outside ExtendDB. A delete Function flagged allow-oom still adds memory through its REMOVE record. Also measured (V10): a Function that starts under the limit runs to the end. 100 writes of 10 KB took used_memory to 3.7 MB with maxmemory at 1.9 MB. OOM therefore does not split a Function, and one Function can overshoot the limit. Define which Functions carry allow-oom, how DeleteTable frees memory, the headroom that the operator keeps, and the error that a client receives.

Search mode

M11. Search mode needs a score mapping, a filter encoding, a module version and an index lifecycle.

  • Scores: VectorHit::score is a distance for Cosine and Euclidean, where lower is closer and 0.0 is identical. For DotProduct it is the dot product, where higher is closer (crates/storage/src/lib.rs:131-145). Measured (S1) with the query vector (1, 0): COSINE returned 0, 0.4, 1 and 2 for (1, 0), (3, 4), (0, 1) and (-1, 0). That matches the SQLite backend's 1 minus cosine (crates/storage-sqlite/src/vector_search.rs:91-127). L2 returned 20 for (3, 4), the squared distance, where ExtendDB reports the distance, about 4.47. IP returned -2 for (3, 4), which is 1 minus the dot product. ExtendDB reports 3 and ranks in the other direction. The RFC does not say how Valkey's scores map to VectorHit::score.
  • Filters: on a default TAG field (S2), @pk:{alice} matched the values "Alice" and "alice", and @pk:{b} matched "a,b". With SEPARATOR | and CASESENSITIVE, @pk:{x} still matched "x|y". A partition-scoped search then returns items from other partitions. The design does not cover the inline filters of VectorSearch (crates/storage/src/lib.rs:186-196) at all. Store a fixed-alphabet encoding, hex for example, of each scoped value in a CASESENSITIVE TAG field, and query that.
  • Version: valkey-bundle 9.0 ships valkey-search 1.0.3 (module version 10003 in MODULE LIST). Measured (S5), it refuses SORTBY and INKEYS with "Unexpected argument". It refuses a query with no KNN clause with "Missing =>", and FT.CREATE requires a vector field. E1 needs queries without a vector clause, which later valkey-search releases support (valkey-search 1.2). Pin the module version in the test matrix.
  • NUMERIC: two 38-digit numbers that differ in the last digit both matched @n:[B B] (S6). Search-backed GSIs therefore fail RFC-0003 1.3 for number keys. That matches the RFC's suspicion and is a reason to drop E1.
  • Index build: FT.CREATE over 200,000 existing hashes took 3.4 s to backfill (S7). A KNN 10 query at 0.5 s returned 10 hits from 20,427 indexed documents. A vector index added to a table that has items answers from part of the table. The backend has to keep it CREATING until FT.INFO reports ready. The shared lifecycle in crates/storage/src/vector_lifecycle/ (ADR-0005) is the place for that, and the RFC does not mention it. After a restart from RDB, the same index reported ready with all 200,000 documents at the first check (S8). The statement that indexes are rebuilt after a restart therefore describes neither case measured here.
  • HNSW: ADR-0006 rule 3 makes the exact scan the reference. It adds an approximate index only after the exact path passes its checks. Open question 6 says that no request shape selects HNSW. Drop the HNSW opt-in from this RFC.

Plan, operations and backups

M12. Phase 1 cannot meet its exit criterion. Phase 1 exits with "full conformance in core mode except snapshots". Transactions and idempotency arrive in Phase 2, together with streams and TTL. transact_get_items and transact_write_items are DataEngine methods (crates/storage/src/lib.rs:481-514). RFC-0002 makes DataEngine mandatory and conformance all-or-nothing per trait. RFC-0003 requires devtools/run-tests --extenddb --all to pass at 100%. Move transactions and idempotency into Phase 1. Either move streams and TTL in as well, or keep Phase 1 unmerged until Phase 2.

M13. The managed services cannot run the backend as specified. The ElastiCache documentation lists config among the commands that are unavailable on caches running Redis OSS. It lists FCALL, FCALL_RO and FUNCTION among the commands that are unavailable on serverless caches (supported and restricted commands). MemoryDB restricts config and module (restricted commands). MemoryDB also partitions each cluster's data into shards (components), and the RFC leaves sharded deployments out of v1. Where config or module is unavailable, the startup checks cannot run, because CONFIG GET reads maxmemory-policy and persistence, and MODULE LIST is the Search probe. ElastiCache Serverless has no Functions at all. The Motivation and the durability table present both services as an operator path. Decide Unresolved question 9 before acceptance. Either drop those claims and the MemoryDB row, or define checks that need neither CONFIG nor MODULE, plus the cluster support that MemoryDB needs.

M14. Backups. With SnapshotEngine unsupported, CreateBackup uses the in-catalog format, as on Cassandra (README, tier table). On Valkey that puts a second copy of the table in the same memory, under noeviction (see M10). The in-catalog format refuses tables with vector indexes (docs/differences-from-dynamodb.md, "Backing up and restoring a table that has vector indexes"). Search mode tables therefore have no backup at all. State both in the differences list, and say how an operator backs up a table larger than the free memory.

Read consistency

M15. The backend cannot tell strongly consistent reads from eventually consistent ones, so read_from_replicas cannot work as specified. When the option is on, the RFC sends eventually consistent reads to replicas and keeps ConsistentRead=true on the primary (its 4.5 item). The storage trait carries no consistency flag. get_item takes the key info and the key, and query and scan take no consistency argument either (crates/storage/src/lib.rs:325-329, :392-401, :412-420). In the engine, ConsistentRead sets the read capacity charge and the GSI refusal (crates/engine/src/get_item.rs:148, crates/engine/src/query.rs:123), and no storage call receives it. With the option on, the backend would serve ConsistentRead=true reads from replicas, which RFC-0003 4.5 forbids. The MongoDB backend refuses a non-primary read preference for this reason (crates/storage-mongodb/src/lib.rs:433-483). A backend can identify only GSI reads as eventually consistent, from index_name and the index lists in TableKeyInfo. Limit replica reads to GSI Query and Scan, drop the option, or propose the trait change in this RFC.

Rules that each backend applies

M16. The RFC says that "the DynamoDB semantics have exactly one implementation, in extenddb_core". The checks live there, but each backend's DataEngine decides where and in what order to apply them. Some DynamoDB behaviour exists only at those call sites. The RFC lists none of it. The existing backends apply these rules, among others:

  • An UpdateItem whose actions are only REMOVE and DELETE, on a key with no item, writes nothing and emits no stream record (crates/storage-postgres/src/data/update_item.rs:232-238). The same rule applies inside a transaction (crates/storage-sqlite/src/data/transactions.rs:509-516, issues #478 and #510).
  • A delete of a missing item emits no REMOVE record (crates/storage-mongodb/src/data_engine.rs:2816-2819).
  • TransactWriteItems checks the keys of every member before it reads any item, and ranks key faults in the service's order (crates/storage-postgres/src/data/transactions.rs:156-174).

List the rules that the Valkey DataEngine applies and where each runs relative to the Functions, so that the conformance table can be checked against them.

Minor

  • m1. Conformance row 8 says "account in every key". Only {p}:idem:{acct}:{token} carries the account. Item, index, TTL and stream keys carry tid, and isolation comes from tid being unique and resolved per account. State that in the conformance table.
  • m2. "InternalServerError (503-class retry)": InternalServerError is HTTP 500 (RFC-0003 9.2), and 503 is ServiceUnavailable. Name the one the backend returns.
  • m3. TransientConflict is not a StorageError variant. MongoDB returns StorageError::Transient after its 50 attempts, and the engine answers that with 503 ServiceUnavailable. TransactionConflict maps to TransactionConflictException (crates/storage/src/error.rs:44-85).
  • m4. The engine owns the 1 MB page budget (PAGE_BYTE_BUDGET, crates/engine/src/read_helpers.rs:76) and measures items with item_size_bytes. The Lua bound counts blob bytes. Keep the Lua cap as a bound on server time, defined in items and bytes, and do not describe it as the DynamoDB limit.
  • m5. The startup probes use CONFIG GET and MODULE LIST, both in @admin and @dangerous, and FUNCTION LOAD is in @write and @scripting (V8). The RFC asks operators for ACL users but defines none. Define a runtime user limited to ~{p}:* and the commands that the backend calls, without @admin or @dangerous. Run the probes and FUNCTION LOAD from init and migrate --yes under a separate user.
  • m6. The Functions delete the entries listed in ix, and read item keys built from sorted-set members. None of those keys appear in KEYS. A standalone server allows that. Under the cluster protocol, a script that touches keys in other slots fails. State it as a standalone-only rule, which also bears on MemoryDB (M13).
  • m7. WorkerStore (process_control_plane_transitions, crates/storage/src/lib.rs:744-751) is a required supertrait that the RFC does not mention. refresh_table_size needs a size and an item count that the layout does not track. Say how both work without a full scan.
  • m8. The memory requirement omits copy-on-write during BGSAVE and AOF rewrite, which under heavy writes can approach the size of the dataset. With noeviction and maxmemory close to the host's RAM, that risks the kernel OOM killer.
  • m9. The engine dispatches RestoreTableToPointInTime (crates/engine/src/lib.rs:583). The differences entry should name the error a Valkey deployment returns.
  • m10. The configuration example omits allow_insecure_remote, which the Network section introduces.

Checked and consistent with the RFC

  • OOM does not split a Function, because the check runs when the Function starts (V9, V10).
  • Isolation on one primary: while a Function runs, other clients wait (V11, where PING returned BUSY). A snapshot_read therefore sees one state (RFC-0003 3.5), and no read sees part of another Function's writes. B3 covers a Function that fails part way.
  • XADD * works inside a Function. Two appends in one call got the same millisecond part with counters 0 and 1 (V5). Records from one call therefore keep their append order.
  • HEXPIRE exists from Valkey 9.0.0 (COMMAND DOCS).
  • Open question 4, for FLAT on one node: in 500 of 500 sequential HSET and FT.SEARCH pairs, the search found its pair's vector (S3). The pairs ran on one connection. A write followed by FT.SEARCH inside one script also saw the write (S4). This does not cover HNSW or concurrent load.
  • NUMERIC fields are double precision, as the RFC suspected (S6).
  • A Rust GLIDE client is now published (GLIDE releases), so E2 can compare it.
  • The key-info cache serves single-table operations without a catalog read, as the RFC says. M1 lists the exceptions.
  • The cited repository files exist: crates/storage-mongodb/tests/pushdown_parity.rs, docs/design/12-auth-authz-cache.md, devtools/run-mongodb-tests, the --backend flag of devtools/run-tests, the check-*-catalog-lock and check-*-older-binary scripts, tests/rust/, and docs/design/15-backup-restore-bench-pr*.md.

Thanks for writing this up, Roberto.

Measurements

Valkey: containers from valkey/valkey:9.0 (Valkey 9.0.8) and valkey/valkey-bundle:9.0 (Valkey 9.0.8, valkey-search module version 10003), driven with valkey-cli through docker exec. Server times are SLOWLOG durations. The replica checks used a second container that replicated the first, and ran only after the primary reported the replica online. The V3 and V4 times come from inside the primary's container, around one valkey-cli call each.

Id Check Result
V1 A Function runs SET k, then HSET on a string key WRONGTYPE. GET k returned the value.
V2 A Function runs SET k, then Lua arithmetic on nil Lua error. GET k returned the value.
V3 No replica. A Function runs SET, then WAIT 1 5000. Then a SET and a separate WAIT 1 1500 on one connection. The Function returned 0 in 33 ms. The separate WAIT returned 0 in 1,606 ms.
V4 The V3 checks with one replica, first online and then frozen with docker pause. INFO replication read on the primary right after each Function. Online: the Function returned 1 in 26 ms, with the replica's acknowledged offset at 15 and the primary's at 67. The separate WAIT returned 1 in 46 ms. Frozen: the Function returned 1 in 46 ms, with offsets of 96 and 162. The separate WAIT returned 0 in 1,536 ms.
V5 A Function runs two XADD * 1795511873523-0 and 1795511873523-1
V6 XADD with id 5-1000000. Then an entry one hour ahead of the clock, followed by two XADD *. Accepted. Then 1795515474000-1 and 1795515474000-2.
V7 A second library that defines put ERR Function put already exists
V8 COMMAND INFO FUNCTION LOAD is in @Write @slow @scripting. CONFIG GET and MODULE LIST are in @admin @slow @dangerous. WAIT and WAITAOF are in @slow @Blocking @connection.
V9 noeviction, used_memory 200 KB over maxmemory Writer Function: OOM. Function with only DEL: OOM. DEL in an allow-oom Function: 1. Plain DEL: 1. Plain SET: OOM.
V10 A Function that starts under the limit and makes 100 writes of 10 KB Completed. used_memory 3,725,816 with maxmemory 1,949,040.
V11 A Function writes, then loops for 4 s, with busy-reply-threshold at 300 ms PING: BUSY. FUNCTION KILL: UNKILLABLE. FUNCTION KILL stopped the same loop without the write.
V12 Server time of the stand-in Functions described in M2, median of 7 Reads of 10, 100 and 1,000 items of 1 KB took 83, 261 and 1,833 µs. Batches of 1, 25 and 100 writes with side effects took 69, 320 and 1,067 µs.
S1 KNN scores for (1,0), (0,1), (-1,0) and (3,4), query (1,0) COSINE: 0, 1, 2, 0.4. L2: 0, 2, 4, 20. IP: 0, 1, 2, -2.
S2 TAG matching Default field: {alice} matched Alice and alice, and {b} matched a,b. With SEPARATOR and CASESENSITIVE: {x} matched x|y.
S3 500 sequential HSET then FT.SEARCH, one connection, FLAT 0 misses
S4 FT.SEARCH inside EVAL, after an HSET in the same script Allowed. It returned the key that the HSET wrote.
S5 SORTBY, INKEYS, and a query without KNN Unexpected argument, Unexpected argument, Missing =>
S6 NUMERIC, two 38-digit values that differ in the last digit, range [B B] Both returned
S7 FT.CREATE over 200,000 hashes, DIM 16 Backfill done at 3.4 s. At 0.5 s, num_docs was 20,427 and KNN 10 returned 10 hits.
S8 Container restart, data loaded from RDB ready with 200,000 documents at the first check, 2.1 s after the restart

DynamoDB, us-east-1, on-demand table with keys pk and sk, 2026-11-24:

Id Request Result
D1 TransactWriteItems with token T and a Put conditioned on attribute_not_exists(pk), then the identical request Success, then success
D2 The same request without a token TransactionCanceledException [ConditionalCheckFailed]
D3 Token T with a different item IdempotentParameterMismatchException
D4 UpdateTable enabling the table's enabled stream ValidationException "Table already has an enabled stream: TableName: ..."
D5 The D1 request again at 570 s and at 660 s Success at 570 s. TransactionCanceledException [ConditionalCheckFailed] at 660 s.

@LeeroyHannigan LeeroyHannigan added the RFC Request for Comments, a proposal open for discussion before implementation label Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFC Request for Comments, a proposal open for discussion before implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants