Firestore is a NoSQL document database designed for real-time sync and offline support. Data is organized in collections of documents with subcollections.
Data modeling: denormalize for read performance. Duplicate data that is read together. Use document references for data that changes independently.
Query limitations: no inequality filters on different fields, no full-text search (use Algolia or Typesense), no aggregate functions in queries (use Cloud Functions).
Security rules: never leave rules open. Use request.auth.uid for user-specific access. Validate data structure with rules. Test with Firebase Emulator.
Cost optimization: minimize document reads by using targeted queries, cache aggressively on the client, and use real-time listeners only where needed.
Batch writes and transactions ensure atomicity. Cloud Functions trigger on document changes for server-side logic.