nerdexam
Google

PROFESSIONAL-CLOUD-DEVELOPER · Question #276

You are a lead developer working on a new retail system that runs on Cloud Run and Firestore. A web UI requirement is for the user to be able to browse through all products. A few months after go-live

The correct answer is A. Modify the query that returns the product list using cursors with limits.. The root cause is that the application is loading all products from Firestore at once, causing memory exhaustion on Cloud Run during high-traffic periods. Option A - using cursors with limits - implements proper pagination in Firestore. Cursors are the Firestore-recommended way t

Optimizing Application Performance

Question

You are a lead developer working on a new retail system that runs on Cloud Run and Firestore. A web UI requirement is for the user to be able to browse through all products. A few months after go-live, you notice that Cloud Run instances are terminated with HTTP 500: Container instances are exceeding memory limits errors during busy times. This error coincides with spikes in the number of Firestore queries. You need to prevent Cloud Run from crashing and decrease the number of Firestore queries. You want to use a solution that optimizes system performance. What should you do?

Options

  • AModify the query that returns the product list using cursors with limits.
  • BCreate a custom index over the products.
  • CModify the query that returns the product list using integer offsets.
  • DModify the Cloud Run configuration to increase the memory limits.

How the community answered

(56 responses)
  • A
    80% (45)
  • B
    11% (6)
  • C
    4% (2)
  • D
    5% (3)

Explanation

The root cause is that the application is loading all products from Firestore at once, causing memory exhaustion on Cloud Run during high-traffic periods. Option A - using cursors with limits - implements proper pagination in Firestore. Cursors are the Firestore-recommended way to paginate because they start reading from a specific document position and fetch only a bounded number of results (e.g., 50 products per page). This directly reduces both the memory consumed per request and the total number of expensive Firestore read operations. Option B (custom index) improves query speed but still returns all documents, not reducing memory load. Option C (integer offsets) is discouraged in Firestore because offsets still scan and charge for all preceding documents, providing no memory relief. Option D (increasing memory limits) is a band-aid that addresses the symptom, not the cause, and is explicitly not performance optimization - the question asks to decrease Firestore queries, which D does not do.

Topics

#Firestore#Cloud Run#Pagination#Performance Optimization

Community Discussion

No community discussion yet for this question.

Full PROFESSIONAL-CLOUD-DEVELOPER Practice