Course contentsShow
← System Design
Lesson 658 of 1,91918. Message Queues and BrokersFree lesson

Topic Subscriptions and Filtering

Creating multiple subscriptions to topics with optional filters to receive relevant message subsets.

Topic Subscriptions and Filtering

What You'll Learn

You'll learn how to create multiple subscriptions to a single topic and apply filters so each subscriber receives only the messages that matter to them.

The Core Idea

In a pub-sub system (which you learned about recently), multiple consumers can subscribe to the same topic. But what if different subscribers need different subsets of messages from that topic?

Topic subscriptions with filtering let each subscriber define rules about which messages they actually want to receive. Instead of getting every message published to a topic, a subscriber can say "only send me messages that match these criteria."

How It Works

Think of a newsletter where you can choose your interests. The publisher sends out articles about "Sports," but you only check boxes for "Basketball" and "Soccer"—you won't receive hockey updates. Similarly, a topic might receive all order events, but:

  • The shipping service subscribes with a filter: status = 'shipped'
  • The fraud detection service subscribes with a filter: amount > 1000
  • The analytics service subscribes with no filter (receives everything)

All three subscribe to the same orders topic, but each gets a different view of the message stream.

Common Filter Types

  • Attribute-based: Filter on message metadata (e.g., region, priority, type)
  • Content-based: Filter on actual message payload (e.g., price > 100)
  • Pattern matching: Use wildcards or regular expressions

Benefits

  • Reduces network bandwidth—subscribers don't receive irrelevant messages
  • Simplifies subscriber logic—less filtering code in the application
  • Allows flexible routing without creating dozens of specialized topics

Key Takeaway: Topic subscriptions with filtering let multiple subscribers share a topic while each receives only the message subset relevant to their needs, reducing noise and network overhead.