---
title: "Create topics"
description: "Create topics on the simulated cluster from a real client, with kafka-topics.sh, the Admin API or automatic creation, within the free-play caps."
url: https://monedula.dev/flock/docs/sim-bridge/how-to/create-topics/
---
Topics you create through the bridge go through the playground's own topic creation, the one the playground's terminal uses for `kafka-topics --create`, so they appear on the canvas like any other topic and follow the same free-play caps.

## Before you start

- A paired bridge, from steps 1 and 2 of [Connect your first app](/flock/docs/sim-bridge/tutorials/connect-your-first-app/).

## With kafka-topics.sh

```bash
bin/kafka-topics.sh --bootstrap-server 127.0.0.1:19092 \
  --create --topic clicks --partitions 3 --replication-factor 3
```

The command sends a CreateTopics request. Leave out `--partitions` or `--replication-factor` and the defaults apply: 1 partition, and a replication factor of 3 or the number of live brokers if that is lower.

To check a topic's settings, describe its configs:

```bash
bin/kafka-configs.sh --bootstrap-server 127.0.0.1:19092 \
  --describe --entity-type topics --entity-name clicks
```

The answer lists the topic configs the playground models, with Kafka's names and default flags.

## With the Admin API

```java
try (Admin admin = Admin.create(Map.of("bootstrap.servers", "127.0.0.1:19092"))) {
  admin.createTopics(List.of(
      new NewTopic("audit", 2, (short) 3).configs(Map.of("cleanup.policy", "compact"))
  )).all().get();
}
```

Configs the playground does not model are accepted and ignored. A `validateOnly` request runs the same checks and creates nothing.

## By producing

A producer that writes to a topic that does not exist creates it with the defaults above, as a broker with automatic topic creation does. [Use the Java client](/flock/docs/sim-bridge/how-to/use-the-java-client/) does this with `payments`.

## When creation is refused

| Error | Why |
| --- | --- |
| `POLICY_VIOLATION` | Over a free-play cap: at most 6 topics besides the one the session starts with, and a partition count the topology can draw. The message names the cap. |
| `TOPIC_ALREADY_EXISTS` | A topic of that name exists. |
| `INVALID_TOPIC_EXCEPTION` | A name Kafka refuses: longer than 249 characters, a character other than letters, digits, `.`, `_` and `-`, or `.` or `..`. The message is Kafka's. |
| `INVALID_REPLICATION_FACTOR` | More replicas than live brokers. |
| `INVALID_PARTITIONS` | Fewer than 1 partition. |
| `INVALID_CONFIG` | A config the playground models, with a value its validation refuses, such as a `cleanup.policy` it does not know. |

Topic creation works in free play only, which is the only mode that pairs with the bridge. While the playground is paused, a creation waits for **Play**.