0
0
GCPcloud~5 mins

Why NoSQL on GCP matters - Performance Analysis

Choose your learning style9 modes available
Time Complexity: Why NoSQL on GCP matters
O(n)
Understanding Time Complexity

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.

Scenario Under Consideration

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 Repeating Operations

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.
How Execution Grows With Input

Each user added requires one separate API call to Firestore.

Input Size (n)Approx. API Calls/Operations
1010 calls
100100 calls
10001000 calls

Pattern observation: The number of calls grows directly with the number of users added.

Final Time Complexity

Time Complexity: O(n)

This means the time to add users grows linearly with how many users you add.

Common Mistake

[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.

Interview Connect

Understanding how NoSQL operations scale helps you design efficient cloud apps and answer questions about performance in real projects.

Self-Check

"What if we batch multiple user additions into a single API call? How would the time complexity change?"