Handling Zero or Negative Timeouts
What you'll learn: How to decide whether to fail fast or proceed when your timeout budget has already expired before making a downstream call.
The Problem: Time Already Ran Out
After propagating timeouts through multiple service hops and calculating remaining time (as you learned in previous lessons), you might discover the timeout budget is already exhausted—zero milliseconds left, or even negative if calculations lag behind reality.
Now you face a critical decision: do you make the downstream call anyway, or fail immediately?
Two Strategic Approaches
1. Fail Fast (Recommended Default)
Reject the request immediately without calling downstream services. Return an error like 504 Gateway Timeout or DEADLINE_EXCEEDED.
Why: Making a call that's already late wastes resources, increases load on struggling systems, and the response will likely be discarded anyway. The client has probably already given up.
Analogy: If you're racing to catch a flight and realize it departed 5 minutes ago, don't sprint to the gate—accept you missed it and book another.
2. Best-Effort Attempt
Make the call anyway with a minimal timeout (e.g., 100ms grace period).
When to use: For critical operations where partial success matters, or when upstream timeout estimates might be pessimistic. Use sparingly and monitor carefully.
Risk: You're adding load to potentially overloaded systems and delaying the inevitable failure response.
Implementation Pattern
if remaining_time <= 0:
log_timeout_expired()
return TimeoutError("Deadline already exceeded")
Most production systems choose fail-fast behavior to prevent cascading load and resource exhaustion.
Key Takeaway: When your timeout budget reaches zero or goes negative, the safest default is to fail fast rather than make downstream calls that waste resources and worsen cascading failures.