Skip to content
Source
Sign inSign up

Load failed batches

Site administration

Load the batches that never got in

Some events never got into ClickHouse, because it refused them or a batch failed every retry, and the consumer wrote them to object storage. Load each file into ClickHouse, then delete it.

2 min read

You need:

  • The Source repository on your computer, neonctl signed in to the TanStack organization on Neon, the AWS CLI and jq.
  • To be signed in to the server as root. See Sign in to the server.

1. Find the file

Each batch is one file in the bucket artifacts of the Neon project source-objects (late-paper-15050690), at analytics-dead/<day>/<id>.jsonl. <day> is the UTC day of the write, and <id> is the id of the first queue message of the batch.

For each file, the Worker logs an error with its name, for example wrote it to object storage at analytics-dead/2026-12-04/<id>.jsonl.

2. Download the file

On your computer, from the root of the Source repository, make a key that lives only for this work, and download the file with it:

umask 077
neonctl credentials create --project-id late-paper-15050690 --branch main --name dead-letters --scope storage:read --scope storage:write --output json > dead-letters-key.json
export AWS_ACCESS_KEY_ID="$(jq -r .token_id dead-letters-key.json)" AWS_SECRET_ACCESS_KEY="$(jq -r .s3_secret_access_key dead-letters-key.json)" AWS_REGION=us-east-1
export NEON_STORAGE="$(grep -o '"NEON_STORAGE_ENDPOINT": "[^"]*"' apps/web/wrangler.keys.jsonc | cut -d'"' -f4)"
aws configure set s3.addressing_style path
aws s3 cp "s3://artifacts/analytics-dead/<day>/<file>" <file> --endpoint-url "$NEON_STORAGE"

3. Copy the file to the server

scp <file> root@<server IPv4>:/root/<file>

4. Insert its rows

On the server, insert the rows of the file. The copy on the server goes only when the insert works:

clickhouse-client --password "$(cat /root/.clickhouse-admin)" --query "INSERT INTO analytics.events FORMAT JSONEachRow" < /root/<file> && rm /root/<file>

Note

If ClickHouse refused the rows before, this insert can fail for the same reason. ClickHouse then prints the reason. Correct the file or the table, then insert again.

5. Delete the file and the key

If the insert worked, delete the file in object storage and your own copy, then revoke the key. Run this on your computer:

aws s3 rm "s3://artifacts/analytics-dead/<day>/<file>" --endpoint-url "$NEON_STORAGE"
rm <file>
neonctl credentials revoke "$(jq -r .token_id dead-letters-key.json)" --project-id late-paper-15050690
rm dead-letters-key.json

Done

The events of the file are in analytics.events, and the file is gone from object storage.

If you load a file two times, ClickHouse keeps one row for each uuid when it merges the parts of the table.

About these files

  • The consumer writes a file when ClickHouse refused the rows (a 400 or 413 answer), or when the batch failed every retry. If ClickHouse is down explains the retries.
  • Each line of the file is one row of analytics.events, as JSON.
  • Nothing deletes these files. Delete each file after you load it.
  • Files from before the move to object storage are in the R2 bucket gitflare-analytics, under dead/. They go with that bucket.