Not all data can wait for a scheduled batch job. Streaming handles continuous, unbounded data flows where latency is measured in seconds, not hours. Understanding when to stream, how to process events, and which architecture fits is essential for modern data engineering.
| Property | Batch | Streaming |
|---|---|---|
| Data model | Bounded dataset (finite) | Unbounded stream (infinite) |
| Latency | Minutes to hours | Seconds to milliseconds |
| Complexity | Lower | Higher |
| State management | Simple (read all, process, write) | Complex (windowing, watermarks, checkpoints) |
| Error recovery | Re-run the job | Checkpointing, exactly-once semantics |
| Cost | Pay per run | Always-on infrastructure |
| Use cases | Reports, training data, ETL | Fraud detection, IoT, real-time dashboards |
Building on processing time is simpler but can produce incorrect results when events arrive late or out of order. Building on event time gives correct results but requires watermarks to handle late arrivals: a watermark is a declaration that says "I believe all events with event time < W have now arrived."
Since streams are infinite, you need boundaries to compute aggregates. Windows define finite chunks of time over the stream.
| Window type | How it works | Example |
|---|---|---|
| Tumbling | Fixed, non-overlapping intervals | Count clicks per 5-minute window |
| Sliding (hopping) | Fixed size, overlapping by a slide interval | Average over 10 minutes, updated every 1 minute |
| Session | Dynamic, based on activity gaps | User session ends after 30 minutes of inactivity |
| Global | Single window over entire stream | Running total (requires trigger) |
| Guarantee | Risk | Use case |
|---|---|---|
| At-most-once | Data loss possible | Logging, metrics where loss is tolerable |
| At-least-once | Duplicates possible | Most pipelines (with dedup downstream) |
| Exactly-once | No loss, no duplicates | Financial transactions, billing |
"Exactly-once" is really "effectively-once": it is achieved through checkpointing plus idempotent writes. The processor may retry, but the combination of checkpoints and idempotent sinks ensures the effect is as if each event was processed exactly once.
Select a tool to understand its role and when to use it.
Role: Event broker (message bus). Not a processor. What it does: Receives events from producers, stores them in durable, partitioned, replayable topics, and delivers them to consumers. Key features: High throughput, fault tolerance, replay capability, configurable retention. Best for: The backbone of event-driven architectures. Every streaming pipeline starts with a broker, and Kafka is the de facto standard.
1. What is the main difference between Lambda and Kappa architecture?
2. What is a watermark in stream processing?
3. Which window type creates non-overlapping, fixed-duration intervals?
4. How is "exactly-once" semantics actually achieved in practice?
5. What is the role of Apache Kafka in a streaming architecture?