Bird
Raised Fist0
Firebasecloud~20 mins

Realtime Database vs Firestore decision in Firebase - Practice Questions

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Firebase Database Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Choosing the right database for hierarchical data

You have a mobile app that stores deeply nested user settings and preferences. Which Firebase database is best suited for this use case?

ARealtime Database, because it supports complex queries on nested data out of the box.
BFirestore, because it stores data in collections and documents, which is better for deeply nested JSON.
CRealtime Database, because it handles hierarchical data with low latency and simple JSON structure.
DFirestore, because it uses a flat JSON tree that automatically flattens nested data.
Attempts:
2 left
💡 Hint

Think about which database uses a JSON tree structure natively and is optimized for nested data.

❓ service_behavior
intermediate
2:00remaining
Handling offline data synchronization

Which Firebase database provides built-in offline support for web clients that automatically syncs data when the connection is restored?

ARealtime Database, but requires manual sync logic on web clients.
BFirestore, but only on mobile clients, not web clients.
CRealtime Database, because it caches data locally and syncs changes automatically when online.
DFirestore, because it supports offline persistence and sync on web and mobile clients.
Attempts:
2 left
💡 Hint

Consider which database supports offline persistence on all client platforms including web.

❓ Architecture
advanced
2:30remaining
Scaling a chat application with many users

You are designing a chat app with millions of users and thousands of messages per second. Which Firebase database is more suitable to handle this scale efficiently?

AFirestore, because it scales automatically with better query performance and supports sharding.
BRealtime Database, because it supports high throughput with simple JSON data and low latency.
CRealtime Database, because it has built-in horizontal scaling across regions.
DFirestore, but it requires manual sharding to handle high write throughput.
Attempts:
2 left
💡 Hint

Think about which database is designed for automatic scaling and complex queries at large scale.

❓ security
advanced
2:30remaining
Implementing granular security rules

You want to restrict user access to only their own data with fine-grained control. Which Firebase database offers more expressive security rules for this purpose?

AFirestore, but security rules are limited to collection-level permissions only.
BFirestore, because its security rules support granular document-level access and complex expressions.
CRealtime Database, but it only supports simple read/write rules without conditions.
DRealtime Database, because its security rules allow complex conditions on JSON paths.
Attempts:
2 left
💡 Hint

Consider which database allows security rules at the document level with complex logic.

✅ Best Practice
expert
3:00remaining
Optimizing cost for a read-heavy app

Your app has millions of users mostly reading data with few writes. Which Firebase database choice and strategy will minimize costs?

AUse Firestore with indexed queries and pagination to reduce document reads.
BUse Realtime Database with shallow queries to limit data downloaded per read.
CUse Realtime Database with frequent full data syncs to cache data locally.
DUse Firestore without indexes to reduce storage costs.
Attempts:
2 left
💡 Hint

Think about how Firestore charges per document read and how indexing affects query efficiency.

Practice

(1/5)
1. Which Firebase database is best suited for simple real-time syncing of data as a JSON tree?
easy
A. Realtime Database
B. Firestore
C. Cloud Storage
D. Firebase Hosting

Solution

  1. Step 1: Understand data structure of Realtime Database

    Realtime Database stores data as a JSON tree, which is simple and fast for syncing.
  2. Step 2: Compare with Firestore

    Firestore uses collections and documents, better for complex queries but not just simple JSON tree syncing.
  3. Final Answer:

    Realtime Database -> Option A
  4. Quick Check:

    Simple JSON tree sync = Realtime Database [OK]
Hint: Simple JSON tree and fast sync? Choose Realtime Database [OK]
Common Mistakes:
  • Confusing Firestore with Realtime Database
  • Choosing Cloud Storage for database needs
  • Thinking Firebase Hosting stores data
2. Which syntax correctly references a document in Firestore?
easy
A. db.store('users').document('user1')
B. db.collection('users').doc('user1')
C. db.get('users/user1')
D. db.ref('users/user1')

Solution

  1. Step 1: Recall Firestore document reference syntax

    Firestore uses collection().doc() to reference documents.
  2. Step 2: Identify incorrect options

    db.ref() is Realtime Database syntax; db.get() and db.store() are invalid here.
  3. Final Answer:

    db.collection('users').doc('user1') -> Option B
  4. Quick Check:

    Firestore document ref = collection().doc() [OK]
Hint: Firestore uses collection().doc() syntax [OK]
Common Mistakes:
  • Using Realtime Database syntax for Firestore
  • Mixing method names like get() or store()
  • Confusing document and collection references
3. Given this Firestore query code, what will be the output if the 'users' collection has documents with ages 20, 25, and 30?
db.collection('users').where('age', '>', 22).get().then(snapshot => {
  let result = [];
  snapshot.forEach(doc => result.push(doc.data().age));
  console.log(result);
});
medium
A. [25, 30]
B. [20, 25, 30]
C. [22, 25]
D. []

Solution

  1. Step 1: Understand the query condition

    The query filters users where age is greater than 22, so ages 25 and 30 qualify.
  2. Step 2: Determine the output array

    The code collects ages from matching documents, so output is [25, 30].
  3. Final Answer:

    [25, 30] -> Option A
  4. Quick Check:

    age > 22 = [25, 30] [OK]
Hint: Filter > 22 excludes 20, includes 25 and 30 [OK]
Common Mistakes:
  • Including 20 which is not > 22
  • Confusing >= with > operator
  • Assuming empty result without checking data
4. You wrote this Realtime Database code but it throws an error:
firebase.database().collection('users').doc('user1').get()

What is the main issue?
medium
A. Missing authentication before accessing database
B. The get() method is asynchronous and needs await
C. Realtime Database does not have collection() or doc() methods
D. The database URL is not specified

Solution

  1. Step 1: Identify API mismatch

    Realtime Database uses ref() instead of collection() and doc(), which are Firestore methods.
  2. Step 2: Confirm correct method usage

    Using collection() and doc() on Realtime Database causes error because those methods don't exist there.
  3. Final Answer:

    Realtime Database does not have collection() or doc() methods -> Option C
  4. Quick Check:

    Realtime DB uses ref(), not collection()/doc() [OK]
Hint: Realtime DB uses ref(), not collection() or doc() [OK]
Common Mistakes:
  • Assuming get() needs await causes confusion
  • Blaming authentication without checking API
  • Thinking database URL causes this syntax error
5. You need to build a chat app that requires fast real-time updates and simple data structure. Which Firebase database should you choose and why?
hard
A. Firestore, because it supports complex queries and offline caching
B. Firestore, because it scales better for large datasets
C. Realtime Database, because it stores data in collections and documents
D. Realtime Database, because it syncs data instantly as a JSON tree

Solution

  1. Step 1: Analyze app requirements

    The chat app needs fast real-time updates and a simple data structure.
  2. Step 2: Match requirements to database features

    Realtime Database syncs data instantly as a JSON tree, ideal for simple real-time apps.
  3. Step 3: Eliminate incorrect options

    Firestore supports complex queries and scales well but is more complex; Realtime Database does not use collections/documents.
  4. Final Answer:

    Realtime Database, because it syncs data instantly as a JSON tree -> Option D
  5. Quick Check:

    Simple real-time chat = Realtime Database [OK]
Hint: Fast real-time + simple data? Pick Realtime Database [OK]
Common Mistakes:
  • Choosing Firestore for simple real-time needs
  • Confusing data structure of Realtime Database
  • Assuming Realtime Database uses collections/documents
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard