Discuss the patterns used to handle failures in microservices.

Handling failures gracefully in microservices relies on a set of established resilience patterns that each address a different way a service call can go wrong.

Key Points: • The Circuit Breaker pattern stops repeated calls to a service that's failing, avoiding further errors and giving it time to recover. • Fallback methods provide an alternative response when a call ultimately fails, so the caller can degrade gracefully instead of surfacing a hard error. • The Retry pattern re-attempts a failed request, typically with backoff delays, to recover from transient issues without manual intervention. • The Bulkhead pattern isolates resources per dependency so a failure or slowdown in one area can't consume resources needed by unrelated services. • The Timeout pattern ensures a slow call doesn't hold resources indefinitely, preventing long waits from tying up threads or connections while waiting for a response that may never come.

Example: A call from the Order Service to a Shipping Rate API might have a 2-second timeout, be wrapped in a circuit breaker, retried once with backoff on transient failure, and fall back to a flat shipping estimate if all else fails — layering multiple patterns around a single dependency.

Interview Tip: A concise interview answer is:

"I typically layer several patterns together — timeouts so a slow call doesn't hang forever, retries with backoff for transient failures, a circuit breaker to stop calling a service that's clearly down, bulkheads to isolate resources per dependency, and fallback methods so the caller degrades gracefully instead of failing outright. Each pattern covers a different failure mode, and together they make the system resilient."