Skip to content

Envelope And Data Policy ​

Envelope mode is a payload compatibility policy. It does not imply Kafka.

The same envelope can be used over local execution, REST, gRPC, SQS, Kafka, or file-backed tests.

Recommendation ​

Keep typed DTO contracts as the normal TPF model. Add envelope compatibility only as an explicit boundary policy for onboarding, polyglot step hosts, and legacy or loose payload domains.

The control envelope must remain strict even when the payload is loose.

Do not allow arbitrary Object to become the whole runtime contract. Only the payload region may be loose.

Why Envelope Mode Exists ​

Use envelope mode for:

  1. Python or non-Java step hosts that should not depend on TPF internals,
  2. external services that already accept generic document envelopes,
  3. compatibility with platforms that use object-like payloads,
  4. gradual migration from loose payloads to typed contracts,
  5. exploratory AI/indexing pipelines where schemas are still changing.

Do not use it to avoid modeling stable business contracts. If the data shape is stable and correctness matters, typed DTOs and mapper validation remain the stronger TPF path.

Independent Decisions ​

DecisionExamplesOwner
Dispatch policylocal, REST, gRPC, SQS, KafkaRuntime boundary
Payload policytyped DTO, protobuf message, JSON envelope, bytes envelope, payload referenceData contract
Persistence policyappend-only record, cache entry, repository claim check, materialized output unitPlugin/runtime store
Replay policyrequire cache, prefer cache, recompute, replay from durable execution stateTPF runtime semantics

Valid combinations include:

BoundaryPayload policy
local step hosttyped DTO or envelope
REST remote operatortyped protobuf-over-HTTP or envelope
gRPC step hosttyped protobuf or envelope bytes
SQS transition workercommand/result envelope with typed serialized payload
Kafka checkpointtyped event or envelope event

If envelope mode requires Kafka, it becomes a Kafka feature. If envelope mode is independent from Kafka, it becomes a TPF compatibility policy.

Data Shapes ​

ShapeSafetyUse when
Typed DTOStrongestJava/TPF-owned code or stable domain contracts
Generated protobufStrongNon-Java step hosts can compile generated contracts
Envelope with schema hintMediumPayload evolves but schema/version is still declared
Envelope with JSON/bytes payloadWeakestCompatibility and rapid onboarding matter more than compile-time safety
Envelope with payload referenceMediumPayload is large and should be materialized out of line

Payload references are a data policy, not a broker policy. They can point to a repository, object store, SQL-backed materialization provider, Redis-backed cache, or local test harness.

Control Fields ​

A future envelope should reserve strict fields for TPF control semantics:

Field groupPurpose
Pipeline identitytenant, pipeline id, release version, contract version
Execution identityexecution id, step id, step index, attempt
Item identityitem id, parent item ids, lineage key, fan-in key
Boundary identityboundary kind, dispatch protocol, step-host id when known
Correlationcorrelation id, idempotency key, await interaction id when relevant
Replay/cachepipeline version, cache policy, replay flag, checkpoint id
Payload metadatapayload encoding, schema hint, content type, payload hash
Payload locationinline payload, bytes, JSON, or payload reference

The payload may be loose. These control fields may not be loose.

Envelope Without Kafka ​

Envelope mode should be usable without Kafka:

  1. Local envelope host: compatibility tests and gradual typing inside one process.
  2. REST envelope host: non-Java services that do not want generated DTO classes yet.
  3. gRPC envelope host: protobuf framing with loose payloads.
  4. SQS transition worker: current command/result envelope shape with serialized payload metadata.

Brokered Data Flow ​

For brokered execution, the record should carry a TPF envelope. The broker record key should derive from TPF semantics:

FlowCandidate key
one-to-one stepitem id or idempotency key
one-to-many outputparent item id plus output index
many-to-one fan-infan-in key or document id
await requestinteraction id or correlation id
checkpoint handoffcheckpoint id or business aggregate id

The broker key should support ordering and grouping, but fan-in correctness remains a TPF responsibility.