Decide Streaming

When to stream vs chunk vs load all. Memory vs complexity.

attac-t a959be1 2 files · 3.5 KB Updated

File contents

Skill: Streaming vs Chunking

"Memory is cheap until it isn't."

The Decision

Load All when:

  • Dataset fits comfortably in memory (<10K records)
  • Need random access or multiple passes
  • Simplicity matters more than memory

Chunk when:

  • Processing in batches (1K-10K per batch)
  • Database operations (insert/update batches)
  • Can tolerate batch boundaries

Stream when:

  • Dataset size unknown or very large (100K+)
  • Processing row-by-row is natural
  • Memory is constrained

The Heuristic

Ask: "What happens if the dataset 10x in size?"

The Quick Test

Ask Answer Use
Will it always be <1K records? Yes Load all
Processing in batches of N? Yes Chunk
Could be millions of records? Yes Stream
Need all data at once for calculation? Yes Load all

Real-World Examples

See examples.md.

attac-t/the-foundry/tree/main/plugins/laravel-ddd/skills/decide-streaming commit a959be1e8c

Frequently asked questions

npx skillmds@latest add attac-t/decide-streaming