← All articles
DataWeave · MuleSoft · Quick Reads · Performance

DataWeave Streaming for Large Payloads: What Changes

When a Mule flow processes a very large CSV, JSON, or XML document, the transformation itself may be simple while memory becomes the real constraint.

DataWeave supports streaming so supported inputs can be processed incrementally instead of requiring the complete document to be indexed in memory first.

That does not mean every DataWeave expression automatically becomes memory-efficient when streaming is enabled.

The transformation must also be compatible with sequential access.

The Core Difference

Without streaming, a useful simplified model is:

read complete document
        |
        v
build/index representation
        |
        v
run transformation

With streaming:

read record
   |
transform
   |
read next record
   |
transform
   |
...

For supported formats, the streaming unit is generally a record or repeated element: for example a row in CSV or an element in a JSON array.

This can substantially reduce peak memory when the transformation can operate one unit at a time.

Example: Streaming-Friendly Mapping

Suppose the input contains a large array of customers.

%dw 2.0
output application/json
---
payload map (customer) -> {
    id: customer.Id,
    name: customer.Name,
    active: customer.Status == "Active"
}

Conceptually, each customer can be transformed independently. The transformation does not need to inspect a future customer before producing the current result.

That is a good fit for streaming.

Sequential Access Is the Important Constraint

Streaming means DataWeave cannot assume arbitrary random access to the complete document.

Patterns that require knowledge of the entire input may require buffering or otherwise reduce the benefit.

Examples to examine carefully include operations that conceptually require:

  • global sorting,
  • repeatedly traversing the same stream,
  • accessing far-ahead data before processing the current record,
  • or constructing a complete in-memory structure before output can begin.

For example, globally sorting millions of records inherently requires a very different memory profile than independently mapping those records.

Streaming Does Not Fix a Large Output Object

Consider this pattern:

payload groupBy $.country

Even if input reading is streamed, grouping the entire data set may require retaining large amounts of state because the final groups depend on all records.

The lesson is important:

Streaming the input does not guarantee that the transformation itself has bounded memory usage.

Think about both input access and the state your algorithm accumulates.

Deferred Output Can Help the Other Side

DataWeave can also support deferred output in appropriate scenarios, allowing generated output to be consumed as it is produced rather than fully materializing it first.

This is especially useful in a pipeline such as:

large source
   |
streaming DataWeave transform
   |
deferred output
   |
downstream writer

The downstream component must also be able to consume the stream appropriately. If a later processor converts everything back into an in-memory object, the end-to-end benefit can disappear.

Think End to End

A common mistake is optimizing one transformation while another stage still materializes the entire payload.

Review the complete flow:

HTTP/File/SFTP reader
        |
        v
DataWeave
        |
        v
logger?
        |
        v
connector
        |
        v
target

Questions to ask:

  1. Can the source connector provide a stream?
  2. Is the DataWeave operation sequential?
  3. Does logging serialize the complete payload?
  4. Does another component convert the stream into a String or Object?
  5. Can the destination consume data incrementally?

A single eager operation can become the memory bottleneck.

When I Would Consider Streaming

Streaming is worth evaluating when:

  • payloads can become large or unpredictable,
  • processing is naturally record-oriented,
  • the transformation does not require global ordering,
  • the source and destination can participate in streaming,
  • and load tests show memory pressure from materializing documents.

For modest payloads, enabling streaming everywhere without measurement can add complexity without meaningful benefit.

Test with Realistic Data

Do not validate a large-data design using a 20-record sample.

Measure with payload sizes close to expected production peaks and observe:

  • heap usage,
  • garbage collection,
  • processing duration,
  • CPU,
  • downstream throughput,
  • and behavior under concurrent requests.

A transformation that looks efficient in isolation may behave differently when several large documents are processed simultaneously.

Final Rule

DataWeave streaming is most effective when the entire processing pattern is sequential.

Use it to avoid materializing large inputs when records can be handled incrementally, but remember that operations such as global aggregation or sorting can still require substantial state.

Streaming is an architectural property of the pipeline, not merely a switch on one DataWeave expression.

CONTINUE READING

Explore closely related architecture, integration and implementation topics.