r/Firebase • u/REEEthanYT • 29d ago
Cloud Firestore Can Firebase provide native per-user Firestore rate limits without replacing realtime listeners?
I am building an app around Firestore's direct client SDK, realtime listeners and offline cache. I want to keep that architecture, but I cannot find a supported native way to cap an otherwise authorised user's billable reads/writes across devices and concurrent connections.
The existing feature request dates from April 2023 and currently has 73 votes:
There are concrete adoption concerns in its comments: Al3life reports moving to Supabase for this feature, capTarget archery says it may rule Firebase out for future projects, and Anatole Couasnon describes adding an API despite choosing Firebase for direct access. These are individual reports, not a survey, but they match the concern blocking my confidence in launching.
I am not asking for authentication or permissions to be replaced. Rules limit what a user can access, but a query-size limit does not limit how often an allowed query runs. App Check attests clients; it is not a configurable allowance for each UID. Budget alerts do not stop usage. Cloud Armor in front of my own API does not control the Google-managed Firestore endpoint the SDK calls.
A custom API/SSE/WebSocket gateway could control traffic routed through it, but rebuilding native listener synchronisation, reconnect handling, cache behaviour and authorisation adds infrastructure, cost and complexity. That is not a viable equivalent for this application. An after-read trigger alone would also be too late to stop the triggering charge or a concurrent burst.
What I would like Firebase to provide is a simple console or rules-level policy, enforced by the service: per-UID rolling/burst allowances shared across devices, plus a database/project backstop. It needs to address document/query volume, writes, initial listener snapshots, subsequent billable updates and reconnects, with clear charging and quota-exceeded semantics. I appreciate that the implementation may be more complex than the setting exposed to developers.
I submitted a detailed feature request yesterday and have asked our Google Cloud contacts to escalate it. Is there a Firestore product owner who can give this an explicit status or link it to the right backend tracker? If a supported solution now preserves direct SDK listeners and actually enforces the allowance, I would welcome a documentation link. Otherwise, please treat this as an adoption and cost-abuse concern that needs an owned response.
Related history: https://github.com/firebase/firebase-js-sdk/issues/647
Official App Check limitations: https://firebase.google.com/docs/app-check
Budget guidance: https://firebase.google.com/docs/firestore/quotas
3
u/inlined Firebaser 28d ago
I do not know the roadmap of firestore and google generally doesn’t commit to roadmaps or timelines publicly. All I can say is that the teams are aware of feature requests like these.
Counting at scale is a surprisingly hard problem. If this were an easy thing to implement Im sure it would be by now. Per your comment this may be a strength Supabase; they aren’t the same product and make different architectural tradeoffs. This gives each product different strengths and weaknesses.
1
u/Fit-Corner2382 28d ago
No supported control meters one authorized UID across devices while direct listeners stay on the client SDK.
A rules get of a usage document is not that meter: concurrent connections can all see the same under-cap value and all proceed, and each get is another billed read. Once a listener is accepted, later matching updates are delivered and charged without a new rolling-quota check. A project quota can reject traffic, unlike a budget alert, but one UID can exhaust it for everyone. Disabling the account leaves current listeners billable until their tokens expire.
1
u/LettersFromTheSky 28d ago
We hit the same wall. I don't have a fix for listeners, but this is where we ended up after a lot of production traffic. It might help you decide what to move and what to leave.
What we limit, and how. Anything expensive or easy to abuse (AI calls, search, third-party API proxies, writes, heavy reads that combine many documents) goes through a callable, not the client SDK. Each callable checks a per-UID, fixed-window counter before it does any work:
set({ [`w${windowStart}`]: FieldValue.increment(1) }, { merge: true })on a per-UID, per-action doc. This is a write with no read first, so it never aborts.get()that same doc. If the count is over the limit, refuse withresource-exhaustedand aretryAtset to the end of the window.The limit holds even under bursts. The k-th increment always reads back at least k, so a client firing 50 requests at once still gets at most the limit through. We used to do this as a read-modify-write transaction. Concurrent requests from the same user locked each other out and retried, which added 8–40% overhead on our busiest limiters. Switching to increment-then-read fixed that.
The limits live in a registry with defaults in code, and admins can override them from a settings page. Overrides are cached for about 60 seconds per function instance, so we can tighten a limit during an incident without deploying. For metered spend on AI (minutes, tokens) we reserve the maximum up front and refund the difference afterwards. Counting only at the end doesn't stop 50 sessions from starting in the same second.
What this doesn't solve: your actual question. Our direct
onSnapshotandgetDocstraffic has the same exposure you describe. A signed-in user who passes App Check can rerun an allowed query or reconnect a listener as often as they like, and none of the above sees it. Rules limit what a user can read, not how often, and a query-size cap in rules only limits each query. We accepted that for low-cost, tightly scoped reads because rebuilding listener sync behind a gateway wasn't worth it. That trade only makes sense when the reads are cheap.So I agree with you: a per-UID read/listener allowance enforced by Firestore itself is a missing platform feature, and you can't fully build it yourself without giving up direct SDK access. If it helps, the practical split for us has been:
1
u/PopKoren 28d ago
No native per UID read quota that I know of, but writes are partly coverable today: keep a per-user doc with a lastWrite timestamp and counter, require every write to update it in the same batch, and use getAfter() in rules to reject writes that arrive too soon. Reads are the real gap, so the usual compromise is bounding listener scope (enforce request.query.limit in rules on every collection) and alerting on per-user read spikes from usage logs. Since you're deep in rules already, I'll mention a scanner I built, Rowly, which reports which collections and Storage paths respond to a signed out client in production: https://rowly.me