Skip to content

A scenario for a data engineer · Junior and up

Revenue doubled overnight

Query · Analytics
Monday, 08:40

A nightly Databricks job appended its batch to the Delta sales table, failed on a later step, and the retry appended the same batch again. The table now holds every order from last night two times.

What do you do?

Tap the one you would do. The answer opens below.

Show the best call

Restore the table to the version before the retry, then change the write to a MERGE on the order id.

Each order is there once again within a minute, and the next retry cannot double anything.

Why

A Delta table keeps its history, so RESTORE takes it back to an earlier version. A MERGE on the key makes a load safe to run twice, as long as the batch holds each key once: rows that are already there are updated, not added again.

Read it in the Databricks docs (opens in a new tab)

The other two

Works, at a price. Rewrite the table without the duplicate rows and leave the job as it is.
Clean for today. The next failed run will do it again.
A poor call. Tell the analysts to put DISTINCT in their queries.
Every report now has to remember. One of them will not.

The words in this scenario

RESTORE and table history.
A Delta table keeps a history of its versions. A query can read an earlier version, and RESTORE puts the table back to one. In the docs (opens in a new tab)
MERGE.
One statement that compares new rows with a table by a key: rows that match are updated or deleted, rows that do not are inserted. In the docs (opens in a new tab)

Go deeper on brickster.ai

More scenarios

Had one like this at work? Send it to us: the best tickets come from real incidents.

Checked against the Databricks documentation on . brickster.ai is independent and is not affiliated with Databricks.