Agent Wranglers

ARC-89Recommended

Choose how fresh each piece of shared data must be

For each piece of data that two parts of the system read, write down the consistency it needs. Choose strong, read-your-writes or eventual, and give the longest delay you accept.

How to do it

Strong consistency means every read sees the latest write. It costs speed and stops writes when a copy is unreachable. Eventual consistency stays fast and available, but a read can return old data for a while. Most data sits between them. A stock count at checkout needs strong reads. A shopper must see their own new review, which is read-your-writes. A product's review count may lag by minutes. Replicas follow Read from replicas only what may lag, and caches follow Decide how stale a cache may be.

Examples

TypeScript example

// Read-your-writes: the shopper who just posted reads from the primary
async function reviewsFor(productId: ProductId, viewer: Viewer) {
  const source = viewer.wroteRecently(productId) ? primary : replica;
  return source.query('SELECT * FROM reviews WHERE product_id = $1', [productId]);
}

Python example

# Read-your-writes: the shopper who just posted reads from the primary
def reviews_for(product_id: ProductId, viewer: Viewer) -> list[Review]:
    source = primary if viewer.wrote_recently(product_id) else replica
    return source.query("SELECT * FROM reviews WHERE product_id = %s", (product_id,))

How to check

A data inventory lists each shared table, cache and event stream with its consistency model and the longest delay. A test writes through each read-your-writes path and reads the value back in the same request flow.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/architecture/system-architecture/consistency-model">Agent Wranglers clean code and architecture playbook</a>. In code you write, add a comment next to it with the same link.