0
0
Microservicessystem_design~10 mins

Health check pattern in Microservices - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a basic health check endpoint in a microservice.

Microservices
GET /health [1] 200 OK
Drag options to blanks, or click blank then click option'
Adelivers
Breturns
Csends
Dresponds
Attempts:
3 left
💡 Hint
Common Mistakes
Using verbs that are not typically used in HTTP response context.
2fill in blank
medium

Complete the code to implement a health check that verifies database connectivity.

Microservices
if database.[1]():
    return 'healthy'
else:
    return 'unhealthy'
Drag options to blanks, or click blank then click option'
Aconnect
Bquery
Cping
Dcheck
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods that perform actual queries instead of simple connectivity checks.
3fill in blank
hard

Fix the error in the health check code that incorrectly returns the status.

Microservices
def health_check():
    status = 'healthy' if service.is_up() else [1]
    return status
Drag options to blanks, or click blank then click option'
A'unhealthy'
BFalse
C'healthy'
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Returning boolean values instead of status strings.
4fill in blank
hard

Fill both blanks to complete the health check that verifies both cache and database status.

Microservices
def health_check():
    cache_status = cache.[1]()
    db_status = database.[2]()
    if cache_status and db_status:
        return 'healthy'
    else:
        return 'unhealthy'
Drag options to blanks, or click blank then click option'
Aping
Bconnect
Cquery
Dcheck
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up methods that perform queries with connectivity checks.
5fill in blank
hard

Fill all three blanks to complete the health check dictionary comprehension filtering only healthy services.

Microservices
health_status = {service: status for service, status in services.items() if status [1] 'healthy' and service.[2]() and not service.[3]()}
Drag options to blanks, or click blank then click option'
A==
Bping
Cis_down
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators or method names.