Data Platforms

Batch Processing vs. Stream Processing 101

batch vs stream processing

Michael Segner

Michael writes about data engineering, data quality, and data teams.

Data is the lifeblood of any organization, but if you don’t do something with all those bits and bytes, they won’t be doing anyone any good. They need to be processed.

There are two key approaches to processing data:

  1. Batch processing, or
  2. Stream processing (sometimes called real-time processing)

In some circles, you’ll hear the first talked about as being the old way of doing things and the second as the more modern approach. The same sort of language is used when comparing monolithic apps to microservices or on-premise solutions to the cloud.

In reality, things aren’t quite that simple in this case…or in those other cases mentioned. Stream processing isn’t so much a replacement for batch processing as it is a different approach, and it’s not without its challenges.

In this post we’ll consider the idea of batch processing vs. stream processing more broadly, covering things like when to use stream processing and when batch processing in big data might be more appropriate.

What is batch processing?

For a long time, the status quo in the space has been to process data in batches, e.g. nightly, weekly, or after every 1,000 entries. This method is tried and tested, and is still used by many large companies today. But there are a couple of reasons why it’s fallen out of favor:

  1. As data gets bigger, with more and more of it being produced by the minute, batch processing fails. Batches need to be processed with exponentially increasing regularity.
  2. In 2022, there’s significant emphasis on real-time analysis in the data space. This isn’t possible with batch processing, as data may be out of date before it can be acted on.

Micro-batch processing is one option that emerged as a possible solution to these problems.

What is micro-batch processing? Well, as the name suggests, it involves processing very small batches of data, often in quick succession. In some cases, micro-batches might be as tiny as a few minutes (or even seconds) worth of data. 

But, as we’ll see below, there are some cases in which that’s still not fast enough…

What is stream processing?

Historically, stream processing has often been referred to as “real-time processing.” That makes sense, because these terms both refer to the practice of handling data as it’s created. 

Real-time processing, however, sort of implies that data is taken somewhere to be dealt with as it arrives in real time. In fact, the process we’re talking about here isn’t that invasive.

The “stream” in stream processing refers to the data stream, more accurately capturing the way that actions are taken while the data remains in a stream. Analytics, enrichment, and ingestion are all possible without causing any disruption to that data stream.

Related: Why you need to prioritize data quality when migrating to stream processing.

Key differences: batch processing vs. stream processing

Some of the differences between stream processing and batch processing are pretty clear. Other differences, however, aren’t quite so obvious. Batch processing and stream processing each have their own distinct advantages and obstacles.

Stream processing achieves much faster (real-time) results than batch processing could ever hope to. Depending on the size of the batch, it might take hours for an analytics system to process all of the data that’s been fed into it. With stream processing, all of the information related to that data is available immediately because it’s processed in real time.

When a large batch of data is processed, analysts can do a deep dive into the implications of that information. With stream processing, analysis is typically more shallow; its emphasis on real-time reaction means that some data collected is only relevant for a short time.

Most legacy systems are compatible with the batch processing methodology because, in most cases, it’s the one that’s already being used. Implementing stream processing may require additional pieces of software or tools, and the knowledge of how to integrate them into your existing business practices.

When to use stream processing vs. batch processing?

Whether batch or stream processing is the best option for you will ultimately come down to what you want to do with the data involved. Batch processing is well-suited to big data sets that require complex analysis, while stream processing is best employed in a situation where the ability to be agile is important, such as stock trading or alerting on medical conditions.

Here’s a few other example of when one or the other may be preferred:

Retail

A retailer that wants to record and analyze their daily sales figures could process these in batches after closing time every day because it’s very unlikely that they would make adjustments to their sales process during a single day based on this information. 

Payment processor

A company that processes payments might use stream processing to monitor transactions in real time. A sudden burst of activity, or irregular activity from different places all over the country, might prompt them to place a hold on the affected account(s) in case of fraud.

Advertising firm

Likewise, a company serving ads or measuring sales might use stream processing to form assumptions about what a customer is on the market for or monitor social media sentiment for, say, reactions to a new product. This allows them to stay relevant and address concerns in the moment, while customers and potential customers are still engaged.

Conclusion

There’s a tendency to pit these two methods – batch processing vs. stream processing, a fight to the death, only one can leave the ring! – against each other as if one is going to come out as the perfect solution. But that’s really not the way to look at this comparison.

In reality, when to use stream processing or batch processing in big data is far more likely to come down to the project you have on your hands: stream processing for those that require instant, though possibly shallower, feedback and batch processing for in-depth analysis of data that isn’t so time-sensitive.

We’ve not only seen above that there’s a place in data for both of these solutions, but that micro-batch processing can (just about) function as a bridge between the two. Hopefully, armed with the knowledge above, you can now figure out which one works for you.


Still grappling with data quality across batch processing, micro-batch processing, and stream processing pipelines? Data observability can help. Reach out to us by selecting a time in the form below.

Our promise: we will show you the product.