How do you handle Firestore rate limits and quota exhaustion?

Answer

Firestore has documented limits that applications must respect: (1) Write rate per document — maximum 1 write/second per document. For high-frequency counters (views, likes), this is a critical constraint; (2) Sustained write rate — new collections and indexes have warming periods; very high initial write rates may hit "resource exhausted" errors; (3) Index write overhead — each indexed field generates additional writes; too many indexes slow writes. Solutions for rate limits: (1) Distributed counters — split a single counter into N shards (e.g., 10 documents), each supporting 1 write/second; total capacity: 10 writes/second; reads sum all shards; (2) Write batching — batch writes with writeBatch() for better throughput; (3) Queue-based writes — buffer writes through Pub/Sub or Cloud Tasks, then write at a controlled rate; (4) Exponential backoff — on "resource exhausted" (429) errors, retry with exponential backoff and jitter; (5) Increase quota — contact Google Cloud support to raise limits for production workloads. Monitor Firestore quotas in the Firebase console under Usage.