# ITopicPartitionConfig

**Kind:** Interface

**Source:** [`packages/microservices/external/kafka.interface.ts`](https://github.com/nestjs/nest/blob/master/packages/microservices/external/kafka.interface.ts#L274)

**Part of:** [Microservices](subsystem-packages-microservices)

`ITopicPartitionConfig` defines Kafka topic partitioning configuration for microservice deployments. It specifies the topic name, total partition count, and optional explicit replica assignments used when creating or configuring Kafka topics.

## Properties

| Property | Type |
|---|---|
| `topic` | `string` |
| `count` | `number` |
| `assignments` | `Array<Array<number>>` |

## Diagram

```mermaid
graph LR
  Config[ITopicPartitionConfig]
  Config --> Topic[topic: string]
  Config --> Count[count: number]
  Config --> Assignments[assignments: number[][]]
  Assignments --> Partition0[Partition replica broker IDs]
  Assignments --> PartitionN[Additional partition replica broker IDs]
```

## Usage

```ts
import type { ITopicPartitionConfig } from './kafka.interface';

const ordersTopicConfig: ITopicPartitionConfig = {
  topic: 'orders.created',
  count: 3,
  assignments: [
    [1, 2, 3],
    [2, 3, 1],
    [3, 1, 2],
  ],
};

// Pass the configuration to the Kafka topic provisioning layer.
await kafkaAdmin.createTopics({
  topics: [
    {
      topic: ordersTopicConfig.topic,
      numPartitions: ordersTopicConfig.count,
      replicaAssignment: ordersTopicConfig.assignments,
    },
  ],
});
```

## AI Coding Instructions

- Keep `count` aligned with the number of entries in `assignments` when explicit assignments are provided.
- Represent each partition assignment as an array of Kafka broker IDs; ordering typically determines the preferred replica leader.
- Use a unique, stable Kafka topic name in `topic`, following the project's topic naming conventions.
- Validate that every broker ID in `assignments` exists in the target Kafka cluster before provisioning.
- Integrate this interface with Kafka admin/topic-creation code rather than consumer or producer runtime configuration.
