This document outlines a comprehensive consistency testing suite for distributed caches (e.g., Redis Cluster, Memcached, or DynamoDB-like systems). The suite focuses on three key consistency properties:
Read-Your-Writes (RYW): A client that performs a write must observe that write (or a newer value) on all subsequent reads from the same logical client/session.
Monotonic Reads (MR): For a given client and key, reads return non-decreasing versions/values over time (no regressions to older values).
Staleness Budgets: Reads return values no older than a configured budget (e.g., ≤ 5 seconds), measured via logical timestamps or vector clocks.
The suite is inspired by tools like Jepsen, PGMemtester, and CockroachDB's consistency checker. It emphasizes automation, chaos engineering, and statistical confidence (e.g., 10k+ operations per run, multiple seeds).
Prerequisites and Assumptions
Cache Interface: Key-value store with PUT(key, value, ttl?), GET(key), optional CAS(key, old, new) for linearizability checks.
Metadata: Values include a logical timestamp (e.g., {data: "foo", ts: 1234567890, client_id: "c1"}). Use hybrid clocks (e.g., TrueTime) or Lamport clocks for ordering.
Clients: Simulated via sessions (e.g., client_id in headers/cookies). Track per-client history.
Environment:
Deploy cache under test (e.g., Docker/K8s).
Generator nodes: Go/Python workers for high-throughput workloads.
Observability: Cache logs + external tracing (Jaeger/OpenTelemetry) for latencies.
Tools:
Language: Go (for speed) or Python (with asyncio).
Orchestration: Jepsen (Clojure) for end-to-end, or custom with knossos model checker.
Chaos: Netflix Chaos Monkey, or tc for network delays/partitions.
Success Criteria: 100% pass rate over 100 runs (or <1% violation rate with confidence intervals).
Multi-Region: Clients in different AZs; measure propagation SLA.
Session Sticky: Use client_id; violate if cross-client but same session.
Oracle Logic (Pseudocode):
go
for each client c, key k in history:
writes = filter(history, c, k, op=PUT)
reads = filter(history, c, k, op=GET)
for each read in reads:
latest_write_ts = max(w.ts for w in writes where w.time <= read.time)
assert read.value.ts >= latest_write_ts
budget_ms = 5000
for each read in history:
writes = filter(history, any_client, read.key, op=PUT, time <= read.time)
if writes.empty(): continue // OK for cache misses
latest_write_ts = max(w.ts for w in writes)
assert read.ts >= latest_write_ts - budget_ms
Metrics: p99 staleness, violations under load.
Integrated Checker and Reporting
Knossos-Like Model: Use finite-state machine for session-per-client histories.
Scaling: Partition space into shards; test cross-shard.
Custom Nemeses:
Nemesis
Effect
Network Partition
30% packet loss
Overload
200% CPU
Clock Skew
±100ms
Sample Implementation Snippet (Go)
go
type Op struct {
Client, Key string
Type string // "PUT", "GET"
Value struct { Data string; TS int64 }
Time time.Time
}
func CheckRYW(history []Op) error {
// As above...
}
This suite achieves high confidence in consistency guarantees. Start with microbenchmarks, scale to chaos. Customize budgets/keys for your cache. For production, run nightly with prod-like traffic capture (tcpcopy). Questions? Let's iterate!