Bird
0
0

How can you implement a Flask health check endpoint that returns HTTP 503 Service Unavailable if a critical service is down, otherwise returns 200 OK?

hard📝 Application Q9 of 15
Flask - Deployment
How can you implement a Flask health check endpoint that returns HTTP 503 Service Unavailable if a critical service is down, otherwise returns 200 OK?
AAlways return 200 OK with a message about service status
BRedirect health check to a maintenance page when service is down
CUse Flask errorhandler to catch service down errors and return 503
DCheck service status in endpoint; return ('Service Unavailable', 503) if down, else ('OK', 200)
Step-by-Step Solution
Solution:
  1. Step 1: Implement conditional response based on service status

    Inside the endpoint, check the critical service; return 503 if down, else 200.
  2. Step 2: Evaluate alternatives

    Always returning 200 hides problems; errorhandler is for exceptions, not status checks; redirect is unnecessary.
  3. Final Answer:

    Check service status in endpoint; return ('Service Unavailable', 503) if down, else ('OK', 200) -> Option D
  4. Quick Check:

    Return 503 status when service is down [OK]
Quick Trick: Return 503 status code when critical service fails [OK]
Common Mistakes:
MISTAKES
  • Ignoring service status and always returning 200
  • Misusing errorhandler for health check status
  • Redirecting instead of returning status code

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes