QA
Senior LevelSoftware Engineering Principles

What are the spectrums of Eventual Consistency models (Read-Your-Writes, Monotonic Reads, Causal Consistency)?

❓ Interview Prompt: Explain Eventual Consistency models, Read-Your-Writes consistency, Monotonic Reads, Monotonic Writes, Causal Consistency, and sticky sessions.

Eventual consistency guarantees that if no new updates are made, all replicas will eventually return the same value. However, systems provide different consistency sub-guarantees:

1
Read-Your-Writes Consistency: Guarantees that if a user updates a record, their subsequent reads will ALWAYS reflect that update (implemented via sticky database routing or primary DB reads for modified keys).
2
Monotonic Reads: Guarantees that if a user reads value $V_1$, they will never subsequently read an older value $V_0$.
3
Causal Consistency: Operations that are causally related are seen by every node in the same order.

Code Implementation Example

typescript
// Enforcing Read-Your-Writes consistency by routing recent writers to Primary DB
export async function getUserProfile(userId: string, userLastWroteAt: number) {
  const secondsSinceWrite = (Date.now() - userLastWroteAt) / 1000;
  
  if (secondsSinceWrite < 5) {
    return await primaryDb.user.findUnique({ where: { id: userId } }); // Primary DB!
  }
  return await replicaDb.user.findUnique({ where: { id: userId } }); // Read Replica!
}
💡Routing recently updated users to Primary DB to guarantee Read-Your-Writes consistency.
🎯 Interview Key Takeaway

Enforce Read-Your-Writes consistency for user-facing actions to eliminate confusing UI cache lags.

#Eventual Consistency#Read-Your-Writes#Replication#Senior
Back to all Software Engineering Principles Questions→

More Software Engineering Principles Interview Questions

Beginner LevelSoftware Engineering Principles

Explain the 5 SOLID Principles of Object-Oriented Software Design with practical refactoring examples.

Beginner LevelSoftware Engineering Principles

What are DRY (Don't Repeat Yourself), KISS (Keep It Simple, Stupid), and YAGNI (You Aren't Gonna Need It)?

Beginner LevelSoftware Engineering Principles

Why is Composition Over Inheritance a fundamental object-oriented design principle?