Distributed Systems Visualizations

Distributed systems run into different questions as soon as one machine is no longer enough. Where should each key live? Can retrying a message repeat a write? Can several resources apply one transaction together? Can several replicas preserve one log through failures? Consistent hashing, message queues, transactional outbox, two-phase commit, and Raft answer those questions. Their diagrams may all contain nodes and messages, but their guarantees are not interchangeable.

A cache ring needs placement that stays mostly stable when capacity changes. A background job needs safe retries when completion is uncertain. A bank transfer needs A, B, and its audit log to change together or not at all. A replicated control plane needs one committed history even when messages arrive late or the network splits. Start by naming the job; then choose the mechanism.

Compare the lessons

LessonMain questionDeciding ruleFailure boundary
Consistent HashingWhich physical node owns a key when membership changes?first active token clockwise from the fixed key tokenonly one adjacent interval should change owner; balance is improved, not guaranteed
Cache-Aside & Cache ConsistencyCan a cache hit be stale after a successful write?load on miss; commit DB, then invalidatean old in-flight read can refill after deletion; TTL starts at fill
Message Queues & RedeliveryCan a retry repeat a committed business write?retain work until ACK; atomically deduplicate the business effectmissing ACK leaves the effect uncertain; another worker can receive the same message
Transactional OutboxHow can a committed change retain its outgoing event?commit business state and event together, then publish with a relaypublication can repeat after a crash; consumers still need idempotency
Two-Phase CommitWhen may A, B, and the log all change?every participant votes YES, then all receive the same decisionone NO aborts everyone; a crashed coordinator can leave prepared locks held
Raft ConsensusWhen may a log entry become committed history?a majority elects the leader and stores its current-term entrya minority may store an entry but cannot commit it

The most common category error is to borrow a rule from the wrong row. Raft's three-of-five majority cannot make a three-resource transaction atomic. Two-phase commit's unanimity would make two delayed replicas freeze a five-server log. Consistent hashing decides placement; it does not replicate data or settle conflicting writes.

A Recommended Order

Start with Consistent Hashing on Node joins. Follow K11 across token zero, then watch N4@220 claim (140, 220]. K5, K6, and K7 change owner; nine keys do not. Switch to Node leaves to see one departed interval transfer to its clockwise successor. Finish on Virtual nodes and compare the fixed-key loads 3/2/7 -> 4/5/3.

Next, run Cache-Aside & Cache Consistency. Follow R1's held v1 while W commits v2 and deletes the key. R2 starts after W completes but hits the late v1 fill. Change only the schedule to One request at a time, then inspect TTL expiry and the separate recovery read.

Next, run Message Queues & Redelivery with ACK lost. Follow the same M1 through two deliveries and two increments. Change only the consumer rule to Deduplicate atomically: the deliveries stay at two while the counter ends at one.

Then run Transactional Outbox with its relay-crash default. The order and pending event commit together. Follow E1 through two publications and one reservation. Compare Dual-write gap with Recover the send intent to isolate the source-side crash window.

Continue with Two-Phase Commit on All yes → commit. Pause at two YES votes, at the coordinator's COMMIT decision, and at the blocking window where P1 is still PREPARED and A is still 100. Load One no → abort to watch a YES voter roll back, then Coordinator crash to leave the locks visibly held.

Finish with Raft Consensus on Election + commit. Three votes make a leader; three stored copies make a current-term entry committable. Then run Minority partition. The two-server side can store set y=7 and still stall at 2 / 5, while the three-server side elects a higher-term leader and commits a different entry at the same index.

That order moves from placement, to retry semantics, to durable publishing intent, to atomic coordination, to replicated agreement. It also makes the vocabulary harder to blur: an owner is not a participant, a prepared value is not a committed log entry, and a hash-ring token is not a quorum vote.

What to Watch

  • In consistent hashing, key dots never move when membership changes. Only their clockwise successor may change.
  • A virtual node is another token position for the same physical machine, not another machine.
  • In cache-aside, deleting a key does not delete a reader-held snapshot. HIT and freshness are separate facts.
  • In message queues, count deliveries separately from committed effects. The same M1 can arrive twice.
  • In 2PC, a purple proposed value is locked but not applied. Two YES votes never cross need ALL YES.
  • In Raft, two stored copies never cross majority = 3. Storage and commitment are separate beats.
  • A coordinator crash can block prepared 2PC participants. A Raft partition blocks only the side without a majority.
  • None of these lessons supplies all the guarantees of the others. Real systems often combine them—for example, a hash ring for placement and Raft inside each shard for replication.

Pick a lesson below and keep your eye on its deciding evidence: the clockwise successor, the durable message ID, the unanimous vote, or the overlapping majority.