Cruxly

Cruxly › Forward deployed engineer › Decomposition Cases

Onboarding a Customer's Messy Data Feeds

the first batch will not be clean, so build the quarantine and the counts before the clever part

Open the interactive lesson

Prompt: a regional retail group wants your analytics product running on their sales and inventory data by the end of the quarter. The data comes from five systems: the point-of-sale software drops CSV files on an SFTP server each night, the warehouse system exports XML, a loyalty system sends a weekly spreadsheet export, an older stock system produces fixed-width text files, and a returns system emails attachments to a shared mailbox. Nobody has a data dictionary. The customer's data lead says: "it's mostly clean."

45 minutes first. The tempting read is "write five parsers and load it." The actual problem is that "mostly clean" is a claim you cannot yet check, and a pipeline that quietly loads wrong data is worse than one that loudly refuses it.

Clarifying questions that matter here

"Can I see a week of real files from each system before I design anything?" Samples beat any description. A day's file shows you the encoding, the date formats, the odd characters and the columns that are always empty. Ask for a normal week and also a bad one, for example the week after a system upgrade or the holiday rush, because the bad week is where the rules break.

"What does one record mean in each system, and what is the unique key?" A "sale" in the point-of-sale file may be one line item, while in the warehouse feed it may be a whole order. If nobody can name the key that makes a record unique, you cannot detect duplicates, and you cannot say whether a re-sent file should replace or add to what you already loaded.

"How do these systems change, and who tells you when they do?" Schema drift is a matter of when, not if: a column renamed after a vendor update, a new status code, a date format that switches on the first of the month. Ask who owns each system, whether changes are announced, and whether there is any test environment.

"Can late or corrected records arrive, and how late?" Returns often arrive days after the sale; a store that was offline may upload a week of data at once. This decides whether yesterday's numbers are final or may still change, and the customer needs to hear that answer explicitly.

"Who will fix a bad record when we find one, and who decides what 'right' is?" If a product code in the stock file does not exist in the product master, the fix might live with the store manager, the warehouse team or the vendor. A pipeline with no named owner for each kind of defect just accumulates a pile of rejected rows nobody reads.

"Which number does the business already trust, and where does it come from?" Almost every customer has a figure, such as daily total sales from the finance report, that people believe. That number is your anchor for proving your load is right.

The decomposition: land raw, validate, quarantine, then reconcile

Slice 1 — land every file untouched, with a receipt. Whatever arrives, copy it as-is into a raw area, tagged with source system, filename, arrival time and a checksum. Never edit a raw file. This is your evidence: when someone says "that number looks wrong," you can replay from the exact bytes that arrived. It also makes the pipeline safe to re-run, since reprocessing a day means reading the raw copy again, not asking the customer to resend.

Slice 2 — one source, end to end, before the other four. Pick the point-of-sale CSVs, because they are probably the highest-value and highest-volume feed, and build the whole path for that one: parse, map to a small common shape (store, product, timestamp, quantity, amount, record key), validate, load. Resist generalizing across five systems yet. You do not know yet which of your assumptions are specific to this feed, and a generic framework built on one example usually fits none of the others.

Slice 3 — a mapping layer that is data, not code. Keep the translation from each source's columns and codes to your common shape in a small, readable mapping file per source: which column holds the date, which format, how status codes translate, which values mean "missing." When the vendor renames a column, the fix is a one-line mapping change that the customer's own analyst can review. Add a schema check at the front: if the column set or a field's type differs from what the mapping expects, stop that file and raise it, rather than loading shifted data.

Slice 4 — validation with a quarantine, not a rejection. Each row passes or fails explicit rules: required fields present, dates parse and are not in the future, quantities are numeric, product codes exist in the master, amount within a plausible range. Rows that fail go to a quarantine table with the reason attached and the original raw reference, and the good rows load anyway. Loading the good rows keeps the business moving; the quarantine makes sure the bad rows are visible and recoverable, instead of silently dropped or silently loaded.

