What happens when a stream is not consumed for an extended period, and how can you avoid duplicate processing in a streaming pipeline?
💡 Model Answer
If a consumer falls behind and a stream is not read for an extended period, the upstream system will accumulate data in its retention window. In Kafka, the broker will keep the data until the retention period expires or the log size limit is reached, potentially causing a backlog that consumes disk space. In Spark Structured Streaming, the engine will hold state for each key until the watermark expires, which can lead to increased memory usage. To avoid duplicate processing, you can use idempotent writes, maintain a checkpoint of processed offsets, and apply deduplication logic. For example, in Kafka you can enable exactly‑once semantics by using transactional producers and consumers. In Spark, you can use the 'dropDuplicates' function on a key column or maintain a separate deduplication table that records processed event IDs. Additionally, using watermarking and windowed aggregations helps limit state size and ensures that late data is handled appropriately.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500