Skip to content
Back to skills

Data Consistency

ASecurity

Audits data consistency for three failures. Concurrent writes that overwrite each other (lost update, read-modify-write, check-then-insert, an ignored version column). Events lost between the database and a queue or external service (dual write, no outbox). Endpoints, webhooks or consumers that break on a retry (double charge, duplicate messages, no idempotency key). Each finding brings the breaking sequence with path:line and the lightest fix; reports and stops. Use it for "can events get lo...

  • 2 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 17, 2026
developmentgosqlgitapidatabasesecurityperformancedocumentation

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 6 files and shows the line behind each finding

Scanned November 17, 2026

npx -y skills add OmarAlex24/audit-skills --skill data-consistency --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Data Consistency?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Data Consistency
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/omaralex24-data-consistency/badge)](https://www.skillsdirectory.com/skills/omaralex24-data-consistency)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: data-consistency
description: Audits data consistency for three failures. Concurrent writes that overwrite each other (lost update, read-modify-write, check-then-insert, an ignored version column). Events lost between the database and a queue or external service (dual write, no outbox). Endpoints, webhooks or consumers that break on a retry (double charge, duplicate messages, no idempotency key). Each finding brings the breaking sequence with path:line and the lightest fix; reports and stops. Use it for "can events get lost?", "is this endpoint idempotent?", "race condition in the database", "optimistic locking", "outbox pattern", "duplicate messages", "is this retry-safe?", "at-least-once delivery", "stale read after write", even without the word "consistency". Status lifecycles go to implicit-state-machines; performance, perf-diagnosis; wrong calculations, correctness-review. Also triggers on Spanish requests such as "revisa la consistencia de datos", "¿se pueden perder eventos?", "¿es idempotente este endpoint?" or "doble cobro".
---

# Data consistency

This skill looks for three families of failures in the user's repo:

- **Overwrites.** Two writers read the same data and one silently erases the other's change, or both create something that had to be unique.
- **Lost events.** The database and the queue (or an external service, an index or a bucket) are written in two steps. If the process dies between the two, one of the sides never finds out.
- **Unsafe retry.** Something sends the same request or the same message again and the effect happens twice: two charges, two emails or the stock decremented twice.

Transactions, queues and strong or eventual consistency are reviewed as checks that feed those three families.

**No sequence, no finding.** Each finding names the actors (two requests, a worker and a job, the client that retries) and the concrete order of steps, with `path:line`, that leads to the bad data. "There could be a race condition" is not a finding.

Write the report in the user's language.

## Non-negotiable rules

- **Report first.** Phases 0 to 5 modify nothing: no code, no repo files, no git, no dependencies. The report goes in the chat. It is saved to a file only if the user asks.
- **Nothing that writes or calls out during the audit.** Do not run tests, builds, migrations, load tests or calls to external services: they write caches or touch databases and queues. The default method is the static trace. If an isolated run would settle a Likely finding, propose it in the report.
- **Before touching a database, print which environment it points to** (host, database name, the environment variable it came from). Nothing runs against production or a shared environment without the user's confirmation. This also applies to a read-only query you want to propose.
- **Apply only what the user picked**, with the test first (phase 6).

## Boundaries with other skills

- **`implicit-state-machines`**: if what gets overwritten is a lifecycle field (`status`, `state`, `phase`) and the problem is an invalid transition or a race between transitions (cancel and ship at once), the finding belongs to that skill. It already uses the write conditioned on state or version as a fix. Data values stay here (balances, stock, counters, averages, fields edited by people), along with uniqueness, events and retries. If a case has both sides, report it once here and point to it.
- **`perf-diagnosis`**: a retry storm or a queue that does not drain are also load problems. What duplicates or loses data is reported here; measuring the load belongs to it.
- **`architecture-review`**: which database to use, monolith or microservices, partition keys.
- **`api-security-review`**: rate limiting and throttling as a defense.
- **`infra-review`**: backups and restore, replicas and their lag as configuration, dev data volumes, queues and brokers as infrastructure (version, limits, alarms). What the code does with the data stays here.
- **`correctness-review`**: a balance, a total or a counter computed wrong with a single actor (the formula, the rounding, the bound), with no concurrency or retries. If the value only goes wrong when two actors interleave or something is retried, it belongs here.
- **`llm-app-review`**: code that calls an LLM: SDK retries that get billed without being recorded, budget reservations not released on the error branch, missing spending caps. Races on the budget or the spending counter (two requests that reserve at once and go over the cap) and retries that duplicate an effect stay here.
- **`code-structure`**: the same write solved several ways as a code design problem, modules that skip the data access layer. Whether that duplicates or loses data stays here.

## Phase 0: scope and engine

1. Use the scope the user gave. In a monorepo with no hint, ask which app or package to audit.
2. Read the project's rules (AGENTS.md, CLAUDE.md, CONTRIBUTING.md) and the ADRs or design docs. Many consistency decisions are documented there ("the push notification is best-effort", "the client retries with the same key"). A deliberate, documented degradation is not a defect.
3. Identify the **engine and the isolation** of each store: Postgres, MySQL, SQLite, DynamoDB, Mongo or Redis, and the isolation level configured or the one it has by default. If the repo supports several engines (migrations for Postgres and SQLite, for example), each sequence must say in which one it holds. The same race can lose data in one and fail with an error in another. See `references/signals.md`, section "Engine and isolation".
4. Inventory the **queues, brokers, webhooks and external clients** (SQS, SNS, Kafka, Redis streams, BullMQ, Celery, cron, Stripe, email, push) and their retry configuration: how many attempts, visibility timeout, DLQ and whether the ack is automatic.
5. Note the **deployment topology**: one instance or several. In-memory locks, counters and notifications are only a problem with several; if the documentation pins a single instance, rule them out citing it.

## Phase 1: map of units of work

Walk every handler, consumer, webhook and job that writes data. For each one note in one line:

- what it writes to the database and whether it is inside a transaction;
- what effects it has outside that transaction: publishing, enqueuing, calling a provider, uploading a file, notifying, writing to another database or to a cache;
- **who can run it twice**: HTTP client or SDK retry, double click, a queue with redelivery, the webhook provider, a cron or Airflow rerun, the mobile app retrying;
- **who else writes the same rows**: other endpoints, jobs, admin scripts and migrations.

Start with a per-file count of transactions, writes, external effects and notifications (the command is in `references/signals.md`, "Quick map") and read first the files where writes and effects coincide. This map is the basis for the three searches. If the scope goes beyond ~30 files and you can launch read-only subagents, split the map by module and ask them only for candidates with `path:line`. You do the verification.

## Phase 2: three searches

Read `references/signals.md` for the signal catalog and the search commands for each family.

**A. Overwrites.** Look for read-modify-write in two statements; aggregates computed in code (balance, stock, average, counter); `save()` of a whole entity loaded earlier; check-then-insert with no unique constraint; a `version` column that exists but that some `UPDATE` does not use or whose affected rows nobody checks; writers that skip the version; business uniqueness rules with no constraint. The sequence is **two interleaved actors**: A reads, B reads, A writes, B writes, and A's change is lost.

**B. Lost events.** Look for a database write followed by a publish, enqueue, external call or upload that is not atomic with it. This includes:

- a **second write to the same database done after the commit**: log, history, counters or projections. It is the easiest case to miss and the cheapest to fix;
- publishing inside an open transaction: the event goes out and the transaction rolls back, or the consumer reads before the commit;
- writing to several stores;
- files moved or deleted before or after the commit;
- two sources of truth for the same data, such as a column that mirrors a file;
- background effects that only log their error (`spawn` or fire-and-forget with no retry);
- ack before the effect;
- promises with no `await` in serverless.

The sequence is **a crash or an error between two concrete lines**, and which side never finds out. If there is already an outbox, review it: that it goes in the same transaction, how the relay marks what was sent, ordering, that the consumer tolerates duplicates, the backlog alert and the cleanup.

**C. Unsafe retry.** First **name the retrier**, with evidence in code or config. Then name the effect that gets duplicated. Without an identifiable retrier, the case is a Smell, not a finding. If there is an idempotency key, check that it is claimed atomically (unique constraint, not "look up then insert"), that it is per operation and not per attempt, that it stores the response, that it reaches the provider and what happens if the process dies between the effect and recording the key. Also review the retry policy: non-retryable errors, no cap, no backoff or jitter, nested retries across several layers, or a caller timeout shorter than the callee's work.

**Cross-cutting checks** (each one feeds A, B or C):

- **Transactions.** Related writes outside a transaction. Network I/O inside a transaction: it holds locks, and the external effect is not undone by the rollback. Errors caught inside the transaction followed by a commit.
- **Queues.** Delivery is at least once, so the consumer has to be idempotent. Review the visibility timeout against the processing time, that the DLQ exists and someone watches it, ordering assumptions and the drain rate against the arrival rate.
- **Strong or eventual.** Read after write against a replica, a cache or a search index. Decisions (balance, stock, permissions) made on a read that may be behind.

## Phase 3: verify and try to rule out

For each candidate:

1. **Invariant**, in one sentence: "stock never goes below 0", "every saved order produces an OrderCreated", "a payment is charged once per order".
2. **Sequence**, numbered, with `path:line` at each step, up to the bad data and what the user or the operator sees.
3. **Try to rule it out.** Look for:
   - unique constraints and partial indexes in the migrations;
   - atomic single-statement updates (`SET n = n + 1`);
   - upserts with conflict on a unique key and conditional writes already present;
   - `SELECT … FOR UPDATE` inside the same transaction;
   - SERIALIZABLE or REPEATABLE READ isolation with handling of the serialization error;
   - SQLite's single writer;
   - deduplication by the provider or the broker, and a lock or queue per entity;
   - a UI that prevents the case: not enough, because a retry does not go through the UI;
   - a periodic reconciliation that repairs the data.

   If what prevents it lives elsewhere and is fragile, the case stays a Smell and you name that guarantee.
4. **Label**: **Confirmed** if you traced every step; **Likely** if a step depends on runtime behavior you did not confirm (a library's retry policy, the queue topology, the deployment's real isolation), and you name that step; **Smell** if it does not happen today, but only by convention or by an external guarantee.
5. **Impact and severity**: what gets lost or duplicated, for whom, and whether it can be repaired; from that, the severity (Critical, High, Medium or Low; scale in the template).

Rule out the healthy candidates in one line: "reviewed, does not happen because…". A report that shows what it ruled out is more credible than one that only brings findings.

If you can launch a subagent, give it the findings and the code paths, but not your reasoning, and ask it to try to rule out each one. Check each objection in the code yourself. If you cannot launch one, make that pass yourself and mark the report "no independent review".

## Phase 4: the lightest fix

Read `references/fixes.md`, which orders the fixes for each family from lightest to heaviest. The rule is to propose the first one that removes the sequence, not the most elegant: a `SET stock = stock - 1 WHERE stock >= 1` beats an outbox, a unique constraint beats an idempotency key table, and moving the log write into the transaction that already exists beats a reconciliation. For each finding write:

- the fix and why it closes the sequence, **checked on every engine the repo supports**: `SELECT … FOR UPDATE` does not exist in SQLite, and `ON CONFLICT` and `RETURNING` vary across engines and versions. If the repo has a query portability rule, the fix respects it;
- **risks**: a new constraint fails if there are already duplicates (they have to be cleaned up first, with the project's migration process), a new 409 is an API contract that has to be communicated to clients, and a new queue is infrastructure;
- **regression test**: which sequence it reproduces and how; for example, two concurrent connections or tasks with a barrier, or a failure injected between the commit and the publish;
- **effort**: S, M or L.

`references/examples.md` has solved examples from the videos (outbox, `version`, idempotency, retries, queues, replicas) for calibration.

## Phase 5: report and stop

Use `references/report-template.md`. End by asking which findings to apply, with your recommended order, and offer in one line to save the report to a file. **Then stop**, even if the original request said "fix it": the user picks after reading.

## Phase 6: apply (only what the user picked)

Confirm in one line what you are going to apply. Then, for each finding:

1. Write the regression test, run it and see that it fails for the expected reason. If the test uses a database, print first which environment it points to; only a local or ephemeral database will do.
2. Apply the fix and see that the test passes.
3. Run the project's checks (lint, typecheck, tests) and report each command with its result. Name the ones you could not run.

Migrations are written with the project's mechanism and are not run against shared environments. No commits, push or PRs unless asked.

## Common mistakes

- Reporting "a transaction is missing" without saying which sequence it breaks. Sometimes the transaction changes nothing: in Postgres with READ COMMITTED, a read-modify-write inside a transaction still loses updates.
- Proposing an outbox for everything. If the event is best-effort and there is reconciliation (the client syncs again), the loss may be acceptable; say so and let the user decide.
- Taking as atomic what goes "to the same database". A log or a history written with another statement after the commit is a dual write, even if it is in the same database.
- Treating the idempotency key as solved because it exists. The typical failure is "look up then insert", or a new key on every attempt.
- Proposing a `SELECT … FOR UPDATE` that lasts as long as a person takes to edit, or a lock around a network call.
- Giving the videos' numbers as rules: "3 retries", "1, 2, 4 s", "Postgres is strong, Dynamo is eventual". They are examples; see `references/sources.md`.
- Citing `path:line` from memory. Every cited line was read in this session.

## Swarm mode

It turns on when the invocation brings a swarm brief (between `[swarm brief]` and `[end of brief]`), with `contract:`, `map:`, `structure:`, `output:` and `data:`. Used on its own, the skill follows the procedure above unchanged, report included. In this mode:

- **Phases:** follow phases 0 to 3 and, from phase 4, only the lightest fix, its risks, the regression test and the effort; you apply nothing. The brief's map replaces reading the docs, engines, queues and topology in phase 0, but read what the map points to and whatever it is missing.
- **No questions and no waiting:** what you would ask the user goes to the `questions` field; you do not stop to wait for an answer.
- **No subagents or reviewers:** the swarm does the independent verification. This overrides the subagent split in phase 1 and the reviewer subagent in phase 3. Make the pass that tries to rule out each finding yourself, prioritize by the map's hot paths and declare in `not_covered` what you did not cover.
- **Data:** only the `data:` command. You never open connections, tunnels or scripts of your own, and you do not read `.env` looking for credentials. If `data:` is "none", what you would have measured goes to `requested_measurements`.
- **Slice:** if the brief brings `slice:`, you only report findings whose main location (`locations[0]`) is in that slice; the membership rule is in the brief and other auditors of this same skill have the other slices. You may open files outside it only to follow a sequence that starts in your slice, and each one goes to `outside_slice` with the reason. A defect that starts outside is not yours: at most, one line in `not_covered` with its path:line. The slice section (`slice map:`) completes the global map. What the brief marks in `exclude:` belongs to no slice: you do not audit it, do not cite it as evidence and do not report anything whose main location falls there; you may open it only to understand a call that leaves the scope, and then it goes to `outside_slice` with the reason.
- **Limits:** you do not modify the audited repo and you do not read other audit runs or other auditors' folders, except what the brief gives you: contract, map, `structure:` and your folder.
- **Metric:** fill `metric` in each finding per `before-after.md` (next to the contract the brief gives), with this skill's row of its "Guide per skill" as the hint: the race or retry test repeated N times, with the lost or duplicated updates it leaves: more than 0 before, 0 after. A metric is a command that is run again, never a count of findings, and you do not invent its result: `{not_measurable: "<why>"}` is valid.
- **Output:** a single file, `findings.json`, in the folder the brief gives (`your folder:`), with the contract's object, and that same object as your answer. In swarm mode you write no readable report and no other file: the report template is for normal mode and the swarm's plan comes from the `findings.json` files. Use the contract's vocabulary: confidence, method, severity, effort and action.

Files in this skill

  • SKILL.md18.1 KB
  • references/examples.md10.5 KB
  • references/fixes.md11.8 KB
  • references/report-template.md3.9 KB
  • references/signals.md19 KB
  • references/sources.md10 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.