Kafka-hot-and-cold-retries - Demo project for elaborating how hot and cold retries can be applied in Kafka

Overview

Apache Kafka® - Hot and Cold Retries

A demo project for elaborating how hot and cold retries can be applied in Apache Kafka®. This repository will be the source and reference codebase of my blog post.

It includes:

  • Application configuration and configuration class to read it
  • Consumer factory to create necessary listener container beans and dead letter queue forwarder
  • Simple service layer which logs the upcoming messages and to create the erroneous cases
  • Topic forwarding strategies and header utilization examples in those strategies
  • Consumer examples for hot and cold retries

Utilities:

  • Also, you can find a simple Kafka cluster to create your own playground before running the application

How to run

The repository comes with a simple Apache Kafka® cluster utilized by docker compose. As a preliminary condition, you may need to run it if there is no connectable Kafka cluster available. Otherwise, you can configure host and port information from application.yml

$ cd kafka-hot-and-cold-retries
$ docker compose up # To make Kafka cluster up and running
$ gradle bootRun # To make the application up and running

Flow

As depicted in the below figure, our journey starts with our producer. It publishes the message on the target topic, and the consumer starts processing. There will not be any problem while consuming in the happy path, and the consumer will be able to process the message.

Flow chart for hot and cold retry execution

But, if the consumer encounters an exception, it will first check whether any hot retry is defined or not. If so, we will try the message consumption up until maximum hot retry attempt or it succeeds in consuming the message. If it fails and reaches the maximum threshold, then it checks whether the cold retry configuration is defined or not. In the worst-case scenario where we do not have any cold retry configured, the message goes to the dead letter queue (DLQ). Otherwise, we will forward the message to the cold retry topic, and make it be processed with some delay. That is why these kinds of topics are called delayed topics.

Note that the delayed topics do not differ from the normal topics in terms of topology but in terminology. You will see that they could also have a hot retry defined in them or even another cold retry topic chained next to another delay topic.

Now, we have forwarded the message to our cold retry topic. One of the main aims here is to chain delay topics with themselves or other ones without blocking the other messages in the same partition. To do that, we will implement the topic forwarding logic for cold retries. Hence, a failure on a cold retry topic will lead to publishing the same message into the same topic again and skipping the current offset. Also, to have a retry threshold, we put custom headers on the topics and check the attempt value in the next consumption. By doing so, the current offset’s message will not block the next offset, and the current failed message will get its new offset at the end of the same partition after incrementing the attempt count (Yay!). Still, it is possible that we can reach the maximum attempt count limit on the cold retry. As a result, this will cause either publishing the message to the next cold retry topic if defined or the dead letter queue as a sink point.

As you can see from the overall flow, the consumers will handle each forwarded message as a fresh message and apply the hot and cold retrials on them again and again in case of failure.

You might also like...
Aagent-new-service-parent - A Springboot Rest Webservice Project that can be deployed to a Docker container

Webservice in a Docker Container A Springboot Rest Webservice Project that can b

This is a skeleton project for Zircon users that can be used to get started with Zircon.
This is a skeleton project for Zircon users that can be used to get started with Zircon.

Zircon Kotlin Skeleton Project This is a skeleton project for Zircon users that can be used to get started with Zircon. Getting started This project w

A seed and demo about how to do end-to-end testing of a Dataflow pipeline

dataflow-e2e-demo This is a demo and a seed project to show how you can end-to-end test a Dataflow pipeline. You can find more about by follwing this

Kotlin TodoMVC – full-stack Kotlin application demo

Kotlin full stack TodoMVC This project is an example implementation of the TodoMVC app written in Kotlin. More specifically, it's the Kotlin port of t

Demo Spting REST Service on Kotlin. Works with PostgreSQL via Spring Data. Data initialization provided by liquibase

Spring Boot REST API with Kotlin Spring Boot REST API service. Spring Data with PostgreSQL. Data initialization with Liquibase. Swagger UI Reference D

Android human matting demo infer by ncnn
Android human matting demo infer by ncnn

ncnn_Android_modnet Android human matting demo infer by ncnn the model from MODNet: Trimap-Free Portrait Matting in Real Time support model 1.mobilene

Spring Boot KeyCloak Demo
Spring Boot KeyCloak Demo

Spring Boot(Kotlin) + Spring Security + Keycloak Demo Docker Keycloak + MariaDB 설정 및 기본 KeyCloak 사용법 Keycloak 이미지와 MariaDB 이미지를 다운 받는다. [root@~]# dock

Demo to show ongoing notification on Huawei P50 Pocket
Demo to show ongoing notification on Huawei P50 Pocket

Bali Demo Demo code to show different ongoing notification types on the Huawei P50 Pocket external screen. Currently the external screen provides THRE

PageRoundDemo - Page Round Demo with kotlin
PageRoundDemo - Page Round Demo with kotlin

PageRoundDemo I don't like the mode of swiping to the bottom to load more, as it

Owner
Berat CANKAR
Software engineer graduated from METU and working at @udemy
Berat CANKAR
kafka test with embedded kafka

kafka-test Requirements running Kafka on localhost:9092 How to use cat sampleuser.json | http POST localhost:9000/produce or use runConfiguration ./.r

null 0 Dec 9, 2021
Michal Kubele 0 Jan 6, 2022
Kafka Streams Processor to unwrap CØSMOS blocks into CØSMOS transactions

Kafka Processor CØSMOS-Block A Kafka Streams Processor to unwrap CØSMOS blocks into CØSMOS transactions. Purpose The Kafka Processor CØSMOS-Block is b

OKP4 – Open Knowledge Protocol For 4 Dec 15, 2022
Kafka Connect connector for CØSMOS based blockchains.

CØSMOS Kafka Connector Kafka Connect connector for CØSMOS based blockchains. Purpose The Kafka Connect CØSMOS Source connector is a Kafka connector us

OKP4 – Open Knowledge Protocol For 6 Nov 23, 2022
Kafka Connect JSLT Single Message Transform

This is an implementation of the Kafka Connect SMT interface to offer transformation capabilities using the Schibsted JSLT library.

willhaben 2 May 25, 2022
sample project that shows you how you can use Ktor to creat a server for real Project.

Ktor-Sample This is a sample project that shows you how you can use Ktor to creat a server for real Project. What is done Save data to database (Get a

Mohamed Emad 4 Dec 23, 2022
A simple demo project based on MVVM clean architecture and material design & animations.

GithubFollows A simple demo project based on MVVM clean architecture and material design & animations. Architecture Specs & Open-source libraries Mini

Jaewoong Eum 288 Dec 25, 2022
TheMovies 🎬 A demo project for The Movie DB based on Kotlin MVVM architecture and material design & animations.

A simple project for The Movie DB based on Kotlin MVVM clean architecture and material design & animations. How to build on your environment

Jaewoong Eum 420 Nov 29, 2022
A demo project which demonstrates the work of javax.servlet.Filter capable of escaping / modifying / removing a part of JSON request based on specified criteria.

Replace Filter Demo A demo project which demonstrates the work of javax.servlet.Filter capable of escaping / modifying / removing a part of JSON reque

Vlad Krava 1 Jan 17, 2022
An Android template you can use to build your project with gradle kotlin dsl

Android Gradle KTS An Android template you can use to build your project with gradle kotlin dsl Build.gradle.kts You can use your project's build.grad

Deep 17 Sep 12, 2022