How Do You Detect a Sudden Drop in Row Count?

The table updated on time and loaded 40% of the rows. Freshness says healthy. How to catch volume drops cheaply in Snowflake and Databricks.

How Do You Detect a Sudden Drop in Row Count?

Row count monitoring is the practice of measuring how many rows a table holds, or how many rows each load added, and alerting when that number moves outside the range the table normally produces. It's the cheapest data quality signal you can collect, and it catches the class of failure that every other cheap signal misses: the pipeline ran, on time, without errors, and delivered the wrong amount of data.

That failure is more common than the loud ones. A job that crashes pages somebody. A job that succeeds with 60% of its input pages nobody, and the first person to notice is usually an analyst asking why yesterday's revenue looks soft.

Why does volume catch what freshness misses?

Because freshness answers "did something arrive?" and volume answers "did enough arrive?" Those are different questions, and the second one is where partial failures hide.

Freshness monitoring watches a timestamp. If MAX(loaded_at) is recent, the table is fresh. That check passes the moment a single row lands. It has no opinion on whether that load contained 1,000,000 rows or 400.

Here are the failures that pass a freshness check and fail a volume check, all of which I've seen or caused:

  • Partial loads. An extract paginates through an API, hits a rate limit on page 40 of 100, and the connector treats the 429 as end-of-data. The load commits 40% of the rows and reports success.
  • A filter bug. Someone changes WHERE status IN ('paid', 'refunded') to WHERE status = 'paid' in a refactor. Every downstream model still builds. Refunds quietly vanish from the revenue table, which is now about 8% smaller.
  • A dropped partition. An upstream job overwrites a date partition with an empty result because its own source was late. The table is "updated" at 06:00 with zero rows for yesterday.
  • A dedupe gone wrong. A ROW_NUMBER() OVER (PARTITION BY customer_id ...) should have partitioned by order_id. Every customer now has exactly one order. The table shrinks by 70% and every row in it is individually valid.

Nothing errors in any of these. Schema, null and freshness checks all pass. Volume is the only cheap check that asks whether the total is plausible.

Failure Freshness check Schema check Null-rate check Volume check
Job didn't run Fails Passes Passes Fails (rows added = 0)
Partial load (40% of rows) Passes Passes Passes Fails
Filter bug drops a segment Passes Passes Passes Fails if segment is >10%
Empty partition overwrite Passes Passes Passes Fails
Bad dedupe key Passes Passes Passes Fails
Column renamed upstream Passes Fails Often fails Passes
Wrong values, right count Passes Passes Passes Passes

The last row is the honest limit: volume can't see the right number of wrong rows. That's for distribution and validity checks, covered in the anomaly detection guide. Volume is the first line, not the only one.

What's the difference between total rows and rows added?

Total rows is the size of the table right now. Rows added is the size of the most recent load. For most tables you should monitor the second one, and teams that monitor the first one usually find out why the hard way.

The arithmetic problem with total rows is dilution. Take an append-only events table with 500 million rows that grows by 2 million a day. A load that delivers 800,000 rows instead of 2 million is a 60% shortfall in what arrived today. As a change in total rows, it's the difference between +0.40% and +0.16%. Both numbers look like a healthy table growing. Any threshold loose enough to tolerate normal variance in a 500-million-row total will never fire on that.

Rows added doesn't dilute. Today's load is compared to previous loads of the same kind, so a 60% shortfall shows up as a 60% shortfall.

Total rows is still the right metric in two cases:

  1. Full-refresh tables. If the table is rebuilt from scratch every run, the total is the load. A dimension table of 40,000 customers that comes back with 22,000 has a problem, and the total tells you directly.
  2. Tables that should never shrink. An append-only ledger losing rows means something deleted data that shouldn't have. A simple "total today is less than total yesterday" check catches it with no learning period at all.

There's a third metric worth knowing about: rows by event date. Instead of counting what the last load added, you count rows whose business timestamp falls in a given day, like COUNT(*) WHERE order_date = CURRENT_DATE - 1. It answers "do we have a full day of orders for yesterday?" regardless of how many loads delivered them. It's the most meaningful metric for business users and the one most distorted by late data.

How do you get row counts cheaply in Snowflake?

Snowflake keeps a row count for every table in its metadata, and reading it costs effectively nothing because no table data is scanned.

