Skip to main content
Quick navigation

Infinite Partitions with Topic Concentration

Conduktor Gateway's topic concentration feature allows you to store multiple topics's data on a single underlying Kafka topic.

To clients, it appears that there are multiple topics and these can be read from as normal but in the underlying Kafka cluster there is a lot less resource required.

In this demo we are going to create a concentrated topic for powering several virtual topics.

Create the virtual topics, produce and consume data to them, and explore how this works.

View the full demo in realtime

You can either follow all the steps manually, or watch the recording

Review the docker compose environment

As can be seen from docker-compose.yaml the demo environment consists of the following services:

  • gateway1
  • gateway2
  • kafka-client
  • kafka1
  • kafka2
  • kafka3
  • schema-registry
  • zookeeper
cat docker-compose.yaml

Starting the docker environment

Start all your docker processes, wait for them to be up and ready, then run in background

  • --wait: Wait for services to be running|healthy. Implies detached mode.
  • --detach: Detached mode: Run containers in the background
docker compose up --detach --wait

Creating virtual cluster teamA

Creating virtual cluster teamA on gateway gateway1 and reviewing the configuration file to access it

# Generate virtual cluster teamA with service account sa
token=$(curl \
--request POST "http://localhost:8888/admin/vclusters/v1/vcluster/teamA/username/sa" \
--header 'Content-Type: application/json' \
--user 'admin:conduktor' \
--silent \
--data-raw '{"lifeTimeSeconds": 7776000}' | jq -r ".token")

# Create access file
echo """
bootstrap.servers=localhost:6969
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username='sa' password='$token';
""" > teamA-sa.properties

# Review file
cat teamA-sa.properties

Create the topic that will hold concentrated topics

Creating on kafka1:

  • Topic hold_many_concentrated_topics with partitions:5 and replication-factor:1
  • Topic hold_many_concentrated_topics_compacted with partitions:5 and replication-factor:1
  • Topic hold_many_concentrated_topics_compacted_deleted with partitions:5 and replication-factor:1
kafka-topics \
--bootstrap-server localhost:19092,localhost:19093,localhost:19094 \
--replication-factor 1 \
--partitions 5 \
--create --if-not-exists \
--topic hold_many_concentrated_topics
kafka-topics \
--bootstrap-server localhost:19092,localhost:19093,localhost:19094 \
--replication-factor 1 \
--partitions 5 \
--config cleanup.policy=compact \
--create --if-not-exists \
--topic hold_many_concentrated_topics_compacted
kafka-topics \
--bootstrap-server localhost:19092,localhost:19093,localhost:19094 \
--replication-factor 1 \
--partitions 5 \
--config cleanup.policy=compact,delete \
--create --if-not-exists \
--topic hold_many_concentrated_topics_compacted_deleted

Creating concentration rule for pattern concentrated-.* to hold_many_concentrated_topics

cat step-07-concentration-rule.json | jq

curl \
--request POST 'http://localhost:8888/admin/vclusters/v1/vcluster/teamA/concentration-rules' \
--header 'Content-Type: application/json' \
--user 'admin:conduktor' \
--silent \
--data "@step-07-concentration-rule.json" | jq

Create concentrated topics

Creating on teamA:

  • Topic concentrated-normal with partitions:1 and replication-factor:1
  • Topic concentrated-deleted with partitions:1 and replication-factor:1
  • Topic concentrated-compact with partitions:1 and replication-factor:1
  • Topic concentrated-delete-compact with partitions:1 and replication-factor:1
  • Topic concentrated-compact-delete with partitions:1 and replication-factor:1
