Create Apache Kafka® topics
Create topics in your Aiven for Apache Kafka® service to organize message streams between producers and consumers.
Understand Kafka topics
A topic in Aiven for Apache Kafka is a named stream of messages. Producers write data to topics, and consumers read from them.
Topic types depend on your Kafka service type.
Topic types
-
Classic topics
- They are available in Classic Kafka and Inkless Kafka services.
- Storage behavior varies by service type:
- In Classic Kafka services, data is stored on local broker disks unless tiered storage is enabled.
- In Inkless Kafka services, classic topics use remote storage by default. You cannot change the storage mode or local retention settings.
-
Diskless topics
- They are available only in Inkless Kafka services.
- They store topic data directly in cloud object storage.
- They require diskless support to be enabled on the service before you create diskless topics.
- You choose classic or diskless per topic when you create the topic.
- You cannot change the topic type after creation.
In Inkless Kafka services, classic and diskless topics can coexist. To choose between them, see Compare diskless and classic topics.
For diskless topic limitations, see Limitations of diskless topics.
Before you begin
Before you create topics in your Aiven for Apache Kafka service, review the following:
- Tiered storage is available in Classic Kafka services, where you can enable and configure it per topic. See Tiered storage.
- Manual topic creation gives you control over partitions, replication, and retention. This approach is preferred in production to prevent accidental topic creation.
- Automatic topic creation is disabled by default. Enable it only when needed (for example, for development clusters). In production, leave it disabled to govern topic creation and avoid accidental topics. On Inkless Kafka, auto-created topics are classic topics. Create diskless topics manually. For more information, see Create topics automatically.
Create an Apache Kafka topic
The topic creation options shown in the Aiven Console depend on the Kafka service type. In Classic Kafka services, you create classic topics. Inkless Kafka services let you choose between classic and diskless topics.
- When you create a topic with the Kafka CLI (
kafka-topics.sh), the Kafka Admin API, or other Kafka clients without specifying a topic type, the topic is created as a classic topic with remote storage by default. - To create a diskless topic, use the Aiven Console or Aiven CLI and explicitly select
the diskless topic type. If you use
kafka-topics.shfor diskless topics, use the script from the Inkless repository.
- Console
- CLI
- Terraform
- Classic Kafka service
- Inkless Kafka service
-
In the Aiven Console, select the Aiven for Apache Kafka service.
-
In the sidebar, click Topics.
-
Click Create topic.
-
Enter a name in the Topic field.
-
Optional: Turn on Enable advanced configurations to set values such as replication, partitions, retention, and cleanup policy.
-
Optional: Click Add configuration to add other Kafka topic parameters.
-
Optional: Under Tiered storage, enable tiered storage for the topic.
noteYou cannot disable tiered storage after you enable it.
-
Click Create topic.
-
In the Aiven Console, select the Aiven for Apache Kafka service.
-
In the sidebar, click Topics.
-
Click Create topic.
-
Enter a name in the Topic field.
-
In Topic type, select one of the following:
- Classic topic
- Diskless topic
noteIn Inkless Kafka services, classic topics use managed remote storage by default. You cannot change storage mode or local retention settings.
-
Optional: Turn on Keep default settings to configure advanced topic settings such as retention, cleanup policy, and message size limits.
noteYou cannot create compacted topics on Inkless Kafka services.
-
Click Create topic.
After creation, the topic appears on the Topics page. The Topic type column shows Classic or Diskless.
When creating topics using the CLI, the required options depend on the topic type.
- Classic topic
- Diskless topic
To create a classic topic:
avn service topic-create \
SERVICE_NAME \
TOPIC_NAME \
--project PROJECT_NAME \
--partitions PARTITION_COUNT \
--replication REPLICATION_FACTOR
To create a diskless topic (Inkless services only):
avn service topic-create \
SERVICE_NAME \
TOPIC_NAME \
--project PROJECT_NAME \
--partitions PARTITION_COUNT \
--replication REPLICATION_FACTOR \
--diskless-enable
Use the --diskless-enable flag to create a diskless topic. Enable diskless topics on
the service before creating them. On Inkless services, omitting the flag creates a
classic topic with remote storage.
Common parameters:
PROJECT_NAME: Aiven project that contains the Kafka service.SERVICE_NAME: Aiven for Apache Kafka service name.TOPIC_NAME: Name of the topic.PARTITION_COUNT: Number of partitions to distribute messages.--replication REPLICATION_FACTOR: Number of replicas for each partition.
- Classic topic
- Diskless topic
Define topics using the
aiven_kafka_topic
resource.
Diskless topics are supported only in Inkless services.
Enable diskless in the aiven_kafka
resource before defining topics
with aiven_kafka_topic.
Related pages