The per-database view is INFORMATION_SCHEMA.TABLES, which has a ROW_COUNT column alongside BYTES and LAST_ALTERED:

-- Current row counts for every base table in one schema.
SELECT
    table_schema,
    table_name,
    row_count,
    bytes,
    last_altered
FROM analytics.INFORMATION_SCHEMA.TABLES
WHERE table_type = 'BASE TABLE'
  AND table_schema = 'MARTS'
ORDER BY row_count DESC;

For the whole account in one query, SNOWFLAKE.ACCOUNT_USAGE.TABLES has the same ROW_COUNT column plus a DELETED timestamp, but Snowflake documents its latency as up to 90 minutes. That's fine for a daily volume check and too slow for an hourly one.

The catch with both views: they're a snapshot. They tell you the count now, not the count yesterday. To get rows added per load you have to keep your own history, which is one table and one scheduled task:

CREATE TABLE IF NOT EXISTS monitoring.row_count_snapshots (
    captured_at   TIMESTAMP_LTZ,
    table_catalog STRING,
    table_schema  STRING,
    table_name    STRING,
    row_count     NUMBER,
    bytes         NUMBER,
    last_altered  TIMESTAMP_LTZ
);

CREATE OR REPLACE TASK monitoring.snapshot_row_counts
    WAREHOUSE = monitoring_wh
    SCHEDULE = 'USING CRON 0 * * * * UTC'
AS
INSERT INTO monitoring.row_count_snapshots
SELECT CURRENT_TIMESTAMP(), table_catalog, table_schema, table_name,
       row_count, bytes, last_altered
FROM analytics.INFORMATION_SCHEMA.TABLES
WHERE table_type = 'BASE TABLE';

ALTER TASK monitoring.snapshot_row_counts RESUME;

Then the change between snapshots is a window function:

SELECT
    table_schema,
    table_name,
    captured_at,
    row_count,
    row_count - LAG(row_count) OVER (
        PARTITION BY table_catalog, table_schema, table_name
        ORDER BY captured_at
    ) AS rows_changed
FROM monitoring.row_count_snapshots
WHERE captured_at >= DATEADD(DAY, -7, CURRENT_TIMESTAMP())
ORDER BY table_schema, table_name, captured_at;

rows_changed is net change: insert 100,000 and purge 100,000 in the same hour and it reads zero. Fine for append-only tables, wrong for anything with deletes.

For tables fed by COPY INTO or Snowpipe, Snowflake gives you that load-level number directly through the COPY_HISTORY table function. It returns one row per file with ROW_COUNT, ROW_PARSED, ERROR_COUNT and a STATUS that includes Partially loaded and Load failed, which is exactly the partial-load case:

SELECT
    DATE_TRUNC('hour', last_load_time) AS load_hour,
    COUNT(*)                           AS files,
    SUM(row_count)                     AS rows_loaded,
    SUM(error_count)                   AS errors,
    COUNT_IF(status <> 'Loaded')       AS files_not_fully_loaded
FROM TABLE(raw.INFORMATION_SCHEMA.COPY_HISTORY(
    TABLE_NAME => 'EVENTS',
    START_TIME => DATEADD(DAY, -7, CURRENT_TIMESTAMP())
))
GROUP BY 1
ORDER BY 1;

The function only looks back 14 days, so if you want a 30-day baseline, write its output to your own table daily as well.

ACCOUNT_USAGE.QUERY_HISTORY has ROWS_INSERTED per statement but no column naming the target table, so you'd be parsing QUERY_TEXT. I wouldn't build a monitor on regex over SQL.

How do you get row counts cheaply in Databricks?

Databricks splits the problem differently. The total is harder to get from metadata, and the per-load number is easier.

Start with what people expect to work and doesn't. DESCRIBE DETAIL returns numFiles, sizeInBytes, lastModified and a handful of table properties. It has no row count column: the documented output has 16 columns and none of them is numRows.

The per-load number lives in the Delta transaction log, exposed through DESCRIBE HISTORY. Every write records an operationMetrics map, and the keys you want depend on the operation:

