Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 0 additions & 168 deletions .github/workflows/backend-ferretdb.yml

This file was deleted.

5 changes: 2 additions & 3 deletions backend/__tests__/bench/authHotPath.bench.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* Auth hot-path latency on one store, for the FerretDB CI leg
* (.github/workflows/backend-ferretdb.yml, bench job). Not part of the suite:
* jest.config.js ignores __tests__/bench/, and the bench job runs it on its own.
* Auth hot-path latency on one store, measured for ADR-034 D7. Not part of the
* suite: jest.config.js ignores __tests__/bench/, so run it by hand.
*
* BENCH_URI=mongodb://localhost:27018 BENCH_LABEL=ferretdb \
* npx jest __tests__/bench --testPathIgnorePatterns=/node_modules/
Expand Down
8 changes: 4 additions & 4 deletions backend/__tests__/utils/externalMongoMemoryServer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Stands in for `mongodb-memory-server` when JEST_EXTERNAL_MONGO_URI is set (the
* FerretDB CI leg, .github/workflows/backend-ferretdb.yml). jest.config.js maps
* Stands in for `mongodb-memory-server` when JEST_EXTERNAL_MONGO_URI is set.
* jest.config.js maps
* the package here only then, so a suite that starts its own server with
* `MongoMemoryServer.create()` runs against the store under test instead of an
* in-memory mongod that would answer the same on both legs.
* `MongoMemoryServer.create()` runs against that server instead of an in-memory
* mongod.
*
* Each create() gets its own database on that server, dropped by stop().
* `new MongoMemoryServer(...)` is left as the real class: the one suite that
Expand Down
7 changes: 3 additions & 4 deletions backend/__tests__/utils/testUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ const setupMongoDb = async () => {
return;
}

