Kafka Streams app does NOT fail when the Kafka cluster goes down
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Apache Kafka is a popular, distributed event streaming platform capable of handling trillions of events a day. Kafka Streams, built on top of the Kafka technology, is a client library for building applications and microservices where the input and output data are stored in Kafka clusters. Understanding how Kafka Streams behaves during failures such as when a Kafka cluster goes down is crucial for building robust, fault-tolerant systems.
Fault Tolerance in Kafka Streams
Kafka Streams is designed to be fault-tolerant. It can automatically recover from errors and continue processing as Kafka clusters become available again. The key to this resilience lies in how Kafka Streams and Kafka itself are designed.
Kafka's Distributed Nature
Kafka's architecture is intrinsically distributed. The data inside Kafka is partitioned and replicated across a cluster of servers. Even when individual brokers or entire clusters fail, Kafka Streams applications can continue to operate, albeit with some operational limitations such as delayed data processing or temporary unavailability of some data partitions.
Kafka Streams and State Stores
Kafka Streams uses local state stores (RocksDB by default) to maintain local copies of part of the data for processing. In the event of a Kafka cluster going down, Kafka Streams applications continue processing data from these local state stores. Data processed during the outage will typically be buffered locally and then written back to Kafka once it recovers.
Fault Tolerance Mechanisms
- Changelogs: Kafka Streams uses internal Kafka topics known as changelog topics to back up the data in its state stores. Therefore, if a Kafka Streams application fails or needs to be relocated to another server, it can restore its state from these changelog topics.
- Committing Offsets: By committing offsets periodically, Kafka Streams ensures that the state of processing is known and can be recovered in the event of a failure. Upon restarting, the application can resume processing from the last committed offset.
Example Scenario
Consider a Kafka Streams application that processes payment transactions. If the Kafka cluster experiences a failure, the application will continue to process transactions based on the data available in its state stores. It might not be able to produce results to Kafka during the outage, but it can buffer them and send them to Kafka once it's back up. This ensures no loss of data and minimal impact on processing continuity.
Handling Prolonged Kafka Cluster Downtime
For extended outages, Kafka Streams applications need to be prepared for potential issues such as:
- State Store Limitations: Local state stores might have limited capacity. System architects must plan for such scenarios by sizing state stores appropriately or by implementing mechanisms to offload older data.
- Dirty Reads: Applications reading from the Kafka cluster need to handle potential delays or inconsistencies in data availability.
Table: Key Features of Kafka Streams for Fault Tolerance
| Feature | Description | Impact on Failure |
| Local State Stores | Stores local copies of data for processing | Enables continued processing despite Kafka downtime |
| Changelogs | Backs up state store data in Kafka topics | Facilitates state recovery after application restart |
| Offset Committing | Tracks progress in data processing | Allows resuming processing from the last known point |
| Replication | Data in Kafka is replicated across brokers | Ensures data is available despite broker failures |
Conclusion
Understanding how Kafka Streams handles Kafka cluster failures is pivotal when designing resilient streaming applications. By leveraging Kafka’s robust architecture and Kafka Streams’ built-in mechanisms such as state stores, changelogs, and committed offsets, developers can ensure that their applications are fault-tolerant and can handle failures gracefully with minimal disruption to data processing. In sum, Kafka Streams’ design offers both resilience and flexibility, making it a fitting choice for mission-critical applications requiring high availability and durability.