Operation Rows added key Rows removed key
WRITE, COPY INTO, CREATE/REPLACE TABLE AS SELECT numOutputRows none
STREAMING UPDATE numOutputRows none
MERGE numTargetRowsInserted numTargetRowsDeleted
DELETE none numDeletedRows
UPDATE none (numUpdatedRows changes rows in place) none
TRUNCATE none file counts only

One trap in that table: MERGE also reports numOutputRows, but that count includes rows copied unchanged while rewriting files. Use numTargetRowsInserted for MERGE or you'll be measuring file rewrite size, not new data.

DESCRIBE HISTORY can be used as a subquery, so you can pull a clean per-load series with plain SQL:

SELECT
    version,
    timestamp,
    operation,
    operationParameters['mode'] AS write_mode,
    CASE
        WHEN operation = 'MERGE'
            THEN CAST(operationMetrics['numTargetRowsInserted'] AS BIGINT)
        WHEN operation IN ('WRITE', 'STREAMING UPDATE', 'COPY INTO',
                           'CREATE TABLE AS SELECT', 'REPLACE TABLE AS SELECT')
            THEN CAST(operationMetrics['numOutputRows'] AS BIGINT)
    END AS rows_added,
    COALESCE(
        CAST(operationMetrics['numTargetRowsDeleted'] AS BIGINT),
        CAST(operationMetrics['numDeletedRows'] AS BIGINT)
    ) AS rows_deleted
FROM (DESCRIBE HISTORY main.sales.orders)
WHERE timestamp >= current_timestamp() - INTERVAL 14 DAYS
ORDER BY version DESC;

write_mode matters. A WRITE with mode Overwrite is a full refresh, so its numOutputRows is the new total, not an increment. Mixing overwrite and append versions in the same baseline gives you nonsense.

Delta keeps 30 days of history by default (delta.logRetentionDuration), so you get a month of baseline for free. On Snowflake, collection starts the day you create the snapshot task.

For the total, you have two options. COUNT(*) works and on a large table costs compute. Or compute statistics and read them back:

ANALYZE TABLE main.sales.orders COMPUTE STATISTICS;

-- The "Statistics" row reads like: 1843 bytes, 2 rows
DESCRIBE TABLE EXTENDED main.sales.orders;

ANALYZE without NOSCAN scans, so it isn't free, though predictive optimization runs it for you on Unity Catalog managed tables. I'd monitor rows added from history and treat the total as secondary.

Here's the side-by-side:

Need Snowflake Databricks
Current total rows, no scan INFORMATION_SCHEMA.TABLES.ROW_COUNT Statistics from ANALYZE (scans when it runs)
Account-wide totals ACCOUNT_USAGE.TABLES (up to 90 min latency) Loop over tables, or a scheduled COUNT(*)
Rows added per load Snapshot diff, or COPY_HISTORY for loads DESCRIBE HISTORY operation metrics
Built-in history None for counts, 14 days for COPY_HISTORY 30 days of log by default
Rows deleted Snapshot diff only (net) numDeletedRows, numTargetRowsDeleted

Which volume check fits which table?

This is the part most volume monitoring gets wrong: applying the same check to every table. The right check depends on how the table is loaded, and a check that's correct for one load pattern produces false alarms or blind spots on another.

Here's the classification I use. Find your table's load pattern in the left column and that row tells you what to measure and what will fool you.

Load pattern How to recognize it Metric to watch Threshold style What fools it
Append-only incremental Rows only inserted; MERGE/DELETE never appear Rows added per load Learned baseline, per weekday Late data shrinks today, inflates tomorrow
Full refresh CREATE OR REPLACE, truncate-insert, Overwrite mode Total rows after each run Ratio to previous run (e.g. within 15%) A refresh that fails halfway can leave an empty table that is still "fresh"
Merge / upsert MERGE in history, updates outnumber inserts Rows inserted, plus total Learned baseline on inserts; total should never drop Total barely moves even when inserts fail
Partition overwrite Daily replaceWhere or INSERT OVERWRITE of one date Rows for the overwritten partition Compare partition to same weekday last week Overwriting with an empty source
Periodic snapshot Full copy of a source appended with a snapshot_date Rows per snapshot_date Ratio to previous snapshot (within 5% is typical) Total grows linearly and looks healthy forever
Event stream / micro-batch Many small writes per hour, STREAMING UPDATE Rows per hour, aggregated Learned baseline per hour-of-week Individual batches are too noisy to score
Soft-delete / SCD2 is_deleted or valid_to columns Active rows (WHERE valid_to IS NULL) Ratio to previous day Total rows only ever goes up

