Cloud SQL pricing in GCP - Time & Space Complexity
We want to understand how the cost of using Cloud SQL changes as we use more resources.
How does adding more databases or increasing usage affect pricing?
Analyze the pricing impact of creating multiple Cloud SQL instances and increasing their usage.
// Pseudocode for provisioning Cloud SQL instances and usage
for (int i = 0; i < n; i++) {
createCloudSQLInstance(cpu=2, memory="8GB");
runQueries(instanceId=i, queryCount=1000);
}
This sequence creates n Cloud SQL instances each with fixed CPU and memory, then runs a fixed number of queries on each.
Look at what repeats as we increase n.
- Primary operation: Creating a Cloud SQL instance and running queries on it.
- How many times: Once per instance, so n times.
Each new instance adds a fixed cost for CPU, memory, and storage, plus query processing costs.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 instances created, 10,000 queries run |
| 100 | 100 instances created, 100,000 queries run |
| 1000 | 1000 instances created, 1,000,000 queries run |
Cost grows directly with the number of instances and queries; doubling instances doubles cost.
Time Complexity: O(n)
This means cost increases in a straight line as you add more Cloud SQL instances and usage.
[X] Wrong: "Adding more instances won't increase cost much because queries are fixed."
[OK] Correct: Each instance adds fixed resource costs, so total cost grows with the number of instances, not just queries.
Understanding how costs grow with resource usage helps you design scalable and budget-friendly cloud solutions.
"What if we increased the CPU and memory per instance instead of the number of instances? How would the time complexity change?"