# `TrogonProto.Consistency.V1Alpha1.Consistency`
[🔗](https://github.com/straw-hat-team/beam-monorepo/blob/trogon_proto@v0.8.1/apps/trogon_proto/lib/__generated__/trogon/consistency/v1alpha1/consistency.pb.ex#L1)

Configuration for read-your-writes consistency guarantees in eventual consistency systems.

Used in query operations to wait for projections/read models to catch up to a specific version
after a write operation. This enables clients to immediately read their own writes despite
projection lag in CQRS/Event Sourcing architectures.

## Consistency Modes

### MinVersion (Recommended - Read-Your-Writes)
Waits for projection to reach AT LEAST the specified version. Will use newer data if available.
Use this after mutations to ensure you can immediately read what you just wrote.

### ExactVersion (Strict - Reproducible Snapshots)
Waits for projection to reach EXACTLY the specified version. Rejects if version is newer.
Use this only when you need reproducible queries at a specific point-in-time (audits, reports).

## Usage Pattern

1. Client performs mutation (e.g., CreateOrder, UpdateInventory)
2. Server returns stream_version (e.g., version 5)
3. Client immediately queries with Consistency:
   - min_version { version: 5 }  (recommended - read-your-writes)
   - exact_version { version: 5 }  (strict - reproducible snapshot)
4. Server retries query until projection reaches version or timeout

## Example

```protobuf
// Mutation response
message CreateOrderResponse {
  string order_id = 1;
  uint64 stream_version = 2;  // Returns: 5
}

// Read-your-writes (recommended)
message GetOrderRequest {
  string order_id = 1;
  trogon.consistency.v1alpha1.Consistency consistency = 2;
}

GetOrderRequest {
  order_id: "order-123",
  consistency: {
    min_version: { version: 5 },
    timeout_duration: "1s",
    delay_duration: "100ms"
  }
}
```

## Server Implementation Guidelines

Servers should:
- Enforce reasonable timeout limits (e.g., default 1s, max 5s)
- Enforce reasonable delay limits (e.g., default 100ms, max 500ms)
- Return unavailable status on timeout with appropriate error metadata
- Return failed precondition status on snapshot expired (ExactVersion only)
- Log when clamping client-provided values

## Reference

Inspired by SpiceDB's Consistency patterns (at_least_as_fresh and at_exact_snapshot modes).
See: https://authzed.com/docs/spicedb/concepts/consistency

# `t`

```elixir
@type t() :: %TrogonProto.Consistency.V1Alpha1.Consistency{
  __unknown_fields__: [Protobuf.unknown_field()],
  delay_duration: Google.Protobuf.Duration.t() | nil,
  requirement:
    {:min_version, TrogonProto.Consistency.V1Alpha1.MinVersion.t() | nil}
    | {:exact_version, TrogonProto.Consistency.V1Alpha1.ExactVersion.t() | nil}
    | nil,
  timeout_duration: Google.Protobuf.Duration.t() | nil
}
```

# `descriptor`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
