nerdexam
Google

PROFESSIONAL-CLOUD-DEVELOPER · Question #289

You are a developer at a social media company. The company runs their social media website on-premises and uses MySQL as a backend to store user profiles and user posts. Your company plans to…

The correct answer is B. Create one root collection for user profiles, and create one subcollection for each user's posts. In Firestore, subcollections are the idiomatic way to model one-to-many relationships. Creating one root collection for user profiles and a subcollection per user for their posts allows efficient queries like 'get all posts for user X' without scanning the entire post dataset…

Designing highly scalable, available, and reliable cloud-native applications

Question

You are a developer at a social media company. The company runs their social media website on-premises and uses MySQL as a backend to store user profiles and user posts. Your company plans to migrate to Google Cloud, and your learn will migrate user profile information to Firestore. You are tasked with designing the Firestore collections. What should you do?

Options

  • ACreate one root collection for user profiles, and create one root collection for user posts.
  • BCreate one root collection for user profiles, and create one subcollection for each user's posts.
  • CCreate one root collection for user profiles, and store each user's post as a nested list in the user
  • DCreate one root collection for user posts, and create one subcollection for each user's profile.

How the community answered

(30 responses)
  • A
    7% (2)
  • B
    83% (25)
  • C
    7% (2)
  • D
    3% (1)

Explanation

In Firestore, subcollections are the idiomatic way to model one-to-many relationships. Creating one root collection for user profiles and a subcollection per user for their posts allows efficient queries like 'get all posts for user X' without scanning the entire post dataset. Option A (two root collections) works but requires client-side joins or denormalization and is less idiomatic. Option C (nested list inside the user document) is dangerous because Firestore documents have a hard 1 MB size limit - a user with many posts would exceed this. Option D inverts the hierarchy in a way that makes fetching a user's profile alongside their posts unnecessarily complex.

Topics

#Firestore#Data Modeling#NoSQL#Collection Design

Community Discussion

No community discussion yet for this question.

Full PROFESSIONAL-CLOUD-DEVELOPER Practice