kafka-topics \
--bootstrap-server localhost:6969 \
--command-config teamA-sa.properties \
--replication-factor 1 \
--partitions 1 \
--create --if-not-exists \
--topic concentrated-normal
kafka-topics \
--bootstrap-server localhost:6969 \
--command-config teamA-sa.properties \
--replication-factor 1 \
--partitions 1 \
--config cleanup.policy=delete \
--create --if-not-exists \
--topic concentrated-deleted
kafka-topics \
--bootstrap-server localhost:6969 \
--command-config teamA-sa.properties \
--replication-factor 1 \
--partitions 1 \
--config cleanup.policy=compact \
--create --if-not-exists \
--topic concentrated-compact
kafka-topics \
--bootstrap-server localhost:6969 \
--command-config teamA-sa.properties \
--replication-factor 1 \
--partitions 1 \
--config cleanup.policy=delete,compact \
--create --if-not-exists \
--topic concentrated-delete-compact
kafka-topics \
--bootstrap-server localhost:6969 \
--command-config teamA-sa.properties \
--replication-factor 1 \
--partitions 1 \
--config cleanup.policy=compact,delete \
--create --if-not-exists \
--topic concentrated-compact-delete

Assert the topics have been created

kafka-topics \
--bootstrap-server localhost:6969 \
--command-config teamA-sa.properties \
--list

Assert the topics have not been created in the underlying kafka cluster

If we list topics from the backend cluster, not from Gateway perspective, we do not see the concentrated topics.

kafka-topics \
--bootstrap-server localhost:19092,localhost:19093,localhost:19094 \
--list

Let's continue created virtual topics, but now with many partitions

Creating on teamA:

  • Topic concentrated-topic-with-10-partitions with partitions:10 and replication-factor:1
  • Topic concentrated-topic-with-100-partitions with partitions:100 and replication-factor:1
kafka-topics \
--bootstrap-server localhost:6969 \
--command-config teamA-sa.properties \
--replication-factor 1 \
--partitions 10 \
--create --if-not-exists \
--topic concentrated-topic-with-10-partitions
kafka-topics \
--bootstrap-server localhost:6969 \
--command-config teamA-sa.properties \
--replication-factor 1 \
--partitions 100 \
--create --if-not-exists \
--topic concentrated-topic-with-100-partitions

Assert they exist in teamA cluster

kafka-topics \
--bootstrap-server localhost:6969 \
--command-config teamA-sa.properties \
--list

Producing 1 message in concentrated-topic-with-10-partitions

Producing 1 message in concentrated-topic-with-10-partitions in cluster teamA

Sending 1 event

{
"type" : "Sports",
"price" : 75,
"color" : "blue"
}

with

echo '{"type": "Sports", "price": 75, "color": "blue"}' | \
kafka-console-producer \
--bootstrap-server localhost:6969 \
--producer.config teamA-sa.properties \
--topic concentrated-topic-with-10-partitions

Consuming from concentrated-topic-with-10-partitions

Consuming from concentrated-topic-with-10-partitions in cluster teamA

kafka-console-consumer \
--bootstrap-server localhost:6969 \
--consumer.config teamA-sa.properties \
--topic concentrated-topic-with-10-partitions \
--from-beginning \
--timeout-ms 10000 | jq

returns 1 event

{
"type" : "Sports",
"price" : 75,
"color" : "blue"
}

Producing 1 message in concentrated-topic-with-100-partitions

Producing 1 message in concentrated-topic-with-100-partitions in cluster teamA

Sending 1 event

{
"msg" : "hello world"
}

with

echo '{"msg":"hello world"}' | \
kafka-console-producer \
--bootstrap-server localhost:6969 \
--producer.config teamA-sa.properties \
--topic concentrated-topic-with-100-partitions

Consuming from concentrated-topic-with-100-partitions

Consuming from concentrated-topic-with-100-partitions in cluster teamA

kafka-console-consumer \
--bootstrap-server localhost:6969 \
--consumer.config teamA-sa.properties \
--topic concentrated-topic-with-100-partitions \
--from-beginning \
--timeout-ms 10000 | jq

Consuming from concentrated-topic-with-100-partitions

Consuming from concentrated-topic-with-100-partitions in cluster teamA

kafka-console-consumer \
--bootstrap-server localhost:6969 \
--consumer.config teamA-sa.properties \
--topic concentrated-topic-with-100-partitions \
--from-beginning \
--timeout-ms 10000 | jq

returns 1 event

{
"msg" : "hello world"
}

Tearing down the docker environment

Remove all your docker processes and associated volumes

  • --volumes: Remove named volumes declared in the "volumes" section of the Compose file and anonymous volumes attached to containers.
docker compose down --volumes

Conclusion

Infinite partitions with topic concentration is really a game changer!