0
0
Firebasecloud~20 mins

Cost optimization (read/write reduction) in Firebase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firestore Cost Optimization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
Understanding Firestore Read Costs

You have a Firestore collection with 1000 documents. You run a query that returns 10 documents. How many document reads will be billed for this query?

A1 document read
B1000 document reads
C10 document reads
D0 document reads
Attempts:
2 left
💡 Hint

Think about how Firestore charges for queries based on documents returned, not total documents in the collection.

Architecture
intermediate
2:00remaining
Improving Firestore Write Performance with Batched Writes

You need to update 50 documents in Firestore. Which approach reduces network calls and improves performance?

AUpdate each document individually with separate write calls
BRead all documents first, then update them one by one
CDelete and recreate the entire collection
DUse a batched write to update all 50 documents in one operation
Attempts:
2 left
💡 Hint

Consider how Firestore handles batched writes and network calls.

security
advanced
2:00remaining
Minimizing Unnecessary Firestore Reads with Security Rules

You want to prevent users from reading documents they shouldn't access to reduce unnecessary read costs. Which security rule snippet correctly restricts reads to only documents where the user's UID matches the document's owner field?

Firebase
match /documents/{docId} {
  allow read: if request.auth.uid == resource.data.owner;
}
Aallow read: if request.auth.uid == resource.data.owner;
Ballow read: if request.auth.uid != resource.data.owner;
Callow read: if true;
Dallow read: if request.auth.uid == null;
Attempts:
2 left
💡 Hint

Think about how to restrict access to only authorized users.

🧠 Conceptual
advanced
2:00remaining
Optimizing Firestore Data Structure for Read Efficiency

You have a Firestore app where users frequently read profile data and their recent activity. Which data structure approach reduces read operations and costs?

ADenormalize recent activity data inside the user profile document
BStore profile and recent activity in separate collections and read them separately
CEmbed recent activity as a subcollection inside each user profile document
DStore all recent activity in a global collection and query by user ID
Attempts:
2 left
💡 Hint

Consider how denormalization can reduce the number of reads.

Best Practice
expert
2:00remaining
Implementing Client-side Caching to Reduce Firestore Reads

You want to minimize Firestore read costs by caching data on the client side. Which approach best balances data freshness and cost savings?

ADisable caching and always fetch fresh data from Firestore
BUse Firestore's offline persistence with periodic manual refreshes
CCache data indefinitely on the client and never refresh
DCache data only in memory and clear cache on every app restart
Attempts:
2 left
💡 Hint

Think about how Firestore's offline persistence works and how to keep data reasonably fresh.