Distributed systems fundamentals
Introducido
7:25
Redes de computadoras
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…
Narración en inglés · subtítulos en inglés y 中文 que puedes cambiar
En esta lección
| English | Significado |
|---|---|
| distributed system/ˈdɪstrɪbjuːtɪd ˈsɪstəm/ | sistema distribuido |
| partial failure/ˈpɑːʃl ˈfeɪlɪə/ | fallo parcial |
| 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 |
Física de la cooperación
- Un sistema distribuido comparte estado entre máquinas con fallas parciales: la caída de una máquina no debe corromper el resto. Los mensajes pueden reordenarse y duplicarse; la idempotencia hace segura la reejecución.
- Un tiempo de espera no significa fallo — significa incertidumbre: el tercer resultado que todo protocolo debe manejar.


A timeout means —
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
The third outcome: the request may or may not have landed - retry idempotently.
When a request times out, the remote machine has crashed.
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
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.
Los relojes no pueden ordenar
- Los relojes de dos máquinas pueden desviarse sin límite, por lo que las marcas temporales no pueden ordenar con seguridad eventos entre máquinas. El reloj de Lamport respeta la causalidad: el envío adjunta $C+1$; la recepción establece $C = \max(C, \text{received}) + 1$.
- P0 envía $m_1$ en $C = 1$; P1 recibe en $C = 2$; P1 envía $m_2$ en $3$; P0 recibe en $4$. Si $a$ ocurre antes que $b$ entonces $C(a) < C(b)$ — en una sola dirección.
P1 sends at C = 3 to P0 at C = 1: on receive, P0 becomes —
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
C = max(1, 3) + 1 = 4.
Idempotencia por diseño
deduct(user, 25, id=xyz)ejecutado dos veces debe deducir una vez: la operación es idempotente por clave — el libro mayor registraxyzcomo realizado y el reintentar es un sin efecto.- Los sistemas seguros contra reintertos se construyen con operaciones idempotentes más un registro de duplicados eliminados, no confiando en que la red deje de duplicar.
deduct(user, 25, id=xyz) twice deducts once because —
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
Idempotent by key: the retry is a no-op against the dedupe ledger.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
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?
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
Need W + R > N: 4 + R > 7, so R = 4.
A majority quorum runs on 5 nodes. How many crashed nodes can it tolerate?
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
A majority of 5 is 3, so up to 2 nodes can be down.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
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:
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
It promised to obey the decision, so it cannot decide alone.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
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?
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
$5 - 4 = 1$.
$N = 5$ with $W = R = 2$ guarantees that every read sees the latest write.
Dificultad 1/5 · 100 monedas + un pequeño bono en el primer intento de hoy
$W + R = 4$ is not more than $N$, so the two sets need not overlap.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
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.
Esta tarjeta es nueva, por eso aparece en inglés hasta que su traducción esté lista.
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 |
¿Qué salió mal? Solo el equipo del sitio ve esta información.