# Kappa Architecture

> Stream-first architecture that eliminates the batch layer by using streaming for everything.

- **Category**: Data Science
- **Subcategory**: Architecture
- **Canonical URL**: https://designpattern.fyi/patterns/kappa-architecture/

---

## Description
**Context**: Lambda architecture requires maintaining two codebases. Kappa simplifies by using only a streaming layer, replaying streams when recomputation is needed.


## Use Cases
Organizations wanting simpler architecture than Lambda while maintaining real-time processing capabilities.



## Implementation Example

```python
# Kappa Architecture Pattern from pyspark.sql import SparkSession from pyspark.sql.functions import *
spark = SparkSession.builder.appName("Kappa").getOrCreate()
# Single streaming pipeline stream = (spark.readStream .format("kafka") .load() .writeStream .foreachBatch(process_batch) .start())
def process_batch(df, batch_id): # Process micro-batch result = df.groupBy("event").count() result.write.format("parquet").save(f"output/{batch_id}")
```



## Trade-offs


### Advantages

- - Single codebase

- - Simpler maintenance

- - Reduced complexity

- - Stream-first design




### Considerations & Drawbacks

- - Stream processing complexity

- - Limited replay capabilities

- - Higher operational cost

- - Immature ecosystem compared to batch







