Concept Data Indexing Best Practices Performance Architecture ~3 min read

Processing Large Files in Data Indexing Systems

Handle large files in data indexing: processing granularity, fan-in/fan-out, and memory pressure, walked through a patent XML example in CocoIndex.

Processing Large Files in Data Indexing Systems

When building data indexing pipelines, handling large files efficiently presents unique challenges. For example, patent XML files from the USPTO can contain hundreds of patents in a single file, with each file being over 1GB in size. Processing such large files requires careful consideration of processing granularity and resource management.

Understanding processing granularity

Processing granularity determines when and how frequently we commit processed data to storage. This seemingly simple decision has significant implications for system reliability, resource utilization, and recovery capabilities.

The trade-offs of commit frequency

While committing after every small operation provides maximum recoverability, it comes with substantial costs:

  • Frequent database writes are expensive
  • Complex logic is needed to track partial progress
  • Performance overhead from constant state synchronization

On the other hand, processing entire large files before committing can lead to:

  • High memory pressure
  • Long periods without checkpoints
  • Risk of losing significant work on failure

Finding the right balance

A reasonable processing granularity typically lies between these extremes. The default approach is to:

  1. Process each source entry independently
  2. Batch commit related entries together
  3. Maintain trackable progress without excessive overhead

Challenging scenarios

1. Non-independent sources (fan-in)

The default granularity breaks down when source entries are interdependent:

  • Join operations between multiple sources
  • Grouping related entries
  • Clustering that spans multiple entries
  • Intersection calculations across sources

After fan-in operations like grouping or joining, we need to establish new processing units at the appropriate granularity - for example, at the group level or post-join entity level.

2. Fan-out with heavy processing

When a single source entry fans out into many derived entries, we face additional challenges:

Light Fan-out

  • Breaking an article into chunks
  • Many small derived entries
  • Manageable memory and processing requirements

Heavy Fan-out

  • Large source files (e.g., 1GB USPTO XML)
  • Thousands of derived entries
  • Computationally intensive processing
  • High memory multiplication factor

The risks of processing at full file granularity include:

  1. Memory Pressure: Processing memory requirements can be N times the input size
  2. Long Checkpoint Intervals: Extended periods without commit points
  3. Recovery Challenges: Failed jobs require full recomputation
  4. Completion Risk: In cloud environments with worker restarts:
    • If processing takes 24 hours but workers restart every 8 hours
    • Job may never complete due to frequent interruptions
    • Resource priority changes can affect stability

Best practices for large file processing

1. Adaptive granularity

After fan-out operations, establish new smaller granularity units for downstream processing:

  • Break large files into manageable chunks
  • Process and commit at chunk level
  • Maintain progress tracking per chunk

A single 1 GB USPTO XML file fans out through CocoIndex into per-patent units of work, each processed and committed independently into the target index — memory stays flat and a restart resumes instead of recomputing the whole file

2. Resource-aware processing

Consider available resources when determining processing units:

  • Memory constraints
  • Processing time limits
  • Worker stability characteristics
  • Recovery requirements

3. Balanced checkpointing

Implement a checkpointing strategy that balances:

  • Recovery capability
  • Processing efficiency
  • Resource utilization
  • System reliability

How CocoIndex helps

CocoIndex provides built-in support for handling large file processing:

  1. Smart Chunking

    • Automatic chunk size optimization
    • Memory-aware processing
    • Efficient progress tracking
  2. Flexible Granularity

    • Configurable processing units
    • Adaptive commit strategies
    • Resource-based optimization
  3. Reliable Processing

    • Robust checkpoint management
    • Efficient recovery mechanisms
    • Progress persistence

By handling these complexities automatically, CocoIndex allows developers to focus on their transformation logic while ensuring reliable and efficient processing of large files.

Conclusion

Processing large files in indexing pipelines requires careful consideration of granularity, resource management, and reliability. Understanding these challenges and implementing appropriate strategies is crucial for building robust indexing systems. CocoIndex provides the tools and framework to handle these complexities effectively, enabling developers to build reliable and efficient large-scale indexing pipelines.

Join our community!

Interested in learning more about CocoIndex? Join our community!

  • Follow our GitHub repository to stay up to date with the latest developments.
  • Check out our documentation to learn more about how CocoIndex can help build robust AI applications with properly indexed data.
  • Join our Discord community to connect with other developers and get support.
  • Follow us on Twitter for the latest updates.

CocoIndex

Fresh context for long-horizon agents.

Frequently asked questions.

What is processing granularity in a data indexing pipeline?

Processing granularity determines when and how frequently a pipeline commits processed data to storage. It looks like a small decision but has significant implications for reliability, resource utilization, and recovery capability — especially when a single source file is very large, such as a USPTO patent XML file that can hold hundreds of patents and exceed 1GB.

See Understanding processing granularity.

What are the trade-offs of committing too often versus too rarely?

Committing after every small operation gives maximum recoverability but is expensive: frequent database writes, complex logic to track partial progress, and overhead from constant state synchronization. Committing only after processing an entire large file causes high memory pressure, long periods without checkpoints, and the risk of losing significant work on failure. A reasonable granularity sits between these extremes — process each source entry independently, batch-commit related entries, and keep trackable progress without excessive overhead.

See The trade-offs of commit frequency and Finding the right balance.

Why does processing a large file at full-file granularity risk never finishing?

Heavy fan-out (e.g. a 1GB XML file expanding into thousands of computationally intensive derived entries) brings memory pressure that can be N times the input size, long intervals between checkpoints, and full recomputation on failure. In cloud environments this creates a completion risk: if a job takes 24 hours but workers restart every 8 hours, frequent interruptions can mean it never completes.

See Fan-out with heavy processing.

What is adaptive granularity for large file processing?

Adaptive granularity means establishing new, smaller processing units after a fan-out operation: break the large file into manageable chunks, process and commit at the chunk level, and maintain progress tracking per chunk. This keeps memory flat and lets a restart resume rather than recompute the whole file.

See Adaptive granularity.

How do fan-in operations like joins and clustering change processing units?

The default per-entry granularity breaks down when source entries are interdependent — joins between sources, grouping related entries, clustering across entries, or cross-source intersections. After such fan-in operations you need to establish new processing units at the appropriate granularity, for example at the group level or the post-join entity level.

See Non-independent sources (fan-in).

How does CocoIndex handle large file processing automatically?

CocoIndex provides built-in support across three areas: smart chunking (automatic chunk-size optimization, memory-aware processing, efficient progress tracking), flexible granularity (configurable processing units, adaptive commit strategies, resource-based optimization), and reliable processing (robust checkpoint management, efficient recovery, progress persistence). This lets developers focus on transformation logic while large files are processed reliably and efficiently.

See How CocoIndex helps.