Designing Data-Intensive Applications
Case 1

Latency, Throughput, and Consistency

Every system design picks a point on the latency–throughput–consistency triangle. Name your choice explicitly.

A reservation system needs linearizable inventory decrements. A YouTube view counter can be approximate. A voting system needs auditability stronger than either. The 'right' consistency level is domain-specific.

Pick your guarantees

Write down what must never happen (double booking, duplicate vote) before choosing databases. The invariant picks the consistency model.

In practice

Instagram tolerates slightly stale like counts (approximate aggregation) but not duplicate posts on retry (idempotent write IDs). Google Spanner pays latency for global consistency where ads billing requires it.

WhatsApp at scale

Message ordering within a chat is strict; global search across chats is weaker or absent. The product promise determines per-feature consistency.

typescript — Read-your-writes vs eventual feed
// Facebook / Instagram: route reads to primary after posting
async function createPost(userId: string, text: string) {
  const post = await db.primary.posts.create({ data: { userId, text } });
  // Sticky session: next reads hit primary or caught-up replica
  session.set("readFromPrimaryUntil", Date.now() + 5_000);
  return post;
}

async function getFeed(userId: string) {
  const client = session.get("readFromPrimaryUntil") > Date.now()
    ? db.primary
    : db.replica;
  return client.feed.findMany({ where: { userId } });
}
Key Takeaways
  • Strong consistency simplifies application logic but adds coordination latency.
  • Eventual consistency scales reads but requires idempotency and conflict handling.
  • Tail latency (p99) matters more than averages for interactive products.
  • Async pipelines improve throughput at the cost of visible lag.
  • CAP is a reminder to plan for partitions — not a menu with three equal options.
  • DDIA Part II concepts map directly to these product-level decisions.
consistencylatencythroughputCAPidempotency