Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:173TECH Sayn Batch Processing

From Leeroopedia
Knowledge Sources
Domains Data_Engineering, ETL
Last Updated 2026-10-17 00:00 GMT

Overview

Technique for processing large incremental loads in bounded batches to control memory usage and enable resumable merge operations.

Description

Batch processing in SAYN applies to incremental copy tasks with max_merge_rows. Instead of loading and merging the entire incremental dataset at once, the task:

  • Loads a batch of max_merge_rows records
  • Merges the batch into the destination
  • Repeats until fewer than max_merge_rows records are returned (indicating the last batch)
  • Capped at 100 iterations to prevent infinite loops

This solves the problem of large incremental loads that would exceed memory or transaction limits. Additionally, max_batch_rows controls the INSERT batch size within each load operation.

Usage

Use this principle when incremental datasets are too large for a single merge operation. Set max_merge_rows for the outer merge loop and max_batch_rows for the inner insert batching.

Theoretical Basis

The batched merge loop:

# Abstract algorithm (NOT real implementation)
for _ in range(100):  # Safety cap
    count = execute(limit=max_merge_rows)
    if count < max_merge_rows:
        break  # Last batch

Each batch:

  1. Query source with LIMIT max_merge_rows ordered by incremental_key
  2. Load into temp table
  3. Merge temp into destination by delete_key
  4. Drop temp table

Practical Guide

# tasks/copy.yaml
copy_large_table:
  type: copy
  source:
    table: events
    db: source_db
  destination:
    table: events
    db: warehouse
  incremental_key: event_id
  delete_key: event_id
  max_merge_rows: 100000  # Merge in batches of 100k
  max_batch_rows: 5000    # Insert in batches of 5k

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment