Skip to content

Interface Types and subType Execution in Delegator Batch

Interactive Diagram

새 탭 ↗

Creating a separate Batch application for every integration looks simple at first, but execution history, restart logic, connection management, and Trace policy are duplicated with every application. Putting every operation into one oversized Step creates the opposite problem: workloads with different throughput and failure semantics run under the same policy.

Delegator Batch keeps a common Runtime while selecting an execution strategy from a type and subType pair. The type identifies the source-to-target connection shape, while the subType identifies the data mutation strategy and processing boundary. Building on The Basic Structure of Spring Batch Jobs and Steps, this article explains how that classification affects memory, transactions, restart, and watermarks.

A type alone cannot select a complete execution policy. Two db2db jobs can have entirely different characteristics: replacing a small reference snapshot and incrementally upserting tens of millions of rows do not have the same memory or rollback boundary. A mutation label such as DELETE_INSERT alone is also insufficient because it does not say whether the source is an RDBMS, a search store, or an internal aggregation query.

typesubTypeExecution formSuitable use
db2dbDELETE_INSERT_COMMONTaskletReplace a small complete snapshot
db2dbUPSERT_COMMONTaskletMerge a bounded set in one operation
db2dbUPSERT_READER_WRITERChunkLarge or restartable incremental synchronization
restREST_COMMONTaskletInvoke a REST Transaction selected by Metadata
search2dbDELETE_INSERT_COMMONTaskletStore search results as a relational summary
platformBatchDELETE_INSERT_COMMONTaskletRebuild an internal aggregate table
platformBatchPURGE_COMMONTaskletDelete data according to retention policy

These values are not arbitrary class names. They form a restricted vocabulary that selects execution strategies registered in the Runtime. Allowing Configuration to inject class names or SQL strings directly would bypass validation and authorization boundaries.

interface:
id: if-order-sync-001
type: db2db
subType: UPSERT_READER_WRITER
sourceRef: order-source
targetRef: analytics-target
chunkSize: 500
watermark:
field: updatedAt
overlapSeconds: 30

sourceRef and targetRef are logical references resolved by the environment. Batch Metadata must not contain endpoints or credentials. Designing Metadata and Contracts for an Integration Platform covers the full Metadata structure and versioning model.

A Three-Step Skeleton Shared by Every Type

Section titled “A Three-Step Skeleton Shared by Every Type”

Placing execution records around the business Step gives different subTypes one observable lifecycle.

PlantUML Diagram
  • insertLogStep records the execution ID, Interface ID, source reference time, and starting status.
  • The Interface Step runs the selected strategy and produces read/write/skip counts and the processed range.
  • updateLogStep records final status, end time, counts, and any watermark that can be committed.

A simple .next(updateLogStep) does not run the final Step when the Interface Step fails. If failure status must always be recorded, use a JobExecutionListener or a failure transition to guarantee finalization. Do not automatically place business data and execution history in one transaction, however. If business rollback also removes the failure record, operators cannot determine whether an execution happened.

The distinction between Tasklet and Chunk is not a coding style choice. It defines commit and restart boundaries.

Chunk-oriented processing sequence in which a step reads items one by one and writes them through the ItemWriter once the chunk is full Source: Spring Batch docs, Chunk-oriented Processing, Spring Batch authors, Apache-2.0

CriterionTasklet bulk processingItemReader/Writer Chunk processing
MemoryMay retain the complete resultBounds memory through chunk size
TransactionWhole operation or an explicit blockUsually commits per chunk
RestartCommonly repeats the whole operationCan resume after a checkpoint
Record countSmall with a known upper boundLarge or continuously growing
Error isolationOne row can fail the operationRetry/skip policy can apply per item
ComplexityLowerRequires Reader state and idempotency design

Do not select a Tasklet only because a strategy is named UPSERT_COMMON. If source results exceed the memory limit or one transaction holds locks too long, use UPSERT_READER_WRITER. Conversely, a complex cursor checkpoint adds operational cost without benefit for a reference set of a few dozen rows.

Even in Chunk processing, a source and target in different databases do not acquire a distributed transaction automatically. A target chunk may commit before checkpoint persistence fails. The target write must therefore produce the same result when the same business key is replayed.

DELETE followed by INSERT makes it easy to align a target snapshot with its source. If the two statements run in separate transactions, however, a failure after DELETE can leave the target empty. A single transaction avoids that gap but can produce a large delete lock, transaction-log growth, and prolonged reader blocking.

For a small table, replace the data within one transaction. For a large table, load a staging table and switch to the validated snapshot. Before switching, compare source and staging counts and check required-key uniqueness. The first design question is not “Can DELETE be retried?” but “Which snapshot can readers observe after failure?”

A bulk UPSERT is appropriate for merging a small incremental set in one transaction. It requires a stable business key. Duplicate keys within one input batch must be removed first or rejected explicitly. The Contract should also say whether multiple records for one key select the last record or fail validation.

UPSERT helps replay, but it is not inherently idempotent. An update clause such as updatedAt = now() or an accumulated total produces a different result every time the same input is replayed.

Reader/Writer processing is appropriate when the data is large or partial restart is required. Offset pagination without a stable sort key can duplicate or omit rows while the source changes. Use a deterministic cursor such as (updatedAt, recordId) and persist its position in ExecutionContext.

A larger chunk is not always faster. It reduces round trips but increases heap use, lock duration, and rollback cost. Tune it using throughput together with p95 chunk duration, rollback count, and database lock wait.

REST_COMMON is a Tasklet that invokes a registered REST Transaction once rather than implementing business logic in the Batch job. When a timeout occurs, the destination may already have processed the request. Automatic retry requires confirmation that the destination supports an idempotency key.

search2db and platformBatch distinguish the data source and operational owner. Storing a search summary requires recording the query period and bucket limit. An internal aggregate records its source data and computed period. Keeping PURGE_COMMON separate from aggregation allows its execution order, permission, and retention cutoff to be reviewed independently.

Advance a Watermark Only for a Successful Range

Section titled “Advance a Watermark Only for a Successful Range”

Incremental extraction can use the previous completion time as the next starting point. Overwriting that value when the Job starts destroys the range needed for replay after failure. Keep in-progress and committed values separate.

committedWatermark = 2024-04-12T01:00:00Z
candidateUpperBound = 2024-04-12T02:00:00Z
queryRange = [committedWatermark - overlap, candidateUpperBound)

The Job fixes candidateUpperBound at startup and promotes it to the new committedWatermark only after the Interface Step succeeds completely. Recomputing the current time for every query changes whether records arriving during execution are included.

A short overlap reduces boundary loss by intentionally reading some rows again, so the target needs UPSERT semantics and a deduplication key. When timestamp precision is low or multiple rows can share a timestamp, store a tuple such as (updatedAt, recordId) instead of a timestamp alone. If source modification times can move backward, a timestamp watermark cannot guarantee correctness; consider a change sequence or CDC.

Design for Failure, Restart, and Concurrent Runs

Section titled “Design for Failure, Restart, and Concurrent Runs”

Failure handling differs by subType.

FailureDefault handlingReason
Invalid Metadata combinationReject before startupRetry cannot make it valid
Source connection timeoutBounded retryIt can be transient
Target deadlockRoll back the chunk and retry with backoffIt can relieve key contention
Schema or mapping errorQuarantine and failRepetition does not fix it
Lost REST responseDo not retry before checking idempotencyThe destination side effect may be complete
Failure during purgeRestart with the same cutoffRecomputing cutoff changes the deletion range

Prevent concurrent execution for the same Interface and business date with a lock or unique Job parameters. Adding a timestamp as an identifying parameter on every run defeats duplicate-run prevention. Assume restart can encounter an already committed chunk, and design target keys and write statements accordingly.

Operational records should include interfaceId, type, subType, JobExecution ID, read/write/skip/retry counts, committed and candidate watermarks, and chunk duration. They should not include complete payloads or connection information.

Even when Steps are created dynamically from Metadata, reject unsupported combinations before execution.

  • UPSERT_READER_WRITER requires chunkSize, a stable sort key, and a checkpoint policy.
  • DELETE_INSERT_COMMON requires an expected maximum count and a rollback or staging strategy.
  • A REST_COMMON retry policy must agree with the destination’s idempotency declaration.
  • PURGE_COMMON requires a retention basis, timezone, dry-run count, and maximum deletion count.
  • Resolve every reference through an allow-list and inject credentials from a secret store.
  • Record Metadata version and checksum in execution history so the Job’s behavior can be reproduced.

A type represents the connection shape, while a subType represents the mutation strategy and transaction boundary. Even under a common insertLogStep → Interface Step → updateLogStep skeleton, Tasklet and Chunk have different memory and restart properties and must be selected according to data volume and failure model.

DELETE-INSERT requires a snapshot-switching strategy, UPSERT requires stable business keys and idempotency, and Chunk requires checkpoints and tolerance for partial commits. A watermark must not be overwritten at startup; only a successfully processed range can be committed. These rules let one Batch Runtime execute many Interfaces without losing the consistency and operational meaning of each workload.