Three rows deserve emphasis.

Snapshot tables are the worst case for total-row checks. A table that appends a full copy of a 2-million-row source every night grows by about 2 million rows a day forever. If tonight's snapshot comes back with 300,000 rows, the total still goes up. A total-row monitor sees growth, a freshness monitor sees a recent snapshot_date, and the dashboard filtered to the latest snapshot shows a business that lost 85% of its customers overnight.

Merge tables hide insert failures inside a stable total. At 5,000 new customers a day on a base of 3 million, an upsert that silently stops inserting moves the total by 0.17% a day.

Full-refresh tables are the easiest case. The previous run is a perfect baseline and a ratio check needs no learning period. If you're starting from zero, start here.

How should you set the thresholds?

The short version: learn a baseline per table from its own history, segment it by weekday, alert on drops harder than on spikes, and add a ratio floor that catches the catastrophic case even when the statistics are confused.

Learn, don't hand-pick. A hand-set minimum like "at least 100,000 rows" is wrong within a quarter as the business grows. A learned baseline moves with the table. The standard approach is mean plus or minus k standard deviations over the last 4 to 8 weeks, where k between 2 and 3 is a reasonable start.

Segment by weekday. Most business tables load far less on weekends. A B2B orders table might do 40,000 rows on a Tuesday and 6,000 on a Sunday. Pool those into one baseline and the standard deviation becomes so wide that a Tuesday with 15,000 rows, a 60% drop, sits comfortably inside it. Comparing Tuesday only to previous Tuesdays fixes that. It also means you need more history: 4 weeks of data is only 4 samples per weekday.

Use the median when you can. One bad day in the history (a backfill that loaded 10x normal) drags the mean and inflates the standard deviation for weeks. The median ignores it.

Weight drops and spikes differently. In my experience the expensive failures are drops: missing data that someone reports on. Spikes are usually duplicates or backfills, which are worth knowing about and rarely worth a page. Alert on drops, warn on spikes.

Add a hard ratio floor. Statistics fail in exactly the situations you care about most: new tables, tables with erratic history, tables whose baseline is already polluted. A rule like "anything below 50% of the median is critical regardless of standard deviation" catches the 40%-of-rows partial load even when the learned band is useless.

Put together, assuming you've built a monitoring.load_volumes table with one row per table per load date (from the snapshot diff, COPY_HISTORY, or DESCRIBE HISTORY queries above), this runs on both Snowflake and Databricks SQL:

WITH baseline AS (
    SELECT
        table_name,
        DAYOFWEEK(load_date)  AS dow,
        MEDIAN(rows_added)    AS median_rows,
        STDDEV(rows_added)    AS sd_rows,
        COUNT(*)              AS samples
    FROM monitoring.load_volumes
    WHERE load_date >= DATEADD(DAY, -56, CURRENT_DATE())
      AND load_date <  CURRENT_DATE()
    GROUP BY table_name, DAYOFWEEK(load_date)
)
SELECT
    t.table_name,
    t.rows_added,
    b.median_rows,
    ROUND(t.rows_added / NULLIF(b.median_rows, 0), 2) AS ratio_to_median,
    CASE
        WHEN b.samples < 4                                THEN 'learning'
        WHEN t.rows_added = 0                             THEN 'critical'
        WHEN t.rows_added < 0.5 * b.median_rows           THEN 'critical'
        WHEN t.rows_added < b.median_rows - 3 * b.sd_rows THEN 'warning'
        WHEN t.rows_added > b.median_rows + 4 * b.sd_rows THEN 'warning'
        ELSE 'ok'
    END AS status
FROM monitoring.load_volumes t
JOIN baseline b
  ON b.table_name = t.table_name
 AND b.dow = DAYOFWEEK(t.load_date)
WHERE t.load_date = CURRENT_DATE();

Eight weeks gives 8 samples per weekday, and the samples < 4 guard keeps a new table quiet until it has enough history to judge. The spike threshold uses 4 standard deviations against 3 for drops, which encodes the asymmetry above.

