A sales sync sends a write to Airtable. Airtable saves the row, but the response gets lost. The workflow sees a timeout and retries. If each attempt creates a record, the same sale appears twice.
Use the Gumroad sale ID as the key for the Airtable write. A buyer can make two purchases with the same email address. In Airtable, an upsert matches against the fields named in fieldsToMergeOn. When there is one match, it updates that row. When there are multiple matches, Airtable rejects the request. Airtable’s update records documentation
Run the retry test
Save the script as replay.mjs and run node replay.mjs. It uses fictional sales and an in-memory destination. The code checks the request fields and models a write whose response is lost.
import assert from "node:assert/strict"; // Uses fictional sales and a simulated destination. It makes no API requests. function airtableUpsert(sale) { const date = new Date(sale.soldAt); if (!sale.id || !sale.productId || !sale.email || !Number.isFinite(date.getTime()) || !Number.isSafeInteger(sale.amountMinor) || !/^[A-Z]{3}$/.test(sale.currency)) { throw new TypeError("A valid sale ID, product, email, date, amount and currency are required"); } return { performUpsert: { fieldsToMergeOn: ["Sale ID"] }, records: [{ fields: { "Sale ID": sale.id, "Buyer email": sale.email, "Sold at": date.toISOString(), "Amount (minor units)": sale.amountMinor, Currency: sale.currency, "Product ID": sale.productId, } }], }; } const table = new Map(); function simulatedWrite(request, loseResponse = false) { const [key] = request.performUpsert.fieldsToMergeOn; const { fields } = request.records[0]; table.set(fields[key], fields); if (loseResponse) throw new Error("Simulated timeout after the write"); } const first = { id: "demo-sale-001", productId: "demo-product", email: "buyer@example.com", soldAt: "2026-11-26T13:00:00Z", amountMinor: 2400, currency: "USD", }; simulatedWrite(airtableUpsert(first)); simulatedWrite(airtableUpsert(first)); assert.equal(table.size, 1, "Replaying the same sale must update one row"); assert.deepEqual(table.get(first.id), { "Sale ID": first.id, "Buyer email": first.email, "Sold at": "2026-11-26T13:00:00.000Z", "Amount (minor units)": 2400, Currency: "USD", "Product ID": "demo-product", }); console.log("PASS: one row for the same sale ID, with the expected amount and currency."); const second = { ...first, id: "demo-sale-002" }; assert.throws(() => simulatedWrite(airtableUpsert(second), true), /timeout after the write/); simulatedWrite(airtableUpsert(second)); assert.equal(table.size, 2, "Two sale IDs must remain distinct, even with the same email"); console.log("PASS: a retry after a lost response leaves one row per sale."); assert.throws(() => simulatedWrite(airtableUpsert({ ...first, id: "" })), TypeError); assert.equal(table.size, 2); console.log("PASS: a sale without a stable ID is rejected before writing."); Local test output
PASS: one row for the same sale ID, with the expected amount and currency. PASS: a retry after a lost response leaves one row per sale. PASS: a sale without a stable ID is rejected before writing. What to check in staging
Send one test sale twice and count rows by sale ID. Next, send a different sale with the same buyer email and check that it gets its own row. Reconcile the amount, currency, and date against the source sale. Use a staging table with a text field for the sale ID, and check for existing duplicate IDs before turning on retries.
The local test models an upsert with a JavaScript Map. Staging is where you verify the real Airtable response, field names and types, and how your workflow handles a failure. Gumroad’s sales data reference
An AI agent prepared this article and ran the sample locally. The three lines above are the actual test output.
