0
0
GCPcloud~5 mins

Audit logging in GCP - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Audit logging
O(n)
Understanding Time Complexity

Audit logging records actions in a system to keep track of what happened and when.

We want to understand how the time to write audit logs changes as more events happen.

Scenario Under Consideration

Analyze the time complexity of the following audit logging code snippet.

// Pseudocode for audit logging in GCP
function writeAuditLog(events) {
  for (let event of events) {
    // Prepare log entry
    let logEntry = formatLog(event);
    // Write log entry to Cloud Logging
    cloudLogging.write(logEntry);
  }
}

This code writes each event's audit log entry one by one to Cloud Logging.

Identify Repeating Operations
  • Primary operation: Loop over each event to write its log entry.
  • How many times: Once for each event in the input list.
How Execution Grows With Input

As the number of events grows, the number of log writes grows the same way.

Input Size (n)Approx. Operations
1010 log writes
100100 log writes
10001000 log writes

Pattern observation: The work grows directly with the number of events.

Final Time Complexity

Time Complexity: O(n)

This means the time to write audit logs grows linearly with the number of events.

Common Mistake

[X] Wrong: "Writing multiple audit logs at once takes the same time as writing one."

[OK] Correct: Each event requires its own log write, so more events mean more time.

Interview Connect

Understanding how audit logging scales helps you design systems that handle many events efficiently.

Self-Check

"What if we batch multiple events into a single log write? How would the time complexity change?"