Bird
Raised Fist0
Microservicessystem_design~20 mins

Health check pattern in Microservices - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Health Check Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is the primary purpose of a health check in microservices?

In a microservices architecture, why do we implement health checks?

ATo automatically update the service's code
BTo increase the service's processing speed
CTo store user data securely
DTo monitor if a service is running and responsive
Attempts:
2 left
💡 Hint

Think about what helps keep the system reliable by knowing if parts are working.

Architecture
intermediate
1:30remaining
Which component typically performs health checks in a microservices system?

In a microservices setup, who usually initiates health checks to verify service status?

AThe service itself periodically checks its own health
BAn external monitoring system or load balancer
CThe database server connected to the service
DThe client application making requests
Attempts:
2 left
💡 Hint

Consider who needs to know if a service is healthy to route traffic properly.

scaling
advanced
2:00remaining
How does health check frequency affect system scalability?

What is the impact of setting very frequent health checks on a microservices system?

AIt can increase network and CPU load, potentially reducing scalability
BIt reduces the number of service instances needed
CIt has no impact on system resources or scalability
DIt always improves scalability by detecting failures faster
Attempts:
2 left
💡 Hint

Think about how often checking status uses resources.

tradeoff
advanced
2:00remaining
What is a tradeoff when choosing between simple and deep health checks?

Choosing between a simple ping check and a deep check (database, dependencies) involves what tradeoff?

ADeep checks never fail; simple checks cause false alarms
BSimple checks always detect all failures; deep checks are unnecessary
CSimple checks are faster but may miss hidden failures; deep checks are slower but more accurate
DThere is no difference; both provide the same information
Attempts:
2 left
💡 Hint

Consider speed versus thoroughness.

estimation
expert
3:00remaining
Estimate the network overhead of health checks in a system with 1000 services checking every 30 seconds

Each health check request and response is 1 KB. How much network data is used per minute by all services combined?

A2000 KB per minute
B200 KB per minute
C120 KB per minute
D100 KB per minute
Attempts:
2 left
💡 Hint

Calculate requests per minute and multiply by data size.

Practice

(1/5)
1. What is the main purpose of the health check pattern in microservices?
easy
A. To regularly verify if a service is running and responsive
B. To increase the size of the service database
C. To encrypt communication between services
D. To deploy new versions of the service automatically

Solution

  1. Step 1: Understand the health check pattern purpose

    The health check pattern is designed to monitor if a microservice is alive and functioning properly by sending simple requests to it.
  2. Step 2: Identify the correct purpose among options

    Only To regularly verify if a service is running and responsive describes this monitoring function, while others describe unrelated tasks like database size, encryption, or deployment.
  3. Final Answer:

    To regularly verify if a service is running and responsive -> Option A
  4. Quick Check:

    Health check = verify service status [OK]
Hint: Health check means checking if service is alive and working [OK]
Common Mistakes:
  • Confusing health check with deployment or encryption
  • Thinking health check changes service data
  • Assuming health check increases service capacity
2. Which of the following is the correct way to implement a health check endpoint in a microservice?
easy
A. Create an endpoint like /health that returns status 200 if service is healthy
B. Create an endpoint that deletes all data when called
C. Create an endpoint that returns service logs only
D. Create an endpoint that restarts the service automatically

Solution

  1. Step 1: Identify typical health check endpoint behavior

    A health check endpoint usually responds with a simple status code like 200 OK to indicate the service is healthy.
  2. Step 2: Match this behavior with the options

    Create an endpoint like /health that returns status 200 if service is healthy matches this by returning status 200 on /health. Other options perform unrelated or harmful actions.
  3. Final Answer:

    Create an endpoint like /health that returns status 200 if service is healthy -> Option A
  4. Quick Check:

    Health endpoint = status 200 OK [OK]
Hint: Health endpoint returns 200 OK if service is fine [OK]
Common Mistakes:
  • Confusing health check with data deletion
  • Expecting health check to return logs
  • Assuming health check restarts service
3. Consider this pseudocode for a health check endpoint:
function healthCheck() {
  if (database.isConnected() && cache.isAvailable()) {
    return { status: 200, message: 'Healthy' };
  } else {
    return { status: 503, message: 'Unhealthy' };
  }
}
What will the endpoint return if the database is connected but the cache is down?
medium
A. An error is thrown
B. { status: 200, message: 'Healthy' }
C. { status: 404, message: 'Not Found' }
D. { status: 503, message: 'Unhealthy' }

Solution

  1. Step 1: Analyze the condition in the healthCheck function

    The function returns healthy only if both database.isConnected() and cache.isAvailable() are true.
  2. Step 2: Evaluate the given scenario

    Database is connected (true), cache is down (false), so the condition is false and the function returns status 503 with 'Unhealthy'.
  3. Final Answer:

    { status: 503, message: 'Unhealthy' } -> Option D
  4. Quick Check:

    Both checks true = 200, else 503 [OK]
Hint: Both dependencies must be healthy for 200 OK [OK]
Common Mistakes:
  • Assuming partial health returns 200 OK
  • Confusing 503 with 404 status
  • Expecting an error instead of status response
4. A microservice health check endpoint is implemented as follows:
GET /health
Response: { "status": "ok" }
But monitoring tools report the service as unhealthy. What is the likely problem?
medium
A. The service is actually down and not responding
B. The endpoint does not return an HTTP status code 200
C. The endpoint URL should be /status instead of /health
D. The response body is missing the word 'healthy'

Solution

  1. Step 1: Understand monitoring tool expectations

    Most monitoring tools expect the health check endpoint to return HTTP status code 200 to mark service healthy.
  2. Step 2: Identify the issue with the current implementation

    The response body contains status 'ok' but if the HTTP status code is not 200, tools may mark it unhealthy.
  3. Final Answer:

    The endpoint does not return an HTTP status code 200 -> Option B
  4. Quick Check:

    Health check needs HTTP 200 status [OK]
Hint: Health check must return HTTP 200 status code [OK]
Common Mistakes:
  • Thinking response body text controls health status
  • Assuming endpoint URL name matters
  • Ignoring actual service availability
5. You design a microservice system with multiple services. To improve reliability, you want to implement health checks that also verify database and cache connectivity. Which approach best follows the health check pattern?
hard
A. Each service exposes a /health endpoint that always returns 200 regardless of dependency status
B. Only one central service exposes a health check endpoint for all services combined
C. Each service exposes a /health endpoint that returns 200 only if all dependencies (database, cache) are reachable; otherwise returns 503
D. Health checks are done by querying the database directly without service endpoints

Solution

  1. Step 1: Understand health check pattern for dependencies

    Health checks should verify the service and its critical dependencies like database and cache to ensure full functionality.
  2. Step 2: Evaluate the options for best practice

    Each service exposes a /health endpoint that returns 200 only if all dependencies (database, cache) are reachable; otherwise returns 503 correctly implements a health endpoint that returns 200 only if all dependencies are healthy, otherwise 503. This supports automatic recovery and monitoring.
  3. Final Answer:

    Each service exposes a /health endpoint that returns 200 only if all dependencies (database, cache) are reachable; otherwise returns 503 -> Option C
  4. Quick Check:

    Health check includes dependencies, returns 200 or 503 [OK]
Hint: Health check must verify all critical dependencies [OK]
Common Mistakes:
  • Ignoring dependency status in health check
  • Relying on a single central health endpoint
  • Checking dependencies outside service endpoints