What are Firestore batch writes?
Answer
Firestore batch writes commit multiple write operations as a single atomic operation — all succeed or all fail. Unlike transactions, batches don't read data — they only write. Supported operations: set, update, delete. Example: const batch = writeBatch(db); batch.set(doc(db, "cities", "NYC"), { name: "New York", state: "NY" }); batch.update(doc(db, "cities", "LA"), { population: increment(1000) }); batch.delete(doc(db, "cities", "OldCity")); await batch.commit(). Batch limits: maximum 500 operations per batch (each set/update/delete counts as one). Benefits over individual writes: (1) Atomicity — all changes apply together or none; (2) Performance — one network round trip instead of N; (3) Consistency — no partial state visible to other readers during batch commit. For deleting large collections, combine pagination with batch deletes: query 500 docs, batch delete, repeat. Batches don't retry on failure and don't read documents (unlike transactions).
Previous
What are Firestore transactions?
Next
How does Firebase Authentication work with custom tokens?