Both Lambda and Kappa architectures ingest and transform an incoming stream. With Lambda, this happens via two parallel paths: a slow, accurate batch process and a faster speed-focused one. In Kappa, there is only a single streaming process, acting upon a persistent and replayable log.
For the majority of telemetry, IoT and event-driven problems, the Kappa model will usually be easier to operate. There are still circumstances where Lambda, or some combination of the two, remains appropriate: for example, where you need perfectly accurate historical figures across many years, or where you have already invested heavily in batch technology.
As we develop telemetry solutions to monitor datacentre facilities, buildings, construction sites and other live environments, the practical question is not which architecture is more fashionable. It is which one your team can run safely, update confidently and recover at 3am when something goes wrong.
Make telemetry fit your operations
PODTECH creates bespoke telemetry and monitoring solutions to fit your facility.
Learn moreTL;DR
- Lambda: A combination of a Batch, Speed and Serving layer. Requires two separate streams of processing.
- Kappa: Consists of a single stream which processes a long-lived log. Changing the computation requires re-running the stream against the log.
- You should consider Kappa if your input is predominantly discrete records, the computation is frequently updated and you have sufficient log depth to enable the latter.
- You may want to retain some form of batch (Lambda) if: a) you require very precise historical data and b) your current batch capability is significant.
- In practice, with advances in processing technology, you will likely find the choice comes down to log length and re-running.
Table of Contents
- What Lambda architecture does
- What Kappa architecture does
- Lambda vs Kappa side by side
- Why Lambda lost ground
- Where Kappa gets hard
- How to choose: a decision guide
- What this means for infrastructure telemetry
- A worked example: cooling telemetry in a data hall
- Perspective
- Putting it into practice
- Build the pipeline with PODTECH
- FAQ
- Sources
What Lambda architecture does
In introducing the concept, Nathan Marz posed it as the task of computing some desired output from your complete dataset. As detailed in their book Big Data, the solution involves maintaining a static dataset of all known data, generating derived datasets or views from this and feeding any remaining fresh data through a speed layer. The outputs from each are combined to satisfy user queries.
Consequently, Lambda comprises:
- Batch layer. An ever-growing dataset of records, which acts as the definitive store and generates the required views.
- Speed layer. Receives the live datastream and feeds the latest data since the previous batch run into the views.
- Serving layer. Populated with the generated views and used to service queries. Outputs from the batch and speed layers are joined.
As a consequence of the above design, the view generated by the batch layer represents the correct answer. Any incorrect value returned from the speed layer will therefore be superseded on the following batch run. Furthermore, a wide range of proven, flexible and powerful tools exist to support the batch layer, including global aggregations. It is also possible to run the batch process on low-cost and best-effort resources, since failures can be addressed on subsequent runs.
Feick et al. in Fundamentals of Real-Time Data Processing Architectures: Lambda and Kappa provide a concrete mapping to commonly-used technologies: Kafka to receive the datastream, Hadoop/MapReduce for the batch layer, Spark for the speed layer and Cassandra for the serving layer. Importantly, they note that while Lambda offers resilience to failure, the requirement to maintain two processing layers in unison gives rise to considerable duplication.
What Kappa architecture does
Kappa was proposed as an alternative to alleviate these issues. In a 2014 article Questioning the Lambda Architecture, Jay Kreps contends that the primary purpose of the batch layer is to allow the datastream to be re-evaluated, and that this can be achieved using just a stream processor.
The key steps are:
- Retain the full history of events for a suitable period, with Kreps suggesting 30 days.
- Deploy a duplicate of the existing stream processor, starting from the earliest event, to populate an alternative results store.
- Switch the dependent systems to consume from the new store once the duplicate has caught up.
- Decommission the original stream processor and associated store.
Re-processing is thus subsumed within the stream-processing workflow. Additionally, Kreps highlights that if your organisation can sustain more than 1PB of data in a Kafka cluster, as did LinkedIn, retaining a substantial volume of logs should come with minimal cost. Finally, he dismisses the notion of managing two streams of code required to deliver consistent outputs across two platforms as being self-evidently undesirable.
His advice is straightforward: if you do not require low latency, rely on a batch platform; otherwise use a stream-based solution. Only combine them if necessary.
Lambda vs Kappa side by side
The core trade-off is simple: Lambda gives you two paths to an answer, while Kappa gives you one path plus replay. That sounds like a small difference, but operationally it changes almost everything.
| Dimension | Lambda | Kappa |
|---|---|---|
| Processing paths | Batch and speedy, combined | Single speed path |
| Codebases | Two, in lock-step | One |
| Source of truth | An immutable store of master records in object or distributed storage | Append-only log, optionally backed by a data lakehouse for shorter retention periods |
| Reprocessing | Re-run existing ETL against the source of truth | Replay the log from position 0 using updated code |
| Cost to reprocess | Low-cost, fault-tolerant batch resources | Short-term roughly 2x increase in resource usage and resulting writes |
| Latency | Seconds along the critical path | Seconds |
| System requirements | Maintain 2 distinct pipelines with associated fail-points and growth characteristics | Single pipeline, single release process and set of alerts |
| Advanced use cases | Unrestricted SQL, worldwide aggregation | Constrained by capabilities of the streaming platform |
This summary captures the main trade-offs highlighted in The HLD Handbook's Lambda vs Kappa page. It is broadly consistent with other sources: Lambda provides redundancy at the expense of added systems, while Kappa does not.
Drawbacks of Lambda
There are three key issues that commonly manifest with Lambda implementations:
- Code duplication. Business logic is duplicated between the batch and speed layers. As a result, any updates to this logic need to flow through both. Failure to do so will lead to discrepancies between the batch layer true values and those published via the speed layer. This is discussed in greater depth by Jimmy Lin in The Lambda and the Kappa.
- Non-trivial combination of outputs. Summing together the batch and speed outputs may be straightforward. However, calculating unique records, median, leading N items, or multi-day customer sessions will require bespoke handling of the combined outputs. See System Design From First Principles.
- Additional operating burden. An extra pipeline to monitor, plan for growth and manage incidents. Not trivial for an organisation with an established 24-hour ops team.
Challenges with Kappa
Implementing a Kappa architecture introduces some additional considerations. Specifically:
- Data retention. Kafka typically retains data for 7 days. Therefore a Kappa system's ability to re-compute historical records is bounded by its configured retention period, absent a secondary longer-term store. You cannot easily fill a 6-month gap using a 7-day retention.
- Time to replay. To keep pace with the incoming record stream, the re-processing pipeline needs to be able to consume records at a higher rate. Depending on the volume of data to be replayed, this may take a significant period and place strain on your streaming cluster.
- Assigning event time. Any re-computation is meaningless if the processing pipeline cannot correctly attribute each record to its original timestamp. A Kappa system does not work if it does not support event time.
- Schemas. Records may have been persisted with a different schema in the past, which must still be readable during replay.
- Consumers. If a downstream system processes records by incrementing a total count, then all records replayed following any disruption will be double-counted. Downstream systems must support key-based updates and any replacement tables should be swapped in atomically.
When Uber detailed their implementation of a Kappa architecture in their engineering blog post, they noted that replaying more than roughly a few days' worth of records into Kafka would saturate their infrastructure and lead to growing backlog. They instead leveraged a Hive partitioned table to feed their stream processor, allowing them to replay records one-by-one while maintaining event-time.
Finally, both Apache Flink and Spark Structured Streaming allow existing batch jobs to be executed in a streaming fashion. Consequently, organisations can reap many of the benefits of Kappa without needing to refactor all existing batch assets. Similarly, KPMG note in Building a fit-for-purpose data processing architecture that Kappa may not be ideal where substantial computation is required on sizeable datasets.
Decision criteria
Several factors will influence whether your organisation adopts Lambda or Kappa. We suggest considering the following:
- Input record format. Is your data primarily composed of discrete events such as device telemetry, energy consumption, user activity, application logs or financial records? Then Kappa is likely a good fit. Alternatively, if data is received as bulk files or database extracts, you will want to rely on batch.
- Desired re-computation window. Do you expect to need to correct records within a relatively short timeframe? Kappa will suffice. Will you be required to demonstrate an accurate value dating back 2 or more years? Maintain a persistent immutable record and consider Lambda.
- Frequency of updates. If your business logic is frequently changing, maintaining 2 parallel sets of code will quickly become onerous.
- Current capabilities. Will your data team benefit from expanding their existing skillset and technology footprint, or starting from scratch?
5. Are there still workloads that require batch?
Naturally, billing, some regulatory reporting and ML work will require access to the complete dataset and remain batch-based, at least until further advances in streaming.
In practice, people tend to converge on some form of combination. You stream to satisfy the primary use case and serve customers, and process a batch load periodically against the lakehouse, for example using Iceberg or Hudi, to reconcile. As noted earlier, the HLD Handbook calls this out explicitly as an honest Lambda architecture: see here. Expect many deployments to land close to that.
Implications for facility and construction telemetry
There is a very compelling case for Kappa-style architectures in the upstream telemetry of buildings and data centres. All of the typical signals such as temperature, pressure, current, liquid level and flow are inherently event-based, and users will expect immediate notification if they breach a configured limit or display anomalies. There is also likely to be a number of additional computed measures that business users will iterate on.
Conversely, there are use cases that would benefit from the ability to:
- Train machine learning algorithms against extended periods of historical data;
- Generate audit-trail capable reports;
- Aggregate and join data across multiple facilities.
Similarly, the chosen time-series database will impact the downstream implementation. See our article on designing a time series database and avoiding cardinality issues. Of course, this assumes that the input data can be reliably tracked and managed, as explored in our piece on implementing a data governance framework for IoT.
A parallel applies to construction sites, where external factors such as wind speed, rainfall and thunder can materially alter working practices. Our article on monitoring these conditions in real time gives one illustration, with the complementary requirements around IoT and analytics to support the construction team covered elsewhere.
Worked example: temperature and flow telemetry
Consider a data centre comprising multiple halls, populated with temperature and flow sensors at high frequency. Suppose your engineering team identifies an improvement to a key calculated parameter following a recent upgrade.
With a traditional Lambda implementation, they will need to update the code in both their fast and slower batch jobs. Once those changes are released, you will observe some transition period before the newly batch-processed figures supersede the fast-track results.
Using a Kappa approach, you simply fire up a duplicate of the existing stream processor, feed it with the historical retained stream and direct output to a fresh dataset. Provided the stream is retained for around 30 days, you will have a complete recalculation available almost immediately. Should your requirement stretch further, you would need to incorporate an archive store or a second lakehouse.
Finally, with a combined approach, the fast-track stream will continue to support customer-facing activities, and a batch process executed against the stored lakehouse images will be used to generate the requisite auditable monthly summary. Again, this is an architecture that we expect to be widely adopted, and is dependent on effective consolidation of disparate data feeds from BMS, PMS, NMS and related systems.
Summary
Ultimately, as illustrated throughout this article, the choice between Lambda and Kappa comes down to: who has to take the call at 3am?
We operate in highly demanding and live settings, spanning new-build and retrofit data centres and other facilities, and the aggregation of existing BMS, PMS and NMS platforms. Adding further layers to an active installation is undesirable, and we therefore favour deploying a single, proven streaming solution to meet the bulk of our telemetry requirements. Batch processes will find their home addressing the remaining needs.
Of course, many of our customers will be looking to evolve their existing infrastructure. In all instances, the focus will be to define an appropriate event stream, associated metadata and reconciliation mechanisms, before decommissioning any legacy flows once sufficient confidence is established.
Our experience and product offering, including PODVIEW, along with our dedicated Telemetry and Software Engineering teams, has been developed to support this, underpinned by a 99.9% availability commitment and 250+ successful implementations.
Harry
The preceding box outlines our thinking. We now consider how to proceed.
Next steps
Regardless of the final architecture, there are a small set of key considerations to address:
- Establish the system(s) of record. Is it the event log, object storage, or a combination? Who controls it?
- Ensure events are time-stamped appropriately. Ideally at point-of-generation, and maintained consistently across all processing jobs.
- Enable repeatable writes to destination stores. Record a globally-unique reference per event, and apply updates via insert/upsert operations.
- Log retention aligned to your reprocessing requirement. Size the log based on the maximum amount of time you anticipate needing to reprocess, then introduce additional tiers of storage or a data lake if required.
- Test a reprocess. Execute a reprocessing operation in a test environment to establish baseline reprocess time under expected production volume.
- Schema evolution. You will need to support reading historical records under the updated schema.
In the case of integrating Building Management Systems, Power Management Systems and other networked assets into such a data flow, we provide BMS and PMS integration.
Implementing the solution with PODTECH
As outlined above, we can implement custom software to suit your use case; whether it be for datacenters, legacy transformation, ML or other mission-critical software-as-a-service. Where a live monitored view of your DC estate is desired off-the-shelf, PODVIEW provides comprehensive live and historical telemetry.
Alternatively, if looking to migrate your current DC estate to a stream-based dataflow, our team can begin with Legacy Transformation and Integration and discuss the specific retention, reprocessing and visualisation needs of your business.
Our people can be deployed as part of your own function.
FAQ
Should I consider Kappa over Lambda?
Kappa tends to be the more obvious choice for a green-field project requiring an event-driven dataflow, given there is no separate batch and speed layer to manage. Of course, if there is a significant requirement to re-run historical records, potentially many years' worth, or you have an extensive batch data estate already in place, Lambda may still apply. In some cases a combination of both will be used.
Does Kappa support any form of batch?
It will depend on the length of time the log can be retained. As noted previously, the log can be traversed by a stream processor in the same manner as a traditional batch. Further, distributed computing frameworks including Apache Flink and Spark Structured Streaming allow equivalent batch and stream implementations.
How much log history is required?
It is dependent on the anticipated period over which records would be re-processed. Out of the box, Kafka supports a 7-day log, likely insufficient for many applications. Kreps' article cites 30 days. Again, supplementary storage or a replicated data lake could be employed to increase the period.
Which platforms form the basis of these architectures?
Typically, Kafka for the ingest, Hadoop ecosystem or Spark for batch, Spark or Flink for the speed layer and Cassandra as a wide-column store. All of these remain valid in a Kappa context, although the final serving datastore will vary depending on the required querying and volume.
References
- Big Data, Chapter 1 (Marz and Warren)
- Fundamentals of Real-Time Data Processing Architectures: Lambda and Kappa
- Questioning the Lambda Architecture, O'Reilly
- Lambda vs Kappa Architecture, The HLD Handbook
- The Lambda and the Kappa, IEEE 2017
- Lesson 15.9: Lambda and Kappa architectures, System Design From First Principles
- Designing a Production-Ready Kappa Architecture, Uber Engineering
- Building a fit-for-purpose data processing architecture, KPMG Belgium
- Batch vs Stream Processing, The HLD Handbook
