software-engineer-blog logoSoftware Engineer Blog

Module 8 · Distributed systems

Unit 31 of 49

Unit 31 · Module 8 · Distributed systems

Consensus and CAP

Agreeing on one value across machines — the hardest thing in the field.

Unit 31 of the free 49-unit computer-science course, in distributed systems. 3 interview questions answered in full and a short self-check.

Nothing published yet

This unit is part of the course map but has no episode or article of its own yet. The units around it do — see what is already published.

Interview questions this unit unlocks

Asked out loud, answered out loud. Read the answer, then say it in your own words.

State the CAP theorem, and say what it does not mean.

When the network partitions, you must choose between consistency and availability — either refuse requests you cannot serve correctly, or serve them and accept divergence. What it does not mean is "pick two of three": partitions are not something you opt out of, they are something the network does to you. Outside a partition you can have both C and A, and the interesting trade-off there is consistency against latency.

PACELC is the sentence that completes it: else — in the normal case — you are trading latency against consistency, and that is the trade you live with every day.

What problem does a consensus algorithm solve?

Getting a set of machines to agree on one value, or one ordering of values, when messages can be delayed or lost and machines can crash. Raft and Paxos do it by electing a leader and having it replicate an append-only log; an entry is committed once a majority has it, which is why clusters are odd-sized — a majority of five survives two failures. Consensus is how you get a single source of truth without a single machine.

What does eventual consistency actually promise?

That if writes stop, all replicas converge on the same value. It promises nothing about when, and nothing about what any individual reader sees in the meantime — including reading their own write back as the old value. It is the right model for a like count and the wrong one for a bank balance, and the useful question is always which of your data can tolerate being briefly wrong.

Self-check — 3 questions

Answer alone, at 2am, with no interviewer in the room.

Part of Everything You Need to Know About Computer Science.