Install kafkajs and use Transport.KAFKA in createMicroservice() and ClientsModule.register(). Configure brokers, clientId, and consumer groupId. clientId identifies the application in Kafka logs; groupId determines which consumer group this instance belongs to — Kafka delivers each message to only one consumer per group.
clientId — identifies this application in Kafka logs and metrics; use a meaningful service name.
groupId — identifies the consumer group; Kafka delivers each message to one consumer per group.
brokers — array of broker addresses; provide multiple for high availability.
NestJS uses kafkajs internally — all kafkajs producer and consumer options are supported.
Each microservice instance with the same groupId competes for partition assignments — enabling horizontal scaling.