Kest

Search

Search the documentation

Microservices

Kafka

Use Kafka for a durable, replayable stream of events.

Kafka is a distributed log: messages are appended to a topic and kept for days or forever. Consumers read at their own pace and can replay history. It handles very high volume and is the usual backbone for event streaming.

app.connectMicroservice(KafkaOptions("kafka:9092", groupId = "orders-service", fromBeginning = false))
import(ClientsModule.register { client("ORDERS", KafkaOptions("kafka:9092")) })   // in the caller's module
  • Requests use a reply topic with a correlation header.
  • A service reads as part of a consumer group (group); instances of one service share the work, and each group sees every message.
  • A consumer group that has never read a topic starts at the end (like NestJS fromBeginning: false), so requests sent before the service existed are not replayed. Pass fromBeginning = true for event processing that needs the history.
  • The consumer group rejoins after a broker restart (tested for a single broker; cluster failover is not tested).
  • Delivery is at least once: make handlers idempotent.

When to choose it

Event streaming, analytics pipelines, audit logs, anything where you want to keep and replay events. For simple request/reply it is heavier than NATS or RabbitMQ.

Your handlers are the same on every transport: see Overview. Compare all of them in Transports compared.

Read more