Maps to: CMU 15-440/640 Spring 2026, learning outcomes “exactly-once, at-most-once, at-least-once”, “end-to-end argument and its application to real systems”, “integration with threading” and “concurrency of operations”. Reading (optional, course list): J. H. Saltzer, D. P. Reed and D. D. Clark, End-to-End Arguments in System Design (ACM TOCS 2(4), 1984). Problem set: PS1 includes exactly-once and end-to-end-latency scenarios; this lecture gives the concepts, not the answers. Project: P1 — your client stub must decide what to do when the server does not answer. Sources: the course page and handouts; Saltzer et al. 1984; A. D. Birrell and B. J. Nelson, Implementing Remote Procedure Calls (1984); B. J. Nelson’s thesis as summarized in Tanenbaum & van Steen ch. 4 (orphans); V. Jacobson, Congestion Avoidance and Control (SIGCOMM 1988) and RFC 6298 (retransmission timers); C. Juszczak, Improving the Performance and Correctness of an NFS Server (USENIX 1989); N. Bronson et al., Metastable Failures in Distributed Systems (HotOS 2021). The slides are not public; this is not a transcript. All numbers come from
code/lecture04/, run on the author’s machine (Apple M4 Pro, macOS, Python 3.13 and 3.9). Code:code/lecture04/. Reading time: ~85 minutes, plus ~25 to run the demos.
0. How to read this lecture
0.1 Learning goals
After this lecture you should be able to:
- List the ways a remote call can fail, and say what the client can and cannot learn in each.
- Define maybe, at-least-once, at-most-once and exactly-once semantics, name the mechanisms each needs (retries, request ids, a duplicate table, its durability, server epochs), and predict how each behaves under loss, duplication and crashes.
- Decide whether an operation is idempotent — in its effect and in its reply — and make non-idempotent operations safe.
- Design the duplicate table: where it lives, and how to garbage-collect it safely (acknowledgments and watermarks, not timeouts).
- Choose timeouts (fixed vs adaptive), and explain how retries can turn a brief stall into a lasting metastable failure — and what stops it (retry budgets, deadlines).
- Explain why per-call guarantees do not order concurrent calls, how replies must be matched to requests, and what orphans are.
- State the end-to-end argument and use it to decide where a function (reliability, duplicate suppression, encryption) belongs.
0.2 Prerequisites and scope
- Prerequisites: Lecture 1 (§3.3, the six failure worlds), Lecture 2 (timeouts and spurious retransmissions), Lecture 3 (stubs, request ids, framing,
rpc.py). - Scope: failures of a single client–server call. Making several servers agree (two-phase commit, Paxos) is Part IV–V; failure detection in general is Lecture 14.
0.3 Section → code map
| Section | Idea | Demo in code/lecture04/ |
|---|---|---|
| §2 | the four semantics under loss, duplicates and a crash | 01_semantics.py Part A |
| §3 | idempotent effects and replies | 02_idempotence.py |
| §4 | garbage-collecting the duplicate table | 03_reply_cache.py |
| §5–6 | timeouts; retry storms | 04_timeouts_and_retries.py |
| §7 | concurrent calls reorder; stale replies on a real connection | 01_semantics.py Part B, 06_real_timeouts.py |
| §9 | the end-to-end argument | 05_end_to_end.py |
| all | RPC client and server on the simulator | rpcsim.py (python3 rpcsim.py runs its self-test) |
rpcsim.py builds on Lecture 1’s dsim.py: an RpcServer and an RpcClient whose knobs (max_tries, dedup=None|"ram"|"disk", check_epoch, gc, adaptive timeouts, backoff, a FIFO worker queue) are exactly the mechanisms of this lecture. The server keeps a god’s-eye count of how many times each call really ran, so every guarantee can be checked, not just claimed.
0.4 Notation
- A call is identified by (client id, sequence number); “the server ran it k times” means the implementation executed k times.
- Epoch (incarnation number): a counter the server increments, on stable storage, every time it restarts.
- RTO: retransmission timeout. SRTT / RTTVAR: smoothed round-trip time and its mean deviation.
1. What can go wrong with one remote call
Lecture 3 built RPC assuming every request arrives and every reply returns. Remove that assumption and five things can go wrong (the classic list in Tanenbaum & van Steen):
- The client cannot locate the server (binding fails, server not running). Easy: report an error.
- The request is lost. The server never ran the call.
- The server crashes — before executing the call, or after executing it but before replying.
- The reply is lost. The server ran the call.
- The client crashes after sending the request. The server may run a call nobody is waiting for — an orphan (§8).
Cases 2–4 look identical to the client: no reply before the timeout (Lecture 1, demo 02: five of six worlds produced the same observation, and in three of them the action had happened). Every RPC system therefore has to choose what it promises, and the choice is called its call semantics.
2. Four semantics, measured
2.1 The definitions
| semantics | client does | server does | guarantee |
|---|---|---|---|
| maybe | send once, wait, give up | execute what arrives | the call ran 0 or 1 times (and the network can make it 2); the client may not know |
| at-least-once | retry until a reply | execute every request it receives | if the client gets a reply, the call ran ≥ 1 times |
| at-most-once | retry with the same request id | remember executed ids (duplicate table in memory); refuse requests addressed to an earlier epoch | the call ran 0 or 1 times; a reply means exactly once; an error means “0 or 1, unknown” |
| exactly-once | retry with the same id until a reply | duplicate table on stable storage, updated atomically with the execution | the call ran exactly 1 time — provided the server eventually recovers and the client keeps trying |
Two details are easy to miss:
- Why the epoch? If the duplicate table is in RAM, a server that crashes and restarts has forgotten which calls it ran. A retry arriving after the restart would be executed again — breaking at-most-once. The fix (from Birrell and Nelson’s era): the server keeps an epoch counter on disk, increments it on every restart, includes it in replies, and the client includes the epoch it bound to in every request. A request from an earlier epoch is refused with “server restarted: outcome unknown” instead of executed. Birrell and Nelson state their system’s guarantee in exactly these terms: if the call returns, it ran once; if it reports an exception, it may have run once or not at all.
- Why “on stable storage, updated atomically”? If the server records “I ran call 17” in a different step from running it, a crash between the two steps loses the record (or the effect). The two must be one atomic action — the subject of transactions (Lectures 16–17).
2.2 The experiment
Demo 01_semantics.py, Part A, runs one withdrawal of $100 per run, 1,000 runs per configuration, with a 10 ms timeout and up to 8 tries. “Ran” is the server’s true execution count; “client” is what the caller was told.
Loss 20% (each direction):
| semantics | ran 0× | ran 1× | ran 2+× | client: ok | client: error | client: no answer |
|---|---|---|---|---|---|---|
| maybe | 222 | 778 | 0 | 621 | 0 | 379 |
| at-least-once | 0 | 792 | 208 | 1000 | 0 | 0 |
| at-most-once | 0 | 1000 | 0 | 1000 | 0 | 0 |
| exactly-once | 0 | 1000 | 0 | 1000 | 0 | 0 |
The network duplicates 30% of messages:
| semantics | ran 0× | ran 1× | ran 2+× | client: ok |
|---|---|---|---|---|
| maybe | 0 | 713 | 287 | 1000 |
| at-least-once | 0 | 713 | 287 | 1000 |
| at-most-once | 0 | 1000 | 0 | 1000 |
| exactly-once | 0 | 1000 | 0 | 1000 |
The server crashes once (0.5–8 ms into the run) and restarts 20 ms later (loss 5%):
| semantics | ran 0× | ran 1× | ran 2+× | client: ok | client: error | client: no answer |
|---|---|---|---|---|---|---|
| maybe | 323 | 677 | 0 | 522 | 0 | 478 |
| at-least-once | 0 | 830 | 170 | 1000 | 0 | 0 |
| at-most-once | 323 | 677 | 0 | 522 | 478 | 0 |
| exactly-once | 0 | 1000 | 0 | 1000 | 0 | 0 |
What the tables say:
- “maybe” is not even at-most-once: when the network duplicates a request, a server without duplicate detection runs it twice (287 of 1000). Duplicate suppression is needed even if the client never retries.
- at-least-once always gives the client an answer, at the price of re-executions (208 with loss, 287 with duplicates, 170 around a crash). It is correct only for idempotent operations (§3).
- at-most-once never ran anything twice, in any scenario. Its price appears at the crash: 478 clients were told “outcome unknown” — and the demo counts that in 155 of those runs the money had moved, in 323 it had not. The client cannot tell which, so at-most-once hands the ambiguity back to the application (which might, for example, ask “did transfer #17 happen?” — if the server keeps that record durably).
- exactly-once (duplicate table on disk) ran every withdrawal once and answered every client — because the server came back after 20 ms. Had the server stayed down, the client would have retried forever or given up without knowing. That is why “exactly-once” is always a conditional promise, and why many systems describe it more modestly as at-least-once delivery plus idempotent (deduplicated) processing — “effectively once”.
3. Idempotence: operations that can safely run twice
3.1 Definition and intuition
An operation is idempotent if executing it twice has the same effect as executing it once: f(f(s)) = f(s) for the state s. “Set the balance to 70” is idempotent; “withdraw 30” is not. “Press the elevator call button” is idempotent; “insert a coin” is not.
Idempotence matters because it lets the client fix a lost reply without any help from the server: just retry. The cheapest RPC system — at-least-once, no duplicate table — is correct for idempotent operations.
3.2 The experiment: effect vs reply
Demo 02_idempotence.py runs each operation under at-least-once semantics on a network losing 20% of messages, 1,000 runs each. Every row replays the same 1,000 seeded network histories, so the same 208 runs lose a reply and re-execute — a controlled experiment where only the operation differs:
| operation | idempotent effect? | ran twice | state wrong | reply wrong |
|---|---|---|---|---|
get(x) | yes | 208 | 0 | 0 |
set(x, 7) | yes | 208 | 0 | 0 |
incr(x, 10) | no | 208 | 208 | 208 |
append(log, 'e') | no | 208 | 208 | 208 |
delete(x) | yes | 208 | 0 | 208 |
create(y, 1) | yes | 208 | 0 | 208 |
cas(x, 5 → 15) | yes | 208 | 0 | 208 |
| (every operation, exactly-once) | 0 | 0 |
The surprise is the last three rows. delete(x) has an idempotent effect (x is gone either way), but the retry answers “no such key” — so a client would report failure for a delete that succeeded. The same holds for create (“already exists”) and compare-and-set (“conflict”). An operation must be idempotent in its effect and its reply to be safely retried.
This is not hypothetical. NFS (Lecture 5) was designed around idempotent operations — reads and writes at explicit offsets, not “read the next bytes” — so that its stateless server could use at-least-once semantics. But remove, create and rename are not idempotent in their replies, and real NFS servers suffered exactly the spurious errors above until they added a duplicate request cache (Juszczak, 1989).
3.3 Making operations safe to retry
- Use absolute values instead of deltas:
set(balance, 70)instead ofwithdraw(30)— but beware concurrent writers, who make “set” lose updates. - Version the state:
write(x, value, if_version=7)succeeds once; a retry finds version 8 and can recognize its own earlier success (if the server returns the current version and the writer’s id). - Give each operation a unique id chosen by the client and let the server remember it: this is the duplicate table of §4, exposed at the application level. Payment APIs call these idempotency keys: the client attaches a random key to “charge $10”, and the server returns the original result for any repeat with the same key.
- Make the interface carry position:
write(file, offset=8192, data)is idempotent;append(file, data)is not. NFS chose the former.
4. The duplicate table, and how to forget it safely
4.1 What to store
At-most-once and exactly-once need the server to remember, for each executed call, its id and its reply (so a duplicate gets the same answer — §3 showed why “no such key” is wrong). Kept forever, this table grows with every call ever made.
4.2 The experiment: three ways to forget
Demo 03_reply_cache.py: one client makes 2,000 sequential incr(x, 1) calls (not idempotent, so any re-execution shows in the final value of x). A relay node between client and server additionally delivers ~2% of requests a second time, 200 ms late — a packet stuck in a queue or a retransmission over a slow path.
| policy | late copies | max table size | dups answered from table | stale copies ignored | final x | extra executions |
|---|---|---|---|---|---|---|
| no garbage collection | 44 | 2000 | 264 | 0 | 2000 | 0 |
| forget after 50 ms (TTL) | 44 | 12 | 226 | 0 | 2038 | 38 |
| forget after 500 ms (TTL) | 44 | 79 | 264 | 0 | 2000 | 0 |
| client acks + per-client watermark | 41 | 1 | 234 | 38 | 2000 | 0 |
- No GC is correct but unbounded.
- A time-to-live (TTL) bounds the table but is unsafe: with 50 ms, 38 delayed duplicates arrived after their entry was forgotten and were executed again. A 500 ms TTL happens to be long enough for this network — at 6× the memory, and with correctness now resting on a guess about the worst-case network delay. Networks have no hard maximum delay; the guess will eventually be wrong.
- Acknowledgments make forgetting safe. Each request carries “I have the replies to all my calls up to seq A” (piggybacked, free). The server can then drop those entries — and keep just one number per client, the watermark A: any later request with seq ≤ A is a stale duplicate and is ignored. The table never exceeded 1 entry, and all 38 stale copies were recognized.
The pattern — per-client sequence numbers, cumulative acknowledgments, a watermark — is the same one TCP uses for its byte stream. And the TTL failure mode is the reason TCP’s TIME_WAIT lasts twice the maximum segment lifetime: an old duplicate must not be mistaken for new data. State that protects correctness may be discarded only when you know it is no longer needed, never when you guess.
5. Timeouts: guessing what “too long” means
5.1 The trade-off
A timeout is the only failure detector a client has, and it is a guess. Too short, and a live-but-slow server is declared dead (a false alarm) and burdened with retries; too long, and a dead server is noticed late. Lecture 2 already showed a fixed timeout shorter than the queueing delay causing a self-inflicted collapse.
5.2 Adaptive timeouts
TCP’s answer (Jacobson 1988; RFC 6298) is to measure the round-trip time and its variability, and set the timeout from both:
with two refinements: Karn’s rule (do not take RTT samples from retransmitted calls — you cannot tell which copy the reply answers) and exponential backoff (double the RTO after each timeout of the same call).
5.3 The experiment
Demo 04_timeouts_and_retries.py, Part A: a server answers in 1–3 ms, slows down at 1.5 s, and dies at 3 s. Each call gets 4 tries; exhausting them reports “server dead”.
Mild slowdown (service 10–20 ms):
| timeout policy | retries sent | late replies (server was alive) | false “server dead” | crash noticed after |
|---|---|---|---|---|
| fixed 5 ms | 1200 | 478 | 28 | 6 ms |
| fixed 25 ms | 152 | 2 | 0 | 95 ms |
| fixed 200 ms | 18 | 0 | 0 | 791 ms |
| adaptive (SRTT + 4 RTTVAR) | 182 | 77 | 0 | 122 ms |
Severe slowdown (service 100–200 ms):
| timeout policy | retries sent | late replies | false “server dead” | crash noticed after |
|---|---|---|---|---|
| fixed 5 ms | 1180 | 480 | 74 | 2 ms |
| fixed 25 ms | 192 | 54 | 14 | 1 ms |
| fixed 200 ms | 18 | 0 | 0 | 674 ms |
| adaptive | 138 | 35 | 3 | 64 ms |
A well-chosen fixed timeout (25 ms) looked perfect under the mild slowdown — but only because 4 × 25 ms happened to exceed those round trips; under the severe slowdown it declared the live server dead 14 times. The adaptive timer was close to the best fixed value in both cases (0 and 3 false alarms, crash noticed after 122 and 64 ms) without knowing the right value in advance. It is not perfect — with only 4 tries a sudden 10× slowdown can still exhaust it — and no timeout can be: in an asynchronous network a slow server and a dead one are indistinguishable (Lecture 14 makes this precise).
6. When retries make things worse: retry storms and metastable failures
6.1 The feedback loop
Retries assume the failure is independent of the retry. Overload breaks that assumption: when the server is slow because it is overloaded, every timeout produces another request, which adds load, which makes the server slower, which causes more timeouts. A brief stall can push the system into a state that sustains itself after the original cause is gone — a metastable failure (Bronson et al., 2021), the mechanism behind many real cloud outages.
6.2 The experiment
Demo 04, Part B: clients send 700 requests/s to a server that can do 1,000/s (one worker, 1 ms each, FIFO queue). Timeout 50 ms, up to 5 tries. The server stalls for 200 ms, from 1.0 to 1.2 s. Successful requests per second and queue length per 250 ms window:
| time (ms) | no retries | immediate retries | backoff + jitter | backoff + 10% retry budget | immediate + server deadlines |
|---|---|---|---|---|---|
| 500–750 | 772/s, q=2 | 772/s, q=2 | 772/s, q=2 | 772/s, q=2 | 772/s, q=2 |
| 1000–1250 (stall) | 4/s, q=122 | 184/s, q=513 | 200/s, q=241 | 8/s, q=150 | 200/s, q=190 |
| 1500–1750 | 180/s, q=19 | 0/s, q=1852 | 472/s, q=686 | 220/s, q=21 | 596/s, q=124 |
| 2000–2250 | 824/s, q=0 | 0/s, q=3181 | 352/s, q=1387 | 800/s, q=0 | 600/s, q=66 |
| 3000–3250 | 732/s, q=0 | 0/s, q=5990 | 124/s, q=3363 | 728/s, q=0 | 840/s, q=4 |
| 4750–5000 | 736/s, q=2 | 0/s, q=10239 | 0/s, q=7758 | 732/s, q=0 | 716/s, q=0 |
| policy | requests | messages sent | server work units | goodput 3–5 s |
|---|---|---|---|---|
| no retries | 3637 | 3637 | 3637 | 732/s |
| immediate retries | 3589 | 15158 | 5486 | 0/s |
| backoff + jitter | 3530 | 13532 | 5486 | 17/s |
| backoff + 10% budget | 3584 | 3634 | 3634 | 733/s |
| immediate + deadlines | 3536 | 5832 | 3896 (1936 skipped) | 728/s |
- Immediate retries never recover. The stall ended at 1.2 s; the overload did not. Every request now waits behind a queue longer than its timeout, times out, and is resent, so the offered load (up to 5 × 700/s) far exceeds capacity forever: goodput 0, queue growing without bound. That is the metastable state.
- Backoff with jitter alone did not recover either — which contradicts the common advice, and is worth understanding. Backoff spreads retries out in time, but it does not reduce their number: while every attempt times out, each request still costs up to 5 sends (13,532 messages for 3,530 requests).
- What worked was capping the extra load. A retry budget (each new request earns 0.1 retry token; a retry spends one; without a token the request gives up) guarantees retries add at most ~10% to the load, and the system recovers within a second. Server-side deadlines — each request carries its client’s deadline, and the server skips requests whose deadline has passed (1,936 skipped) — stop the server from wasting capacity on answers nobody is waiting for. Production RPC systems use both, plus load shedding and circuit breakers.
Remember also Lecture 2’s hedged requests: a hedge is a deliberate duplicate, so it is safe only for idempotent or deduplicated calls, and it too must be budgeted.
7. Concurrency of operations and integration with threads
7.1 Exactly-once per call is not ordering between calls
Demo 01, Part B: two threads of one client issue set(x, 1) and, 1 ms later, set(x, 2), on a network losing 30% of messages, with exactly-once semantics. In 363 of 1,000 runs the server executed set(x, 1) last (its first request was lost, and its retry overtook the second call), leaving x = 1. Issued sequentially — waiting for the first reply before sending the second — the same calls ended with x = 2 in all 1,000 runs.
Each call ran exactly once; the order of concurrent calls is not part of any per-call guarantee. If order matters, the client must wait for each reply, or attach per-client sequence numbers and have the server execute them in order (a hold-back queue, as with Lecture 1’s sequencer).
7.2 Matching replies to requests (real sockets)
Demo 06_real_timeouts.py uses Lecture 3’s rpc.py over a real loopback connection. A call slow_incr(150 ms) times out on the client after 50 ms; 200 ms later the client calls add(2, 3) on the same connection:
| rpc.py connection (one call at a time) | replies matched by id | |
|---|---|---|
| call 1 | slow_incr: RpcTimeout after 50 ms | slow_incr: RpcTimeout after 50 ms |
| call 2 | add(2, 3) → ProtocolError: reply id 1 ≠ request id 2 | add(2, 3) → 5 |
server ran slow_incr | 1 time | 1 time |
Two lessons on real sockets. First, the timeout cancelled nothing: the server ran slow_incr although the client was told “timeout” — Lecture 1’s ambiguity, now with TCP. Second, the late reply was still in the byte stream, so the next call read it. Lecture 3’s reply-id check turned that into an error; without it, add(2, 3) would have silently returned slow_incr’s result. A client must match replies to requests by id and discard stale ones (or close the connection after a timeout — which is also the safe response if the timeout fired in the middle of reading a frame, leaving the stream desynchronized). A multi-threaded client that keeps several calls outstanding on one connection needs exactly this table of outstanding ids, routing each reply to the thread waiting for it.
7.3 On the server side
Lecture 3 showed the server is a concurrent program: shared state needs locks, and calls from different clients interleave. Add retries and duplicates, and the duplicate table itself becomes shared state that every server thread reads and writes — it must be updated atomically with the execution it records.
8. Orphans: when the client is the one that fails
If a client crashes after sending a request, the server may keep working on a call nobody is waiting for — an orphan. Orphans waste resources, may hold locks, and, worst, a restarted client can receive replies to calls it no longer remembers. The classic remedies (from Nelson’s thesis, as summarized by Tanenbaum & van Steen):
- extermination: the client logs each call on stable storage before sending it, and after a reboot explicitly kills its orphans;
- reincarnation: the rebooted client announces a new epoch, and servers kill computations belonging to its old epochs (the client-side mirror of §2.1’s server epochs);
- gentle reincarnation: as above, but kill only computations whose owner cannot be found;
- expiration: each call gets a time quantum and must be renewed by the client; an unrenewed call is abandoned. This is a lease — the idea that returns, for cache consistency, in Lecture 7.
None is perfect: killing an orphan halfway may leave its effects half-done (again: transactions), and expiration depends on reasonably synchronized clocks.
9. The end-to-end argument
9.1 The careful file transfer
Saltzer, Reed and Clark ask a deceptively simple question: a file must move from host A’s disk to host B’s disk, through a network. Where should the check “it arrived intact” live? They list the threats: (1) A’s disk returns bad data; (2) software at A or B makes a mistake while buffering or copying; (3) hardware at A or B makes a transient error while doing so; (4) the network drops, changes or duplicates packets; (5) either host crashes part way through.
Making the network perfectly reliable addresses only threat (4). Threats (1), (2), (3) and (5) happen outside the network, at the ends or inside intermediate nodes. The only way to defeat all of them is for the application at B to compute a checksum of the file as written and compare it with A’s checksum of the original, retrying on a mismatch. And once that end-to-end check exists, per-hop reliability is no longer needed for correctness.
The paper’s “too-real example”: at MIT, a network of gateways checksummed each hop, and programmers assumed it was reliable; one gateway swapped a pair of bytes about once per million bytes while copying between buffers — after one hop’s checksum was verified and before the next was computed. Source files of an operating system were silently corrupted, and their owners had to compare them by hand against old listings.
9.2 The experiment, with real bytes
Demo 05_end_to_end.py moves a 25.6 KB file (100 packets of 256 random bytes) from A through gateways G1, G2 to B, 100 times per cell. Links may flip a byte; gateway G1 may swap a byte pair inside the node (once per 200 packets — far more often than MIT’s gateway, so the effect is visible in 100 transfers). Each hop can verify a CRC32 and retransmit; the endpoints can compare SHA-256 hashes and retry the whole file.
| scenario | strategy | silently corrupted | attempts per file | transmissions per file |
|---|---|---|---|---|
| noisy links (1%/packet/hop) | per-hop CRC + retransmit | 0 | 1.00 | 303 |
| end-to-end hash + retry | 0 | 20.49 | 6,147 | |
| both | 0 | 1.00 | 303 | |
| clean links, bad gateway | per-hop CRC + retransmit | 44 of 100 | 1.00 | 300 |
| end-to-end hash + retry | 0 | 1.86 | 558 | |
| both | 0 | 1.86 | 558 | |
| noisy links + bad gateway | per-hop CRC + retransmit | 36 of 100 | 1.00 | 303 |
| end-to-end hash + retry | 0 | 35.70 | 10,710 | |
| both | 0 | 1.47 | 445 |
- Per-hop reliability does not give correctness: with a faulty gateway, the “reliable network” accepted a corrupted file in 44 of 100 transfers — every hop’s CRC was correct.
- The end-to-end check gives correctness against everything on the path: zero silently corrupted files in every end-to-end cell.
- But per-hop reliability is a big performance win when links are noisy: end-to-end alone needed 20 whole-file attempts and 20× the transmissions. Part B computes the exact cost: with per-packet, per-hop corruption probability
poverhhops, an end-to-end-only attempt succeeds with probability(1−p)^{hn}, so the expected cost grows exponentially with the file lengthn:
| packets in file | P(an attempt is clean) | end-to-end only: E[transmissions] | with per-hop retransmission | ratio |
|---|---|---|---|---|
| 25 | 0.471 | 159 | 76 | 2.1 |
| 100 | 0.0490 | 6,120 | 303 | 20.2 |
| 200 | 0.0024 | 249,000 | 606 | 412 |
| 800 | 3.4 × 10⁻¹¹ | 7.2 × 10¹³ | 2,424 | 3.0 × 10¹⁰ |
This is exactly the paper’s §2.3: lower layers should provide some reliability — as a performance enhancement, not as a guarantee of correctness.
9.3 The argument, stated
A function can be implemented completely and correctly only with the knowledge and help of the application at the endpoints of the communication. Providing it as a feature of the communication system itself is not possible; an incomplete version may be useful as a performance enhancement.
The argument applies far beyond checksums — and you have already used it:
- Duplicate suppression: the network may suppress duplicate packets, but only the application knows that two requests are “the same withdrawal”. Our request ids and reply caches (§2–4) are end-to-end.
- Delivery acknowledgment: TCP’s ACK says the bytes reached the host’s kernel, not that the application acted on them. Only an application-level reply (“withdrawal done”) means the work was done.
- Encryption: per-link encryption leaves data in the clear inside every router and server it passes through; only end-to-end encryption protects it from them.
- Lecture 3’s 40% valid-but-wrong corruptions: no parser can catch them; an end-to-end checksum can.
The argument is not “never put functions in lower layers”; it is “know which layer can guarantee the property, and treat everything below as an optimization whose value is measured”.
10. A checklist for an RPC client and server (concepts)
Putting the lecture together, a careful RPC design answers each of these explicitly:
- Ids: does every call carry a unique (client, sequence) id? Are replies matched by id?
- Classification: which operations are idempotent in effect and reply? Which need deduplication?
- Duplicate table: in memory (plus epochs) or on stable storage? Updated atomically with the execution? Garbage-collected by acknowledgment, not by timeout?
- Timeouts: fixed or adaptive? What does the client do when it gives up — and what does it tell its caller (“failed” vs “unknown”)?
- Retries: bounded by a budget? With backoff and jitter? Do requests carry deadlines the server honours?
- Connections: after a timeout, is the connection reset or are stale replies discarded?
- Ordering: do concurrent calls from one client need to execute in order?
- Orphans: what happens to a call whose client died?
- End to end: what does the application verify at the ends (checksums, application-level acknowledgments)?
Project 1 asks you to make your own choices on several of these for remote file operations; these notes deliberately do not make them for you.
Summary
- Lost requests, lost replies and server crashes look the same to a client; the call semantics says what the RPC system promises anyway.
- maybe: 0 or 1 executions (or 2 if the network duplicates). At-least-once: retries; ≥ 1 execution (208/1000 double withdrawals at 20% loss). At-most-once: retries + request ids + a duplicate table + server epochs; never twice, but after a crash the client may learn only “outcome unknown” (478 runs; in 155 the money had moved). Exactly-once: the duplicate table on stable storage, atomic with the execution — exactly once in every run, if the server comes back.
- Idempotence must hold for the effect and the reply:
delete,createand compare-and-set kept the right state but answered wrongly on every retry (208/208). Make operations idempotent where possible; use client-chosen ids and a durable reply cache for the rest. - Forget duplicates by acknowledgment, not by time: a 50 ms TTL re-executed 38 late duplicates; per-client acks + watermark kept the table at 1 entry with no re-executions.
- Timeouts are guesses; adaptive ones (SRTT + 4·RTTVAR, Karn’s rule, backoff) track changing latency without knowing it in advance.
- Retries can sustain an overload after its cause is gone (a metastable failure): immediate retries never recovered from a 200 ms stall, and backoff alone did not either; retry budgets and server-side deadlines did.
- Per-call guarantees do not order concurrent calls (363/1000 reorderings); replies must be matched to requests by id (a late reply poisoned the next call on a real connection); orphans need extermination, reincarnation or expiration (leases).
- End-to-end argument: per-hop checks accepted corrupted files in 44/100 transfers through a faulty gateway; the end-to-end hash caught all of them; per-hop retransmission remains a performance optimization whose value grows exponentially with transfer size.
Common pitfalls
- Treating a timeout as a failure. It means “I stopped waiting”. The call may have run, may be running, or may run later.
- Retrying non-idempotent calls without request ids (at-least-once for
withdraw). - Checking only the effect for idempotence: retries of
delete/create/renamereturn misleading errors. - Keeping the duplicate table in RAM without epochs: a restarted server re-executes retries.
- Garbage-collecting the duplicate table by age: delayed duplicates arrive after their entry is gone.
- Immediate, unbounded retries against an overloaded server; trusting backoff alone to cap load.
- Assuming exactly-once implies ordering of concurrent calls.
- Reusing a connection after a timeout without discarding stale replies.
- Relying on the network for correctness (“TCP is reliable, so the file is fine”).
Exercises
-
Classify. For each operation, say whether its effect and its reply are idempotent: (a)
x = x * 2; (b)set price = 10; (c) send an email; (d)write 4 KB at offset 8192; (e)read the next 4 KB(server keeps the file position); (f)rename a b; (g)append(log, entry)where the server ignores entries whose unique entry-id it has seen.Answer
(a) Neither. (b) Both (effect and reply "ok") — but concurrent writers can still interleave. (c) Neither: a retry sends a second email. (d) Both: same bytes at the same place, same reply. (e) Neither: the retry reads the *following* 4 KB, because the server's position moved — which is why NFS passes offsets explicitly. (f) Effect yes if the retry finds `a` already gone and `b` present (nothing changes), but the reply on retry is "no such file a": not idempotent in its reply. (g) Both, if the reply for a duplicate is the same "ok": the dedup by entry-id makes a non-idempotent operation idempotent. -
“Outcome unknown”. Under at-most-once semantics a client calls
transfer(#17, $100)and receives “server restarted: outcome unknown”. What can it do? What must the server have recorded for that option to exist?Answer
Retrying blindly risks a double transfer; giving up risks a lost one. The safe option is to *ask*: "did transfer #17 happen?" — which works only if the server recorded, durably and atomically with the transfer itself, that #17 was executed (a client-chosen transfer id stored with the account update). In other words, to resolve the ambiguity the application needs exactly the durable record that exactly-once semantics would have kept. -
Sizing the duplicate table. A server has 10,000 clients, each making 100 calls per second, with 1 KB replies. Estimate the table size (a) with acknowledgment-based GC and sequential clients, (b) with a 60-second TTL.
Answer
(a) At most one unacknowledged call per sequential client: ~10,000 entries × 1 KB ≈ 10 MB, plus one watermark integer per client. (b) Every reply of the last 60 s: 10,000 × 100 × 60 = 6×10⁷ entries ≈ 60 GB — and still unsafe for duplicates delayed more than 60 s. -
Run the estimator. Start with SRTT = 10 ms and RTTVAR = 5 ms (RTO = 30 ms). Apply the update of §5.2 for samples 10, 12, 30 and 11 ms. What is the RTO after each? What happens to RTO when the 30 ms sample arrives, and why is that desirable?
Answer
After 10: SRTT 10.0, RTTVAR 3.75, RTO 25.0. After 12: SRTT 10.25, RTTVAR 3.31, RTO 23.5. After 30: SRTT 12.72, RTTVAR 7.42, RTO 42.4. After 11: SRTT 12.50, RTTVAR 6.00, RTO 36.5. The outlier moves SRTT only a little (weight 1/8) but RTTVAR a lot (weight 1/4 on a large deviation), so the RTO jumps — the estimator becomes more patient as soon as latency becomes *variable*, which is exactly when a fixed timeout starts to cry wolf. -
Storm arithmetic. Clients send 700 requests/s to a server that can do 1,000/s. During an overload every attempt times out, and clients retry up to 4 more times. (a) What load do they offer? (b) With a 10% retry budget? (c) Why can’t backoff alone bring (a) under 1,000/s while every attempt times out?
Answer
(a) Up to 5 × 700 = 3,500 requests/s — 3.5× capacity, so the queue keeps growing and every attempt keeps timing out (self-sustaining). (b) At most 700 × 1.1 = 770/s < 1,000/s, so the queue drains and timeouts stop. (c) Backoff changes *when* the 5 attempts are sent, not *how many*: over any long interval each request still contributes 5 sends while the timeouts persist. It helps against brief synchronized bursts, not against sustained overload. -
End-to-end confidentiality. A messaging service uses TLS from the phone to its server and from its server to the recipient’s phone. Is the message confidential end to end? Use §9.3.
Answer
No. TLS protects each hop, but the message is decrypted and re-encrypted at the server, which (and anyone who compromises it) can read it — the same structure as per-hop checksums with a faulty gateway. Only encryption performed by the sending application and removed only by the receiving application ("end-to-end encryption") protects against the intermediate node. -
Saltzer’s exponential, by hand. A 10,000-packet file crosses 3 hops whose links corrupt a packet with probability 0.001. (a) What is the probability that an attempt with no per-hop recovery arrives clean? (b) Expected transmissions with per-hop retransmission?
Answer
(a) (1 − 0.001)^30,000 ≈ e^−30 ≈ 9×10⁻¹⁴: an end-to-end-only transfer would essentially never finish. (b) 30,000 / 0.999 ≈ 30,030 transmissions. This is why a real network corrects most errors per hop and the application still checks end to end. -
Ordered asynchronous calls. Design a client library that lets one thread issue many asynchronous calls to one server, but guarantees the server executes them in issue order despite loss and retries.
Answer
Number the calls 1, 2, 3, … per client; the server executes call k only after k−1 (holding back early arrivals in a queue keyed by sequence number) and keeps the per-client watermark and reply cache of §4 to suppress duplicates. Replies carry the sequence number so the client can match them (§7.2). This is TCP's ordered-delivery mechanism lifted to whole calls; its cost is head-of-line blocking — a lost call k delays every later call until its retry arrives.
Related project and problem set (concepts only)
- Project 1: your interposed
open,read,write,close,lseek,stat,unlink,getdirentriesandgetdirtreestubs must behave sensibly when the server or the network misbehaves. Which of them are idempotent (§3), what a timeout should mean for a file operation (§5), and whether your server needs to remember anything (§4) are design questions for you; this lecture gives the vocabulary, not the answers. - Problem Set 1 includes an exactly-once scenario and an end-to-end latency analysis of a multi-tier service; §2 and §9, plus Lecture 2’s tail-latency section, are the background.
Further reading
- J. H. Saltzer, D. P. Reed, D. D. Clark, “End-to-End Arguments in System Design”, ACM TOCS 2(4), 1984 (course reading).
- A. D. Birrell and B. J. Nelson, “Implementing Remote Procedure Calls”, ACM TOCS 2(1), 1984 — call semantics, call ids, exceptions on server crash.
- A. S. Tanenbaum and M. van Steen, Distributed Systems, 3rd ed., §8.3 (reliable client–server communication: the five failure classes, orphans).
- V. Jacobson, “Congestion Avoidance and Control”, SIGCOMM 1988; V. Paxson et al., “Computing TCP’s Retransmission Timer”, RFC 6298, 2011.
- C. Juszczak, “Improving the Performance and Correctness of an NFS Server”, USENIX Winter 1989 — the duplicate request cache.
- N. Bronson, A. Aghayev, A. Charapko, T. Zhu, “Metastable Failures in Distributed Systems”, HotOS 2021.
Preview of Lecture 5 — Distributed file systems and naming
With RPC and its failure semantics in hand, we can build the first big distributed system of the course: a file system shared by thousands of users. We compare two designs that made opposite choices. NFS keeps the server stateless, so it can use idempotent operations and at-least-once RPC, and pays with weak consistency and constant traffic. AFS (the Andrew File System, built at CMU and still serving /afs) caches whole files on clients and keeps state at the server — callbacks — to scale to thousands of users. We will also look at naming (how /afs/cs.cmu.edu/... finds its server) and at interposition, the technique that lets unmodified programs use a remote file system — the heart of Project 1.
术语表 (Glossary, English → 中文)
| English | 中文 |
|---|---|
| call semantics | 调用语义 |
| maybe semantics | “也许”语义(至多尝试一次) |
| at-least-once / at-most-once / exactly-once | 至少一次 / 至多一次 / 恰好一次 |
| effectively-once | 实际上的恰好一次(去重后的至少一次) |
| request id / sequence number | 请求标识 / 序列号 |
| duplicate table / reply cache | 重复请求表 / 应答缓存 |
| duplicate request cache (NFS) | 重复请求缓存 |
| duplicate suppression / deduplication | 重复抑制 / 去重 |
| epoch / incarnation number | 纪元 / 化身号(重启编号) |
| stable storage | 稳定存储 |
| atomicity | 原子性 |
| idempotent / idempotence | 幂等的 / 幂等性 |
| idempotency key | 幂等键 |
| compare-and-set (CAS) | 比较并设置 |
| versioned write | 带版本号的写 |
| garbage collection | 垃圾回收 |
| time-to-live (TTL) | 生存时间 |
| acknowledgment / watermark | 确认 / 水位线 |
| retransmission timeout (RTO) | 重传超时 |
| smoothed RTT (SRTT) / RTT variance (RTTVAR) | 平滑往返时间 / 往返时间偏差 |
| Karn’s rule | Karn 规则 |
| exponential backoff / jitter | 指数退避 / 随机抖动 |
| false alarm (false positive) | 误报 |
| failure detector | 故障检测器 |
| retry storm | 重试风暴 |
| metastable failure | 亚稳态故障 |
| retry budget | 重试预算 |
| deadline (propagation) | 截止时间(传递) |
| load shedding / circuit breaker | 负载削减 / 熔断器 |
| hold-back queue | 暂存队列 |
| head-of-line blocking | 队头阻塞 |
| stale reply | 过期应答 |
| orphan computation | 孤儿计算 |
| extermination / reincarnation / expiration | 灭绝 / 转世 / 过期(孤儿处理策略) |
| lease | 租约 |
| end-to-end argument | 端到端原则 |
| careful file transfer | 谨慎文件传输 |
| per-hop (hop-by-hop) check | 逐跳校验 |
| CRC (cyclic redundancy check) / hash | 循环冗余校验 / 哈希 |
| end-to-end encryption | 端到端加密 |
| performance enhancement | 性能增强 |