Skip to content
Ameen Abozaid
MID-030

Distributed consistency

  • 5 Lessons
  • 2 h practice (estimate)
On this page 8 topics

Overview

Topics

  • Strong vs eventual consistency
  • CAP and PACELC
  • consistency trade-offs

Learn first

2 h of practice (estimate)

Learning outcomes

  1. Distinguish strong, eventual, causal, and read-your-writes consistency with examples.
  2. Explain CAP and PACELC accurately, including what they do not say.
  3. Choose a consistency level per use case and design the user experience for eventual consistency.

Lessons

  1. 01Consistency models
  2. 02CAP, correctly
  3. 03PACELC
  4. 04Designing for eventual consistency
  5. 05Demo: read-your-writes across services

Lab and exercises

Lab

MID-030-LAB1 · Consistency budget

Outcomes: 1–3 · Time: ~2 h List every Shop operation (browse catalog, search, add to cart, place order, pay, reserve stock, order history, admin price change, stock display). For each, specify the required consistency model, acceptable staleness, and how the UI behaves during lag (for example "order pending"). Get the table reviewed and apply it to the API: status fields, 202 responses, and read paths.

Acceptance: reviewed table applied to the API; each row maps to a concrete endpoint behavior.

Exercises (assessment: scenario quiz)

IDOutcomeTask
MID-030-EX011Give one Shop example each for strong, eventual, causal, and read-your-writes consistency.
MID-030-EX021A user changes their address and sees the old one on refresh. Name the missing guarantee and two ways to provide it.
MID-030-EX032A colleague says "Kafka is AP, so we have no consistency problems to design for." Correct the statement.
MID-030-EX042Explain PACELC in four sentences using sync vs async replication.
MID-030-EX053Choose the consistency level for: last-item stock reservation, product reviews count, payment status. Justify each.
MID-030-EX063Redesign "place order" so the UI is honest about asynchronous steps: statuses and endpoints.
Show solutions
  • EX01 Strong: reserving the last unit. Eventual: view counters. Causal: a review reply after its review. Read-your-writes: my order list after checkout.
  • EX02 Read-your-writes. Return the updated resource in the write response; read from the primary right after a write; wait for a version.
  • EX03 AP/CP describes behavior during a partition for a specific operation and configuration; consumers still see lag, duplicates, and reordering, so consistency must be designed per use case.
  • EX04 During a partition choose availability or consistency. Otherwise choose latency or consistency. Sync replication waits for replicas: consistent, slower. Async replication returns early: faster, stale reads possible.
  • EX05 Stock: strong (one owner, transactional decrement). Review count: eventual. Payment status: strong at the payment service, shown to users as eventual with explicit states.
  • EX06 POST /orders returns 202 and Location; statuses PENDING, CONFIRMED, REJECTED; GET /orders/{id} shows status; UI polls or subscribes.

Outcome 2 is also covered by quiz Q04 to Q07; the lab covers outcome 3 at API level.

Quiz

Outcomes: O1 consistency models · O2 CAP and PACELC · O3 choosing and designing.

A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.

  1. 1Every read sees the latest completed write. This is:O1
  2. 2A reply must never appear before its question. The needed model is:O1
  3. 3After you post a comment you cannot see it, but others can. Missing:O1
  4. 4CAP's trade-off applies:O2
  5. 5The "C" in CAP means:O2
  6. 6PACELC adds, for normal operation, a trade-off between:O2
  7. 7"Our whole system is AP" is:O2
  8. 8Best model for decrementing the last unit of stock:O3
  9. 9Best response for an order finishing asynchronously:O3
  10. 10Which hides eventual consistency badly?O3

Practical part

Six exercises MID-030-EX01 to EX06 plus the consistency-budget lab. Pass: at least five exercises, 8 of 10 quiz answers, and a reviewed table applied to the API.

Common mistakes

"we chose AP" as a system-wide statement; hiding eventual consistency from users.

Assessment

Scenario quiz.

Career relevance

Distributed data (SRB-003).

Type to search levels, phases, modules and lessons.