// JEST_EXTERNAL_MONGO_URI runs the unit tier against another server, for the
// FerretDB CI leg (self-host stores Mongo data in Postgres through
// FerretDB). Each suite gets its own database and drops it on close. The
// name is new on purpose: the compose files already set TEST_MONGO_URI,
// JEST_EXTERNAL_MONGO_URI runs the unit tier against another server. Each
// suite gets its own database and drops it on close. The name is new on
// purpose: the compose files already set TEST_MONGO_URI,
// and `./dev.sh test` must stay in-memory.
if (process.env.JEST_EXTERNAL_MONGO_URI) {
/* eslint-disable global-require */
Expand Down
4 changes: 2 additions & 2 deletions backend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
// and rejects `maxWorkers: undefined` ("has to be of type string or number"), so
// on CI the key must be absent entirely, not present-and-undefined.
...(process.env.CI ? {} : { maxWorkers: 2 }),
// The FerretDB leg points every suite at one server: suites that start their
// JEST_EXTERNAL_MONGO_URI points every suite at one server: suites that start their
// own MongoMemoryServer get a database on it instead (externalMongoMemoryServer).
...(process.env.JEST_EXTERNAL_MONGO_URI ? {
moduleNameMapper: { '^mongodb-memory-server$': '<rootDir>/__tests__/utils/externalMongoMemoryServer.js' },
Expand All @@ -25,7 +25,7 @@ module.exports = {
// (!**/__tests__/utils/**); this makes the two agree.
'__tests__/utils/',
'__tests__/setup.js',
// Benchmarks run on their own (the FerretDB workflow's bench job).
// Benchmarks run on their own.
'__tests__/bench/',
],
// Pre-download/cache the mongod binary ONCE before any worker starts so
Expand Down
50 changes: 26 additions & 24 deletions docs/adr/ADR-034-postgres-single-store.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ direction does not settle three things, and each is named where it lives:** the
mismatch log that a read cut may tolerate (D3 sets it at zero unexplained mismatches, which may prove
too strict for models with clock-derived fields).

**Amended 2026-11-05 (D7).** A self-hosted instance can run its Mongo layer on FerretDB, which
stores it in Postgres, so self-host gets to one database engine before the per-model migration
does. Production stays on MongoDB. D1 to D6 are unchanged as the direction; the model-by-model
work (the dual-store helper and the D6 waves) is paused while D7 ships. **Open in D7:** latency
under real load (the CI bench seeds its store); deadlocks between concurrent writers that don't
upsert; failing suites not yet traced to a group; and the compose and Helm path plus a clean-install
walk, which are not built, so a self-hoster can't pick FerretDB from them yet.
**Amended 2026-11-05 (D7: considered, not adopted).** Running self-host's Mongo layer on FerretDB
was measured and walked, and the founder dropped it the same day: FerretDB's last release is v2.7.0
(2025-11-10). **Self-host is MongoDB plus Postgres**, and that path is walked nightly. The
migration to Postgres only is paused until the founder reopens it, so the open waves in D6 are not
work in progress. What already shipped stays enforced: the D4 freeze on new Mongo models fails CI,
and `requirePgConfigured` stands. D7 stays below as the record.

**Deciders:** founder (direction), eng lead (plan).

Expand All @@ -27,9 +26,7 @@ walk, which are not built, so a self-hoster can't pick FerretDB from them yet.
- **The vector search index** (`services/vectorSearchService.ts`, a local SQLite file with `sqlite-vec`)
is derived from pod content and rebuilt from it. It is an index, not a store of record.
- **ADR-011** (shell-first): this is kernel work and launch does not wait on it.
- **FerretDB (D7) is a deployment choice for self-host, not the target store.** It changes which
server answers the Mongo wire protocol on an instance that picks it, and nothing about where a
model's data is meant to end up. Code still talks to Mongoose; D1 to D6 still describe the move off it.
- **FerretDB (D7) was considered and not adopted.** No supported install uses it.

## Context: the split, measured at `origin/main` `e2cb8c2fc` (2026-11-02)

Expand Down Expand Up @@ -182,13 +179,18 @@ step 1 is the only step that edits callers:
The waves hold 66 models. `Message` leaves in Wave 0, and the three models added after the first count
join Wave 1, which accounts for all 70. The order inside Wave 5 is open.

### D7. Self-host may run the Mongo layer on FerretDB (amended 2026-11-05)
### D7. FerretDB for self-host's Mongo layer: considered, not adopted (2026-11-05)
**Outcome.** Not adopted. Commonly ships no compose or Helm path for it, and a self-hoster shouldn't
pick it. FerretDB has had no release since v2.7.0 (2025-11-10). The DocumentDB project's own gateway
(`pg_documentdb_gw`) was named as an alternative, and that spike was stopped before it produced a
result. What follows records what was measured, in the present tense of that day.

FerretDB 2.7 (Apache-2.0) speaks the Mongo wire protocol and keeps the data in Postgres through
the DocumentDB extension (MIT). A self-hoster then runs Postgres alone: the chat tables and the
the DocumentDB extension (MIT). A self-hoster would then run Postgres alone: the chat tables and the
Mongo layer on one engine. Production stays on MongoDB.

**Measured.** The backend suite, run on both stores through the same harness (each suite gets its
own database on a real server; `TEST_MONGO_URI`, `.github/workflows/backend-ferretdb.yml`), at
own database on a real server; `JEST_EXTERNAL_MONGO_URI`, `.github/workflows/backend-ferretdb.yml`), at
`20c6bfb4` (main as of 2026-11-05 plus that harness, #3492), without the fixes below. CI run
42001537424; #3492 lists every suite:

Expand Down Expand Up @@ -220,22 +222,16 @@ missing collection errors. The rest of what Commonly leans on behaves the same:
`findOneAndUpdate` claims, `$inc`, TTL indexes, partial indexes on equality and `$exists`, `$text`,
`$lookup`, pipeline updates, `arrayFilters`, majority write concern.

**Rules for new Mongo-layer code**, so self-host does not rot: no collation, no `$in` (or other
**Rules proposed for new Mongo-layer code, which don't bind now that D7 isn't adopted:** no collation, no `$in` (or other
operator) in a partial index filter, and every check for a lost race goes through
`isDuplicateKeyError`. A known gap: existing refusals that read `keyPattern` (signup, username
change and a few others) still surface a code-1 refusal as a 500 on FerretDB (#3495 lists them). The
FerretDB workflow (`backend-ferretdb.yml`, #3492) runs the suite on both stores nightly and on
dispatch. It stays off pull requests while FerretDB is red: a failing job marks every backend PR
UNSTABLE even under `continue-on-error`, and the press takes only CLEAN PRs. It moves to pull
requests, as a required check, once it is green. A nightly walk of the self-host path itself, on
both stores, is #3516.
change and a few others) still surface a code-1 refusal as a 500 on FerretDB (#3495 lists them). The FerretDB CI workflow (#3492) was removed when D7 was not adopted.

**Constraints.** The DocumentDB extension needs a superuser and `shared_preload_libraries`
(`pg_cron`, `documentdb`), so it runs on a Postgres the instance owns, not on a managed one. The
`ferretdb/postgres-documentdb` image also bundles PostGIS (GPL-2.0-or-later). Commonly references
that image by tag only in CI (`backend-ferretdb.yml`) and does not redistribute it. Compose and Helm
support is not built yet; when it lands it references the image the same way, and a self-hoster
pulls it from its publisher.
that image by tag only in that CI workflow and did not redistribute it. Compose and Helm support
was drafted in #3506 and not merged.

**Auth hot path** (CI bench `backend/__tests__/bench/authHotPath.bench.js`: 5,000 users, 2,000 pods,
3,000 timed runs after 200 warm-up, the same three hand-built indexes on both stores, each store on
Expand All @@ -250,7 +246,13 @@ trip, not a cold read:
| User by username (login) | 0.94 / 1.07 / 1.70 | 0.63 / 0.69 / 0.90 |

FerretDB adds about 0.3 to 1 ms at p95 per query, the write the most: inside a request's budget for
a self-hosted instance, and the reason production stays on MongoDB until the Postgres port.
a self-hosted instance.

**Clean-install walk, 2026-11-05.** The local compose profile with the unmerged FerretDB override
reached sign-up, pods and messages. A bring-your-own agent failed at attach, because issuing a
runtime token writes with a collation (`update.updates.collation` is not supported). With the unmerged
fixes applied (#3491, #3493, #3495 on #3506), Claude Code answered an @mention. None of those PRs
was merged for this decision.

## Risks
- **Copy drift is a bug we already have.** The Postgres `pods`, `pod_members` and `users` rows are synced
Expand Down
6 changes: 2 additions & 4 deletions docs/database/DATABASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,11 @@ and pod" or "one open row per identical request" has to hold under concurrent wr
- **Identity gets its own index.** Identical concurrent callers walk the slots in the same
order and usually collide on the same slot. They don't when a lower slot frees mid-race, so
a second partial unique index on the identity key is what guarantees one open row.
- **Decide which index refused by reading the data, not the error.** FerretDB can answer a
lost race with a code-1 error that has no `keyPattern` (ADR-034).
- **Decide what a refusal means by reading the data, not the error.** A slot refusal doesn't say
whether an identical open row exists; only the rows do.
- **Adding a unique index to a collection that already has data:** make it partial on a field
only new code writes (`toolCallSlot: { $exists: true }`). Older rows, including any existing
duplicates, are never indexed, so the boot-time `autoIndex` build cannot fail on them.
Partial filters use equality and `$exists` only; FerretDB refuses `$in` and other operators
there (ADR-034).

### Pattern: a terminal transition whose side effects can be retried

Expand Down
5 changes: 3 additions & 2 deletions docs/database/POSTGRESQL_MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# PostgreSQL Message Storage Migration

> **Where this is heading:** [ADR-034](../adr/ADR-034-postgres-single-store.md) makes Postgres the single
> data store and records the measured split as of 2026-11-02. The table below describes chat only.
> **Where this was heading:** [ADR-034](../adr/ADR-034-postgres-single-store.md) set Postgres as the single
> data store and records the measured split as of 2026-11-02. That migration is paused. The table below
> describes chat only.

For schema upgrades and the repository extraction template, see
[Versioned PostgreSQL changes](schema-migrations.md).
Expand Down
Loading