CodexBloom - Programming Q&A Platform

Firebase Firestore transactions timing out on large collections in Android app

๐Ÿ‘€ Views: 29 ๐Ÿ’ฌ Answers: 1 ๐Ÿ“… Created: 2025-06-18
android firebase firestore transactions performance kotlin

I'm writing unit tests and This might be a silly question, but I've looked through the documentation and I'm still confused about I am experiencing issues with Firestore transactions timing out when trying to update documents in large collections (over 10,000 documents) in my Android app. I am using the Firebase Firestore SDK version 24.0.1, and the transaction fails with the following behavior message: `com.google.firebase.firestore.FirebaseFirestoreException: The transaction timed out.` This happens when I try to update multiple documents in a single transaction. Hereโ€™s the code Iโ€™m using: ```kotlin val firestore = FirebaseFirestore.getInstance() firestore.runTransaction { transaction -> val querySnapshot = transaction.get(firestore.collection("myCollection")) for (document in querySnapshot.documents) { transaction.update(document.reference, "fieldName", newValue) } } .addOnSuccessListener { Log.d("Firestore", "Transaction success!") } .addOnFailureListener { e -> Log.e("Firestore", "Transaction failure: $e") } ``` I've tried increasing the Firestore timeout settings with `FirebaseFirestoreSettings` but it didnโ€™t have any effect. Additionally, I've also looked into batching updates instead of using transactions, but I require the atomicity that transactions provide. Is there a best practice for handling large updates in Firestore that I might have overlooked? Any suggestions on how to improve performance or mitigate these timeouts would be greatly appreciated! Any help would be greatly appreciated! My development environment is Linux. I'd love to hear your thoughts on this. My team is using Kotlin for this REST API. Cheers for any assistance!