VAYULearn
Colour theme
Investigate a failure
VAYU Learn

Kafka & Streaming

Real-Time vs Batch: Cost vs Latency Trade-offs (Deep Dive)

When Streaming Is the Right Answer — And When It’s Just the Expensive One

Kafka & StreamingSpark & PySparkData Architecture & Reliability
Streaming reduces latency — but introduces operational complexity, coordination overhead, and always-on infrastructure cost.

Most systems don’t need millisecond latency. They need correctly chosen trade-offs.

The product team wants real-time dashboards. The data team builds Kafka, Flink, a feature store, and a Redis cache. Six months later: $80,000/month in infrastructure. The dashboard updates every 15 minutes.
Because that’s what the business actually needed.
The latency requirement was never 100ms. It was never even 1 minute. Nobody asked.

“Real-time” is the most expensive word in data engineering.

Not because streaming is inherently costly. But because it gets chosen for the wrong reasons — hype, cargo-culting, vague product requirements — and the cost only becomes visible months later, buried in cloud bills and operational overhead.

Most data pipelines that run on streaming infrastructure today could have been built as batch pipelines at a fraction of the cost and complexity. The business outcomes would be identical.

This blog is about understanding when that’s true — and when it isn’t.


TL;DR

  • Streaming costs 5–10× more than batch to build, operate, and debug
  • Most “real-time” requirements are actually micro-batch requirements in disguise
  • Latency is only worth paying for when delay directly causes measurable business harm
  • Batch pipelines fail visibly; streaming pipelines fail silently and compound
  • The right architecture question is not “should we stream?” — it is “what does latency actually cost us?”

Real-time is not a feature. It is a cost. Only pay it when the latency is load-bearing.


🧠 The Core Distinction

Batch and streaming are not different speeds of the same thing. They are fundamentally different programming models with different correctness semantics, different failure modes, and different operational realities.

Batch processes bounded datasets at scheduled intervals. The dataset has a defined start and end. The job runs, completes, and produces a result.

Streaming processes unbounded event sequences continuously. There is no “end.” The system must handle late arrivals, out-of-order events, state accumulation, and partial results — forever.

That “forever” is where the complexity lives.


⏱️ Latency Is Not Binary

The first mistake most teams make is treating latency as binary: real-time or not real-time.

In practice, latency requirements fall across a spectrum:

Most product requirements land in the “near real-time” or “micro-batch” band.

Most streaming architectures are designed for the “hard real-time” band.

The mismatch is where cost explodes.


💰 The True Cost of Streaming

Engineers often compare streaming vs batch on compute cost alone. That’s the wrong comparison.

The full cost of a streaming pipeline includes:

[H3] Infrastructure Cost

  • Always-on compute (streaming jobs don’t stop between events)
  • Kafka or Pulsar cluster — brokers, replication, storage
  • Stream processor cluster (Flink / Spark Streaming)
  • Online feature store (Redis or equivalent) — hot data, low latency
  • Monitoring, alerting, dead-letter queues

Engineering Cost

  • Designing for state management — windowed aggregations, late data, watermarks
  • Idempotency logic at every write path
  • Exactly-once or at-least-once semantics (and the deduplication infrastructure either requires)
  • Schema evolution without breaking consumers
  • Backpressure handling
  • Replay and recovery procedures

Operational Cost

  • On-call for a system that runs 24/7
  • Consumer lag monitoring
  • Feature freshness SLOs
  • Incident response when Kafka falls behind at 2AM

Batch pipelines have none of the always-on cost. They have scheduled compute cost — and most cloud providers charge only for what runs.

Streaming pipeline (modest scale):
Kafka cluster (3 brokers, m5.xlarge): ~$800/month
Flink cluster (4 workers, m5.2xlarge): ~$1,400/month
Redis (r6g.large, 2 replicas): ~$600/month
Monitoring + storage: ~$300/month
─────────────────────────────────────────────────────
Total: ~$3,100/month

Equivalent batch pipeline (15-min schedule):
EMR cluster (spins up, runs, terminates): ~$200/month
S3 storage + reads: ~$80/month
Airflow orchestration: ~$60/month
─────────────────────────────────────────────────────
Total: ~$340/month

For a business metric that updates every 15 minutes: $3,100/month vs $340/month.

The streaming pipeline is 9× more expensive and 10× harder to operate — for identical business value.


🏗️ Architecture Comparison

Batch Pipeline Architecture

Scheduled Trigger (Airflow / cron)
↓
Source Read
(DB, S3, API, Kafka snapshot)
↓
Transform + Aggregate
(Spark / dbt / SQL)
↓
Write Output
(Data warehouse, S3, dashboard DB)
↓
Job Completes

