Posts

Showing posts with the label kafka

Kafka: How to handle duplicate messages

Image
Kafka is "at least once" by default. ???? What is "At Least Once" in Kafka? (Simple Explanation) "At least once" means: Kafka guarantees that every message will be delivered , But sometimes the same message might be delivered more than once (duplicate). 🔁 Why it happens: If a consumer crashes or times out, Kafka resends the message after retry.            (Here, what I meant by resend  that Kafka allows to pull the same message. If you know about Kafka Architecture it does not push/ send messages to consumer. Instead consumer is the one pulls the messages) If the system didn’t record that it already processed it, it may process it again . 🛠 Example: You (Consumer) receive a payment event. You process it and update the database. But before you commit (Telling Kafka "I have successfully processed this message" or in other words consumer failed to submit the offset to Kafka ), the consumer crashes. Kafka thinks it fa...

Apache Kafka - The basics

Image
 What is Kafka? Event and Message streaming platform Yes, It is open-source and freely available. There are some commercial availabilities also.  Producers( AKA publishers) push messages/events to Kafka Consumers( AKA subscribers) listen & receive messages/events Publisher ?? Subscriber ??  Don't worry. Let's take a look at it before digging deep. 😊 Publisher Subscriber Pattern. Consider below case. A sender sends message to the receiver.  Sender needs to know the receiver address ( means receiver address should configure in Sender side) Both parties should agreed upon common protocol/format for data sending and receiving.  Now see this case,  Now 3 receiver addresses should configure in sender side.  And if you need to add a new one, then sender side also has a change to be done.  Imagine multiple sender sending multiple receivers ,  Yes. the configuration is a mess now. It is not easy to add a new receiver because there can be many sen...