Skip to main content

Consistency Models — How Fresh Is Your Read?

Defines how up-to-date reads are relative to writes — from strong (always latest) to eventual (converges eventually).

When to use

  • Strong consistency: financial transactions, inventory counts, anything where stale reads cause harm
  • Eventual consistency: social feeds, shopping carts, analytics — staleness is acceptable
  • Causal consistency: collaborative editing, messaging — you must see your own writes

Tradeoffs

  • Strong requires coordination across replicas (latency cost per write)
  • Eventual requires conflict resolution strategy (complexity on read)
// Read-your-writes: route reads to primary after a write
func (c *Client) UpdateUser(ctx context.Context, user User) error {
if err := c.primary.Write(ctx, user); err != nil {
return err
}
// Pin next read to primary to see our own write
c.session.SetReadPreference(Primary)
return nil
}

func (c *Client) GetUser(ctx context.Context, id string) (User, error) {
pref := c.session.ReadPreference()
if pref == Primary {
c.session.SetReadPreference(SecondaryPreferred) // reset after use
return c.primary.Read(ctx, id)
}
return c.replica.Read(ctx, id)
}

Gotcha: Eventual consistency does NOT mean random. It means replicas converge if writes stop. The window can be milliseconds or minutes depending on topology.