Start at k = 3 for drops and count false alarms for two weeks. More than one a week means the wrong check for the load pattern or missing weekday segmentation; loosening k is the last fix, not the first. A volume monitor that fires weekly on noise gets muted, and a muted monitor is worse than none because it looks like coverage. The same dynamic shows up at scale as an alert storm, where one upstream drop fans out into a volume alert on every downstream table.

What breaks volume monitoring?

Every one of these produces a false alarm, a missed failure, or both. Most volume monitors that teams abandon were killed by one of them.

Late-arriving data. If you count rows by event date, yesterday is never complete at 06:00. Mobile events trickle in for 48 hours; a partner file for Monday arrives Wednesday. A check on "rows where event_date = yesterday" at 06:00 sees a 20% shortfall every single day, and a fix is to measure the same lag consistently: compare yesterday-at-06:00 to the previous day-at-06:00 values from history, not to final settled counts. Counting by load time instead of event time sidesteps the problem entirely, which is a good reason to prefer rows-added-per-load for alerting and keep event-date counts for reporting.

Deletes and retention jobs. A nightly job that purges rows older than 90 days makes net change negative or flat on a table that loaded perfectly. If you're diffing snapshots, you'll alert on every purge. Either measure inserts directly (Databricks history, COPY_HISTORY), or schedule the snapshot so the purge and the load land in different windows.

Backfills. A backfill that reloads 30 days of history produces a 30x spike, then pollutes the baseline for the next 8 weeks. Medians help. Better is to exclude known backfill loads from the baseline, which is easy on Databricks if your backfill jobs set a userMetadata commit message, and easy anywhere if your orchestrator tags them.

Checks that run mid-load. Truncate-then-insert leaves a window where the table is empty, and a check on a clock can land in it. Trigger volume checks from the orchestrator after the job completes.

Seasonality beyond weekly. A weekday baseline can't know that month-end runs 3x normal on a billing table. Keep a short list of known-heavy days and suppress spike warnings on them; for most teams that beats modeling it.

Upstream volume that genuinely dropped. Sometimes the business really did have a bad day, or a marketing campaign ended. A volume monitor can't tell a real drop from a broken one by looking at a single table. Comparing a table to its upstream source helps: if raw_orders dropped 30% and fct_orders dropped 30%, the pipeline is fine and the business is not. If raw_orders is flat and fct_orders dropped 30%, the pipeline lost data. That ratio check is the most useful volume check most teams never build, and it pairs naturally with pipeline monitoring at each hop.

How does AnomalyArmor handle row counts?

I built AnomalyArmor's row count monitoring, so here's what it actually does today, including where it's weaker than the approach above.

It counts with a query, not metadata. Each check runs SELECT COUNT(*) against the table. If the schedule has a timestamp column configured, it counts rows whose timestamp falls in a trailing window (1, 6, 12, 24 or 168 hours, default 24) instead of the whole table. That trailing-window count is a rows-added proxy based on the table's own timestamp, which means it's subject to the late-data problem above in a way that Databricks history metrics aren't. On a large table without a timestamp column, it's a full count, and the cost of that depends on your warehouse.

It's on by default alongside freshness. When you create a freshness schedule, a row count schedule is created with it, using the same timestamp column, checking hourly, in learning mode, with sensitivity 2.

Learning, then a band. It needs 7 measurements before it judges anything, and baselines on up to 30 days of history. The band is mean plus or minus sensitivity times the sample standard deviation, where sensitivity runs from 1 (tight) to 4 (loose). If the history has zero variance, it falls back to a percentage margin of 10% per sensitivity step.

Drops are graded, spikes aren't. A count below the band is a warning, and below half the band's lower edge it's an anomaly. A count above the band is only ever a warning. That's the same asymmetry I argued for above.

Explicit thresholds are an option. You can turn learning off and set a minimum, and if you don't set a maximum it defaults to 10x the minimum.

Weekday handling is opt-in, and it's a different model from per-weekday baselines. There's an operating-period mode that splits history into active and dormant periods, either from a configured business-hours schedule or learned automatically. In a dormant period a low count is expected and only unexpected activity is flagged. With that mode off, which is the default, the baseline pools every measurement together. The pattern analysis does detect seasonality, but the threshold it produces is still one mean and one standard deviation, so a strong weekly cycle widens the band rather than being modeled per weekday. That's the honest weak spot, and if your table has a 6x weekday-to-weekend swing, either turn on operating periods or expect the band to be loose.

