Skip to content

Reduce Firestore query and listener read amplification #9889

Closed

Description

@Git-on-my-level

Goal

Identify and reduce avoidable Firestore read amplification in Omi's high-volume query and realtime-listener paths without changing product semantics, consistency expectations, or user-data retention.

Current shape of the problem

The application has both:

  • backend paths that execute Firestore queries and collection scans; and
  • client/realtime paths that attach snapshot listeners and can reconnect or refetch.

The initial investigation suggests likely opportunity areas are duplicate listener attachment, reconnect loops, polling/repeated fetches, broad or unbounded list queries, fan-out reads, and cache misses. This issue intentionally excludes billing figures, production record contents, user identifiers, and exports of production data.

Requested investigation

  1. Build a source-level map of the main Firestore read paths in backend, mobile, desktop, and web surfaces.
  2. Identify query/listener patterns that can amplify reads, prioritizing shared/high-traffic code paths rather than one-off admin scripts.
  3. Propose privacy-safe aggregated telemetry that can attribute read behavior without storing user content or raw identifiers. Useful dimensions may include route/feature, collection category, query shape/boundedness, listener attach/re-attach/dispose events, returned-vs-read document counts, retry reason, and cache source/hit status.
  4. Recommend a small, testable first fix with explicit expected behavior and regression coverage.
  5. Document which proposals require product/consistency validation before rollout.

Constraints

  • Do not inspect, export, or include production document contents, user identifiers, credentials, or billing data in issue discussion, tests, or logs.
  • Prefer source inspection, local emulator tests, and aggregated privacy-safe instrumentation.
  • Do not change listener semantics, query ordering, pagination, cache policy, or data retention without focused behavioral tests and a separately reviewed implementation.
  • Treat Firestore reads as a cross-surface concern: a local optimization must not introduce stale UI, missed realtime updates, duplicate processing, or retry storms.

Acceptance criteria

  • Source-level inventory of top shared read/query/listener paths and their suspected amplification mechanism.
  • Proposal for minimal privacy-safe aggregated telemetry, including cardinality controls and no user-content logging.
  • Ranked shortlist of candidate changes, each with risk and validation plan.
  • One narrowly scoped first implementation proposal with regression-test outline.
  • Clear statement of any production evidence still needed before selecting the first fix.

Activity

  1. aryanorastar commented on Aug 6, 2026

    @aryanorastar
    Collaborator

    VERIFY (contributor triage): Still OPEN as an investigation epic, but substantial amplification work already landed:

    • #9891 — perf: reduce Firestore read amplification (merged)
    • #10440 — backend 504 read amplification
    • #11062 — dedupe all-time usage reads
    • Related alerts #10950 / #10817 remain separate

    Issue ACs ask for inventory + privacy-safe telemetry design + ranked proposals before a first fix — not a cold shrink PR. Next honest step is maintainer/ops evidence of remaining hot paths post-#9891, not another speculative read-path change.

    Standing down from a new PR until residual amplification is named with source + test plan.

  2. added
    backend
    p1
    on Aug 9, 2026
  3. beastoin commented on Aug 9, 2026

    @beastoin
    Collaborator

    Escalation — consolidated tracking issue filed

    The Firestore reads alert has fired 43 incidents (407 breaches) since onset Jul 28, with values trending up despite 6 merged hot-path fixes (#10750, #10778, #10781, #10902, #11062, #11197). Currently in a 32h+ continuous breach.

    Filed #11282 as the consolidated tracking issue with full alert history and fix history.

    Note: Root cause determination and fix plan require maintainer review and approval. No existing issue (including this one) is pre-accepted as the root cause or fix approach.

  4. gx01718-source commented on Sep 8, 2026

    @gx01718-source

    @josancamon19 — following the contribution guide's invitation to suggest bounties, would a US$100 bounty to restore Query Explain through the existing read probe be useful for this investigation?

    #12281 explicitly accepted the loss of StreamGenerator.get_explain_metrics() because there were no in-tree Explain callers. This is that documented limitation, not a newly discovered incident cause. At cb23ae3, I reproduced it with the unchanged probe and Firestore SDK 2.20.0: all six baseline Query/Aggregation .get() cases passed; installing the probe left both ordinary cases working but made all four plan/analyze cases raise AttributeError: 'generator' object has no attribute 'get_explain_metrics'.

    Verification was an offline Python 3.12.14 harness using real SDK get/stream methods, synthetic _make_stream responses and blocked socket connections. It was not your Python 3.11 backend merge gate or a production test.

    The proposed scope is one focused PR restoring Explain access for Query/Aggregation get and stream, with regression coverage in the existing probe test suite, preserving lazy iteration, existing counters, bounded labels and telemetry fault isolation. Backend-required verification would precede a PR. This would enable diagnostics; it would not by itself reduce reads or close this audit.

    There is no approved bounty or payment assumed. If this capability is now wanted, please confirm the scope and bounty before implementation, under your published merged-code/eligibility rules. If it remains intentionally out of scope, I will leave it here.

  5. gx01718-source commented on Sep 10, 2026

    @gx01718-source

    @josancamon19 — I saw that this epic was closed via #13233. That changes how I would scope my earlier proposal: any Query Explain restoration should be a separate, optional diagnostics task, without reopening this investigation or claiming a reduction in production reads.

    The proposed US$100 scope remains Query/Aggregation get and stream compatibility through the existing read probe, with regression coverage and the repository's required checks. My earlier reproduction was tied to the stated commit; I have not presented it as a test of current main.

    Is that separate diagnostic capability still useful enough to commission? If so, please confirm the paid scope and applicable bounty terms before implementation. If it is no longer needed after the recent work, a brief confirmation would help me close the proposal.

    Thanks,
    Chris

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendp1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions