Distributed systems fundamentals
도입됨
7:25
컴퓨터 네트워크
A network carries your bytes across a planet of machines that owe each other nothing. The first three units move a frame: layering, the link layer with IP, and…
영어 내레이션 · 영어와 중국어 자막 전환 가능
이 수업의 내용
| English | 의미 |
|---|---|
| distributed system/ˈdɪstrɪbjuːtɪd ˈsɪstəm/ | 분산 시스템 |
| partial failure/ˈpɑːʃl ˈfeɪlɪə/ | 부분 고장 |
| idempotence/ˈaɪdmpəʊtəns/ | doing an operation twice has the same effect as doing it once |
| Lamport clock/ˈlæmpɔːt klɒk/ | a counter that orders events in a distributed system so causes come before effects |
| happens before/ˈhæpənz bɪˈfɔː/ | the order relation in which one event could have caused another |
| idempotent operations | |
| replicas/ˈreplɪkəz/ | copies of the same data kept on different machines |
| quorum/ˈkwɔːrəm/ | the number of replicas that must agree for a read or write to succeed |
| partitions/pɑːˈtɪʃnz/ | (network) breaks that split a distributed system into groups that cannot reach each other |
| two-phase commit/tuː feɪz kəˈmɪt/ | a protocol that commits a distributed transaction only if every participant votes yes, and aborts it otherwise |
| version ordering |
Working together across machines
- A distributed system 分布式系统 shares state across machines and must live with partial failure 部分故障: one machine crashing must not damage the rest. Messages arrive out of order or twice, and idempotence 幂等性 makes running an operation again safe.
- A timeout does not mean "failed". It means "unknown": a third outcome that every protocol must handle.

A timeout means —
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
The third outcome: the request may or may not have landed - retry idempotently.
When a request times out, the remote machine has crashed.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
A timeout means unknown: the request, the reply or the machine may be lost or just slow. That is why retried operations must be idempotent.
Clocks cannot order events
- The clocks of two machines drift apart without limit, so timestamps cannot safely order events on different machines. The Lamport clock 兰波特时钟 follows cause and effect: a send attaches $C+1$; a receive sets $C = \max(C, \text{received}) + 1$.
- P0 sends $m_1$ at $C = 1$; P1 receives it at $C = 2$; P1 sends $m_2$ at $3$; P0 receives it at $4$. If $a$ happens before 先于发生 $b$, then $C(a) < C(b)$. This works in one direction only.
P1 sends at C = 3 to P0 at C = 1: on receive, P0 becomes —
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
C = max(1, 3) + 1 = 4.
Idempotence by design
deduct(user, 25, id=xyz)run twice must deduct only once. The operation is idempotent by its key: the ledger recordsxyzas done, and the retry does nothing.- Systems that are safe to retry are built from idempotent operations 幂等操作 plus a ledger that removes duplicates, not from hoping the network stops sending things twice.
deduct(user, 25, id=xyz) twice deducts once because —
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Idempotent by key: the retry is a no-op against the dedupe ledger.
Replicas and quorums
- Keep $N$ copies (replicas 副本). A write waits for $W$ acknowledgements and a read asks $R$ replicas. If $W + R > N$, every read overlaps the latest write (a quorum 法定数). With $N = 5$, $W = R = 3$ works, and a majority still answers with $2$ nodes down.
- When the network partitions 分区, a system must choose: refuse some requests to stay consistent, or answer everyone and risk old data. That is the CAP trade-off, and it applies only during a partition.
A store keeps N = 7 replicas and writes to W = 4. What is the smallest R that guarantees a read quorum overlaps a completed write quorum?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Need W + R > N: 4 + R > 7, so R = 4.
A majority quorum runs on 5 nodes. How many crashed nodes can it tolerate?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
A majority of 5 is 3, so up to 2 nodes can be down.
All commit or none
- In two-phase commit 两阶段提交, the coordinator asks every participant "can you commit?" and commits only if all vote yes; one "no" aborts everyone.
- A participant that voted yes must wait for the decision. If the coordinator crashes at that moment, the participant is blocked, holding its locks, until the coordinator comes back.
In two-phase commit, a participant voted yes and the coordinator crashed. The participant:
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
It promised to obey the decision, so it cannot decide alone.
Worked example: choosing W and R
- With $N = 5$, $W = 4$ and $R = 2$: $W + R = 6 > 5$, so a read overlaps each completed write. With suitable version ordering 版本排序 and read resolution, it can return the latest completed write. Reads survive 3 failed nodes, but writes fail once 2 are down.
- $W = R = 3$ balances the two and tolerates 2 failures for both. $W = R = 2$ is faster, but $4 \le 5$, so a read can miss the newest write.
$N = 5$, $W = 4$: the most nodes that can be down while writes still succeed?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
$5 - 4 = 1$.
$N = 5$ with $W = R = 2$ guarantees that every read sees the latest write.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
$W + R = 4$ is not more than $N$, so the two sets need not overlap.
Marks that slip away
- Ordering events by wall clock. Clocks drift without limit; Lamport timestamps follow cause and effect instead.
- Retrying a call that is not idempotent. A retried
deductwithout an id charges twice. Record the id and skip duplicates. - Reading $C(a) < C(b)$ as "$a$ happened before $b$". Lamport clocks 兰波特时钟 guarantee only the other direction.
Recap
- Partial failure 部分故障 is normal; a timeout means unknown, not failed.
- Lamport clocks: send $C + 1$; receive $\max(C, \text{received}) + 1$; happens-before implies a smaller clock.
- Idempotent operations plus a ledger that removes duplicates make retries safe.
- Quorums with $N = 5$ replicas, and how many nodes can be down while each still works:
| W, R | Reads see latest? | Writes | Reads |
|---|---|---|---|
| 4, 2 | yes | 1 | 3 |
| 3, 3 | yes | 2 | 2 |
| 2, 2 | no | 3 | 3 |
어떤 문제가 있었나요? 사이트 팀만 이 내용을 볼 수 있습니다.