← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

Eventual Consistency

Architecture PHP 5.0+ Intermediate
debt(d9/e5/b7/t5)
d9 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'silent in production until users hit it' (d9). The detection_hints explicitly state 'automated: no' and describe the pattern as a read-after-write expecting immediate consistency. There is no static analysis tool that can catch this architectural assumption mismatch — it only surfaces when users observe stale data in production, often intermittently depending on replication lag.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix suggests designing reads to tolerate stale data and routing certain reads to the primary, but the common_mistakes reveal multiple dimensions: UI changes to communicate lag to users, operational changes (monitoring replication lag), identifying which operations require strong consistency and rerouting them. This is not a single-line patch — it touches read paths, UI/UX, and operational monitoring across the codebase.

b7 Burden Structural debt — long-term weight of choosing wrong

Closest to 'strong gravitational pull' (b7). Eventual consistency applies to web, api, and queue-worker contexts and is an architectural-level choice. Once a system is built on eventually-consistent stores or async consumers, every feature that reads after writing must account for it. The applies_to scope (web, api, queue-worker) means virtually every developer touching the system is shaped by this constraint — cache invalidation, user-facing feedback, financial safety checks all bend around it.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap (a documented gotcha most devs eventually learn)' (t5). The misconception field captures a real but correctable misunderstanding: developers believe inconsistency may be permanent or unbounded rather than milliseconds-to-seconds. The common_mistakes reinforce this — reading immediately after a write expecting the new value is a classic, widely-documented gotcha that most distributed systems developers encounter and learn from, but it is not catastrophic in the way that contradicts a nearly universal mental model.

About DEBT scoring →

Also Known As

eventual consistency model BASE properties weak consistency

TL;DR

A consistency model where replicas may diverge temporarily but converge to the same value given no new writes — trading immediacy for availability.

Explanation

Eventual consistency (AP in CAP) allows read replicas and distributed caches to serve slightly stale data until replication catches up. Two concurrent readers may briefly see different values after a write. Practical PHP implications: never assume a read immediately following a write returns the updated value when using read replicas; implement compensating logic (re-fetch after write, optimistic UI updates with eventual server sync). Many business domains naturally tolerate eventual consistency (social feeds, shopping cart totals) while others require strong consistency (financial account balances, inventory reservation).

Diagram

flowchart TD
    WRITE[Write to primary] --> PRI[(Primary DB)]
    PRI -->|async replicate| R1[(Replica 1<br/>lag 100ms)]
    PRI -->|async replicate| R2[(Replica 2<br/>lag 300ms)]
    READ[Read from replica] --> R1
    R1 -->|may return| STALE[Stale data<br/>100ms behind]
    subgraph Mitigations
        RYW[Read-your-writes<br/>route to primary after write]
        SESSION[Session consistency<br/>same replica per user]
        MONO[Monotonic reads<br/>never go backwards]
    end
style STALE fill:#f85149,color:#fff
style RYW fill:#238636,color:#fff
style SESSION fill:#238636,color:#fff

Common Misconception

Eventual consistency means data might be wrong forever. It means replicas converge to the same state given enough time without new updates — not that data stays inconsistent indefinitely. The window of inconsistency is typically milliseconds to seconds, not unbounded.

Why It Matters

Eventual consistency accepts temporary divergence between nodes in exchange for availability and partition tolerance — understanding when it applies prevents building distributed systems that assume synchronous strong consistency.

Common Mistakes

  • Building UIs that read immediately after a write and expecting the new value — the read may hit an out-of-date replica.
  • Not communicating eventual consistency to users — showing a spinner or 'update in progress' manages expectations.
  • Using eventual consistency for operations that require strong consistency (financial transfers, inventory deduction).
  • Not monitoring replication lag — eventual consistency without lag metrics is a blind spot.

Code Examples

✗ Vulnerable
// Reads own write assuming strong consistency:
$db->insert('orders', $orderData);
$order = $db->readFromReplica('SELECT * FROM orders WHERE id = ?', [$id]);
// May return null — replica may not have caught up yet
// Fix: read-after-write from primary, or use read-your-writes session consistency
✓ Fixed
// Eventual consistency — system converges to consistent state over time
// Common in: read replicas, distributed caches, event-driven systems

// Handle stale reads gracefully:
public function getOrderStatus(int $orderId): string {
    // Read from replica (may be 100ms behind primary)
    $order = Order::on('replica')->find($orderId);

    // Show last-known status with staleness indicator if needed:
    return [
        'status'    => $order?->status ?? 'processing',
        'as_of'     => $order?->updated_at,
        'note'      => 'Status may take a moment to update',
    ];
}

// After write, redirect to a page that doesn't require fresh data:
// POST /orders → 202 Accepted → poll /orders/{id}/status

// Or: write to primary, read from primary immediately after write (read-your-writes):
$order = Order::on('primary')->find($orderId);

Added 15 Mar 2026
Edited 22 Mar 2026
Views 180
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 2 pings W 2 pings T 0 pings F 2 pings S 0 pings S 3 pings M 1 ping T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
Google 42 Amazonbot 12 Perplexity 9 Ahrefs 9 Scrapy 9 SEMrush 8 PetalBot 8 Unknown AI 4 Majestic 3 Bing 3 Sogou 3 Twitter/X 2 Applebot 2 Baidu 2 Meta AI 1 Qwen 1 Brave Search 1
crawler 116 crawler_json 2 pre-tracking 1
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: High
⚡ Quick Fix
Design reads to tolerate stale data and use idempotent writes — if a user must see their own write immediately, read from the primary (read-your-writes consistency)
📦 Applies To
PHP 5.0+ web api queue-worker
🔗 Prerequisites
🔍 Detection Hints
Read after write expecting immediate consistency from read replica or async message consumer
Auto-detectable: ✗ No
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: High Context: File Tests: Update


✓ schema.org compliant