Properties:

  • Bounded input — job always finishes
  • Reprocessing is trivial — rerun the job
  • Debugging is straightforward — inspect the input, inspect the output
  • Failure is visible — the job either ran or it didn’t
  • Cost is proportional to data volume and frequency

Streaming Pipeline Architecture

Event Source
↓
Kafka
(retention window, partitioned)
↓
Stream Processor (Flink / Spark Structured Streaming)
(stateful: windows, joins, aggregations)
↓
Online Store / Cache (Redis / DynamoDB)
↓
Serving Layer (API / Dashboard / Model)

Properties:

  • Unbounded input — the job never finishes
  • Reprocessing requires replaying the topic and managing state reconstruction
  • Debugging requires correlating event timestamps across distributed logs
  • Failure is subtle — consumer lag, partial state, stale features
  • Cost is proportional to peak throughput × always-on duration

Hybrid Architecture (Lambda / Kappa Variants)

Most mature data platforms don’t choose one or the other. They layer them:

Streaming path:  Events → Kafka → Flink → Redis   (seconds latency)
Batch path: Events → S3 → Spark → DW (hourly aggregates)
Serving layer: Query merges both — real-time delta + batch baseline

This gives you accurate historical aggregates from batch and low-latency recent data from streaming — at the cost of maintaining two code paths that must produce consistent results.

The consistency challenge is real. If your streaming logic and batch logic diverge, you get different answers depending on which path serves the query. This is a correctness problem, not just a performance problem.


💥 The Failure Modes Are Completely Different

How Batch Fails

Batch pipelines fail visibly and cleanly:

  • The job doesn’t start (dependency not met)
  • The job starts and crashes (OOM, schema error, bad data)
  • The job finishes but produces wrong output (logic error)

All three are detectable. The first two are immediately visible. The third requires data quality checks — but at least the blast radius is bounded to one run.

Recovery: fix the bug, rerun the job, backfill if needed.

How Streaming Fails

Streaming pipelines fail invisibly and compoundingly:

# Consumer lag — silent until it isn't
consumer_lag = latest_offset - committed_offset

# If lag grows unbounded:
# → features become stale
# → decisions are made on old data
# → no error is raised
# → dashboards show "healthy" consumer status

if consumer_lag > MAX_ACCEPTABLE_LAG:
trigger_alert(f"Consumer {consumer_group} is {consumer_lag} events behind")

The failure modes unique to streaming:

  • Consumer lag accumulation — the pipeline falls behind and never catches up
  • State explosion — windowed state grows without bound, causing OOM crashes on the stream processor
  • Late data arriving after the watermark — silently dropped, causing under-counting
  • Backpressure cascade — a slow downstream causes upstream buffer overflow, causing Kafka producer to block, causing the upstream service to slow down
  • Exactly-once violations — a retry produces a duplicate event that inflates a metric
  • Feature freshness drift — a backpressure event causes the model to serve decisions on 12-minute-old features, with no error raised

Recovery for streaming failures is orders of magnitude harder than batch. You must:

  1. Identify where in the event stream the failure began
  2. Reset consumer offsets to the correct position
  3. Recompute stateful aggregations from that point
  4. Ensure downstream systems handle replayed events idempotently
  5. Reconcile the online store state with the recomputed state

For batch: delete the bad partition, rerun the job.


⚖️ The Decision Framework

The right question is not “should we use streaming?”

The right question is: what is the actual cost of latency to the business?

If the answer is “users are exposed to fraud that wouldn’t exist with fresher data” — that’s a hard latency requirement. Build streaming.

If the answer is “the dashboard would be more satisfying to look at” — that’s not a latency requirement. Build batch.

Use streaming when:

  • A decision must be made in milliseconds (fraud, pricing, recommendations)
  • Delayed data directly causes business harm (missed SLAs, missed fraud, missed safety events)
  • The event stream itself is the product (user activity feeds, live sports scores, real-time bidding)
  • Downstream systems require event-driven triggers (not just data availability)

Use batch when:

  • Results are consumed by humans on schedules (daily reports, weekly analytics)
  • The business question is about history, not the present moment
  • Latency tolerance is measured in minutes or hours
  • The data volume makes always-on compute economically irrational
  • The team is small and operational overhead matters

Use micro-batch when:

  • You need sub-hour freshness but not sub-minute
  • The dataset is bounded per interval (hourly snapshots, 15-minute aggregates)
  • You want batch simplicity with reduced latency

Spark Structured Streaming with trigger intervals is micro-batch in practice:

# Micro-batch: runs every 5 minutes, processes accumulated events
query = (
df.writeStream
.trigger(processingTime="5 minutes")
.outputMode("append")
.format("delta")
.option("checkpointLocation", "/checkpoints/metrics")
.start("/data/metrics")
)

This gives you 5-minute latency with the operational simplicity of a near-batch job. For most “near real-time” use cases, this is the right answer — not a full Flink topology.


