Bird
0
0

Which code snippet correctly shows a fallback for a microservice call to handle failure gracefully?

easy📝 Conceptual Q3 of 15
Microservices - Resilience Patterns
Which code snippet correctly shows a fallback for a microservice call to handle failure gracefully?
AcallService() && fallbackResponse()
Bif (callService()) { throw error; } else { fallbackResponse(); }
Ctry { return callService(); } catch { return fallbackResponse(); }
Dreturn callService() + fallbackResponse();
Step-by-Step Solution
Solution:
  1. Step 1: Understand fallback implementation

    A fallback is used when the main call fails, typically handled with try-catch.
  2. Step 2: Analyze each snippet

    try { return callService(); } catch { return fallbackResponse(); } uses try-catch to return fallback on failure, which is correct. Others misuse logic or syntax.
  3. Final Answer:

    try { return callService(); } catch { return fallbackResponse(); } -> Option C
  4. Quick Check:

    Try-catch fallback = Correct fallback pattern [OK]
Quick Trick: Use try-catch to provide fallback on failure [OK]
Common Mistakes:
MISTAKES
  • Using logical operators incorrectly for fallback
  • Throwing error inside success condition
  • Combining responses instead of fallback

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes