Health checks configuration in GCP - Time & Space Complexity
When setting up health checks in cloud infrastructure, it's important to understand how the number of checks affects system performance.
We want to know how the time to complete health checks grows as we add more instances to monitor.
Analyze the time complexity of configuring health checks for multiple instances.
// Create a health check
resource "google_compute_health_check" "example" {
name = "example-health-check"
check_interval_sec = 5
timeout_sec = 5
healthy_threshold = 2
unhealthy_threshold = 2
http_health_check {
port = 80
}
}
// Attach health check to each instance group
resource "google_compute_instance_group" "example_group" {
count = var.instance_count
name = "instance-group-${count.index}"
zone = var.zone
health_checks = [google_compute_health_check.example.self_link]
}
This sequence creates one health check and attaches it to multiple instance groups, each representing a set of instances.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Attaching the health check to each instance group.
- How many times: Once per instance group, equal to the number of groups (n).
As the number of instance groups increases, the number of times the health check is attached grows proportionally.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 attach operations |
| 100 | 100 attach operations |
| 1000 | 1000 attach operations |
Pattern observation: The number of attach operations grows linearly with the number of instance groups.
Time Complexity: O(n)
This means the time to configure health checks grows directly in proportion to the number of instance groups.
[X] Wrong: "Adding more instance groups won't affect the time because the health check is created only once."
[OK] Correct: While the health check resource is created once, attaching it to each instance group requires separate operations that add up as groups increase.
Understanding how configuration steps scale with resources shows you can design cloud setups that remain manageable as systems grow.
"What if we created a separate health check for each instance group instead of sharing one? How would the time complexity change?"
Practice
What is the main purpose of a health check in Google Cloud Platform?
Solution
Step 1: Understand health check function
Health checks regularly test if servers respond correctly to requests.Step 2: Identify main purpose
This helps detect unhealthy servers so they can be fixed or replaced.Final Answer:
To monitor if servers are working properly -> Option BQuick Check:
Health check = Monitor server health [OK]
- Confusing health checks with backups
- Thinking health checks increase speed
- Assuming health checks add storage
Which of the following is the correct way to specify a TCP health check in a Google Cloud load balancer configuration?
{
"type": "TCP",
"port": 80,
"checkIntervalSec": 5
}Solution
Step 1: Identify correct health check type
TCP health checks use "type": "TCP" to test TCP connections on the port.Step 2: Match correct JSON syntax
The example matches the correct syntax with type TCP, port 80, and interval 5 seconds.Final Answer:
{ "type": "TCP", "port": 80, "checkIntervalSec": 5 } -> Option AQuick Check:
TCP type with port 80 = { "type": "TCP", "port": 80, "checkIntervalSec": 5 } [OK]
- Using HTTP instead of TCP for TCP check
- Using unsupported types like UDP or ICMP
- Wrong JSON syntax or missing fields
Given this health check configuration snippet, what will happen if the server does not respond within 10 seconds?
{
"type": "HTTP",
"port": 8080,
"timeoutSec": 10,
"unhealthyThreshold": 3
}Solution
Step 1: Understand timeout and threshold
The timeoutSec of 10 means the check waits 10 seconds for a response before failing.Step 2: Apply unhealthyThreshold logic
The server must fail 3 consecutive checks to be marked unhealthy.Final Answer:
The server is marked unhealthy after 3 failed checks -> Option AQuick Check:
Timeout + 3 failures = unhealthy after 3 tries [OK]
- Thinking server is removed immediately after 1 failure
- Ignoring unhealthyThreshold setting
- Assuming server restarts automatically
Identify the error in this health check configuration snippet:
{
"type": "HTTP",
"port": "eighty",
"requestPath": "/health",
"checkIntervalSec": 5
}Solution
Step 1: Check port field type
The port value is "eighty" as a string, but it must be a numeric value like 80.Step 2: Validate other fields
requestPath is valid for HTTP, checkIntervalSec can be 5, and type "HTTP" is correct.Final Answer:
Port must be a number, not a string -> Option CQuick Check:
Port number must be numeric [OK]
- Using string instead of number for port
- Thinking requestPath is invalid for HTTP
- Assuming checkIntervalSec minimum is 10
You want to configure a health check that verifies your web app responds with HTTP 200 on path /status every 15 seconds, and marks the server unhealthy after 2 failures. Which configuration is correct?
Solution
Step 1: Match health check type and path
The app uses HTTP checks on path "/status" so type must be "HTTP" and requestPath "/status".Step 2: Verify timing and thresholds
Check interval is 15 seconds and unhealthyThreshold is 2, matching requirements.Step 3: Confirm port number
Port 80 is standard for HTTP, so it fits the web app default.Final Answer:
{ "type": "HTTP", "port": 80, "requestPath": "/status", "checkIntervalSec": 15, "unhealthyThreshold": 2 } -> Option DQuick Check:
HTTP + /status + 15s + 2 failures = { "type": "HTTP", "port": 80, "requestPath": "/status", "checkIntervalSec": 15, "unhealthyThreshold": 2 } [OK]
- Using TCP type for HTTP path
- Wrong requestPath or port
- Incorrect checkIntervalSec or unhealthyThreshold
Ready to prove it?
Pass the test and this pattern moves unknown
