ImportKit. Commit, fail, continue.

Import CSV or JSON Lines from a local file or an HTTP export into your database. ImportKit 1.0.0 validates each record and saves confirmed progress. The SQLite example shows what happens if a write succeeds just before the importer stops.

npm install @altitud-studio/importkit@1.0.0
Runtime
Node.js 24+
Included readers
CSV and JSONL
Version
v1.0.0
License
MIT

Failure happens between two acknowledgments.

This example keeps the checkpoint in a file and the orders in SQLite. A process can stop between the database commit and the checkpoint write.

  1. Read and validate

    The reader produces records and the application validates or transforms each one. Prepared values form a bounded batch.

  2. Persist the batch

    The destination commits its writes. The records already exist, even though ImportKit has not saved the new progress yet.

  3. Lose the acknowledgment

    The demo simulates a failure after the SQLite commit. With no checkpoint for that batch, the next run delivers it again.

  4. Replay the same identities

    IDs stay stable on resume, even with a different batch size. The example uses a unique constraint to recognise and deduplicate repeated deliveries.

The guarantees have explicit boundaries.

At-least-once delivery

With a separate checkpoint, a committed batch can be delivered again. The demo deduplicates by record ID. With one batch in flight, a destination can also persist the supplied checkpoint and rows in the same transaction to prevent that replay.

Identity before offsets

fileSource identifies a local file by its SHA-256. httpSource uses a strong ETag that must change with the content. Checkpoints count parsed records, so a quoted newline in CSV stays inside its row.

Two limits for each batch

batchSize limits record count. maxBatchBytes and measureRecordBytes work together to limit measured bytes per batch. Commits run one at a time by default. With concurrency set up to 16, batches may finish out of order and progress advances only through consecutive confirmed batches.

Measurement has its own contract

Keep mapped values stable until their commitBatch resolves. With one commit in flight, a pending batch and the next value can approach twice the measured byte budget. Concurrent commits retain more batches. Measure heap and RSS separately for your workload.

Validate before writing.

validateFile checks the source without writing to a destination or saving a checkpoint. Supply a Standard Schema v1 schema, a mapRecord function, or both. A schema runs before mapping.

const report = await validateFile({
  source: fileSource('./orders.csv'),
  reader: csvReader(),
  importId: 'orders-november',
  transformVersion: 'orders-v1',
  mapRecord: parseOrder,
  maxIssues: 100,
});

The example calls the application's parseOrder for each record. Issues identify its index and starting line. Schema issues can include the field path. maxIssues limits the details retained while the importer's counters keep running.

valid
Traversal completes without invalid records.
invalid
Traversal completes with records rejected by the schema or mapping.
incomplete
A structural parsing error stops traversal. Operational failures are thrown as errors.

You can reproduce the failure.

The demo uses fictional orders and a local SQLite database. It runs an import, simulates a lost acknowledgment and resumes to check destination deduplication.

git clone --branch v1.0.0 --depth 1 https://github.com/Altitud-Studio-S-L-U/importkit.git
cd importkit
npm ci
npm run demo:recovery

Run npm run demo:transactional to compare a second SQLite destination that commits rows and progress together. The large-file measurements below use a separate in-memory verification destination.

Read the executable example

Large-file measurements with ImportKit 0.3.0

Four imports with CSV and JSONL generated on disk. The result includes verified count, order, values and digest alongside the memory observed in each process.

Import process high-water RSS; one observation per case.
FileRecordsPeak RSS
CSV · 1 GB244,14181.91 MiB
CSV · 10 GB2,441,40785.39 MiB
JSONL · 1 GB244,14188.18 MiB
JSONL · 10 GB2,441,40781.86 MiB

Exact decimal sizes: 1 GB = 1,000,000,000 bytes and 10 GB = 10,000,000,000 bytes. 1 MiB = 1,048,576 bytes.

Node.js 24.11.1 on Linux WSL2 x64. Synthetic ASCII rows of approximately 4 KiB; batches capped at 1 measured MiB. A 512 MiB cgroup, with no swap or OOM events.

Each phase uses a fresh process. The 1 GB cases ran validation and import; the 10 GB cases ran import. Up to two cases overlapped and filesystem caches were not cleared.

The runner sets maxSourceBytes to the file size. The destination simulates acknowledgment with a bounded verifier, without a database; checkpoints are written to disk. These peaks describe the experiment and do not guarantee universal RAM usage.

What this tool covers.

The cost of traversal

O(N + R + H + B) describes an import with linear decoding. N counts source bytes, R records, H CSV columns and B committed batches. Schema validation, application callbacks and durable writes add their own costs.

A successful local import reads about 2N bytes and a full local validation reads 3N. An HTTP run with a strong ETag streams the response once. Resuming traverses the source from the beginning and skips mapping and delivery for confirmed records.

  • Included readers support CSV with headers and JSON Lines. Other formats can implement RecordReader; PDF extraction and XLSX, ZIP or XML readers are not included.
  • Sources must stay immutable during a run. httpSource requires a strong ETag, Content-Length and an unencoded HTTP 200 response from the final URL. A custom ByteSource can read other storage.
  • fileCheckpointStore can resume a checkpoint written by 0.3. A custom checkpoint store can implement lock() to coordinate concurrent workers.
  • The application supplies validation, permissions and idempotent persistence. Preflight validation does not make a later import globally transactional.
Read the full contract

Let’s talk about your next step.

Tell us what you need to build, connect or improve. Together, we define a starting point and a clear scope.

info@altitudstudio.ad

Altitud Studio SLU processes your data to answer your enquiry based on legitimate interest or handle your quote request by taking precontractual steps. You can exercise your rights of access, rectification, erasure and objection at info@altitudstudio.ad. Learn more in our privacy policy.

Your privacy

Altitud Studio SLU only activates optional cookies with your permission. Choose and save your preferences, or accept or reject all optional cookies. Necessary cookies remain active.