The Retry That Doubled the Rows

Concepts covered: Idempotency

A nightly load that appends

The Airbnb question is easier to answer on a load small enough to follow row by row, so this section shrinks it to a bookshop whose day holds 4 orders. An online bookshop keeps every order in an orders table inside its operational database. Each night at 02:00, a task called load_daily_orders copies the previous day's orders into a warehouse table named daily_orders. A revenue dashboard reads that warehouse table every morning, and the finance team reads the dashboard.

Each night the task copies one day of orders from the operational database into the warehouse, where the dashboard reads them.
  • orders (source, operational database)
  • load_daily_orders (transform, nightly batch task)
  • daily_orders (storage, warehouse table)
  • revenue dashboard (consumer, read each morning)
  • orders -> load_daily_orders
  • load_daily_orders -> daily_orders
  • daily_orders -> revenue dashboard

In SQL terms, the load for the night of 2026-03-15 does this. It reads the orders placed on 2026-03-14 and adds them to the warehouse table.

INSERT INTO daily_orders
SELECT
  order_id,
  order_date,
  amount
FROM orders
WHERE order_date = DATE '2026-03-14'

INSERT INTO is an append. It adds the rows it is handed to whatever the table already holds, and it never looks at the table first. daily_orders has no enforced unique key on order_id, as is typical of warehouse tables, so nothing stops a second copy of a row from landing. On a night with no failures that gap costs nothing: 4 orders in the source become 4 rows in the warehouse.

Attempt 1 dies halfway

The task sends its rows to the warehouse in batches. On this night it has written the first batch, orders 1001 and 1002, when the connection to the warehouse drops at 02:03. The task exits with an error. The 2 rows it already wrote stay in daily_orders, because the crash stopped the work where it stood and cleaned up nothing.

The source holds 4 orders worth $150. The warehouse holds 2 of them, worth $75. At this point the problem is visible: the task is red and the day is short by 2 orders.

A warehouse will often undo a single statement that fails midway. A load is rarely a single statement: batches, files and multi-step tasks all leave partial work behind when they crash.

The retry finishes the job, and the damage

The orchestrator waits 5 minutes and runs the task again at 02:08. The retry starts from the first line of the task. It reads all 4 orders for 2026-03-14 and appends all 4. This time the connection holds, the task turns green, and every downstream task is told the load succeeded.

order_idorder_dateamountwritten by
10012026-03-1430attempt 1
10022026-03-1445attempt 1
10012026-03-1430retry
10022026-03-1445retry
10032026-03-1420retry
10042026-03-1455retry

The last column is added for this page. The real table keeps no record of which attempt wrote a row.

daily_orders now holds 6 rows for a day with 4 orders. Orders 1001 and 1002 each appear 2 times. The dashboard sums the amount column and reports $225 for a day that earned $150, which is 50% too high. No alarm fires, because the final attempt succeeded and the task is green.

Recognizing the pattern

This failure needs 3 things at once: a write that appends, an attempt that fails after writing some of its rows, and something that runs the task again. Take away any one of them and the duplicates never appear, which is why the bug can hide for months in a pipeline that rarely fails.

The size of the overcount depends on how far the failed attempt got. Had it written all 4 rows and crashed before reporting success, the day would end with 8 rows and doubled revenue.

On another night the source has 10 orders for the day. Attempt 1 appends 7 of them and crashes. The retry runs the whole task and succeeds. How many rows does the warehouse hold for that day?

On both attempts the task did what its code says. The flaw is in what the write does when it runs a second time, and that behavior has a name.

About this lesson

This section is part of the Idempotent Reruns: Beginner lesson on DataDriven, the home of data engineering. Lessons cover SQL, Python, Spark, data modeling and pipeline architecture, and each section pairs its explanation with worked examples and practice you run as you go.