skip to content

You're designing a multi-region e-commerce platform and need to decide where different features - shopping cart, inventory count, order history - sit on the consistency spectrum from linearizable down to eventual. Walk through how you'd choose, and name a real system that lets you tune this per operation.

level: principalimportance: should knowfreq 60%

answer

  1. map each operation to the weakest model that avoids a real business bug
  2. Cosmos DB's five named levels: strong/bounded-staleness/session/consistent-prefix/eventual
  3. session level = read-your-writes within a session
  4. per-request tuning: DynamoDB ConsistentRead flag, Cassandra CL
  5. mixing models across related features can create new subtle bugs

basics

~20 s

Different parts of an app need different guarantees - showing 'item in stock' can be a little stale, but charging a card exactly once needs strong guarantees. Good systems let you pick the guarantee per operation instead of one setting for everything.

solid answer

~50 s

The right approach is to map each operation to the weakest consistency model that still avoids a real business problem, since stronger guarantees cost latency and availability. Shopping cart adds/removes are user-scoped and low-conflict, so read-your-writes is usually enough - the shopper must see their own cart update immediately, but global ordering doesn't matter. Inventory counts used for 'in stock' badges can tolerate eventual consistency since occasional staleness is a recoverable display issue, while the actual stock decrement during checkout needs a strong guarantee, such as a linearizable conditional write, to prevent overselling past zero. Order history can be causally consistent - an order confirmation must appear after its payment event, but unrelated orders from different users need no ordering. Real systems support this per-operation tuning: Azure Cosmos DB offers five named levels, an account default that a request can override for its reads; DynamoDB lets you choose eventually-consistent or strongly-consistent reads per request; Cassandra lets you set a read/write consistency level per query.

go deeper

for a junior

Not expected to design this; can informally guess which parts need to be 'more careful,' like checkout versus a view count.

for a middle

Should recognize different features have different needs and name at least one weaker model appropriate for a low-stakes feature.

for a senior

Should map specific operations to specific models with reasoning and know at least one real system offering tunable consistency.

for a principal

Should reason about the organizational and operational cost of mixing models across features, pick concrete mechanisms per operation, accurately reference a named system's actual consistency-level offerings, and weigh the cost of defaulting to the strongest level everywhere.

