<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shuaib Ayomide on Medium]]></title>
        <description><![CDATA[Stories by Shuaib Ayomide on Medium]]></description>
        <link>https://medium.com/@ayomidewasiushuaib?source=rss-300ad88313d6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*oBRc6lRdpTCFVRmHnFIo5Q.jpeg</url>
            <title>Stories by Shuaib Ayomide on Medium</title>
            <link>https://medium.com/@ayomidewasiushuaib?source=rss-300ad88313d6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 16:38:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ayomidewasiushuaib/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Finding Ledger Bugs Before Your Customers Do: Building a Read-Only Data-Quality Check Suite]]></title>
            <link>https://medium.com/@ayomidewasiushuaib/finding-ledger-bugs-before-your-customers-do-building-a-read-only-data-quality-check-suite-86802a30baab?source=rss-300ad88313d6------2</link>
            <guid isPermaLink="false">https://medium.com/p/86802a30baab</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-quality]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Shuaib Ayomide]]></dc:creator>
            <pubDate>Wed, 28 Oct 2026 21:46:58 GMT</pubDate>
            <atom:updated>2026-10-28T21:46:58.135Z</atom:updated>
            <content:encoded><![CDATA[<h4>How I turned one-off database diagnostics into a repeatable suite of SQL checks for ledger and transaction data.</h4><p>Every backend team that handles financial data ends up with a folder of one-off diagnostic scripts: one to check a ledger’s state, one to verify totals, one to audit mismatched webhooks, and so on.</p><p>Each script was written while chasing a specific problem, run until the problem was understood, and then forgotten. Months later a similar issue appears. The old script might still exist, but nobody remembers where it is, what it assumes, or whether it is safe to run again.</p><p>I was asked to fix exactly this: turn those scattered diagnostics into a repeatable, read-only data-quality suite that finds suspicious ledger and transaction data before customers do.</p><p>Here are the design decisions that mattered, what the first run taught me, and what I’d improve next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rlER_XxYNtdHuhz-UuOs6Q.jpeg" /></figure><h3>Why ledger data needs its own checks</h3><p>In a typical CRUD app, an inconsistent record might cause a display glitch. In a financial system, it can affect reconciliation, accounting records or tax calculations. Ledger data is also unusually well suited to automated checks, because it has <strong>invariants</strong>: conditions that must hold when the system works correctly. For example:</p><ul><li>Debits and credits balance within a journal entry.</li><li>A materialised balance reconciles with its underlying entries.</li><li>A completed transaction has its expected ledger record.</li></ul><p>Each of these can be written as a query for the records that <em>violate</em> the condition. If the data is healthy, the query returns zero rows.</p><h3>Principle 1: Every check tests one clear invariant</h3><p>I wanted every check to look the same, so anyone could read, review or add one. Each has an ID, a description, a severity, a suggested owner, and an expected result of zero rows.</p><p>An illustrative example (table and column names are generic):</p><pre>-- TXN-001: Find completed transactions that do not have a matching ledger entry.<br>-- Severity: blocker | Owner: backend<br>-- How it works:<br>-- 1. Select the transaction ID to identify records that need investigation.<br>-- 2. LEFT JOIN ledger_entries to keep all transactions, even those without a matching ledger entry.<br>-- 3. Filter for transactions with a status of &#39;COMPLETED&#39;.<br>-- 4. Use le.id IS NULL to identify transactions with no matching ledger entry.<br>-- Expected result: Zero rows. Any returned ID indicates a potential data-integrity issue.<br><br>SELECT t.id<br>FROM transactions AS t<br>LEFT JOIN ledger_entries AS le<br>    ON le.transaction_id = t.id<br>WHERE t.status = &#39;COMPLETED&#39;<br>  AND le.id IS NULL;</pre><p>The LEFT JOIN keeps completed transactions even when no ledger entry exists, and IS NULL isolates the unmatched ones. But the SQL is the easy part. Whether <em>every</em> completed transaction must have a ledger entry, including exceptional states and historical records, comes from the business rules. Understanding the invariant matters as much as writing the query.</p><h3>Principle 2: Return identifiers, not customer data</h3><p>Findings end up in tickets, chat threads and pull requests. Returning names, emails or amounts spreads sensitive data into places it was never meant to live. So each check returns only the row IDs needed for investigation:</p><pre>|check_id | severity | row_id<br>|TXN-001  |blocker   | txn_123</pre><p>An engineer with the right access can look up the full record through the normal controlled workflow. IDs can still be sensitive, so reports should follow your organisation’s data-handling rules. The principle is simply to collect enough to identify a problem without copying more than the investigation needs.</p><h3>Principle 3: Severity drives the response</h3><p>Not every failure deserves the same reaction. I used three levels:</p><ul><li><strong>Blocker:</strong> financial or filing correctness may be at risk. The runner exits non-zero.</li><li><strong>Warning:</strong> suspicious and needs investigation, but doesn’t fail the run.</li><li><strong>Info:</strong> useful for monitoring, no action required.</li></ul><p>This is what makes the exit code meaningful. If every warning fails the run, people stop trusting it. If a blocker can still exit with 0, automation will report an unhealthy run as a success.</p><h3>Principle 4: Read-only, enforced by the database</h3><p>A diagnostic tool that can write to the database can create a second problem while you investigate the first. I used three layers:</p><ol><li>Plain<strong> </strong>.sql<strong> </strong>files, so reviewers can inspect each query quickly.</li><li>Statement validation in the runner, which only accepts SELECT and WITH ... SELECT.</li><li>A read-only database role.</li></ol><p>The third is the one that counts. A string check is not a SQL security boundary, since comments, multiple statements and complex expressions can all get past a naive filter. The validator is a useful extra layer, but read-only access should be guaranteed by database permissions, not promised by code.</p><h3>The runner</h3><p>The runner turns individual checks into a repeatable workflow:</p><ol><li>Load and validate the registered checks.</li><li>Run them against the target environment.</li><li>Record each outcome with any returned row IDs.</li><li>Write a dated CSV and a human-readable summary.</li><li>Exit with a code based on the severity policy.</li></ol><p>Each check ends as <strong>PASS</strong> (no violating rows), <strong>FAIL</strong> (violating rows found) or <strong>ERROR</strong> (the query didn’t complete). The distinction matters. A failure is evidence of a possibly inconsistent dataset. An error tells you nothing about the invariant at all.</p><p>A --dry-run mode lists the check inventory without touching the database, which made pull request review much easier.</p><p>Dated reports help too. If the same ID appears in consecutive runs, the issue persists. If it disappears, that’s a good sign, though not proof of a fix: the record may have changed or been deleted.</p><h3>Testing the checks themselves</h3><p>A runner can execute every query successfully and still mislead you. A wrong join condition can make a check return zero rows while inconsistent data sits right there. In financial systems that false confidence is dangerous.</p><p>So each check needs two fixtures:</p><ul><li>a <strong>passing fixture</strong> that satisfies the invariant and returns zero rows</li><li>a <strong>failing fixture</strong> that deliberately breaks it and must be caught</li></ul><p>If you can’t construct a failing fixture, you probably don’t understand what the check is testing yet. These fixtures also act as regression tests when the schema or business rules change.</p><h3>What the first run showed</h3><p>The suite covers more than 25 checks across ledger integrity, transactions, materialised balances and several product areas. The first staging run completed with zero execution errors, and a handful of checks failed, including a warning on materialised balances.</p><p>Two lessons stood out.</p><p><strong>A finding is not a confirmed bug.</strong> A flagged record might be a genuine inconsistency, leftover test data, a legitimate accounting adjustment, or a check whose assumptions don’t match the real business rules. A data-quality check detects a condition. Investigation establishes what it means. That is why triage with a backend engineer was part of the deliverable, not an afterthought.</p><p><strong>Zero errors matters as much as the failures.</strong> An errored check can’t tell you whether its invariant holds. Keeping errors at zero meant every pass and fail came from a check that actually completed. It didn’t mean the data was perfect, only that the suite evaluated what it was designed to evaluate.</p><h3>Detect here, fix elsewhere</h3><p>The suite only detects. It doesn’t repair balances or rewrite history. The right fix depends on the cause, and an automated correction made without understanding the accounting rules can make things worse. Confirmed findings become separate tickets, with remediation going through a dedicated, reviewed backfill process. The suite answers “where should we look?” and the remediation workflow answers “what is the safe way to fix it?”</p><h3>Scheduling: not just a cron job</h3><p>A daily run is the obvious next step, but I proposed it rather than enabling it in production. Before turning it on, I’d want answers to a few questions:</p><ul><li>Which environment and read-only credentials will it use?</li><li>Where are reports stored, and who can read them?</li><li>How are blocker failures surfaced, and who owns triage?</li><li>How are recurring warnings tracked without becoming noise?</li><li>What happens if the runner itself fails?</li></ul><p>A new automated process touching production data should go through the system owners’ normal review and approval.</p><h3>Next steps</h3><ul><li><strong>Start from invariants.</strong> I began by translating existing scripts, which carries their undocumented assumptions along. Next time I’d write down the critical invariants and their owners first, then map the old scripts onto them.</li><li><strong>Compare runs.</strong> Dated reports already hold the data. Tracking first-seen and last-seen dates and linking findings to tickets would make triage faster.</li><li><strong>Automate the fixtures.</strong> Passing and failing tests should be required for every new check.</li><li><strong>Measure usefulness, not check count.</strong> Confirmed findings, false positives, time to triage and time to resolution say far more than the size of the inventory.</li></ul><h3>Takeaways</h3><ol><li>Express each check as an invariant and expect zero rows when the data is healthy.</li><li>Return IDs, not customer data.</li><li>Let severity decide the exit code, and enforce read-only access with database permissions.</li><li>Test every check with a passing and a failing fixture.</li><li>Keep detection separate from remediation, and treat ownership and triage as part of the work.</li></ol><p>The best data-quality suite is usually a boring one. Most days everything passes, and when something doesn’t, the right engineer finds out from a report instead of a customer.</p><p><em>If you’ve built a similar data-quality suite, I’d love to hear how you handle recurring findings, triage ownership and scheduling.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86802a30baab" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>