Firestore 429 error

When committing to firestore, I always encounter these 2 errors:

429 This project has exceeded their maximum bandwidth for writes, please retry with exponential backoff. To learn more about limits, see ‘Maximum writes per second per database’ under ‘Usage and limits’ section of the support documentation.

or

429 This project has exceeded their maximum request_rate/bandwidth/doucment_rate for writes, please retry with exponential backoff. To learn more about limits, see ‘Maximum writes per second per database’ under ‘Usage and limits’ section of the support documentation.

Those error messages are too ambiguous, and I’ve checked the Usage and limits but could not find anything useful :<

At the same time, the write speed of Firestore is only 20~30/s.

So I don’t think it’s an issue about too many writes… BTW, I’m using coroutine in Python to commit to Firestore(in order to make the whole process faster) , and there may have some data with the same document name. I’m not sure whether update to same document cause this problem. Any suggestions?

We have enabled billing, and sometimes the write speed could reach 8k/s.

Thanks!

Firestore write rate limit errors, often signaled by error code 429, occur when your project surpasses the maximum write capacity for your Firestore database. These errors can manifest due to a variety of reasons, such as exceeding the overall write rate limit, updating the same document too frequently, or initiating too many concurrent writes, possibly due to the use of coroutines.

Strategies to Alleviate Write Rate Limit Errors:

  1. Optimize Write Frequency: Assess and refine your write patterns to minimize frequency. This can be achieved by batching writes, queuing write operations, or introducing rate limiting.

  2. Distribute Writes Across Documents: If you’re frequently updating a single document, consider distributing these updates across multiple documents to circumvent single-document write rate limits.

  3. Implement Firestore Transactions: Use transactions for atomic updates to multiple fields within a document, ensuring consistency and preventing issues from concurrent writes.

  4. Proactive Monitoring: Utilize Firebase Console or Cloud Monitoring tools to vigilantly track write operations, identifying and addressing high-activity periods.

  5. Plan Evaluation and Upgrade: If write rate limits are a consistent bottleneck, review your Firestore plan for potential upgrades to increase capacity. Prioritize this after ensuring that optimization strategies are in place.

Additional Considerations:

  • Exponential Backoff: Implement exponential backoff in your retry logic following a 429 error, gradually increasing the delay between retries to reduce load and improve success rates.

  • Concurrency Control: When using coroutines, manage concurrency with care to avoid simultaneous write requests that exceed Firestore’s capacity. Tools like semaphores can help regulate concurrency.

  • Data Modeling: Revisit your data model for potential optimizations. A well-structured data model can significantly reduce the need for frequent writes.

  • Write Distribution: Ensure that writes are evenly distributed across collections and indexes to prevent localized rate limiting.

  • Adherence to Best Practices: Consult Firestore’s best practices for insights on data structuring and query optimization to enhance performance and efficiency.

  • Security Rules Check: Verify that Firestore security rules are not unintentionally increasing read or write operations.

  • Transaction Optimization: Use transactions judiciously, as they are resource-intensive. Ensure they are necessary for the consistency they provide.

  • Documentation and Support: Regularly consult the latest Firestore documentation for current limits and best practices. If issues persist, Google Cloud’s support team can offer tailored assistance.