Skip to content

Replay failed Redshift loads ​

Use this runbook when a "Firehose dropped a batch it could not load into Redshift" alert lands in an <env>-data-alerts Slack channel. It covers what the alert means, how to find the cause, and how to replay the dropped batch so Redshift catches up with Luna.

What the alert means ​

Each service's streams Lambda sends DynamoDB changes to a Kinesis Firehose delivery stream. Firehose buffers them into batches (up to three minutes or 5 MB) and writes each batch as a gzipped object to the environment's Redshift data bucket in S3 (<env>-redshift-data-and-digital-luna-bucket), under the table's prefix (for example engagements_billing/2026/10/09/00/). It then COPYs that batch from S3 into a table in the Redshift staging schema. When a COPY fails, Firehose retries for the stream's retry window (300 seconds on most streams), then gives up and writes an error manifest to S3. That manifest triggers the alert.

By the time you see the alert:

  • The whole batch is missing from Redshift. COPY is all-or-nothing, so one bad record drops every record in that batch.
  • The data still exists. The original gzipped files are still in the bucket, and the manifest lists them. Replaying the manifest loads them.
  • Reports built on that table are wrong until the batch is replayed.

The alert names the manifest key. Its first segment is the table, and the file name contains the delivery stream:

text
engagements_billing/errors/manifests/2026/10/09/00/polaris-engagements-billing-redshift-deliverystream-1-2026-10-09-00-01-27-...

TIP

Failures are usually deterministic: the same record fails on every retry, and on every later batch that contains it. Fix the cause before you replay, or the replay fails the same way.

This runbook covers loads that reach Firehose. A failure inside a streams Lambda (for example a Firehose permission error) is logged in that Lambda's own log group and doesn't raise this alert. See Debug Redshift streams.

Environments ​

EnvironmentClusterDatabaseData bucketAWS account
polarispolarispolarispolaris-redshift-data-and-digital-luna-bucket851725171061
stagingstagingstagingstaging-redshift-data-and-digital-luna-bucket851725171061
productionprodprodproduction-redshift-data-and-digital-luna-bucket666243557741

Production is read-only for triage. Only run the replay steps in production once the data team has agreed the fix.

1. Find the cause ​

Firehose delivery logs ​

Firehose logs each failed attempt to the log group /aws/kinesisfirehose/<env>-redshift-delivery-streams (kept for 30 days), in the log stream <stream-name>-redshift-delivery (for example engagements-billing-redshift-delivery). This CloudWatch Logs Insights query summarises every failing stream over a time range:

sql
filter ispresent(errorCode)
| stats count(*) as attempts, min(@timestamp) as first_seen, max(@timestamp) as last_seen by @logStream, errorCode
| sort attempts desc

The log group only receives entries when a delivery fails, so an empty result means no failures in that range.

stl_load_errors ​

For Redshift.DataLoadFailed, Redshift records the failing row, column and reason. Run this in Query editor v2 on the environment's cluster, narrowing the time range to the alert:

sql
select e.starttime,
       p.name as tbl,
       trim(e.colname) as col,
       trim(e.type) as type,
       e.col_length,
       e.err_code,
       trim(e.err_reason) as reason,
       trim(e.raw_field_value) as raw_value,
       trim(e.filename) as file
from stl_load_errors e
left join (select distinct id, trim(name) as name from stv_tbl_perm) p on p.id = e.tbl
where e.starttime > '2026-10-09 00:00'
order by e.starttime desc
limit 50;

stl_load_errors keeps only a few days of history, so check it soon after the alert.

From the CLI

