// Module included in the following assemblies:
//
// assembly-using-the-topic-operator.adoc

[id='ref-topic-replication-{context}']
= Configuring topics for replication and number of partitions

The recommended configuration for topics managed by the Topic Operator is a topic replication factor of 3, and a minimum of 2 in-sync replicas.

[source,shell,subs="+attributes"]
----
apiVersion: {KafkaTopicApiVersion}
kind: KafkaTopic
metadata:
  name: my-topic
  labels:
    strimzi.io/cluster: my-cluster
spec:
  partitions: 10 # <1>
  replicas: 3 # <2>
  config:
    min.insync.replicas: 2 # <3>
  #...
----
<1> The number of partitions for the topic.
<2> The number of replica topic partitions. Currently, this cannot be changed in the `KafkaTopic` resource, but it can be changed using the `kafka-reassign-partitions.sh` tool.
<3> The minimum number of replica partitions that a message must be successfully written to, or an exception is raised.

NOTE: In-sync replicas are used in conjunction with the `acks` configuration for producer applications.
The `acks` configuration determines the number of follower partitions a message must be replicated to before the message is acknowledged as successfully received.
The bidirectional Topic Operator runs with `acks=all` for its internal topics whereby messages must be acknowledged by all in-sync replicas.

When scaling Kafka clusters by adding or removing brokers, replication factor configuration is not changed and replicas are not reassigned automatically.
However, you can use the `kafka-reassign-partitions.sh` tool to change the replication factor, and manually reassign replicas to brokers.

Alternatively, though the integration of Cruise Control for Strimzi cannot change the replication factor for topics,
the optimization proposals it generates for rebalancing Kafka include commands that transfer partition replicas and change partition leadership.

[role="_additional-resources"]
.Additional resources
* xref:assembly-downgrade-{context}[Downgrading Strimzi]
* xref:con-partition-reassignment-str[]
* xref:cruise-control-concepts-str[]
