Skip to content
Lahore, Pakistan — Working worldwideSenior full-stack & AI agent engineer
Baqir Naqvi
Currently booking new projects — typical response within 24 hours

HomeServicesFirebase Developer: Firestore Architecture, Auth & Cloud Functions

Firebase · Firestore

Firebase Developer: Firestore Architecture, Auth & Cloud Functions

I'm a senior engineer who works on the hard part of Firebase: Firestore data modelling that keeps reads cheap, security rules that actually enforce tenancy, Cloud Functions that don't double-fire, and bills that stop growing faster than the user base. Anyone can wire up a Firestore collection. What costs teams real money is a data model chosen in week one that turns every dashboard load into 400 document reads. I build Firebase apps that survive scale, and when Firestore is the wrong fit I'll tell you and migrate you off it.

The Firebase work that's actually hard

Getting data into Firestore is easy. What's hard is everything that follows: modelling documents so common screens cost a handful of reads instead of hundreds, writing security rules that hold under a real threat model, keeping Cloud Functions idempotent, and stopping the bill from compounding. That's the work I take on.

  • Firestore data modelling — collection and subcollection structure, denormalisation, and aggregate documents designed around your actual read paths, not a tidy-looking ERD.
  • Security rules — tenancy and role enforcement written per operation and tested, with attention to the get() and exists() calls that silently bill you a read on every request.
  • Composite indexes & query design — indexes that match your queries, and query shapes that avoid the multi-range patterns Firestore charges index-entry reads for.
  • Cloud Functions — idempotent triggers, retry and dead-letter handling, cold-start reduction, and background jobs that don't fire twice on the same document.
  • Multi-tenancy — tenant isolation that works with Firestore's rules model rather than fighting it, including per-tenant data export and deletion.
  • Billing & cost control — instrumenting where reads come from, then removing them. Usually the biggest single line item on a Firebase bill.
  • Migrations — Firestore to Postgres or Supabase when the document model has stopped paying for itself, done incrementally with dual writes rather than a big-bang cutover.

Why Firebase bills surprise people

Firestore charges per document read, and the operations that generate reads are not the ones most teams watch. A listener that reconnects re-reads its whole result set. An offset of 500 bills you 500 reads to return 20 documents. A count() over a million matching documents costs about a thousand reads, so polling one counter every thirty seconds can run into tens of dollars a month on its own.

None of that is Firestore being unreasonable — it's a documented, per-operation pricing model working exactly as designed. It just punishes data models that were chosen before anyone read the pricing page. I wrote a full breakdown with current numbers in Firestore pricing at scale, including what a million documents genuinely costs and the five patterns that account for most runaway bills.

Storing a million documents in Firestore costs pennies. Reading them badly, a hundred times a day, is what costs money.

When I'd tell you to leave Firebase

Firebase is an excellent fit for mobile-first apps, realtime collaboration, and products where the document model matches the domain. I'd move you off it when you're routinely fighting the query model — needing joins, multi-field range filters, transactional reporting, or ad-hoc analytics that Firestore was never built to serve.

That migration is a real project, not a weekend, and I do it incrementally: dual-write to both stores, backfill, verify parity, cut reads over per surface, then retire the old path. If you're heading that way, the Supabase and Next.js SaaS pages describe where teams usually land.

Relevant experience

I built Database Vault, a production SaaS that performs automated backups across PostgreSQL, MySQL, MongoDB, Firebase, and Supabase. Backing up a Firestore database means reading every document in it on a schedule — which is about the most direct education in Firestore read costs, pagination, and rate limits available. That product also gave me the migration tooling I use when moving clients between engines.

Alongside that I build AI and SaaS platforms such as VenueX, so I'm assessing your Firebase setup as part of a product, not in isolation.

Getting started

If the problem is the bill, send me a screenshot of your Firebase usage breakdown and a description of your busiest screen — that's usually enough to identify the top two or three read sources before I've touched the code.

If it's a build or a migration, describe the product and where the current model is fighting you. Send me the details and I'll give you a straight assessment of whether the fix is a data model change, a rules change, or a different database.

Frequently asked questions

Often, yes. The quickest wins are usually replacing offsets with cursors, fixing listeners that re-read their full result set on reconnect, caching or precomputing counts instead of calling count() on a hot path, and trimming get() calls inside security rules. Those are targeted changes. A data model rewrite is a bigger job and I'd only recommend it if the cheap fixes don't get you there.

If your data is relational and you'll need joins, aggregates, or reporting, start with Postgres — retrofitting those onto Firestore is painful. If you're mobile-first, want offline sync and realtime out of the box, and your data is naturally document-shaped, Firestore will get you further faster. I'll give you a recommendation based on your actual read patterns rather than a general preference.

Yes — they're usually the same engagement. Custom claims for roles, session handling on the server, and Cloud Functions that are idempotent and handle retries properly. Functions that fire twice on the same document are one of the most common production bugs I'm asked to fix.

Yes, and I do it incrementally rather than as a single cutover: dual-write to both stores, backfill history, verify the two agree, then move reads across one surface at a time. It's slower on paper and dramatically safer in practice. Timeline depends on how much logic sits in security rules and Cloud Functions rather than in your application code.

Proof: related case studies

  • Database Vault: Backup & Recovery SaaS Engineering — Database Vault is a secure SaaS product for automated cloud database backups — PostgreSQL, MySQL, MongoDB, Firebase, and Supabase — with encrypted storage, scheduling, monitoring, and one-click restore. I founded and built the product end to end.
  • VenueX AI: Multi-channel Sales Agent Engineering — Led engineering for VenueX AI — the AI sales platform built for wedding venues, event spaces, golf clubs, and caterers. The product positions itself as an always-on sales team that replies in seconds across email, SMS, and website chat, then qualifies leads and books tours on real calendar availability.

Want this built for your business?

Tell me what you're trying to ship. I typically respond within 24 hours on business days.

Last updated Aug 13, 2026