Partial failures and the network

Topic 1 of 9 in Week 5: Distributed systems and service communication9 min readIntermediateFree course

Overview

On one machine, a function call either returns or the whole program crashes. Across a network, a call can vanish into silence: maybe the other side never got it, maybe it did the work and the reply was lost, maybe it’s just slow. This uncertainty, called partial failure, is what makes distributed systems fundamentally harder than single-machine programs. Week 5 is about living with it.

What the network can do to you

Assume any message can be:

  • lost (a dropped packet, a crashed process, a full queue),
  • delayed by an arbitrary amount (congestion, garbage-collection pauses, a retry storm),
  • duplicated (a retry after a lost acknowledgement),
  • reordered (two messages taking different paths).

And any node can be slow rather than dead. From the outside, a node that’s paused for 30 seconds is indistinguishable from one that has crashed, until it wakes up and carries on as if nothing happened.

A timeout tells you nothing

Partial failure: a timeout tells you nothing. In three cases the caller sends a request to a payments service and eventually times out. If the request was lost, the charge never ran. If the server crashed while processing, the customer may or may not have been charged. If the response was lost, the customer was charged but the caller doesn’t know. Retries must be safe (idempotent) and every remote call needs a timeout. Design for unknown outcomes: check status, reconcile later, or make the operation repeatable.

When a call times out, there are three possibilities, and you can’t tell which one happened. For reading a profile, that’s harmless: try again. For charging a card or creating an order, guessing wrong means double charges or lost orders.

Habits that keep systems correct

Always set timeouts

Without one, a slow dependency ties up your threads or connections until you run out (week 6, resilience). Base timeouts on the dependency’s normal p99 latency, plus a margin.

Make operations idempotent

If repeating an operation is harmless, a timeout becomes easy: retry. Use idempotency keys, unique constraints and “set to” rather than “add” updates (week 4).

Model unknown states explicitly

Instead of “paid” or “failed”, have PAYMENT_PENDING for “we asked and don’t know yet”. Show users honest messages (“processing”) and resolve the state later.

Reconcile

Periodically compare your records with the other side’s: payments with the provider’s settlement report, inventory with the warehouse system. Reconciliation catches whatever the online path missed.

Prefer asynchronous flows for long work

Rather than holding a request open while a slow partner processes it, send a message and receive a callback or webhook when it’s done.

Detecting failure

Systems detect failed nodes with heartbeats and timeouts: if a node hasn’t been heard from in, say, 10 seconds, it’s presumed dead. Choosing the timeout is a trade-off:

  • too short: false alarms during brief pauses, causing needless failovers that themselves cause disruption,
  • too long: slow reaction to real failures.

Because “presumed dead” can be wrong, systems that elect leaders must make sure a node that wakes up after a pause can’t keep acting as leader (fencing tokens, leases; see the consensus lesson).

The fallacies of distributed computing

A classic list of false assumptions engineers make: the network is reliable; latency is zero; bandwidth is infinite; the network is secure; topology doesn’t change; there is one administrator; transport cost is zero; the network is homogeneous. Each one has caused real outages. Designs that hold up assume the opposite.

In an interview

When a design calls another service or an external API on a critical path, say: “Calls have timeouts and are retried with backoff; the payment call uses the order ID as an idempotency key; if the outcome is unknown, the order stays pending and a reconciliation job and the provider’s webhook settle it.” This is exactly the kind of failure thinking interviewers look for.

Recap

Distributed systems fail partially: messages are lost, delayed, duplicated or reordered, and a slow node looks dead. A timeout doesn’t tell you whether an operation happened. Protect correctness with timeouts, idempotency, explicit pending states, reconciliation and asynchronous flows, and treat failure detection as a best guess.

Exercise

The payment timed out

Your checkout service calls an external payment API with a 3-second timeout. A call times out. (a) List the three things that might have happened. (b) Why is 'just retry' dangerous here, and what makes it safe? (c) If the retry also times out, what should the user see, and how does the system find out the truth later?

Text
(a)
(b)
(c)

Summary

  • In a distributed system some parts can fail while others keep running; this is a partial failure.
  • Networks can lose, delay, duplicate and reorder messages, and a slow node looks the same as a dead one.
  • A timeout means 'I don't know', not 'it failed': the operation may or may not have happened.
  • Every remote call needs a timeout, and retries need idempotency.
  • Design for unknown outcomes with status checks, reconciliation and explicit intermediate states.