Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 3

Batch vs. Streaming: Latency, Throughput, and Use Cases

Recommended resources

Welcome to the third lesson in our series on Data Pipeline Fundamentals. In our previous session, we established that your project will follow a modern ELT (Extract, Load, Transform) architecture. We decided on the sequence of operations: extracting data from your sources, loading it raw into PostgreSQL, and then transforming it with dbt.

Today, we address the next critical architectural question: when should these operations run? This brings us to the two fundamental models of data processing: batch and streaming. Your goal involves handling diverse data sources, including APIs, files, and real-time streams, making this topic particularly relevant. Understanding the trade-offs between these two approaches will allow you to select the right tool for the right job within your pipeline.

By the end of this lesson, you will be able to compare batch and streaming processing in terms of their latency, throughput, and common use cases, enabling you to make deliberate design choices for your project.

The Core Trade-off: Latency vs. Throughput

Before we dive into batch and streaming, we need to be precise about two key performance metrics: latency and throughput. They are the fundamental currency in which we measure and compare data systems.

The following short video provides a clear and concise explanation of these two essential concepts.

Throughput vs Latency | System Design

This video from System Design School, "Throughput vs Latency," breaks down these two critical metrics and explains their relationship.

Please watch the entire video. As you watch, focus on these definitions: Throughput (how much): The amount of data processed per unit of time (e.g., records per second). The goal is often to maximize this. Latency (how long): The time delay for a single piece of data to complete its journey through the system. The goal is often to minimize this. The Trade-off (comparison section): Note the discussion on how optimizing for one can sometimes negatively impact the other.

To summarize:

  • High-throughput systems are optimized for processing massive amounts of data efficiently, even if it takes a while for any single item to get through.
  • Low-latency systems are optimized for speed and responsiveness, ensuring a single piece of information is processed as quickly as possible.

This trade-off is the central axis on which the batch vs. streaming decision turns.


Two Models of Processing

At a high level, the architectural difference between batch and streaming is straightforward. Batch processing involves collecting data over a period and processing it together in a group. Stream processing involves processing data continuously, as soon as it is generated.

The diagram below offers a clear visual distinction between these two architectures.

This diagram illustrates the architectural difference between batch and stream processing. In Batch Processing (top), data is collected first, stored, and then processed in discrete, scheduled jobs. In Data Stream Processing (bottom), real-time events are processed continuously as they arrive, producing live results.

In the Batch Processing model, you can see data being accumulated in a storage system (like a database). At a scheduled time, a processing job runs, takes a large chunk of data, and produces a result. This is an efficient way to handle large volumes and is the model used by orchestrators like Apache Airflow.

In the Data Stream Processing model, there is no large, intermediate storage where data waits. "Real time events" flow into a "Continuous data processing" engine and results are produced immediately. This is the model used by systems like Apache Kafka.


A Detailed Comparison

Now, let's explore the differences in more detail. The following article from DataCamp provides an excellent breakdown of the key characteristics, use cases, and decision criteria for each approach.

Batch vs Stream Processing: When to Use Each and Why It ...

This article provides a comprehensive comparison, which will form the basis of our understanding.

Please read the article, focusing on the following sections: Read the definitions for Batch Processing and Stream Processing to solidify your understanding of the basic concepts. Pay close attention to the section titled Differences Between Batch Processing and Streaming Processing. This directly addresses the core of today's learning outcome, comparing the two across latency, volume, complexity, and cost. Review the summary table under that section for a quick reference. Finally, scan the batch use cases and streaming use cases to see how these concepts apply in practice.

Let's synthesize this information into a clear comparison, which is also reflected in the table below.

This table provides a side-by-side comparison of batch and stream processing across four key dimensions: definition, typical use cases, advantages, and limitations.

Key Dimensions of Comparison

  • Latency:

    • Batch: High latency. Data is processed on a schedule (e.g., every hour, once a day). This means insights are inherently delayed. The data is "stale" by the time you analyze it.
    • Stream: Low latency. Data is processed in near real-time (milliseconds to seconds). Insights are available almost instantaneously.
  • Throughput & Data Scope:

    • Batch: Designed for high throughput on large, bounded datasets. It processes a complete, known quantity of data at once. Your experience with analytical SQL over entire tables in PostgreSQL is a perfect example of batch-style thinking.
    • Stream: Designed for potentially infinite, unbounded streams of individual events or micro-batches. While it can handle high volume (throughput), its main focus is on continuous flow.
  • Complexity & Cost:

    • Batch: Conceptually simpler. A batch job either succeeds or fails. It can be run during off-peak hours to save costs. Tools like Airflow are designed to manage these scheduled, well-defined tasks.
    • Stream: More complex to implement and manage. It requires an "always-on" infrastructure and careful handling of state, message ordering, and fault tolerance (e.g., what if a processing node fails?). This can lead to higher operational and infrastructure costs.

Applying This to Your Project: A Hybrid Approach

So, which one is right for your project? The answer is both. Modern data pipelines are rarely purely batch or purely streaming; they are often hybrid systems that use the best tool for each specific task.

Let's consider your project's two main goals:

  1. Powering an analytics dashboard:

    • Question: Do your dashboard users need to see data that is accurate to the millisecond, or is an hourly or daily refresh sufficient?
    • Likely Answer: For most analytics dashboards, batch processing is perfectly suitable and more efficient. You can collect data from your APIs and CSVs, run an ELT pipeline using Airflow and dbt on a schedule (e.g., every hour), and update the dashboard tables. This is a classic, robust, and cost-effective batch workflow.
  2. Feeding data to a third-party NLP AI:

    • Question: Does this AI service provide real-time feedback? For example, is it a real-time chatbot, a content moderation service, or a system that needs to react instantly to new information?
    • Likely Answer: If the requirement is for immediate processing and reaction, this is a prime use case for stream processing. You would use Apache Kafka to ingest events as they happen, a Python consumer would process them immediately, call the NLP API, and perhaps trigger a downstream action.

Your chosen technology stack—Airflow for orchestration and Kafka for streaming—perfectly reflects this hybrid reality. You will build a batch pipeline for the predictable, scheduled ingestion and transformation, and a streaming pipeline for the low-latency, event-driven component. In later modules, we will even explore how to use dbt to model and merge the data from both of these pipelines into unified tables for analysis.


Key Takeaways

  • Batch Processing collects and processes data in large, scheduled chunks. It is optimized for high throughput and is ideal for scenarios where high latency is acceptable, like daily reporting or data warehousing.
  • Stream Processing processes data continuously as it arrives. It is optimized for low latency and is essential for real-time applications like fraud detection, IoT monitoring, and live recommendation engines.
  • The choice between them is a trade-off, primarily driven by the business requirement for data freshness.
  • Most modern data platforms, including the one you are building, are hybrid, using batch for efficiency and streaming for immediacy.

Next time

Now that we understand the "how" (ELT) and "when" (batch vs. stream) of data processing, we need to ensure our pipeline is robust and reliable. What happens if a batch job runs twice by mistake, or if a streaming message is delivered more than once? The system's output must remain correct. This brings us to a critical principle in data engineering: idempotency. In our next lesson, we will explore what idempotency is and why it's non-negotiable for building trustworthy data pipelines.