Google Professional Cloud Developer Question 452
Select 3Google Cloud PlatformYou are building a RESTful API on Google Cloud that retrieves a large dataset from Firestore. To improve performance and user experience, you decide to implement pagination. Which of the following steps are necessary to implement efficient and scalable pagination with Firestore?
- A
Use query cursors such as
startAt()andendAt()to fetch specific subsets of data. - B
Retrieve the entire dataset, then slice it into pages on the client side.
- C
Use a fixed page size and pass the last document's reference to the next query.
- D
Sort the data by a specific field before applying pagination.
- E
Store all paginated results in a temporary Cloud Storage file for faster access.
Show answer and explanation
Correct answers: A, C, D
Explanation
When implementing pagination in Firestore, you need to fetch data in subsets using query cursors (startAt() or endAt()) and maintain a fixed page size to ensure consistency. Sorting by a specific field helps produce reliable and repeatable results. Avoid retrieving the entire dataset or adding unnecessary complexity, as these approaches are inefficient and do not scale well.
- A. Correct.
Correct. Firestore query cursors like
startAt()andendAt()allow you to fetch specific subsets of data, which is essential for efficient pagination. - B. Incorrect.
Incorrect. Retrieving the entire dataset defeats the purpose of pagination and can lead to performance issues, especially with large datasets.
- C. Correct.
Correct. Using a fixed page size and passing the last document's reference to the next query ensures that the pagination is consistent and efficient.
- D. Correct.
Correct. Sorting the data by a specific field ensures the pagination is predictable and consistent across queries.
- E. Incorrect.
Incorrect. Storing paginated results in Cloud Storage is unnecessary and adds complexity without improving performance for Firestore queries.