🧪 Production Scenario: When Batch Was the Right Answer

A fintech company built a real-time transaction categorization pipeline:

  • Kafka ingested every transaction event
  • Flink computed rolling category aggregates per user
  • Redis served the aggregates to the mobile app’s spending insights feature

The feature showed users their spending by category, updated in real time.

Infrastructure cost: ~$4,200/month.

Six months in, the product team ran a user study. Users checked the spending insights feature on average once per day — in the morning, before work.

The real-time updates were never observed. Users saw the same data whether it was 30 seconds old or 12 hours old.

They rebuilt it as a batch pipeline. Nightly Spark job, results written to a read-replica at midnight. Cost: ~$180/month.

No user noticed the difference. The product metric (feature engagement) was unchanged.

The streaming pipeline solved a latency problem that didn’t exist.


🧪 Production Scenario: When Streaming Was Non-Negotiable

A payments company processed 40,000 transactions per second at peak. Their fraud model scored each transaction before authorization.

Initial architecture: batch model scoring every 5 minutes.

At 5-minute latency, fraud models were making authorization decisions on features that were already 5 minutes stale. For card-present fraud (someone physically using a stolen card), the attacker could run 8–10 fraudulent transactions before the model’s feature window updated.

Loss rate: significant and growing.

They rebuilt with a real-time feature pipeline:

  • Transaction events → Kafka → Flink (sub-second feature computation)
  • Features → Redis (< 10ms lookup)
  • Model → scored within the authorization window (< 100ms total)

After migration: fraud detection rate increased materially. The business case was unambiguous.

The 5-minute batch latency was directly causing financial harm. Streaming was the only correct answer.


🛡️ Operational Lessons

1. Define latency requirements in writing before architecture discussions.

“Real-time” means different things to every person in the room. “Updates within 30 seconds of an event” is a requirement. “Real-time” is not.

2. Cost the always-on compute before committing.

Before choosing streaming, price the always-on infrastructure for your event volume and processing requirements. Compare it to the equivalent scheduled batch cost. The difference will be larger than you expect.

3. Micro-batch solves 80% of “near real-time” requirements at batch cost.

Spark Structured Streaming with a 5-minute trigger is not streaming in the operational sense. It runs, it completes, it produces results. Its failure modes are much closer to batch than to true streaming. Default to it before reaching for Flink.

4. Streaming and batch are not mutually exclusive.

The Lambda/Kappa pattern exists because different access patterns require different latency guarantees. A fraud scoring system needs true streaming. The same company’s monthly reporting does not. Design each pipeline for its actual latency class.

5. Operationally, streaming debt is real.

A batch job that breaks wakes up your on-call once. A streaming pipeline that falls behind can cause cascading failures across every downstream system that depends on fresh features. Weigh the operational burden against the latency benefit — honestly.


🚀 Final Takeaway

Streaming is not better than batch.

It is more expensive, more complex, and harder to operate — in exchange for lower latency.

That trade-off is worth making when latency directly determines business outcomes. It is not worth making when the business outcome is identical whether the data is 30 seconds old or 30 minutes old.

The most expensive mistake in modern data engineering is not building the wrong thing. It is building the right thing for the wrong latency requirement.

📌 Core Principle

Real-time is not a feature. It is a cost.
Only pay it when the latency is load-bearing.

🔥 Next in Series

💸 How to Cut Your Spark Cloud Bill by 60% — What Actually Works

You’ve built the pipeline. It runs.

But every month the cloud bill arrives and someone asks why data engineering costs this much.

Next, we break down:

  • the specific Spark patterns that silently destroy cost efficiency
  • why shuffle is your biggest enemy and how to eliminate it
  • partitioning mistakes that double your compute spend
  • the over-streaming tax — paying streaming prices for batch problems
  • practical optimizations that produce real, measurable savings

Not theoretical tuning tips. Actual changes that reduced production bills by 40–60% at real scale.


🔔 Follow for More

Follow TheDataForge for high-signal deep dives on Spark, Kafka, Streaming, Lakehouse, and real-world data engineering — no fluff, only engineering truth.

⚡️Let’s connect — I post daily Big Data & Spark insights at DataForgeX on X.

💬 Comment Below

Have you inherited a streaming pipeline that should have been batch?

Or been forced to build batch where streaming was clearly needed and management wouldn’t approve the cost?

What’s the most expensive latency mismatch you’ve seen — where the architecture was built for a requirement that didn’t actually exist in production?

👇 Real stories from engineers who’ve had to explain a $40K cloud bill to a product manager.


🏷️ Tags

#data-engineering #apache-kafka #apache-spark #distributed-systems #streaming-systems #system-design #big-data #cost-optimization #real-time-data #production-engineering