{
  "id": "pub-sub",
  "title": "Redis pub/sub messaging",
  "url": "https://redis.io/docs/latest/develop/use-cases/pub-sub/",
  "summary": "Broadcast real-time events to many consumers with Redis pub/sub.",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc"
  ],
  "last_updated": "2026-05-14T08:58:05-05:00",
  "children": [
    {
      "id": "redis-py",
      "summary": "Implement Redis pub/sub messaging in Python with redis-py",
      "title": "Redis pub/sub with redis-py",
      "url": "https://redis.io/docs/latest/develop/use-cases/pub-sub/redis-py/"
    },
    {
      "id": "nodejs",
      "summary": "Implement Redis pub/sub messaging in Node.js with node-redis",
      "title": "Redis pub/sub with node-redis",
      "url": "https://redis.io/docs/latest/develop/use-cases/pub-sub/nodejs/"
    },
    {
      "id": "go",
      "summary": "Implement Redis pub/sub messaging in Go with go-redis",
      "title": "Redis pub/sub with go-redis",
      "url": "https://redis.io/docs/latest/develop/use-cases/pub-sub/go/"
    },
    {
      "id": "java-jedis",
      "summary": "Implement Redis pub/sub messaging in Java with Jedis",
      "title": "Redis pub/sub with Jedis",
      "url": "https://redis.io/docs/latest/develop/use-cases/pub-sub/java-jedis/"
    },
    {
      "id": "java-lettuce",
      "summary": "Implement Redis pub/sub messaging in Java with Lettuce",
      "title": "Redis pub/sub with Lettuce",
      "url": "https://redis.io/docs/latest/develop/use-cases/pub-sub/java-lettuce/"
    },
    {
      "id": "dotnet",
      "summary": "Implement Redis pub/sub messaging in C# with StackExchange.Redis",
      "title": "Redis pub/sub with StackExchange.Redis",
      "url": "https://redis.io/docs/latest/develop/use-cases/pub-sub/dotnet/"
    },
    {
      "id": "php",
      "summary": "Implement Redis pub/sub messaging in PHP with Predis",
      "title": "Redis pub/sub with Predis",
      "url": "https://redis.io/docs/latest/develop/use-cases/pub-sub/php/"
    },
    {
      "id": "ruby",
      "summary": "Implement Redis pub/sub messaging in Ruby with redis-rb",
      "title": "Redis pub/sub with redis-rb",
      "url": "https://redis.io/docs/latest/develop/use-cases/pub-sub/ruby/"
    },
    {
      "id": "rust",
      "summary": "Implement Redis pub/sub messaging in Rust with redis-rs",
      "title": "Redis pub/sub with redis-rs",
      "url": "https://redis.io/docs/latest/develop/use-cases/pub-sub/rust/"
    }
  ],
  "page_type": "content",
  "content_hash": "917e0a251e59801f4f00d02baf44088ec2a63fa3eedce1e79ffd70705c1557d8",
  "sections": [
    {
      "id": "when-to-use-redis-pub-sub",
      "title": "When to use Redis pub/sub",
      "role": "overview",
      "text": "Use Redis pub/sub when you need to broadcast real-time events — notifications, chat messages, cache invalidation signals, UI updates — from one or more producers to many consumers without tight coupling."
    },
    {
      "id": "why-the-problem-is-hard",
      "title": "Why the problem is hard",
      "role": "content",
      "text": "Point-to-point communication between services creates tight coupling that becomes brittle as\nthe number of producers and consumers grows. Each new subscriber means another integration.\nSome of the obvious workarounds have real drawbacks:\n\n-   **In-process event buses** don't work across instances or services — every new pod or worker\n    starts with an empty bus.\n-   **Full message brokers** (Kafka, RabbitMQ) add operational overhead and latency that's\n    overkill when you don't need message persistence, replay, or delivery guarantees.\n-   **Per-pair direct connections** (one publisher, one subscriber, hard-coded URLs) don't fan\n    out and don't survive instance churn — adding a fourth consumer means touching the producer.\n\nA workable broadcast layer needs sub-millisecond fan-out, no per-subscriber configuration on\nthe publisher side, and a way to route events through named topics so subscribers can pick what\nthey care about without coordinating with publishers.\n\nIf you also need persistence, replay, or at-least-once delivery, the answer is\n[Redis Streams](https://redis.io/docs/latest/develop/data-types/streams), not pub/sub — the two solve\ndifferent problems on the same infrastructure."
    },
    {
      "id": "what-you-can-expect-from-a-redis-solution",
      "title": "What you can expect from a Redis solution",
      "role": "content",
      "text": "You can:\n\n-   Fan out events across microservices, pods, or edge nodes without direct service-to-service\n    calls.\n-   Broadcast cache invalidation to all application instances simultaneously.\n-   Push real-time updates to WebSocket clients across multiple server nodes (the\n    [Socket.IO](https://socket.io/) Redis adapter pattern).\n-   Signal user presence, typing indicators, or live dashboard updates with sub-millisecond\n    latency.\n-   Subscribe to flexible topic hierarchies with glob patterns — a single `orders:*`\n    subscription captures all order events without per-channel wiring.\n-   Keep durable state in regular Redis keys or external systems and use pub/sub purely as the\n    transport."
    },
    {
      "id": "how-redis-supports-the-solution",
      "title": "How Redis supports the solution",
      "role": "content",
      "text": "In practice, a publisher calls `PUBLISH channel payload` and Redis fans the message out to every\nclient currently subscribed to that channel, in the order the messages were published.\nSubscribers register interest with `SUBSCRIBE channel` (exact-match) or `PSUBSCRIBE pattern`\n(glob-match), and the connection then switches into a subscribe-only mode that pushes incoming\nmessages over the same socket. Delivery is at-most-once: a subscriber that's offline when the\nmessage is published misses it for good.\n\nRedis provides the following features that make it a good fit for broadcast messaging:\n\n-   [`PUBLISH`](https://redis.io/docs/latest/commands/publish) for fan-out from any client to every active\n    subscriber of a channel, with a sub-millisecond hop through Redis.\n-   [`SUBSCRIBE`](https://redis.io/docs/latest/commands/subscribe) and\n    [`UNSUBSCRIBE`](https://redis.io/docs/latest/commands/unsubscribe) for exact-match channel\n    subscriptions, the simplest topic-based routing model.\n-   [`PSUBSCRIBE`](https://redis.io/docs/latest/commands/psubscribe) and\n    [`PUNSUBSCRIBE`](https://redis.io/docs/latest/commands/punsubscribe) for glob-style pattern\n    subscriptions (`cache:invalidate:*`, `news.*.headline`), so a subscriber can listen to whole\n    topic hierarchies without pre-registering every channel.\n-   [`PUBSUB CHANNELS`](https://redis.io/docs/latest/commands/pubsub-channels),\n    [`PUBSUB NUMSUB`](https://redis.io/docs/latest/commands/pubsub-numsub), and\n    [`PUBSUB NUMPAT`](https://redis.io/docs/latest/commands/pubsub-numpat) for introspection — list active\n    channels, count subscribers per channel, count active pattern subscriptions.\n-   [Sharded pub/sub](https://redis.io/docs/latest/develop/pubsub#sharded-pubsub)\n    ([`SSUBSCRIBE`](https://redis.io/docs/latest/commands/ssubscribe),\n    [`SPUBLISH`](https://redis.io/docs/latest/commands/spublish)) in Redis 7.0+ so the same pattern scales\n    horizontally on a Redis Cluster without every message touching every node.\n-   No message storage overhead — messages are delivered to active subscribers and discarded\n    immediately, keeping the messaging path stateless and fast.\n-   [Keyspace notifications](https://redis.io/docs/latest/develop/pubsub/keyspace-notifications) for\n    receiving events about key changes (`SET`, expiration, eviction) through the same pub/sub\n    transport."
    },
    {
      "id": "ecosystem",
      "title": "Ecosystem",
      "role": "content",
      "text": "The following frameworks and libraries use Redis pub/sub for broadcast messaging:\n\n-   **Node.js**: [Socket.IO](https://socket.io/) Redis adapter for cross-node WebSocket fan-out\n-   **Python**: [`redis-py`](https://redis.readthedocs.io/) subscribers with\n    [FastAPI](https://fastapi.tiangolo.com/) or [Django Channels](https://channels.readthedocs.io/)\n    for WebSocket push and event listeners\n-   **Java**: [Spring Data Redis](https://spring.io/projects/spring-data-redis) message listener\n    containers for inter-service messaging\n-   **Ruby**: [Action Cable](https://guides.rubyonrails.org/action_cable_overview.html) Redis\n    adapter for Rails WebSocket broadcasting\n-   **Go**: [`go-redis`](https://github.com/redis/go-redis) `PubSub` for event listeners and\n    cluster-wide notifications\n-   **Infrastructure**: [Kong](https://konghq.com/) and [NGINX](https://www.nginx.com/) event\n    hooks; Kubernetes cluster-wide event bus via a shared Redis instance"
    },
    {
      "id": "code-examples-to-build-your-own-redis-pub-sub-broadcaster",
      "title": "Code examples to build your own Redis pub/sub broadcaster",
      "role": "example",
      "text": "The following guides show how to build a simple Redis-backed pub/sub broadcaster.\nEach guide includes a runnable interactive demo for each of the following client libraries:\n\n* [redis-py (Python)](https://redis.io/docs/latest/develop/use-cases/pub-sub/redis-py)\n* [node-redis (Node.js)](https://redis.io/docs/latest/develop/use-cases/pub-sub/nodejs)\n* [go-redis (Go)](https://redis.io/docs/latest/develop/use-cases/pub-sub/go)\n* [Jedis (Java)](https://redis.io/docs/latest/develop/use-cases/pub-sub/java-jedis)\n* [Lettuce (Java)](https://redis.io/docs/latest/develop/use-cases/pub-sub/java-lettuce)\n* [StackExchange.Redis (C#)](https://redis.io/docs/latest/develop/use-cases/pub-sub/dotnet)\n* [Predis (PHP)](https://redis.io/docs/latest/develop/use-cases/pub-sub/php)\n* [redis-rb (Ruby)](https://redis.io/docs/latest/develop/use-cases/pub-sub/ruby)\n* [redis-rs (Rust)](https://redis.io/docs/latest/develop/use-cases/pub-sub/rust)"
    }
  ],
  "examples": []
}
