Lesson 11 of 17
16. Consistency and CAP

16.10 How do you choose consistency for each feature?

3 min read+10 XP

At the bank: The bank doesn't use one rule for everything. Withdrawals: phone first, always. Updating the newsletter address: whenever. Showing the customer their own last deposit: make sure they see it.

In the system: Choose consistency per feature, not per company. For each one, ask: what does a stale answer cost, and what does no answer cost?

features of one app placed from strong to eventual consistency.

Figure: one app, different consistency for each feature.

For the bookstore:

  • Gift-card balance, payment, seat or stock at checkout: strong. A stale balance means spending money twice (the Level 4 bug: two ₹400 purchases from a ₹500 card during a partition). Route these to a single leader or a consensus-backed store, and accept occasional errors during failures.
  • Unique username or email: strong (or a single place that owns the check; Chapter 15, section 15.7).
  • "My cart", "my orders", my profile: read-your-writes. The user must see their own changes; others can lag.
  • Comments and replies: causal. Replies never before the comment they answer.
  • Likes, view counts, trending lists, recommendations: eventual. Fast and always available; a few seconds behind is fine.

A useful pattern: eventual for display, strong for the decision. Show an eventually consistent "only 3 left" on the product page, and do the strongly consistent stock check at checkout (Chapter 12, section 12.9).

Memory code: "Price the stale answer and the missing answer; pick per feature."