Lesson 1 of 9 · 24m
Batch vs Streaming: Choosing the Shape of the Pipeline
Decide based on freshness requirements, correction semantics, operational cost, and failure behavior rather than fashion or vendor pressure.
The worst streaming system I inherited was built to answer a question once a day. It had Kafka, a stateful stream processor, checkpointing, schema registry integration, and three on-call rotations — all so a finance report could be delivered by 8 AM. A twenty-minute batch job would have been more accurate, cheaper, and easier to backfill. Choose the shape of the pipeline from the decision it feeds, not from the architecture diagram you want.
Start with the decision latency
Ask how quickly someone can act on the result:
fraud decision in a checkout milliseconds to seconds
operations alerting seconds to minutes
product analytics dashboard minutes to hours
finance reconciliation hours to days
regulatory reporting days, with exact correction rulesIf the consumer cannot act before tomorrow morning, sub-minute freshness is not free value; it is operational risk purchased with real money.
Batch is not primitive
Batch has a powerful property: bounded input. You can inspect the complete input, run deterministic transformations, validate output, publish atomically, and rerun the whole thing when logic changes.
def run_partition(day) -> None:
raw = read_partition("events/orders", day)
clean = transform_orders(raw)
validate(clean)
write_staging(clean, table="analytics.orders", partition=day)
commit_partition(table="analytics.orders", partition=day)The important detail is the explicit partition boundary. It gives you a unit of correctness, retry, audit, and replacement.
Streaming is for continuous decisions
Streaming pays for complexity when latency changes behavior: fraud checks, inventory reservation, live personalization, log aggregation for alerting, or operational control loops. A minimal Kafka consumer still carries state and delivery semantics:
consumer = KafkaConsumer(
"orders.v1",
bootstrap_servers=["kafka-1:9092", "kafka-2:9092"],
group_id="order-enrichment",
enable_auto_commit=False,
)
for batch in poll_batches(consumer):
rows = [transform(record.value) for record in batch]
write_idempotently(rows)
consumer.commit()Notice what streaming does not remove: malformed input, late events, duplicates, schema changes, and backfills. It only moves those problems into continuous time.
Compare total cost, not brochure latency
Streaming systems pay continuously for brokers, state, checkpoints, rebalancing, partition management, and specialist debugging. Batch systems often pay in bursts but can become expensive when they rescan too much history. The right comparison includes people, recovery time, correctness, cloud spend, and the cost of being wrong.
Field notes
- "Near real time" is not a requirement. Ask for a number, a consumer, and the action taken when the number is late.
- Event time and processing time are different; a mobile device can emit yesterday's event today.
- If backfill is impossible, your streaming architecture is unfinished no matter how elegant the runtime path looks.
Was this lesson helpful?