## The method The practical skill is not picking a single consistency model for an entire application but mapping each distinct operation or feature to the weakest model on the spectrum, linearizable down through sequential, causal, client-centric, and eventual, that still avoids a genuine business-level correctness problem. Every step up the spectrum toward stronger guarantees costs latency, throughput, or availability, while every step down risks a visible or silent correctness bug if chosen carelessly. ## Mapping the features of one platform Concretely, consider an e-commerce platform's three example features. - **Shopping cart.** A shopping cart's add and remove operations are naturally scoped to a single user and low-conflict, since nobody else is editing your cart, so a client-centric guarantee, read-your-writes so the shopper always sees their own edit immediately, plus monotonic reads so the cart never appears to go backward, is exactly enough; there is no need for global ordering across all shoppers' carts. - **The stock badge.** An 'X items in stock' badge shown to browsing shoppers is a display-only, informational field where a few seconds of staleness has essentially no cost, making eventual consistency a fine, cheap fit. - **The inventory decrement.** The actual inventory decrement that happens at checkout is different in kind: allowing two concurrent checkouts to both succeed past a stock count of zero is a real, costly business failure, oversold inventory, refunds, damaged trust, so that specific write needs a strong guarantee, typically a linearizable conditional write or a quorum-based conditional write, even while the rest of the catalog stays on cheaper models. - **Order history.** Order history sits in between: an order confirmation must always appear after the payment event it depends on, a causal relationship, but two different customers' unrelated orders need no relative ordering between them, making causal consistency the natural fit. ## The per-operation knob Several real systems expose this as an explicit, per-operation knob rather than forcing an all-or-nothing choice. **Azure Cosmos DB** offers five named consistency levels. | Level | What it gives you | |---|---| | **strong** | or linearizable | | **bounded staleness** | reads lag writes by a bounded time or operation count | | **session** | within one client session, reads honor read-your-writes, monotonic reads and write-follows-reads, tracked by a session token the client carries; it is the default level | | **consistent prefix** | single-document writes are eventually consistent, while writes committed together in one transaction are always seen together, never in part | | **eventual** | no ordering guarantee beyond convergence | The level is set as the account's default, which applies to every database and container under it, and a client can override it for its reads, on a single request or a client instance. - **Amazon DynamoDB** offers a simpler two-way version of the same idea: a per-request 'ConsistentRead' boolean lets a caller pay for a strongly consistent read exactly when it needs one, defaulting to cheaper eventually consistent reads otherwise. - **Apache Cassandra** exposes a tunable consistency level per query, ONE, QUORUM, ALL, and others, letting a team dial the number of replicas that must acknowledge a read or write independently for every single query in the codebase. ## What mixing models costs The trade-off of this per-operation approach is organizational and cognitive, not just technical: mixing consistency levels across features that reference each other creates new subtle failure surfaces that don't exist in a single-model system. In the inventory example, the badge and the checkout decrement can legitimately disagree at any instant, the badge might say '5 left' the moment checkout is failing the sixth concurrent buyer, and that's not a bug, but it is something every engineer touching that code needs to understand, or they'll wrongly treat the badge number as authoritative for a business decision it was never meant to support. Teams adopting tunable consistency take on a real documentation and testing burden: - every field or operation needs an explicit answer to which consistency level it uses and why; - test suites need to exercise the actual staleness or reordering windows the weaker levels permit, not just the happy path. ## Getting it wrong, in both directions Getting this wrong fails in both directions. - **Too weak.** Choosing too weak a model for a correctness-critical path is the more damaging mistake: an inventory decrement left on a weaker level than checkout requires lets two concurrent checkouts both see the last unit as available and both succeed, overselling stock that then has to be refunded. - **Too strong.** The less-discussed but also real mistake is choosing too strong a model everywhere out of caution: forcing every read of a read-heavy, geo-distributed product catalog through a single linearizable leader adds unnecessary cross-region latency to the vast majority of traffic that never needed the guarantee, directly hurting tail latency and, ultimately, availability during any partition or leader failover, a cost paid continuously for a correctness guarantee only a small fraction of operations actually required.

  • What does a cloud database's 'session' consistency level guarantee, and why would it make a sensible default?
    Scoped by a token the client carries with each request, a session level makes the client's reads reflect its own writes, and a product may add other session guarantees such as write-follows-reads, all without coordinating across every client. It suits a default because much application code acts for one signed-in user, whose own edits must not vanish, while its cost can stay close to eventual consistency's.
  • What's the risk of mixing consistency levels across features that reference each other, like an eventually-consistent inventory badge feeding into a linearizable checkout decrement?
    The two can disagree: checkout correctly prevents overselling because the decrement itself is coordinated, but the badge shown to the shopper may say stock remains while checkout simultaneously fails, creating a confusing but not incorrect UX gap. Teams need to explicitly document which reads are authoritative for decisions versus purely informational, so engineers don't assume a display number is safe to use for a business decision.
  • Why can't the inventory decrement during checkout just use eventual consistency like the display badge does?
    Overselling, accepting more orders than physical stock, is a correctness violation with real cost: refunds, damaged trust, manual reconciliation. The decrement path needs a guarantee strong enough to prevent two concurrent checkouts from both succeeding past zero stock, typically a linearizable counter, a quorum-based conditional write, or a serialized queue for that specific key, even if the rest of the catalog stays eventually consistent.

Like choosing shipping speed per package rather than paying for overnight shipping on everything or slow-boat on everything - urgent items get expedited, strong guarantees, low-stakes items go standard, eventual.

  • picks one consistency model for the entire system without discussing per-operation trade-offs
  • doesn't recognize that inventory display and inventory decrement need different guarantees
  • can't name a real system that offers tunable, per-request consistency levels
  • assumes stronger consistency has no operational cost, so 'just use strong everywhere' is presented as a free win

context