The Redshift Data API works with the cluster credentials secret, RedshiftCluserCredentials (the typo is in the secret's name). Run aws redshift-data execute-statement with --cluster-identifier, --database and --secret-arn, then describe-statement --id <id> and get-statement-result --id <id>.

Cluster health ​

If the logs show connection or cluster errors rather than a data error, check the cluster in the Redshift console around the alert time: status, events and maintenance, disk space and connections. This kind of failure is transient, so the batch can be replayed as soon as the cluster is healthy.

Common causes ​

ErrorExampleFix
Redshift.TableNotFoundThe stream's target table was never created in this environment.Create the table, or remove the stream if nothing uses it.
1204 String length exceeds DDL lengthengagement_contact_id was varchar(250) in polaris and an engagement with 7 contacts streamed 258 characters.Widen the column to match production, then replay.
8001 Invalid data, raw value like 1674816269655A timestamp column received raw epoch milliseconds because the streams code didn't convert the value.Fix the streams handler. Fix the data before replaying.
1204 Date value exceeds max length, with a free-text raw valueA ^ in user-entered text split the field, because ^ is the delimiter for every stream, so every following column shifted right.Fix the streams code. The batch can't be replayed as it is. Ask the data team how to handle it.

2. Replay the batch ​

Replay once the cause is fixed. If several batches dropped, replay them in time order.

All delivery streams use the same COPY options:

text
region 'eu-west-1' delimiter '^' timeformat 'auto' dateformat 'auto' acceptinvchars EMPTYASNULL COMPUPDATE OFF STATUPDATE OFF GZIP

Run these steps in one Query editor v2 tab, so the temporary table survives between statements. Replace the bucket, manifest key, account, environment, table and key column.

From the CLI

Each execute-statement call is a separate session, so the temporary table won't survive between calls. Pass the statements together to aws redshift-data batch-execute-statement --sqls "<statement 1>" "<statement 2>" ..., which runs them in one session and one transaction. describe-statement --id <id> shows each statement's status and any error. Fetch one statement's rows with get-statement-result --id <id>:<n>. COPY reports 0 result rows even when it loads data, so count the temporary table to see what it loaded.

  1. Load the dropped batch into a temporary copy of the staging table rather than straight into staging:

    sql
    create temp table replay_batch (like staging.<table>);
    
    copy replay_batch
    from 's3://<data bucket>/<manifest key from the alert>'
    iam_role 'arn:aws:iam::<account>:role/<env>-redshift-cluster-permissions-role'
    manifest
    region 'eu-west-1' delimiter '^' timeformat 'auto' dateformat 'auto'
    acceptinvchars emptyasnull compupdate off statupdate off gzip;
  2. Confirm none of those rows are already in staging. Match on the table's key column and load_timestamp (the last column of most staging tables); expect 0:

    sql
    select count(*)
    from replay_batch r
    join staging.<table> s
      on s.<key column> = r.<key column>
     and s.load_timestamp = r.load_timestamp;

    Steps 1 and 2 change nothing in staging, so run them on their own first as a dry run. Check select count(*) from replay_batch looks like a full batch before going on.

  3. Append the rows to staging:

    sql
    insert into staging.<table> select * from replay_batch;
  4. Confirm the rows landed. Use the batch's lowest and highest load_timestamp from replay_batch. Both counts should equal the dry run's row count:

    sql
    select count(*) as replayed_rows,
           sum(case when processed_ind = 0 then 1 else 0 end) as unprocessed
    from staging.<table>
    where load_timestamp between <min load_timestamp> and <max load_timestamp>;

Replayed rows arrive with processed_ind = 0 and their original load_timestamp, exactly as Firehose would have loaded them.

WARNING

Avoid replaying while the data team's scheduled jobs are writing to the same tables. Concurrent writes can cause Redshift serialisation conflicts.

3. Follow up ​

How a replayed row reaches the reports depends on what reads the staging table. Tell the data team which tables and time ranges you replayed.

  • Full-refresh dbt models (most transformed_* models, materialized='table') rebuild from staging.* on every run, so they pick up replayed rows on their next scheduled run.

  • Incremental dbt models (built on scd_transform_incremental or incremental_key_filter) only pick up rows newer than the latest update_timestamp they've already processed. A replayed row keeps its original, older load_timestamp, so these models skip it unless the same key also has a newer event. They need a --full-refresh. To list the models downstream of a staging table, run this from data/ after . ./load_env.sh (see the data/README.md setup):

    bash
    dbt ls --select "source:raw_data.<table>+" --resource-type model \
      --project-dir dbt_project --profiles-dir dbt_project --target <target>

    <target> is a dbt target from data/dbt_project/profiles.yml: polaris, staging or prod. Use prod for production, not production.

  • Redshift load procedures (for example staging.load_daily_allocations_absences for actuals) live in Redshift, not in this repo. Check with the data team before replaying into a table that one of them processes.

TIP

Re-saving records in Luna isn't a reliable way to recover. Streams only re-send a record when it changes, and some refreshes skip unchanged records completely: the actuals refresh (updateAndiActualsBetweenRange) ignores actuals whose content hasn't changed. Replay from the manifest instead.

Made with ❤️ by the Luna team