Stream lab
One claims feed, three architectures. Read the log event by event as a nightly batch, as Lambda (a speed layer and a batch layer) and as Kappa (one streaming job over a log you can replay), then inject a late correction and see latency, cost and which views agree.
Exercise: A late correction, handled both ways
The adjuster's correction to C-103 arrives at 09:56, long after its window closed. Harbour Mutual's dashboard must show the right totals: Kappa's view before the nightly batch, Lambda's after it, with the speed layer running the same code as the batch layer and never counting a claim twice.
- The late correction stays in the feed.
- Kappa's view is right in every window before the nightly batch.
- Lambda's view is right in every window after the nightly batch.
- The speed layer runs the same code as the batch layer.
- No view ever counts a claim twice.
| Architecture | Minutes until a claim shows | Windows right before the batch | Windows right after it | Events read | Cost | Code paths |
|---|---|---|---|---|---|---|
| Batch | 808 | 0 of 4 | 4 of 4 | 12 | 5.2 | 1 |
| Lambda | 1 | 3 of 4 | 4 of 4 | 24 | 30.4 | 2 |
| Kappa | 1 | 3 of 4 | 3 of 4 | 12 | 25.2 | 1 |
Windows are by event time, when the claim happened. A streaming job keeps a window open until its watermark, the latest event time it has seen less the allowed lateness, passes the window's end; anything that arrives for a closed window is dropped. The nightly batch reads the whole log, so it is always right, but only once a day.
Used in
- Chapter 29 · Integration patterns: batch, streaming, APIs and sharing
- Chapter 30 · Lambda and Kappa: architectures for streaming
- Chapter 31 · Pipeline patterns: choosing and combining
Glossary: Lambda architectureKappa architectureEvent timeWatermark