# Databricks REPLACE USING flows are GA: choosing the key and sequence

> REPLACE USING flows are GA in Lakeflow pipelines. The key and the sequence column decide whether a partial snapshot lands cleanly or loses rows.

By Preetham Reddy, 3 December 2026. Databricks Field Guide, TechFabric. Canonical: https://databricks.techfabric.com/notes/replace-using-flows-are-now-generally-available/

Some sources resend every row for a region, an account or a file whenever one of them changes, and we'd stop folding those into a table with [AUTO CDC](15-real-time-and-cdc.md#scd-type-2-keeping-history-with-auto-cdc) or a hand-written merge now that a flow exists for them. [REPLACE USING flows](https://docs.databricks.com/aws/en/ldp/flows-replace-using) became [generally available on 1 December 2026](https://docs.databricks.com/aws/en/release-notes/product/2026/december#replace-using-flows-are-now-generally-available) in Lakeflow pipelines and for standalone streaming tables defined in SQL, on Databricks Runtime 18.2 and above.

Our worry is quiet data loss. Two choices decide what survives each load, the key columns and the `SEQUENCE BY` column, and choosing either at the wrong grain drops rows or piles them up without a failed update to warn anyone.

> **Our position**: Use REPLACE USING when a source resends a whole group of rows at a time. Key it on the column that names that group, sequence it by a number the source stamps once per file in the order it produced them, and fail the update on a bad file so the group's last good rows stay in place.

```mermaid How a store's price file reaches the current price table
flowchart LR
  A["Store system writes a price file"] --> B["Export number on every row"]
  B --> C["Expectation fails a null export number"]
  C --> D["REPLACE USING store_id"]
  D --> E["store_prices_current"]
  E --> F["Store totals downstream"]
  E --> G["Per store count and freshness checks"]
```

## Take a store price feed

Take a feed where each store's system drops a file holding its whole price list whenever any price in it changes. We'd key the flow on `store_id` and sequence it by an export number the store's system writes onto every row of the file, rising with each file that store sends.

Each half of that design blocks a different loss.

Suppose someone keys it one level finer, on `store_id` and `sku`, so it looks like a primary key. Delisted products never leave. The new file has no row for them, and keys missing from an update are left untouched.

Closed stores keep their last price list under either key, for the same reason. If the business needs closed stores gone, we'd ask the source for full snapshots and use [AUTO CDC FROM SNAPSHOT](https://docs.databricks.com/aws/en/ldp/cdc), which compares snapshots to determine changes. If stores only go quiet, we'd alert on any store whose latest file is older than its usual interval, alongside the table-level freshness checks in the [observability chapter](36-observability.md#the-signals-already-in-the-platform), since one stale store hides easily inside a table that's otherwise current.

Sequencing by each row's `price_updated_at` loses rows the other way. Only the highest sequence for a key is applied, so the prices edited most recently land and the rest of that store's list is dropped. We'd expect this one to get through code review, because a per-row timestamp looks like the obvious sequence column.

## What we'd ask of the loader

The export number has to come from the store's system, stamped before the file leaves it. A number the ingest job assigns on arrival orders files by when they landed, so a delayed older file would replace a newer list, which is the out-of-order case the sequence column is there to stop.

Rows that share a key and a sequence are all kept, which is how a store's list survives as one group. It's also why we'd reject a store that sends two files under one number, since rows that [tie on key and sequence](https://docs.databricks.com/aws/en/ldp/flows-replace-using) are kept as duplicates.

We'd put an `expect_or_fail` on the export number too, since a null sequence can lead to undefined behaviour. Bad prices are harder. A `drop` expectation treats a dropped row as if the source never produced it, so on a group-keyed table we'd expect the file's remaining rows to replace the store's list without that product, which then disappears from the target until the next file. We'd fail the update instead and keep the old list visible while someone fixes the file.

## Cutting over from a merge

The merge this replaces is code we'd be glad to delete. Its delete-then-insert per store becomes the key, and its guard against a late, older file becomes the sequence.

It can't be switched in place, though. A REPLACE USING target has to be created within the pipeline and takes no other flow beside it, so we'd build the new table next to the old one, as a [standalone streaming table](https://docs.databricks.com/aws/en/sql/mv-st/streaming#replace-using) with the `BY NAME` the SQL form requires:

```sql
CREATE OR REFRESH STREAMING TABLE store_prices_current
FLOW REPLACE USING (store_id) SEQUENCE BY export_id BY NAME
SELECT store_id, sku, price, export_id
FROM STREAM(raw.store_price_files);
```

Before any report reads it, we'd compare row counts per store between the two tables after each load. A store whose count drifts points at a key at the wrong grain or a sequence that ties, before a reader finds it in a report. Store totals then go in a table downstream, because the flow's query can't aggregate.
