blog by OSO

Batch vs Real time stream processing: A beginners guide 

Sion Smith
Sion Smith 8 August 2023
OSO beginner guide comparing batch vs real-time stream processing, with white title text on a navy panel and a lime Blogs label.

What is the difference between batch vs real time stream processing? Both approaches have their own advantages and challenges, and understanding them helps teams make informed decisions about which method to use for their data processing needs.

Why does choosing the wrong architecture create risk?

When it comes to data processing, getting it wrong can have serious consequences. Data leaks can occur, causing problems downstream. Additionally, introducing additional state can complicate the entire process. For example, when multiple sources are involved, idempotency becomes a complex question. In a distributed system, the order of processing can vary, leading to potential issues. This is why transactions are crucial in ensuring that streaming events are not processed more than once.

ConcernBatch processingReal-time stream processing
Data shapeBounded datasets, usually on a scheduleUnbounded events as they arrive
OrderingEasier to reason about within a job runOrder can vary in a distributed system
IdempotencyOften handled per job or table rebuildMust be designed into every task
Breaking schema changeReset / recreate destination; consumers must adaptIncremental pipeline usually needs a full restart
Compatible schema changeCan often run incrementallyCan often run incrementally

Why does idempotency matter for stream processing?

Implementing idempotency on top of every stream processing task can be extremely complex. It requires careful consideration and ongoing maintenance as software and pipelines evolve. Having built-in functionalities in a platform can greatly simplify the process and reduce the risk of errors.

It’s important to remember that no program is perfect from the start, especially in the world of software development. Bugs are expected in the initial versions, and that’s how software is built. Having inbuilt functionalities in a platform can help address these issues and make the development process smoother.

How does schema evolution differ in batch and stream pipelines?

Even if you use a schema-less database, there is always some schema attached to the data, whether it’s at the application layer or elsewhere. Adding new features or fields to the schema can be a challenging task, especially when backward-incompatible changes need to be made.

Dealing with schema evolution can be messy, and it’s important to understand how it compares between batch processing and stream processing.

Incompatible schema changes

When there is a completely incompatible schema change, both batch and real-time stream processing systems require a reset. In an incremental pipeline, where data is processed incrementally, a complete schema change requires starting from the beginning. The schema of the table in the destination needs to be updated, and the entire process needs to be recreated.

In the batch world, if the schema change is not done incrementally, a naive approach of creating a new table for each run can work. However, from an end-to-end perspective, there is still a problem: consumers of the data will need to adjust their processes when the schema changes, and communication becomes difficult.

Compatible schema changes

There are also compatible schema changes, such as adding a new column or allowing null values in a column. These changes are generally easier to handle and can be done incrementally without causing major disruptions. However, there is not always a clear answer to what is considered a breaking schema change. Determining whether a change requires a restart or can be handled automatically is difficult and often requires user input.

What is the ideal approach to schema changes?

The ideal approach for consumers of data is to handle schema changes incrementally until a fundamentally incompatible change occurs. This allows for a simpler conceptual model where users can query a table that is kept up to date incrementally. When the schema changes, users can assume that the schema might have changed and adjust their processes accordingly. Using GitOps for this can help bridge the gap between development and operations.

In the end, the user always has the final say in determining whether data is compatible and how to handle schema changes. If the data is compatible, the schema can be modified on a go-forward basis. If not, a restart and a new table may be necessary.

Key takeaway: batch and stream processing both work—but the wrong choice amplifies risk around idempotency, ordering and schema evolution. Prefer incremental, compatible changes; treat breaking schema changes as a full reset; and involve data consumers when deciding whether a change is compatible.

Both batch and real-time stream processing have their own advantages and challenges. Understand the differences and make decisions based on the specific needs of your data processing tasks. Incremental changes are generally preferred until a fundamentally incompatible schema change occurs. Determining compatibility can be difficult, and user involvement is crucial.

Frequently asked questions

What is the difference between batch and real-time stream processing?

Batch processing runs over bounded datasets, typically on a schedule. Real-time stream processing handles unbounded events as they arrive. Both can power analytics and pipelines; the trade-offs show up in ordering, idempotency and how you evolve schemas.

Why is idempotency harder in stream processing?

In a distributed stream, the same event can be delivered more than once and processing order can vary. You must design idempotency into each task (or rely on platform features), whereas batch jobs often rebuild or replace outputs per run.

Do incompatible schema changes affect batch and stream the same way?

Yes for a full break: both usually need a reset. Incremental stream pipelines typically restart from the beginning with an updated destination schema; batch can sometimes create a new table per run, but consumers still have to adapt.

What counts as a compatible schema change?

Examples include adding a new column or allowing nulls in a column. These can often be applied incrementally. Whether a change is truly non-breaking is not always obvious and often needs human judgement.

Who decides if a schema change is compatible?

The data consumers. If the data remains compatible, evolve the schema going forward; if not, plan a restart and a new table (or equivalent cutover) and communicate clearly with downstream teams.

Get started with OSO professional services for Apache Kafka

Have a question about batch vs stream architectures on Kafka? Speak with our engineers about the right processing model for your pipelines.

CONTACT US
OSO
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.