Skip to content

๐Ÿ“จ Pub/Sub Backend Configuration

MSight supports pluggable pub/sub backends to handle internal message distribution. The system provides three interchangeable options:

  • Redis
  • NATS
  • Kafka

This allows you to select the most appropriate messaging backend based on your deployment environment and application needs.


๐Ÿ”ง Choosing the Backend

Set the backend using the environment variable:

export MSIGHT_PUBSUB_BACKEND=redis  # Options: redis, nats, kafka

If MSIGHT_PUBSUB_BACKEND is unset, the system defaults to:

redis

๐Ÿงช Usage

NATS

To use nats backend, specify the following environment variables:

export MSIGHT_PUBSUB_BACKEND=nats
export MSIGHT_NATS_SERVERS="['nats://localhost:4222']"

If you want to use queue to group subscriber, in your node configs, pass in a group_id:

configs = NodeConfig(group_id=queue_id_you_want)

Kafka

To use Kafka backend, specify the following environment variables:

export MSIGHT_PUBSUB_BACKEND=kafka
export MSIGHT_KAFKA_SERVERS="['localhost:9092']"

โš ๏ธ Redis requires no additional configuration if it's running on the default port locally.


๐Ÿ“Š Comparison of Pub/Sub Backends

Feature Redis NATS Kafka
Persistence โŒ No โŒ No โœ… Yes
Delivery Guarantee โŒ Best-effort โŒ Best-effort โœ… At-least-once
Message Routing Broadcast Broadcast or Queue Group Queue Group (group.id)
Supports Load Balancing โŒ No โœ… with specified group_id in node configs โœ…
Subscribers Get All Messages โœ… Always โœ… (unless grouped) โŒ Only one per group
Latency โšก Very low โšก Very low ๐Ÿข Higher (but scalable)
Setup Complexity ๐ŸŸข Easiest ๐ŸŸก Moderate ๐Ÿ”ด Most complex
Recommended Use Case Dev/test, simple messaging Real-time sensor streaming Durable, high-throughput pipelines

โœ… Recommendations

Use Redis when:

  • You want a quick, minimal setup.
  • You are handling few sensors and the volume of messages, number of subscribers is not large
  • Or you are working in a local dev/test environment.

Use NATS when:

  • You need low-latency, high-performance message delivery.
  • You want optional load balancing via queue groups.
  • You don't need message persistence or replay.

Use Kafka when:

  • You need durable, replayable messaging.
  • You have multiple services consuming from the same stream with coordination.
  • You're running a high-volume production pipeline.