Best practices for topics and tags

Updated at:

When message streams share a single topic, differences in type, volume, or priority cause consumers to compete for throughput -- low-volume, latency-sensitive messages get stuck behind high-volume traffic. Topics and tags give you a two-level classification scheme: topics separate independent message streams, and tags subdivide related messages within a topic so consumers receive only what they need.

How topics and tags work together

A topic is the first-level classifier. Each topic represents an independent message stream. Consumers subscribe to topics, and messages in different topics have no inherent relationship.

A tag is the second-level classifier. Producers set a tag on each message to subdivide traffic within a topic. Consumers filter by tag to receive only matching messages.

Relationship between topics and tags

Tags classify related messages within the same topic -- for example, subsets of a larger category, or sequential stages of a workflow. Messages in different topics are independent streams with no shared relationship.

When to create a separate topic vs. use a tag

Four criteria determine whether a message category belongs in its own topic or as a tag under an existing topic.

Criterion

Create a separate topic

Use a tag

Message type

Different message types (normal, transactional, scheduled, ordered) require separate topics. Tags cannot distinguish message types.

Same-type messages that need sub-classification.

Business domain

Unrelated domains -- for example, Taobao transaction messages and JD logistics messages.

Related sub-categories within one domain -- for example, electrical appliance orders, women's clothing orders, and cosmetics orders within Tmall transaction messages.

Priority and latency

Messages with different priority levels that need independent throughput -- for example, Hema (1-hour delivery) logistics, Tmall Supermarket (24-hour delivery) logistics, and Taobao (relatively slower delivery) logistics.

Messages that share the same priority level.

Volume disparity

Low-volume messages with strict latency requirements. Sharing a topic with high-volume traffic starves low-volume consumers waiting behind large message backlogs.

Messages with comparable volume that share throughput capacity without contention.

Decision flowchart

Evaluate these questions in order. Stop at the first "yes":

  1. Are the message types different? (normal vs. transactional vs. scheduled vs. ordered)

    • Yes: separate topics. Tags cannot separate message types.

  2. Are the messages from unrelated business domains?

    • Yes: separate topics.

  3. Do the messages have different priority or latency requirements?

    • Yes: separate topics to provide independent throughput.

  4. Is there a significant volume difference that could starve low-volume consumers?

    • Yes: separate topics.

  5. None of the above apply?

    • Use tags within the same topic to sub-classify related messages.

Trade-offs

Choosing between topics and tags involves balancing isolation against operational overhead:

Factor

More topics (finer isolation)

Fewer topics with tags (coarser isolation)

Consumer isolation

Each consumer group subscribes independently with dedicated throughput.

Consumers share throughput within the topic and filter by tag.

Operational overhead

More topics to create, monitor, and manage.

Fewer resources to manage; filtering is handled at the consumer level.

Message ordering

Ordered messages are scoped per topic. Separating unrelated streams prevents ordering conflicts.

All messages within a topic share the same ordering scope.

Flexibility

Adding a message category requires creating and configuring a new topic.

Adding a message category requires only a new tag value -- no infrastructure change.

Example: e-commerce order and payment system

Consider the Tmall transaction platform, which processes order messages and payment messages. The following walkthrough shows how to apply the decision criteria.

Step 1 -- Separate by business domain (topics)

Order processing and payment processing are distinct domains with different consumers, processing logic, and failure-handling strategies. Apply criterion 2 (business domain) and create two topics:

  • Topic_Order -- all order-related messages

  • Topic_Pay -- all payment-related messages

Step 2 -- Sub-classify by product category (tags)

Within Topic_Order, different product categories route to dedicated fulfillment systems. Because these messages share the same type, priority, and volume profile, they belong in one topic with tags:

Tag

Consumer

Why a tag (not a topic)

electrical-appliances

Appliance fulfillment system

Same message type, same priority

mens-wear

Clothing fulfillment system

Same message type, same priority

womens-wear

Clothing fulfillment system

Same message type, same priority

cosmetics

Cosmetics fulfillment system

Same message type, same priority

Each downstream system subscribes to Topic_Order and filters by the tags it handles. For example, the cosmetics fulfillment system sets its tag filter to cosmetics and ignores all other order messages.

Result

This two-level structure keeps the architecture clean: topics separate independent business flows with dedicated throughput, and tags route messages to specialized consumers within each flow -- without requiring additional topics.

Related topics