Queries icon
List icon
Loop icon
Assert icon
Download icon
Size icon
Move icon
Schedule icon

Commit SFTP JSON Batches to PostgreSQL Before Archiving

Ingest SFTP JSON batches into PostgreSQL with a transactional ledger, reject conflicting replays, and archive source files only after commit.

Categories
Data

Acknowledge partner deliveries only after their records and processing ledger commit together. Each feed/batch ID has one immutable SHA256; replaying identical bytes skips inserts, while changed content under the same ID fails.

How it works

  1. Create sample tables, then list up to ten ready files in name order. Ignore producer .part uploads.
  2. Download each file, enforce a 1 MiB bound, and obtain its SHA256 from the SFTP task.
  3. Validate JSON and insert the ledger plus records in one PostgreSQL transaction. SQL errors roll back both.
  4. Recheck the remote checksum, then move the source into an execution-specific archive directory.

What you get

  • Durable batch history and immutable per-batch inventory rows.
  • Retry after archive failure without duplicate inserts. SQL failure leaves the source in the inbox.
  • A quiet successful run when no files are ready; failed batches remain for operator correction.

Who it's for

Data engineers consuming small partner inventory snapshots over SFTP.

Why orchestrate this with Kestra

Native file tasks surround a database transaction, making the commit/acknowledgement boundary and retry behavior visible in one execution. No custom ingestion script is needed.

Prerequisites

PostgreSQL with permission to create/use kestra_sftp_ingest, and writable SFTP inbox/archive directories. Producers must publish immutable, unique *.ready.json names by renaming completed uploads; this flow must be their sole archiver. Keep bytes unchanged until acknowledged. Use a trusted network or a host-key-pinned SSH tunnel: the FS SFTP tasks do not enforce server host-key checking. The checksum recheck is not a filesystem lock.

Secrets

  • POSTGRES_JDBC_URL, POSTGRES_USERNAME, POSTGRES_PASSWORD: database connection.
  • SFTP_HOST, SFTP_USERNAME, SFTP_PASSWORD: the server and scoped partner account.

Quick start

  1. Configure secrets and the feed, port and directory inputs. Import without catalog-only extend.
  2. Publish batch.ready.json containing {"batch_id":"delivery-001","records":[{"item_id":"sku-1","quantity":12}]}. Use 1-1000 records, unique item IDs and nonnegative integer quantities.
  3. Execute and inspect the ledger, rows and archive. Repair failed source batches before retrying; never reuse a committed ID for different bytes.
  4. Set any non-default feed, port and directory inputs on the Schedule and enable it. Polling revisits unarchived files, including failed deliveries.

How to extend

Adapt the sample record schema, add failure notifications, or retain immutable raw snapshots with the ledger.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.