Where results go. Each check writes to a history table, and warnings, anomalies and errors show up in the asset's action-required list. Backfilling history is supported if the schedule has a timestamp column, so you don't always have to wait a week for the learning period.

What it doesn't do: it doesn't read DESCRIBE HISTORY operation metrics or COPY_HISTORY, so it can't separate inserts from deletes on a merge table the way the queries above can. It's a side project, and that's on the list rather than shipped.

What should you set up this week?

Five steps, in order of return on effort.

  1. Classify your top 20 tables by load pattern. Use the table in the load-pattern section above. This takes an hour and tells you which tables a generic total-row check is actively misleading you on, which is usually the snapshot and merge tables.
  2. Turn on ratio checks for full-refresh tables. No learning needed. "Within 15% of the previous run" catches the catastrophic case on day one.
  3. Start collecting load-level history. On Snowflake, create the snapshot task now, because every day you wait is a day of baseline you don't have. On Databricks, you already have 30 days in DESCRIBE HISTORY; materialize it to a table so it survives log cleanup.
  4. Add the 50% floor everywhere. Before tuning any statistics, a single "rows added below half the weekday median is critical" rule catches most of the expensive failures in this post.
  5. Build one upstream ratio check. Pick your most important fact table and compare its daily rows added to its main source. That one check distinguishes "the pipeline lost data" from "the business had a slow day," which is the first question anyone asks when a volume alert fires.

Volume won't catch wrong values. It will catch missing data, which is the failure that most often reaches a stakeholder before it reaches you. For where it sits next to schema, freshness and distribution checks, the data quality dimensions post maps the whole set.

Frequently asked questions

What is row count monitoring?

Row count monitoring tracks how many rows a table holds or how many each load adds, and alerts when the number falls outside the table's normal range. It catches partial loads, filter bugs and dropped partitions that pass freshness and schema checks.

What is the difference between volume monitoring and freshness monitoring?

Freshness checks whether new data arrived recently. Volume checks whether enough arrived. A load that delivers 40% of its rows on time passes freshness and fails volume, so you need both.

Should I monitor total rows or rows added per load?

Rows added per load for append and merge tables, because a large total dilutes a big shortfall into a fraction of a percent. Total rows for full-refresh tables, where the total is the load, and for tables that should never shrink.

How do I get a table's row count in Snowflake without scanning it?

Query INFORMATION_SCHEMA.TABLES and read ROW_COUNT. For every database at once, SNOWFLAKE.ACCOUNT_USAGE.TABLES has the same column, with up to 90 minutes of latency.

Does DESCRIBE DETAIL return a row count in Databricks?

No. It returns file count, size in bytes and table properties. For rows written per operation, use the operationMetrics column from DESCRIBE HISTORY. For a total, use COUNT(*) or the statistics from ANALYZE TABLE ... COMPUTE STATISTICS.

Which Delta operation metric shows rows added by a MERGE?

numTargetRowsInserted. MERGE also reports numOutputRows, but that includes rows copied unchanged during file rewrites, so it overstates new data.

What threshold should I use for a row count drop?

Start with 3 standard deviations below a weekday median, plus a hard floor that flags anything under 50% of the median as critical. Tune by counting false alarms over two weeks rather than by guessing.

Why does my row count check alert every Monday?

Your baseline almost certainly pools weekdays and weekends, so Monday's load gets compared to an average dragged down by Saturday and Sunday. Segment the baseline by day of week.

How do I handle late-arriving data in volume checks?

Count by load time, not event time, for alerting. If you must count by event date, compare against historical counts taken at the same lag, such as yesterday-at-06:00 versus previous days-at-06:00, rather than against final settled totals.

Do deletes break row count monitoring?

They break net-change checks. A purge job makes a healthy load look like a drop. Measure inserts directly where the platform exposes them, or schedule snapshots so the purge and the load fall in separate windows.

How do I tell a real business drop from a pipeline bug?

Compare the table's volume to its upstream source. If both dropped by the same percentage, the data is probably real. If the source is flat and the downstream table dropped, the pipeline lost rows.