Chapter 27 · Production Capstone: Design, Secure, Scale, Search, Recover, and Operate a Firestore Application
Add Aggregation, Vector Retrieval, Enterprise Pipeline or MongoDB Compatibility Only Where Requirements Justify Them
Evaluate aggregation, vector retrieval, Enterprise Pipeline and MongoDB compatibility through explicit requirement/evidence gates instead of feature accumulation.
1. Advanced capability review: earn complexity with evidence
AtlasMart stakeholders now ask for “live sales totals,” “semantic product search,” “joins,” and “MongoDB compatibility.” Those phrases map to very different mechanisms. The capstone does not enable them by default. It creates a decision gate for each one: requirement, supported interface, launch stage, client/server boundary, index/cost model, security path, measurable success criterion and fallback.
- Choose read-time aggregation, materialized summaries or external analytics from freshness/scale/cost requirements.
- Add vector retrieval only with an embedding/version/relevance contract and a supported server path.
- Distinguish Enterprise Core from Pipeline and current GA/Preview feature boundaries.
- Use MongoDB compatibility only for a real driver/tool/migration dependency and test compatibility feature by feature.
- Record an explicit reject/accept decision so unused advanced features do not become hidden architecture debt.
Use the Emulator Suite, a Firebase demo project, or an isolated test project for destructive, security-sensitive, billing-sensitive, migration, backup/restore, or write-heavy exercises unless the lesson explicitly marks managed verification as required. Treat shown output as expected evidence unless it is explicitly identified as captured output, and re-check current Firebase/Google Cloud edition, mode, quota, pricing, and security documentation before production execution.
AtlasMart keeps project ID
demo-atlasmart-firestore, Standard edition /
Native mode / Core operations, database
(default), Node.js 22+, Firebase CLI course
baseline 15.30.0, Firebase JavaScript SDK
12.19.0, Firebase Admin Node SDK
14.4.0,
@firebase/rules-unit-testing 5.0.2, Firestore
emulator 127.0.0.1:8080, Auth emulator
127.0.0.1:9099, and Emulator UI
127.0.0.1:4000. The mandatory capstone uses only
a demo- project and local tooling. Managed
location, production IAM/App Check, real composite/vector
indexes, Query Explain/Insights, billing, quotas, Key
Visualizer, scheduled backups/PITR, CMEK/network controls,
Enterprise/Pipeline, and MongoDB-compatibility validation are
optional managed evidence and are never inferred from emulator
success. Where a managed Standard example needs a concrete
location, this chapter uses us-central1 only as
an explicit example—not a universal recommendation.
2. Capability gate matrix
| Request | Default capstone decision | Why | Evidence required to reverse decision |
|---|---|---|---|
| Live cart badge count | Materialized cart field or client-known count. | Tiny bounded operational state; no warehouse/query-time scan needed. | Mismatch rate and write amplification show materialization is worse. |
| Admin daily order count |
Read-time count() for bounded operational
slice; warehouse for large historical analytics.
|
Simple operational question, but aggregation still scans index entries and is not a warehouse. | Measured frequency/scan/cost or analytics complexity exceeds operational database role. |
| Semantic product discovery | OFF at launch; optional Standard vector server path. | No launch requirement yet; embeddings add generation/version/evaluation pipeline. | Offline lexical/tag search misses an agreed relevance target and vector A/B evaluation improves it. |
| Cross-collection relational join | Do not switch editions for convenience. | Core model already supports launch journeys; joins can hide modeling/cost complexity. | A Pipeline-only query materially reduces application complexity with acceptable cost/client constraints. |
| MongoDB driver API | Reject. | No legacy MongoDB application/tool dependency exists. | Migration/portability requirement appears and compatibility matrix passes. |
3. Aggregation: operational answer, not analytics strategy
// Standard Native server-side operational aggregateconst q = db.collection("orders") .where("ownerUid", "==", uid) .where("status", "==", "completed");const countSnap = await q.count().get();console.log({ completedOrders: countSnap.data().count });
Read-time aggregation is useful when the indexed scan remains bounded by the operational access pattern. It is billed according to current aggregation/index-entry semantics, is not a realtime listener, and should not be repeated across huge historical datasets as a substitute for an analytical system. For a realtime dashboard with strict latency and high query frequency, a transactionally or event-maintained summary may be more appropriate—at the cost of write amplification and reconciliation logic.
4. Vector retrieval: search vectors, do not invent semantics
Firestore stores/searches vector values; it does not generate embeddings. Standard vector search currently supports a maximum embedding dimension of 2,048, a maximum 1,000 returned documents per nearest-neighbor query, no realtime snapshot listener, and server client support rather than the ordinary browser/mobile listener path. AtlasMart therefore treats semantic search as an optional backend capability.
// Learning fixture only: not a semantic model.const embeddings = { "red ceramic mug": [0.91, 0.11, 0.02, 0.34], "steel water bottle": [0.08, 0.88, 0.14, 0.22], "insulated travel cup": [0.62, 0.41, 0.07, 0.51]};const embeddingMeta = { provider: "deterministic-course-fixture", model: "atlasmart-4d-v1", dimensions: 4, normalization: "unit-like fixture", generatedAt: "2026-09-17"};
A production vector feature needs model/provider/version/dimensions/normalization metadata, backfill/update behavior, authorization-preserving metadata filters, recall/relevance evaluation, latency and cost. A small cosine score is not proof of business relevance.
5. Enterprise Native: Core and Pipeline are different interfaces
Current Firestore release notes mark Enterprise Native and Pipeline as GA. Enterprise indexing is optional rather than automatically created as in Standard, and the pricing model is byte/unit based. Pipeline can add richer composable server-side operations and subquery joins. But client offline/realtime behavior and launch stage are feature-specific: Pipeline text/geospatial search and Pipeline DML stages are currently Preview, so the capstone must not treat “Enterprise” as one uniformly GA surface.
Stay on Standard Core. Nothing in the launch journeys requires Pipeline-only expressiveness, and the direct Firebase client realtime/offline + Rules surface is already a strong requirement. Revisit only with measured query or economic evidence.
6. MongoDB compatibility: compatibility surface, not database identity
Firestore with MongoDB compatibility is an Enterprise mode
intended for applications that need MongoDB drivers/tools/API
compatibility. It is not mongod running in Google
Cloud and should not inherit MongoDB operational assumptions,
supported-command assumptions, transaction/change-stream
assumptions, index definitions or security roles without
testing.
{ "capability": "mongodb-compatibility", "launchDecision": "REJECT", "reason": "AtlasMart has no MongoDB driver/tool/migration dependency", "reconsiderIf": [ "legacy service must retain a supported MongoDB driver/ODM", "migration program requires compatible endpoint", "compatibility test matrix passes queries/types/indexes/transactions/tools" ], "neverAssume": "drop-in equivalence"}
7. Deliberately wrong approach: “advanced” means “better”
Enable Enterprise Pipeline, vector search and MongoDB compatibility in one architecture diagram, then ask which client uses which API, which auth surface protects it, which billing model applies, how it works offline, and how it is tested locally. The design immediately becomes ambiguous.
The repair is to keep capabilities mutually explicit. Standard Native Core remains the launch contract. Optional vector search is one server-side feature flag. Enterprise/Pipeline and MongoDB compatibility are alternative database/interface decisions, not transparent decorations on the same request path.
8. Mandatory local lab: capability evaluation harness
- Run the core AtlasMart product search fixture by tags/category and record top results.
-
Run deterministic 4-D vector similarity over the same products
and compute a small relevance fixture (
precision@3or judged top-3). - Run a local operational order count and a materialized summary; intentionally corrupt the summary and demonstrate reconciliation.
-
Create decision JSON files for aggregation, vector, Enterprise
Pipeline and MongoDB compatibility with
ACCEPT/REJECT, evidence and rollback. -
Do not claim real vector index latency, Enterprise RU/WU
economics, Pipeline query plans or MongoDB driver parity from
the local simulation; mark those
VERIFY_MANAGED.
const judgedRelevant = new Set(["p-mug-red", "p-travel-cup"]);const returned = ["p-mug-red", "p-bottle-steel", "p-travel-cup"];const hits = returned.filter(id => judgedRelevant.has(id)).length;const precisionAt3 = hits / returned.length;console.log({ precisionAt3 });if (precisionAt3 < 0.66) throw new Error("vector feature does not earn launch complexity");
Aggregation has an operational scope; materialized summaries have reconciliation; vector is optional behind a quality gate; Enterprise/Pipeline and MongoDB compatibility remain rejected absent requirements. Every rejected feature has a documented reconsideration trigger.
Production judgment and bridge
Architecture maturity includes saying “not yet.” Lesson 4 stress-tests the chosen design: hotspots, offline conflicts, Rules, recovery, observability and rollback. The goal is to discover whether the apparently simple Standard/Core design survives adverse conditions.
Knowledge check
- Why is a Firestore aggregation not automatically a warehouse workload?
- What metadata must accompany stored embeddings?
- What is the current launch status of Enterprise Native/Pipeline versus Pipeline text/geospatial/DML?
- Why is MongoDB compatibility rejected for AtlasMart launch?
- What kind of evidence can justify revisiting Standard?
Review the answers
1. Aggregation is an operational indexed query mechanism; repeated large historical analytics can have different scale/cost/modeling needs.
2. At least provider/model/version, dimensions, normalization/generation policy and data-version linkage.
3. Enterprise Native/Pipeline are GA; text/geospatial search and Pipeline DML are feature-specific Preview surfaces as of the review date.
4. There is no MongoDB application/tool/migration dependency, so compatibility would add complexity without value.
5. Measured query expressiveness, client constraints, scale, latency, cost or migration requirements—not preference.
Summary and next step
This lesson established the working contract for Add Aggregation, Vector Retrieval, Enterprise Pipeline or MongoDB Compatibility Only Where Requirements Justify Them. Keep its edition/mode assumptions, trust boundary, verification evidence, and operational constraints explicit when reusing the pattern.
Next, continue to Load-Test Hotspots, Test Offline/Conflict Paths, Run Security Tests, Enable Backup/PITR, Monitor Queries, and Rehearse Recovery.
Authoritative references
- Firebase: Cloud Firestore documentation — Standard Native/Core application semantics.
- Firebase: Security Rules conditions — Rules are not filters and server libraries bypass Rules in favor of IAM/ADC.
- Firebase: Connect to the Cloud Firestore emulator — demo projects and emulator/production differences.
- Firebase: Transactions and batched writes — retries, atomicity and offline constraints.
- Firebase: Firestore best practices — hotspot avoidance and gradual traffic ramping.
- Firebase: Firestore pricing — document/index-entry/listener/aggregation billing in Standard.
- Firebase: Vector search — vector indexes, dimensions, query limits and supported server SDKs.
- Google Cloud: Firestore release notes — current Enterprise/Pipeline launch status and product changes.
- Google Cloud: Core and Pipeline query interfaces — Standard/Enterprise indexing and query-interface differences.
- Google Cloud: Firestore with MongoDB compatibility overview — serverless compatibility surface, not MongoDB itself.
- Google Cloud: Firestore backups and restore — managed recovery mechanisms.
- Google Cloud: Point-in-time recovery — historical recovery window and managed semantics.