Have you ever waited outside a coffee shop for that friend who always texts, "five more minutes"? Five minutes turn into twenty and you’re left sipping lukewarm coffee while pondering the meaning of friendship. That’s exactly what happens inside a distributed system when one service keeps waiting for another that’s gone AWOL. Except instead of wasted caffeine, you’re burning CPU, holding threads, and stacking up latency for every other request in line.
Enter the timeout: a hard deadline-the digital equivalent of “I’m leaving if you’re not here by 5:05.”
What’s a Timeout?
A timeout is nothing more than a timer you attach to an outgoing call: “I need an answer within n seconds or I’m moving on.” Without it, a stalled dependency can freeze your whole application while users stare at an endless spinner.
Picking the right duration is all context. Too short and you’ll bail on healthy services; too long and you’re letting the slowpoke dictate the pace.
Service B Has Ghosted-Now What?
Here are five playbooks for coping when your deadline expires.
1. Serve a Fallback (Graceful Degradation)
If the avatar service stays silent, show a generic silhouette. If the review count times out, default to “0 reviews.” The page still loads and users stay happy.
2. Retry-But Politely
Maybe the network sneezed. Try again with exponential back-off: wait 1 s, then 2 s, then 4 s. Safe for idempotent reads; dangerous for non-idempotent writes like “transfer $100.”
3. Retry After a Status Check
Suppose the request might have gone through but the response got lost. Before retrying, ask a quick “Did you already process order #123?” This extra step prevents accidental duplicates-two pizzas delivered instead of one.
4. Fail Fast and Bubble Up
Sometimes you simply can’t continue without the data. Throw an exception, log context (“inventory service timeout”), surface a clear 503, and release resources immediately. Better an honest error than a mystery stall.
5. Flip the Model-Go Asynchronous
If you’re layering timeouts on top of timeouts, maybe the call shouldn’t be synchronous at all. Publish a message to a queue, let the other service work at its own pace, and handle the reply when it arrives. No waiting, no blockage.
Choosing Your Strategy
A profile photo can fall back to a placeholder; a funds-transfer endpoint must avoid duplicates at all costs. Weigh business criticality, idempotency, and user impact before choosing your approach.
Wrap-Up
Timeouts are basic etiquette for services: be patient, but don’t let anyone hold up the party. Set them, tune them, and have a plan for when they fire. Your systems-and your users-will thank you.