0
0
Firebasecloud~20 mins

Data modeling best practices in Firebase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firebase Data Modeling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Choosing the right data structure in Firebase

You want to store user profiles in Firebase Realtime Database. Which data structure is best to allow quick access to each user by their unique ID?

AStore user profiles as a dictionary where each key is the user ID and the value is the profile data.
BStore user profiles in separate databases for each user.
CStore user profiles as a single string with all profiles concatenated.
DStore all user profiles in a list where each profile is an item without keys.
Attempts:
2 left
💡 Hint

Think about how you can quickly find a user profile by ID without scanning all data.

Architecture
intermediate
2:00remaining
Avoiding data duplication in Firebase

You have a list of products and a list of orders referencing those products. What is the best way to model this to avoid duplicating product details in each order?

AStore product IDs inside orders and keep product details in a separate products collection.
BStore full product details inside each order entry.
CStore orders inside each product entry.
DDuplicate product details in both products and orders collections.
Attempts:
2 left
💡 Hint

Think about how to keep data consistent and avoid repeating the same information.

security
advanced
2:30remaining
Securing nested data in Firebase Realtime Database

You want to restrict write access so users can only update their own profile data nested under /users/{userId}. Which Firebase Realtime Database rule correctly enforces this?

A
{
  "rules": {
    "users": {
      "$userId": {
        ".write": "true"
      }
    }
  }
}
B
{
  "rules": {
    "users": {
      "$userId": {
        ".write": "auth != null"
      }
    }
  }
}
C
{
  "rules": {
    "users": {
      "$userId": {
        ".write": "auth.uid == 'admin'"
      }
    }
  }
}
D
{
  "rules": {
    "users": {
      "$userId": {
        ".write": "auth != null && auth.uid == $userId"
      }
    }
  }
}
Attempts:
2 left
💡 Hint

Users should only write to their own user ID path, not others.

service_behavior
advanced
2:00remaining
Understanding Firebase Realtime Database event triggers

What happens when you attach a listener to /messages that triggers on child_added event?

AThe listener triggers every time any child under /messages is changed or removed.
BThe listener triggers once for each existing child under /messages and then for every new child added.
CThe listener triggers only once when the first child is added under /messages.
DThe listener triggers only once when the listener is attached.
Attempts:
2 left
💡 Hint

Think about how Firebase sends data when you first attach a listener.

Best Practice
expert
3:00remaining
Optimizing Firebase data structure for scalability

You have a chat app with thousands of users and millions of messages. Which data modeling approach best supports fast queries and scalability?

AStore all messages in a single list under <code>/messages</code> with no further nesting.
BStore messages as separate top-level nodes with random keys and no grouping.
CNest messages under each chat room ID, e.g., <code>/chatRooms/{roomId}/messages</code>, and paginate queries by timestamp.
DStore all messages inside each user's profile to keep data together.
Attempts:
2 left
💡 Hint

Think about how to limit data downloaded and keep queries efficient.