From 204827d275bdb6e46ee452f7d1d25acc11f6d898 Mon Sep 17 00:00:00 2001 From: Lee Hannigan Date: Sun, 25 Oct 2026 21:25:48 +0000 Subject: [PATCH 1/3] docs: describe the PostgreSQL read replica mode as a proposal, not current behaviour Four design documents stated a read replica mode in the present tense: a storage.postgres.read_replica_url setting with read_replica_pool_size, a read_pool field on PostgresEngine, a read_pool() helper, and ConsistentRead=false reads routed to a streaming replica. None of it exists: grep read_replica over crates/ returns nothing, PostgresConfig carries deny_unknown_fields, and every item read and write runs on data_pool. An operator who copied read_replica_url from the configuration reference got a server that refused to start. - 01-requirements: REQ-DATA-015 states what the backends do (the flag reaches storage as ReadOptions::consistent_read; every in-tree backend serves both values from the copy that took the write) and REQ-PG-008 is marked proposed with the startup refusal named. - 02-high-level-design 4.7: the decision is strongly consistent reads today, the replica route a proposal; the rationale bullets are in the conditional. - 04-component-storage 5.2: the pool sketch is labelled a proposal (5.3 is rewritten by #559). - 08-component-config: the read_replica_url environment row and the two sample lines are removed, since the setting stops the server. - technical-debt F-2 and the TODO index line say the same in the same tense. Closes #561 --- docs/design/01-requirements.md | 4 ++-- docs/design/02-high-level-design.md | 14 +++++++------- docs/design/04-component-storage.md | 5 +++++ docs/design/08-component-config.md | 5 ----- docs/technical-debt.md | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/design/01-requirements.md b/docs/design/01-requirements.md index 394412bd2..b35a683f5 100755 --- a/docs/design/01-requirements.md +++ b/docs/design/01-requirements.md @@ -164,7 +164,7 @@ These are the core CRUD operations. All must be fully implemented. - REQ-DATA-012: TransactGetItems must be atomic — consistent snapshot of up to 100 items - REQ-DATA-013: All data operations must support legacy `Expected` and `ConditionalOperator` parameters (converted internally to expressions) - REQ-DATA-014: All write operations must trigger stream event capture when streams are enabled on the table -- REQ-DATA-015: `ConsistentRead` parameter must be accepted on GetItem, Query, Scan, and BatchGetItem. When a read replica is configured, `ConsistentRead=false` reads must route to the replica; `ConsistentRead=true` reads must route to the primary. When no replica is configured, all reads are strongly consistent. Capacity calculations must reflect the consistency mode regardless of replica configuration (0.5 RCU for eventually consistent, 1.0 RCU for strongly consistent). +- REQ-DATA-015: `ConsistentRead` parameter must be accepted on GetItem, Query, Scan, and BatchGetItem. Capacity calculations must reflect the consistency mode (0.5 RCU for eventually consistent, 1.0 RCU for strongly consistent). No in-tree backend routes a read on the parameter. Routing `ConsistentRead=false` reads to a follower is proposed for the PostgreSQL backend (REQ-PG-008) and not implemented. ### 3.2 Control Plane Operations (In Scope) @@ -449,7 +449,7 @@ The catalog database stores extenddb metadata: table definitions, indexes, tags, - REQ-PG-005: Use parameterized queries for all read operations to prevent SQL injection - REQ-PG-006: Schema migrations managed via embedded migration files - REQ-PG-007: Support PostgreSQL 14+ -- REQ-PG-008: Support optional read replica connection for eventually consistent reads. When `read_replica_url` is configured, `ConsistentRead=false` reads (GetItem, Query, Scan, BatchGetItem) route to the replica pool. All writes and `ConsistentRead=true` reads always use the primary pool. +- REQ-PG-008 (proposed, not implemented): Support an optional read replica connection for eventually consistent reads. When a `read_replica_url` is configured, `ConsistentRead=false` reads (GetItem, Query, Scan, BatchGetItem) would route to the replica pool, and all writes and `ConsistentRead=true` reads would use the primary pool. The backend has no such setting today: `PostgresStorageConfig` (`crates/storage-postgres/src/config.rs`) refuses unknown fields, so a configuration carrying `read_replica_url` stops the server at startup. Every item read and write runs on the data pool (`data_pool`). Design document 04, section 5.3, sketches the proposal with one replica URL; design document 11, Stage 2, plans the same routing with a `replicas` list. ## 9. Expression Engine Requirements diff --git a/docs/design/02-high-level-design.md b/docs/design/02-high-level-design.md index 3a680e615..02472aecd 100755 --- a/docs/design/02-high-level-design.md +++ b/docs/design/02-high-level-design.md @@ -265,18 +265,18 @@ sequenceDiagram - sqlx provides native async PostgreSQL support - The storage trait being async allows backends that use network I/O (e.g., a future DynamoDB-backed backend for testing, or a distributed storage backend) -### 4.7 Read Consistency via Optional Read Replica +### 4.7 Read Consistency and the Proposed PostgreSQL Read Replica -**Decision:** All reads are strongly consistent by default. Eventually consistent reads (`ConsistentRead=false`) are supported by routing to an optional PostgreSQL streaming replica. +**Decision:** The PostgreSQL backend serves every item read from `data_pool`, the pool that takes the writes, so its reads are strongly consistent whatever `ConsistentRead` says. The flag is accepted and charged (0.5 RCU for eventually consistent, 1.0 RCU for strongly consistent). Routing `ConsistentRead=false` reads to a PostgreSQL streaming replica is a proposal (design document 04, section 5.3; REQ-PG-008; design document 11, Stage 2) and not code that exists. **Rationale:** - DynamoDB's eventual consistency is a consequence of reading from storage replicas that haven't received the latest write yet — it's not artificial delays or queues - Strongly consistent is strictly stronger than eventually consistent — any application that works against eventually consistent DynamoDB also works against a strongly consistent backend -- For migration testing (relational → DynamoDB), teams need to surface bugs where application code assumes strong consistency on default reads. A real read replica provides genuine staleness without synthetic delays -- The read replica is opt-in via `storage.postgres.read_replica_url`. When unset, all reads hit the primary — simple, correct, and matching what DynamoDB Local and other emulators do -- Writes always go to the primary. `ConsistentRead=true` always reads from the primary. Only `ConsistentRead=false` reads route to the replica -- Capacity calculations always reflect the consistency mode (0.5 RCU for eventually consistent, 1.0 RCU for strongly consistent) regardless of whether a replica is configured -- This requires zero changes to the storage trait, engine, or server — it's entirely contained in the PostgreSQL backend's pool selection logic +- For migration testing (relational → DynamoDB), teams need to surface bugs where application code assumes strong consistency on default reads. A read replica would return values that lag the primary without synthetic delays +- In the proposal the replica is opt-in; when it is unset, all reads go to the primary, which is what the backend does today +- Writes always go to the primary. `ConsistentRead=true` always reads from the primary. In the proposal only `ConsistentRead=false` reads route to the replica +- Capacity calculations always reflect the consistency mode (0.5 RCU for eventually consistent, 1.0 RCU for strongly consistent) whether or not a replica exists +- The proposal routes on the flag inside the PostgreSQL backend, so it needs the storage trait to carry the flag (design document 11, Stage 1); with that in place it needs no change to the engine or server and is contained in the backend's pool selection ## 5. Data Flow diff --git a/docs/design/04-component-storage.md b/docs/design/04-component-storage.md index d3591a5bd..e3e217741 100755 --- a/docs/design/04-component-storage.md +++ b/docs/design/04-component-storage.md @@ -419,6 +419,11 @@ The PostgreSQL backend uses two categories of tables: ### 5.2 Connection Pooling +The sketch below is a proposal for a read replica mode, not code in this repository; section 5.3 states what the +backend does today. It predates the split into a catalog pool and a data pool: its `pool` stands for today's +`data_pool`. `PostgresStorageConfig` refuses unknown fields, so a configuration carrying `read_replica_url` or +`read_replica_pool_size` stops the server at startup. + ```rust use sqlx::postgres::PgPoolOptions; diff --git a/docs/design/08-component-config.md b/docs/design/08-component-config.md index 8e7e59f15..a95678b32 100755 --- a/docs/design/08-component-config.md +++ b/docs/design/08-component-config.md @@ -49,7 +49,6 @@ Environment variables use double-underscore (`__`) as a nesting separator, prefi | `server.port` | `EXTENDDB__SERVER__PORT` | | `server.bind_addr` | `EXTENDDB__SERVER__BIND_ADDR` | | `storage.postgres.connection_string` | `EXTENDDB__STORAGE__POSTGRES__CONNECTION_STRING` | -| `storage.postgres.read_replica_url` | `EXTENDDB__STORAGE__POSTGRES__READ_REPLICA_URL` | | `storage.sqlite.path` | `EXTENDDB__STORAGE__SQLITE__PATH` | | `auth.provider` | `EXTENDDB__AUTH__PROVIDER` | | `auth.encryption_key` | `EXTENDDB__AUTH__ENCRYPTION_KEY` | @@ -111,10 +110,6 @@ backend = "postgres" # "postgres" | future: "sqlite", "mysql" [storage.postgres] connection_string = "postgresql://localhost:5432/extenddb" # Set credentials via env var in production pool_size = 20 -read_replica_url = "" # Optional: PostgreSQL streaming replica for eventually consistent reads. - # When set, ConsistentRead=false reads route here. When empty, all reads - # use the primary (strongly consistent). Recommended for migration testing. -read_replica_pool_size = 20 # Pool size for the read replica (defaults to pool_size if unset) connection_timeout_secs = 5 statement_timeout_secs = 30 diff --git a/docs/technical-debt.md b/docs/technical-debt.md index 59bd8819a..7b67ac387 100755 --- a/docs/technical-debt.md +++ b/docs/technical-debt.md @@ -14,7 +14,7 @@ Last updated: 2026-09-16 | # | Item | Location | Priority | Origin | |---|------|----------|----------|--------| | F-1 | `AttributesToGet` (legacy API) not supported | `core/types/batch.rs:27` | Low | P6 | -| F-2 | `ConsistentRead=false` not routed to read replica | `core/types/item.rs:166` | Low | P5 | +| F-2 | `ConsistentRead=false` is served the same way as `ConsistentRead=true` on every backend; the PostgreSQL read replica mode that would route it is proposed, not built (REQ-PG-008) | `core/types/item.rs:176` | Low | P5 | | F-3 | Import/export: full Ion parser not implemented (JSON subset only) | `engine/import_export.rs:339` | Medium | P24 | | F-4 | Import/export: full Ion writer not implemented (JSON subset only) | `engine/import_export.rs:433` | Medium | P24 | | F-5 | `PutItem` returns `None` for `Item` field instead of omitting it | `server/lib.rs:235` | Low | P2 | From 6dcd780fee78c403505925037ee85e2a8fb5ecf1 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Tue, 24 Nov 2026 23:18:12 +0000 Subject: [PATCH 2/3] docs: label section 5.3 as the proposal and correct the read consistency claims Review of 204827d2 found four statements in the new text that do not hold at this head. It also found two keys in a sample that the server refuses. - 04-component-storage 5.2 and 5.3: the 5.2 label pointed at 5.3 for what the backend does today. 5.3 still described the replica mode in the present tense. Both sections now read as the proposal. The backend serves every item read and write from data_pool. The read_pool helper and read_replica_url exist only in the sketch. The single-node paragraph carries the label "what the backend does today", the replica paragraph the label "proposed". - 02-high-level-design 4.7: "its reads are strongly consistent whatever ConsistentRead says" holds for base table and local secondary index reads. Global secondary index rows go through the propagation queue (index_propagation_delay_ms, default 10 ms), so a read on a GSI can lag the base table. The decision says so. The last rationale bullet now reads the same before and after the trait carries the flag: the proposal depends on design document 11, Stage 1. - 08-component-config: connection_timeout_secs and statement_timeout_secs are removed from the [storage.postgres] sample. PostgresStorageConfig refuses them with the same unknown field error as read_replica_url. A commented catalog_pool_size line lists the third key the struct has, as the admin guide does. The rest of the section 3 sample is #585. - 01-requirements REQ-PG-008: the pointer names sections 5.2 and 5.3 of document 04, since the code sketch is in 5.2 and the prose in 5.3. Corrections to the message of 204827d2. The flag reaches the engine as GetItemInput::consistent_read and does not reach storage. The SQLite, PostgreSQL and MongoDB backends serve every read from the copy that took the write. The Cassandra backend reads at LOCAL_QUORUM since #945. The struct that refuses unknown fields is PostgresStorageConfig, not PostgresConfig. docs/todo-index.md has no change in this PR, because its line already reads in the future tense. Refs #561 --- docs/design/01-requirements.md | 2 +- docs/design/02-high-level-design.md | 4 ++-- docs/design/04-component-storage.md | 27 ++++++++++++++------------- docs/design/08-component-config.md | 3 +-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/design/01-requirements.md b/docs/design/01-requirements.md index a17a5c5ab..204ce746e 100755 --- a/docs/design/01-requirements.md +++ b/docs/design/01-requirements.md @@ -448,7 +448,7 @@ The catalog database stores extenddb metadata: table definitions, indexes, tags, - REQ-PG-005: Use parameterized queries for all read operations to prevent SQL injection - REQ-PG-006: Schema migrations managed via embedded migration files - REQ-PG-007: Support PostgreSQL 14+ -- REQ-PG-008 (proposed, not implemented): Support an optional read replica connection for eventually consistent reads. When a `read_replica_url` is configured, `ConsistentRead=false` reads (GetItem, Query, Scan, BatchGetItem) would route to the replica pool, and all writes and `ConsistentRead=true` reads would use the primary pool. The backend has no such setting today: `PostgresStorageConfig` (`crates/storage-postgres/src/config.rs`) refuses unknown fields, so a configuration carrying `read_replica_url` stops the server at startup. Every item read and write runs on the data pool (`data_pool`). Design document 04, section 5.3, sketches the proposal with one replica URL; design document 11, Stage 2, plans the same routing with a `replicas` list. +- REQ-PG-008 (proposed, not implemented): Support an optional read replica connection for eventually consistent reads. When a `read_replica_url` is configured, `ConsistentRead=false` reads (GetItem, Query, Scan, BatchGetItem) would route to the replica pool, and all writes and `ConsistentRead=true` reads would use the primary pool. The backend has no such setting today: `PostgresStorageConfig` (`crates/storage-postgres/src/config.rs`) refuses unknown fields, so a configuration carrying `read_replica_url` stops the server at startup. Every item read and write runs on the data pool (`data_pool`). Design document 04, sections 5.2 and 5.3, describe the proposal with one replica URL; design document 11, Stage 2, plans the same routing with a `replicas` list. ## 9. Expression Engine Requirements diff --git a/docs/design/02-high-level-design.md b/docs/design/02-high-level-design.md index aae04bc77..d05555be0 100755 --- a/docs/design/02-high-level-design.md +++ b/docs/design/02-high-level-design.md @@ -269,7 +269,7 @@ sequenceDiagram ### 4.7 Read Consistency and the Proposed PostgreSQL Read Replica -**Decision:** The PostgreSQL backend serves every item read from `data_pool`, the pool that takes the writes, so its reads are strongly consistent whatever `ConsistentRead` says. The flag is accepted and charged (0.5 RCU for eventually consistent, 1.0 RCU for strongly consistent). Routing `ConsistentRead=false` reads to a PostgreSQL streaming replica is a proposal (design document 04, section 5.3; REQ-PG-008; design document 11, Stage 2) and not code that exists. +**Decision:** The PostgreSQL backend serves every item read from `data_pool`, the pool that takes the writes, so its base table and local secondary index reads are strongly consistent whatever `ConsistentRead` says. Global secondary index rows are maintained through the propagation queue (`index_propagation_delay_ms`, default 10 ms; design document 04, section 6), so a read on a GSI can lag the base table, as on the service. The flag is accepted and charged (0.5 RCU for eventually consistent, 1.0 RCU for strongly consistent). Routing `ConsistentRead=false` reads to a PostgreSQL streaming replica is a proposal (design document 04, section 5.3; REQ-PG-008; design document 11, Stage 2) and not code that exists. **Rationale:** - DynamoDB's eventual consistency is a consequence of reading from storage replicas that haven't received the latest write yet — it's not artificial delays or queues @@ -278,7 +278,7 @@ sequenceDiagram - In the proposal the replica is opt-in; when it is unset, all reads go to the primary, which is what the backend does today - Writes always go to the primary. `ConsistentRead=true` always reads from the primary. In the proposal only `ConsistentRead=false` reads route to the replica - Capacity calculations always reflect the consistency mode (0.5 RCU for eventually consistent, 1.0 RCU for strongly consistent) whether or not a replica exists -- The proposal routes on the flag inside the PostgreSQL backend, so it needs the storage trait to carry the flag (design document 11, Stage 1); with that in place it needs no change to the engine or server and is contained in the backend's pool selection +- The proposal routes on the flag inside the PostgreSQL backend, so it depends on the storage trait carrying the flag to the backend (design document 11, Stage 1); with the flag in the trait it needs no change to the engine or server and is contained in the backend's pool selection ## 5. Data Flow diff --git a/docs/design/04-component-storage.md b/docs/design/04-component-storage.md index e832ba4cb..153570e49 100755 --- a/docs/design/04-component-storage.md +++ b/docs/design/04-component-storage.md @@ -431,10 +431,10 @@ The PostgreSQL backend uses two categories of tables: ### 5.2 Connection Pooling -The sketch below is a proposal for a read replica mode, not code in this repository; section 5.3 states what the -backend does today. It predates the split into a catalog pool and a data pool: its `pool` stands for today's -`data_pool`. `PostgresStorageConfig` refuses unknown fields, so a configuration carrying `read_replica_url` or -`read_replica_pool_size` stops the server at startup. +The sketch below and the read replica mode of section 5.3 are a proposal, not code in this repository. Today the +backend serves every item read and write from `data_pool`. The sketch predates the split into a catalog pool and a +data pool: its `pool` stands for today's `data_pool`. `PostgresStorageConfig` refuses unknown fields, so a +configuration carrying `read_replica_url` or `read_replica_pool_size` stops the server at startup. ```rust use sqlx::postgres::PgPoolOptions; @@ -486,18 +486,19 @@ impl PostgresEngine { ### 5.3 Read Consistency Model DynamoDB supports two read consistency modes: strongly consistent and eventually consistent (the default). The -PostgreSQL backend models this via an optional read replica. +PostgreSQL backend in this repository serves every item read and write from `data_pool`; the `read_pool` and +`read_replica_url` in the sketch above are a proposal for a read replica mode, not code that exists. -**Single-node mode (no read replica configured):** All reads are strongly consistent regardless of the `consistent_read` +**Single-node mode (what the backend does today):** All reads are strongly consistent regardless of the `consistent_read` flag. This is strictly stronger than the DynamoDB spec and compatible with all applications. The `consistent_read` parameter is accepted and correctly reflected in capacity calculations (eventually consistent reads consume 0.5 RCU vs 1.0 RCU for strongly consistent). -**Read replica mode (`read_replica_url` configured):** Eventually consistent reads (`consistent_read=false`) are routed -to a PostgreSQL streaming replica that is naturally a few milliseconds behind the primary. Strongly consistent reads -(`consistent_read=true`) always read from the primary. This mirrors how DynamoDB achieves eventual consistency -— via storage node replicas — and surfaces the exact class of bugs that applications may encounter in production -DynamoDB (e.g., read-after-write without `ConsistentRead=true` returning stale data). +**Read replica mode (proposed, `read_replica_url` configured):** Eventually consistent reads (`consistent_read=false`) +would be routed to a PostgreSQL streaming replica that is a few milliseconds behind the primary. Strongly consistent +reads (`consistent_read=true`) would always read from the primary. This mirrors how DynamoDB achieves eventual +consistency through storage node replicas and surfaces the class of bugs that applications meet in production +DynamoDB (a read after a write without `ConsistentRead=true` returning the earlier value). **Which operations are affected:** - `GetItem`: uses `consistent_read` field (default `false` in DynamoDB) @@ -507,8 +508,8 @@ DynamoDB (e.g., read-after-write without `ConsistentRead=true` returning stale d - `TransactGetItems`: always strongly consistent (DynamoDB spec — serializable isolation) - All write operations: always use the primary pool -The `read_pool()` helper method on `PostgresEngine` encapsulates this routing. All read implementations call -`self.read_pool(input.consistent_read)` instead of `&self.pool` directly. +In the proposal, a `read_pool()` helper on `PostgresEngine` encapsulates this routing and every read implementation +calls it instead of `&self.data_pool` directly. ### 5.4 Query Translation diff --git a/docs/design/08-component-config.md b/docs/design/08-component-config.md index ba5b0a2ae..718f34ade 100755 --- a/docs/design/08-component-config.md +++ b/docs/design/08-component-config.md @@ -111,8 +111,7 @@ backend = "postgres" # "postgres" | future: "sqlite", "mysql" [storage.postgres] connection_string = "postgresql://localhost:5432/extenddb" # Set credentials via env var in production pool_size = 20 -connection_timeout_secs = 5 -statement_timeout_secs = 30 +# catalog_pool_size = 20 # management pool, defaults to pool_size; minimum 10 [auth] provider = "builtin" # "none" | "builtin" | "aws_iam" | future: "azure_ad" From a2506c229bc62c9a23840dedbeabae1e30f3df22 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Tue, 24 Nov 2026 23:32:25 +0000 Subject: [PATCH 3/3] docs: name the GSI lag in the single-node paragraph of section 5.3 Section 4.7 of the high-level design now says that base table and local secondary index reads are strongly consistent. It also says that GSI rows go through the propagation queue. The single-node paragraph of document 04, section 5.3, still said that all reads are strongly consistent. This PR relabels that paragraph. It now says the same as section 4.7 and points at section 6 for the queue. Refs #561 Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> --- docs/design/04-component-storage.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/design/04-component-storage.md b/docs/design/04-component-storage.md index 153570e49..ff283867b 100755 --- a/docs/design/04-component-storage.md +++ b/docs/design/04-component-storage.md @@ -489,10 +489,11 @@ DynamoDB supports two read consistency modes: strongly consistent and eventually PostgreSQL backend in this repository serves every item read and write from `data_pool`; the `read_pool` and `read_replica_url` in the sketch above are a proposal for a read replica mode, not code that exists. -**Single-node mode (what the backend does today):** All reads are strongly consistent regardless of the `consistent_read` -flag. This is strictly stronger than the DynamoDB spec and compatible with all applications. The `consistent_read` -parameter is accepted and correctly reflected in capacity calculations (eventually consistent reads consume 0.5 RCU vs -1.0 RCU for strongly consistent). +**Single-node mode (what the backend does today):** Base table and local secondary index reads are strongly consistent +regardless of the `consistent_read` flag. This is strictly stronger than the DynamoDB spec and compatible with all +applications. Global secondary index rows go through the propagation queue (section 6), so a read on a GSI can lag the +base table, as on the service. The `consistent_read` parameter is accepted and correctly reflected in capacity +calculations (eventually consistent reads consume 0.5 RCU vs 1.0 RCU for strongly consistent). **Read replica mode (proposed, `read_replica_url` configured):** Eventually consistent reads (`consistent_read=false`) would be routed to a PostgreSQL streaming replica that is a few milliseconds behind the primary. Strongly consistent