0
0
Rest APIprogramming~5 mins

SLA and uptime tracking in Rest API - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: SLA and uptime tracking
O(n)
Understanding Time Complexity

When tracking SLA and uptime via a REST API, it's important to know how the time to process requests grows as data increases.

We want to understand how the system handles more uptime records or checks.

Scenario Under Consideration

Analyze the time complexity of the following code snippet.


GET /uptime-records

// Server fetches all uptime records from database
// Then filters records within the requested time range
// Finally calculates uptime percentage for that period
    

This code fetches and processes uptime data to calculate SLA compliance.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: Looping through all uptime records to filter and calculate uptime.
  • How many times: Once for each uptime record stored in the database.
How Execution Grows With Input

As the number of uptime records grows, the time to process them grows too.

Input Size (n)Approx. Operations
1010 checks
100100 checks
10001000 checks

Pattern observation: The operations grow directly with the number of records.

Final Time Complexity

Time Complexity: O(n)

This means the time to calculate uptime grows linearly with the number of uptime records.

Common Mistake

[X] Wrong: "The time to calculate uptime stays the same no matter how many records there are."

[OK] Correct: Each record must be checked to calculate uptime, so more records mean more work.

Interview Connect

Understanding how data size affects API response time helps you design better systems and answer real-world questions confidently.

Self-Check

"What if the API cached pre-calculated uptime percentages? How would the time complexity change?"