Slice 5 — duplicates and late records by key. Use the record key and a source timestamp so that loading the same file twice changes nothing (an upsert, not an append), and a corrected record replaces the earlier version while keeping the old one in history. Late arrivals land in the right business day, and the day is marked "provisional" until a stated cutoff, for example seven days, after which it is closed.

Slice 6 — reconciliation the customer can verify. For each file and each day, publish a small table: rows received, rows loaded, rows quarantined (with reasons), and the total amount loaded next to the total the source system reports. Received must equal loaded plus quarantined; if not, that is a bug of yours. Then compare daily totals to the trusted finance figure. Once the customer can check your numbers against their own, trust stops being something you ask for.

The riskiest unknown, and who owns data quality

The riskiest unknown is not the formats; it is the meaning of the data. Parsers are mechanical. The danger is the point-of-sale "amount" that is sometimes tax-inclusive and sometimes not, the status code "3" that means "returned" in one store group and "on hold" in another, or the timestamp recorded in the store's local time in one feed and in UTC in another. These produce rows that pass every format check and are still wrong. You find them only by comparing against something the business trusts.

So the first week's deliverable is a reconciliation for one feed and a few days of data. Load the point-of-sale CSVs for, for example, the last 30 days and compare each day's total to the finance report. Expect a gap; the interesting part is the pattern. A constant percentage points to tax, a gap on specific stores points to a store-specific rule, a gap on specific days points to late records or timezone cutoffs. Each pattern becomes a question you take to a named person, which is far better than a vague "the data is dirty."

Be honest about the expectation. Tell the customer on day one: the first loads will have exceptions, that is normal and not a failure; the goal is for every exception to be visible, counted and assigned, and for the number to shrink over weeks. Do not promise "100% clean." Promise "every row is either loaded or accounted for, and you can check that yourselves." For example, a good week-four target might be that fewer than 1% of rows are quarantined, with every reason category explained.

Who owns the fixes. Agree this in writing before the first big load, not after. A workable split: the customer owns the truth about their business (what a code means, which store is right), you own the pipeline and its rules, and each quarantine reason category has a named person on their side and a target response time. Fixes to the source belong at the source whenever possible, since patching it silently in your pipeline hides the problem and breaks the day the source changes. Where a source cannot be fixed, the correction goes in the mapping file as an explicit, reviewed rule with a comment saying why.

Follow-ups they will ask

"The warehouse vendor upgraded last night and today's file has a new column order. What happened to our numbers?" Nothing, if the schema check did its job: the file stopped at the front door, the other feeds loaded normally, and an alert named the feed and the difference in columns. The fix is a mapping change, tested against the raw file you already have, then reprocessed. The thing to avoid is a parser that reads by position and happily loads quantities into the price column.

"A store was offline for a week and just sent everything at once." Business dates come from the record's own timestamp, not from arrival time, so the week lands in the right days, those days are marked as revised, and the reconciliation shows rows received late. Anyone who already looked at last week's dashboard should be told it changed, which is why the "provisional until closed" label matters.

"Can you just fix the product codes in your pipeline so we stop seeing the quarantine?" Sometimes, with care. If the mapping is genuinely known (an old code always means a specific new code), put it in the mapping file as a reviewed rule. If it is a guess, do not: guessed fixes make the quarantine look empty while the numbers drift away from reality. Ask what the customer would rather have: a visible gap or a confident guess, and let them decide with the percentages in front of them.

"Why do your totals differ from finance by 0.4%?" Walk to the reconciliation table rather than defending the number. A small residual with a known explanation (rows in quarantine, a day still provisional, rounding at line level) is a good result. An unexplained residual is the one to chase, and showing that you list it openly builds more trust than a total that happens to match.

"Now add a sixth system next month." The mapping-as-data design makes this a day or two of work to land, map and validate, plus however long the customer takes to answer the meaning questions. Be careful to say the second part out loud; it is usually the slower one.

How to say it in the interview

"I'll take 'mostly clean' as a hypothesis rather than a fact. My plan is to build the plumbing that tells us how clean it really is, and that lets the customer verify every number I load, before I build anything that depends on the data being right."

Checklist

Practice this interactively
Share this lessonWhatsAppLinkedInX

Related lessons