
Answer-first summary for fast verification
Answer: Modify the query that returns the product list using cursors.
The issue arises because the current implementation retrieves all products in a single query, causing high memory usage in Cloud Run and excessive Datastore reads. To resolve this, pagination using cursors (D) is the optimal solution. Cursors allow efficient traversal of query results without the overhead of offsets (A), which consume read operations for skipped entities. By using cursors with limits (implicit in cursor-based pagination), the query retrieves smaller chunks of data per request, reducing memory pressure on Cloud Run and minimizing Datastore read operations. Increasing memory limits (C) is a temporary fix and does not address the root cause. While using limits (B) is necessary, it alone does not enable efficient pagination without cursors. Thus, the correct answer is D.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
As a lead developer for a retail system running on Cloud Run and Firestore in Datastore mode, you initially implemented an MVP feature that displays all available products by fetching the entire list from Firestore. After go-live, you observe Cloud Run instances crashing with HTTP 500 errors due to memory limits during peak traffic, correlated with spikes in Datastore entity reads. How can you optimize system performance to prevent Cloud Run crashes and reduce Datastore read operations?
A
Modify the query that returns the product list using integer offsets.
B
Modify the query that returns the product list using limits.
C
Modify the Cloud Run configuration to increase the memory limits.
D
Modify the query that returns the product list using cursors.