Google Professional Cloud Developer Question 402
Single answerGoogle Cloud PlatformYou are building a serverless web application hosted on Cloud Run that interacts with a Cloud SQL PostgreSQL database. During load testing, you notice connection failures as traffic increases. How can you optimize the application's connection management to avoid these failures?
- A
Use a database connection pooler like Cloud SQL Auth Proxy to manage connections efficiently.
- B
Increase the maximum connections allowed by the Cloud SQL instance.
- C
Configure your application to use a shared Cloud SQL user across all instances.
- D
Deploy a custom proxy service within your VPC network to handle connection pooling.
Show answer and explanation
Correct answer: A
Explanation
Cloud Run scales horizontally by creating multiple instances to handle traffic spikes, which can lead to many concurrent database connections. This can overwhelm the Cloud SQL instance, as it has a limit on the number of connections. Using the Cloud SQL Auth Proxy enables efficient connection pooling, which minimizes the number of active connections while allowing your application to scale seamlessly.
- A. Correct.
Using a database connection pooler like Cloud SQL Auth Proxy is a recommended approach for managing connections efficiently in serverless environments such as Cloud Run. It helps reduce the number of concurrent connections to the database by pooling and reusing connections.
- B. Incorrect.
While increasing the maximum connections of your Cloud SQL instance might temporarily alleviate the issue, it is not a scalable or cost-efficient solution. Long-term, managing connections effectively through pooling is better.
- C. Incorrect.
Using a shared Cloud SQL user does not directly address the problem of connection management or pooling. It only standardizes access credentials across instances.
- D. Incorrect.
Deploying a custom proxy service for connection pooling is unnecessary because Google Cloud provides native solutions like the Cloud SQL Auth Proxy, which are more secure and easier to manage.