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
Recall & Review
beginner
What is the purpose of the health check pattern in microservices?
The health check pattern helps monitor if a microservice is running properly and ready to handle requests. It allows systems to detect failures early and take action like restarting or rerouting traffic.
Click to reveal answer
beginner
Name two common types of health checks used in microservices.
1. Liveness check: verifies if the service is alive and not stuck. 2. Readiness check: verifies if the service is ready to accept traffic and perform work.
Click to reveal answer
intermediate
Why should health checks be lightweight and fast?
Health checks run frequently and must not add heavy load or delay. Lightweight checks ensure quick responses so monitoring systems can react promptly without affecting service performance.
Click to reveal answer
intermediate
How does a load balancer use health checks in microservices?
A load balancer uses health checks to decide which service instances are healthy and can receive traffic. It stops sending requests to unhealthy instances to maintain system reliability.
Click to reveal answer
beginner
What could happen if a microservice does not implement health checks?
Without health checks, failures may go unnoticed, causing requests to fail or hang. This can degrade user experience and make recovery slower because the system cannot detect or isolate problems automatically.
Click to reveal answer
Which health check verifies if a service is ready to accept traffic?
APerformance check
BLiveness check
CDependency check
DReadiness check
✗ Incorrect
Readiness checks confirm if the service is ready to handle requests, while liveness checks only verify if the service is alive.
What is a key characteristic of a good health check endpoint?
ALightweight and fast response
BLong processing time
CRequires user authentication
DHeavy database queries
✗ Incorrect
Health checks should be lightweight and fast to avoid adding load and to provide quick status updates.
How often are health checks typically performed in microservices?
AEvery few seconds to minutes
BOnce a day
COnly at startup
DNever
✗ Incorrect
Health checks run frequently, often every few seconds or minutes, to quickly detect issues.
What role does a load balancer play with health checks?
AIt shuts down unhealthy services
BIt ignores health check results
CIt routes traffic only to healthy instances
DIt performs database backups
✗ Incorrect
Load balancers use health check results to route traffic only to healthy service instances.
Which of these is NOT a benefit of implementing health checks?
AEarly failure detection
BIncreased service downtime
CAutomatic traffic routing
DImproved user experience
✗ Incorrect
Health checks help reduce downtime by detecting failures early, not increase it.
Explain the difference between liveness and readiness health checks in microservices.
Think about when a service is alive but not ready.
You got /4 concepts.
Describe how health checks improve reliability in a microservices architecture.
Consider what happens when a service fails without health checks.
You got /4 concepts.
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
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.
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.
Final Answer:
To regularly verify if a service is running and responsive -> Option A
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
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.
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.
Final Answer:
Create an endpoint like /health that returns status 200 if service is healthy -> Option A
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:
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
Step 1: Analyze the condition in the healthCheck function
The function returns healthy only if both database.isConnected() and cache.isAvailable() are true.
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'.
Final Answer:
{ status: 503, message: 'Unhealthy' } -> Option D
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
Step 1: Understand monitoring tool expectations
Most monitoring tools expect the health check endpoint to return HTTP status code 200 to mark service healthy.
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.
Final Answer:
The endpoint does not return an HTTP status code 200 -> Option B
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
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.
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.
Final Answer:
Each service exposes a /health endpoint that returns 200 only if all dependencies (database, cache) are reachable; otherwise returns 503 -> Option C
Quick Check:
Health check includes dependencies, returns 200 or 503 [OK]
Hint: Health check must verify all critical dependencies [OK]