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 + monotonic reads bundled
  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, often linearizable or quorum-based guarantee 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 exposes five named consistency levels selectable per container or request; 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, and accurately reference a named system's actual consistency-level offerings.

## The method Real production systems rarely pick a single consistency model for an entire application; the practical skill is 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 counter, 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 Real systems increasingly expose this as an explicit, per-operation knob rather than forcing an all-or-nothing choice. **Azure Cosmos DB** is the most explicit industry example: it offers five named, selectable consistency levels. | Level | What it gives you | |---|---| | **strong** | or linearizable | | **bounded staleness** | reads lag writes by a bounded time or operation count | | **session** | bundles read-your-writes and monotonic reads scoped to a client-held session token and is the default level because it fixes the most common perceived-bug complaints cheaply | | **consistent prefix** | reads never see writes out of the order they were originally written though gaps are allowed | | **eventual** | no ordering guarantee beyond convergence | All five are configurable per container or overridable per individual request. - **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 The most common production failure mode from getting this wrong runs in both directions. - **Too weak.** Choosing too weak a model for a correctness-critical path is the classic and most damaging mistake, flash-sale overselling incidents, where an inventory decrement was accidentally left on a weaker consistency level than checkout actually required, are a recurring real-world pattern across e-commerce platforms. - **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.

  • Why is a cloud database's 'session' consistency level typically described as combining read-your-writes and monotonic reads, and why would that be the default?
    Session consistency scopes client-centric guarantees to a session token carried with each request - within that session the client always sees its own writes and never observes an older value after a newer one, without requiring global coordination across all clients. It's a good default because it fixes the most common perceived-bug complaints, like 'my edit vanished' or 'data went backward', at a fraction of linearizability's cost, and most application code is naturally structured around a logged-in user's session.
  • 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.

saying these in an interview costs you the question

  • 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