Why NoSQL on GCP matters - Performance Analysis
When using NoSQL databases on GCP, it's important to understand how the time to perform operations changes as data grows.
We want to know how the number of database calls grows when we add more data or requests.
Analyze the time complexity of the following operation sequence.
// Using Firestore NoSQL database on GCP
const db = Firestore();
async function addUsers(users) {
for (const user of users) {
await db.collection('users').add(user);
}
}
// Adds each user document one by one to the 'users' collection
This code adds multiple user records to a Firestore collection, one at a time.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Adding a user document to Firestore collection.
- How many times: Once per user in the input list.
Each user added requires one separate API call to Firestore.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 calls |
| 100 | 100 calls |
| 1000 | 1000 calls |
Pattern observation: The number of calls grows directly with the number of users added.
Time Complexity: O(n)
This means the time to add users grows linearly with how many users you add.
[X] Wrong: "Adding many users at once will take the same time as adding one user."
[OK] Correct: Each user requires a separate call, so more users mean more calls and more time.
Understanding how NoSQL operations scale helps you design efficient cloud apps and answer questions about performance in real projects.
"What if we batch multiple user additions into a single API call? How would the time complexity change?"