The engines that process endless streams of events (Kafka Streams, Flink, Spark Streaming).
A streaming engine is software that processes an endless flow of events as they arrive: counting, joining, filtering and summing them, and sending results on, all with low delay.
A normal batch job reads a finished file and stops. A streaming job never finishes. Events keep coming, so it must give answers while the data is still arriving. A streaming engine is the tool that runs such jobs on many machines, and handles the hard parts: ordering, time, state and failures.
An engine reads from a source (often a log such as Kafka), runs a pipeline of operators (filter, map, group, window, join), and writes to a sink (a database, another topic, a dashboard). The work is split by key across many parallel workers, and each worker keeps the state for its keys.
Event time is when something really happened (a phone taps "buy" at 10:00:05). Processing time is when the engine sees it (maybe 10:00:09, because the phone was in a tunnel). Good results use event time. The engine then needs a way to decide when a window is complete. That is the job of the watermark.
| Window | How it is cut | Good for |
|---|---|---|
| Tumbling | Fixed size, no overlap (every 1 minute) | Counts per minute or per hour |
| Sliding (hopping) | Fixed size that moves by a smaller step, so windows overlap | A moving average, such as the last 5 minutes updated every minute |
| Session | Grows while events keep coming, closes after a quiet gap | User visits, where the length depends on the user |
| Global | One window for everything, with a custom trigger | Special cases with your own rules |
| Idea | Meaning | Effect |
|---|---|---|
| Event time | When the event really happened | Correct results, even if events arrive late or out of order |
| Processing time | When the engine sees the event | Simple and fast, but results depend on network delays |
| Watermark | The engine's estimate of how far event time has progressed | Decides when a window can fire |
| Allowed lateness | Extra time to still accept late events and update a result | More correct, but results may be corrected after being sent |
| Side output for late data | Send events that missed their window to a separate place | Nothing is silently lost |
| Guarantee | Meaning | Cost |
|---|---|---|
| At most once | An event is processed zero or one time. Nothing is repeated, but some may be lost | Cheapest, results may be too low |
| At least once | Every event is processed, but some twice after a failure | Duplicates must be handled (idempotent writes) |
| Exactly once (effect) | Each event changes the state once, even after failures. Done with checkpoints and transactional or idempotent output | More work and some delay |
| Engine | Style |
|---|---|
| Apache Flink | True event-by-event streaming with strong state and event-time support |
| Kafka Streams | A library you embed in your app, reading and writing Kafka topics |
| Spark Structured Streaming | Treats a stream as a growing table, usually processed in small chunks (micro-batches) |
| Cloud services | Managed options such as Google Dataflow (Apache Beam) and Amazon Kinesis analytics |
| Window | Truth | Result | Status |
|---|---|---|---|
| 0s to 10s | 6 | 5 | fired at 12s, dropped 1 late |
| 10s to 20s | 5 | 5 | fired at 23s |
| 20s to 30s | 6 | 6 | fired at 33s |
| 30s to 40s | 3 | 3β¦ | waiting: no newer event moves the watermark |
| 40s to 50s | 1 | 1β¦ | waiting: no newer event moves the watermark |
A simplified model with fixed events. Sliding windows slide by half their size. Session windows are built from all events, even dropped ones. Real engines such as Flink or Spark can also keep late events with an allowed-lateness setting.
| Term | Meaning in easy words |
|---|---|
| Stream | An endless, ordered flow of events |
| Window | A slice of the stream (by time or by gap) that is summarised together |
| Event time | The time an event really happened |
| Processing time | The time the engine handles the event |
| Watermark | The engine's estimate that no older events are still to come |
| Late event | An event that arrives after the watermark has passed its window |
| State | Data a job remembers between events, such as counts or join tables |
| Checkpoint | A saved copy of state and source position, for recovery |
| Key / partition | How events are divided among parallel workers |
| Backpressure | Slowing the source when a later step cannot keep up |
| Exactly-once | Each event changes the state once, even if the job restarts |
| Choice | We gain | We lose |
|---|---|---|
| Longer watermark delay | More late events are counted | Results come out later |
| Shorter watermark delay | Quick results | More late events dropped or corrected later |
| Event time | Correct results | Needs watermarks and more state |
| Processing time | Simple and fast | Results change with network delays |
| Frequent checkpoints | Less to redo after a crash | More overhead while running |
| Exactly-once output | No duplicate or lost effects | More complex, with some added delay |
| Micro-batches | Simpler, can share batch tools | A little more delay than event-by-event |