What is Publish Subscribe Model?
Updated: Oct 27

The publish subscribe model is a way for software components to exchange messages without the sender addressing each receiver directly. Publishers send messages to a named topic or another classification. Subscribers register the information they want, and messaging infrastructure routes matching messages to them. One publication can therefore reach several independent applications.
Often shortened to pub/sub, this is an architectural pattern rather than one network protocol. MQTT implements it for connected devices; other systems use different routing, storage and delivery rules. The pattern explains who is interested in a message. It does not, by itself, promise that an offline device will receive it later, that processing will happen instantly or that a command will run exactly once.
From subscription to application: follow one message
Consider an environmental sensor publishing a new temperature reading. The sensor knows the messaging service and a destination classification, but it need not maintain a list of dashboards, recorders and alerting applications. Those applications express their interests independently. A broker, event bus or equivalent routing system joins the two sides.
A subscriber first registers an interest, such as a topic filter. The service checks the request and records an accepted subscription. When a publisher supplies a matching message, the infrastructure determines which subscriptions are eligible and arranges delivery. The receiving application then parses the data and decides what to do. Subscription acceptance, message transfer and successful application processing are separate observations.
The same program can both publish and subscribe. A heating controller might receive sensor readings and publish its own operating state. These are communication roles, not permanent categories of equipment. Nor does asynchronous messaging require every client API to return immediately: a library can expose blocking calls, callbacks or an asynchronous interface.
Our MQTT guide explains the protocol used in many such device systems. Within MQTT, clients connect to a server commonly called a broker. The publisher-to-broker exchange and the broker-to-subscriber exchange are separate, so a successful publishing result does not identify every downstream consumer or confirm their final actions.
A topic is a routing label, not the reading itself
Suppose the sensor publishes to home/lounge/temperature with a payload containing a value and a timestamp. An MQTT subscriber interested in all room temperatures could use home/+/temperature. An archive interested in that home’s complete topic subtree could use home/#. A bedroom-only subscription would not match this lounge publication.
Subscription filter | Result for home/lounge/temperature |
|---|---|
home/+/temperature | Matches: + covers the lounge level. |
home/# | Matches: # covers the remaining topic levels. |
home/bedroom/temperature | Does not match: bedroom and lounge differ. |
These are MQTT examples, not a universal pub/sub syntax. In MQTT, + matches one complete topic level, while # matches the parent and any following levels and must appear at the end. Names are case-sensitive, and an initial wildcard does not automatically include topics beginning with $. A publisher uses a concrete topic name, not a wildcard filter.
The MQTT 5.0 specification defines these matching rules. It also distinguishes topic matching from payload interpretation. A normal MQTT filter does not mean “send only temperatures above 25 degrees”. That requires application logic or a separately supported broker feature. Topic names, payload fields, units and schema versions must form a shared contract even though the publisher does not list its subscribers.
Decoupling removes some dependencies and leaves others
Pub/sub lets a new dashboard subscribe without asking the sensor publisher to add another receiver address. Independent consumers can evolve or be replaced while the publisher continues using the agreed message contract. This is useful when several teams or applications need different views of the same observations.
The remaining dependencies are substantial. Components still need the correct service address, credentials, topic conventions and compatible data. Changing temperature from Celsius to an undocumented integer scale can break subscribers without changing a single route. A new optional field may be compatible; removing or redefining an existing field may require an explicitly versioned contract.
Time independence is conditional. A routing service with no message storage cannot deliver yesterday’s publication to a subscriber that only connects today. Storage, retained state, session queues and replay capabilities add different forms of time separation. They must be selected and tested rather than inferred from the words publish and subscribe.
The intermediary also creates an operational dependency. Capacity, routing configuration, storage health and availability now matter at that service. Clustering and replication can improve a particular deployment, but the architectural pattern does not prescribe them or eliminate every failure. Pub/sub can reduce direct coupling without making the complete system automatically faster or simpler.
Copies for independent consumers, shared work for a group
With ordinary independent subscriptions, each interested consumer receives its own copy. A dashboard can display a reading while an archive records it and an alerting application evaluates it. None needs to compete with the others for the sole copy, because all three have a distinct job.
Work sharing answers a different question: which one of several equivalent workers should process a job? If three archive workers all use independent subscriptions, they can each process the same reading. That is not automatically three times the useful archive capacity; it may be three copies of the work.
The RabbitMQ publish/subscribe tutorial shows the distinction through a fanout exchange and separate bound queues. An exchange can route a copy to each relevant queue. Multiple workers consuming from one queue instead share that queue’s deliveries. The AMQP guide distinguishes RabbitMQ’s exchange model from the AMQP 1.0 protocol, so those product concepts should not be presented as one universal AMQP layout.
MQTT 5 has a shared-subscription form, such as $share/archive/home/+/temperature. Several sessions joining that same shared subscription share its matching publications: the server selects one member for a publication, rather than delivering it to every member as independent subscriptions would. The standard leaves selection criteria to the implementation; it does not guarantee round-robin distribution.
Different shared groups remain independent, and a normal subscription can coexist with a shared subscription. A client whose interests overlap can therefore receive additional copies. “One selected worker” describes the group’s routing decision, not an unconditional exactly-once business-processing guarantee after every retry or failure.

Storage decides what a late subscriber can recover
Core NATS is a useful counterexample to the assumption that all pub/sub systems retain publications. Its current documentation describes live, at-most-once delivery to interested connected subscribers, without storing messages for offline consumers. A subscriber that was absent cannot request that missing history from Core NATS later.
JetStream adds a storage layer to NATS. Streams capture matching subjects, while consumers maintain independent reading positions and support configured replay and acknowledgement behaviour. Storage type, retention limits, expiry and replication still determine what survives and remains available. A feature named persistence is not an unlimited archive or proof against every storage failure.
MQTT offers other mechanisms with different purposes. A continuing session can preserve subscriptions and pending delivery state under its session and QoS rules. A retained publication represents a stored latest value for a topic, subject to server support, expiry and subscription options. It is not a complete sequence of every historical change. MQTT 5 shared subscriptions also do not receive retained messages merely by joining the group.
Ask what recovery actually means for the application. A dashboard might need a fresh state snapshot after reconnecting. An audit process might need every event in a bounded history. An old “turn on” command might be unsafe or irrelevant after a long outage. Those needs lead to different storage and expiry choices, even if all three use pub/sub routing.
An original model: traffic grows where the copies are made
Techie Broadband used a deterministic Python 3.12.14 model to check the example topic matches and a simple capacity calculation. Assume a publisher produces 12 messages each second, each containing a 200-byte application payload. Assume three independent subscribers match every message. This is an explanatory model, not a broker test or a broadband traffic capture.
The publisher sends 12 × 200 = 2,400 payload bytes per second to the broker. The broker sends three copies, giving 12 × 200 × 3 = 7,200 payload bytes per second across its outgoing subscriber deliveries. One input message has become three output payload copies. The publisher’s own upload does not triple merely because a third subscriber appears, provided the broker performs that fan-out.
Modelled path | Application payload rate |
|---|---|
Publisher to broker | 2,400 bytes/s: one copy of each reading. |
Broker to three subscribers combined | 7,200 bytes/s: three matching copies. |
One subscriber’s incoming stream | 2,400 bytes/s: its own matching copy. |
These totals exclude topic names, protocol headers, acknowledgements, TCP/IP, TLS, retransmissions and any subsequent services. They also do not describe how a broker stores copies internally. Actual bandwidth depends on the complete protocol and deployment. Twelve readings per second is a chosen illustrative input, not a claim about a typical sensor or a recommended sampling rate.
A slow subscriber creates a rate problem
Now keep the arrival rate at 12 messages per second but let one consumer finish only eight per second. With an initially empty queue, constant rates and no drops, expiry or flow control, its backlog grows by four messages each second. After 60 seconds it contains 240 waiting messages, representing 48,000 bytes of payload before storage overhead.
A larger buffer delays exhaustion but does not remove this sustained mismatch. The design needs a suitable response: faster processing, reduced input, shared work, a retention policy or controlled rejection. Product behaviour differs. Some systems accumulate messages within limits; others drop messages or disconnect slow consumers. Monitor queue age and application completion as well as connection health.
Delivery, ordering and successful work have different boundaries
An acknowledgement from a messaging service can establish a particular protocol or storage milestone. It does not generally prove that every subscriber has finished its own transaction. The MQTT QoS guide explains why delivery levels and application effects must be assessed separately. A consumer may receive an event, commit a change and then lose its acknowledgement, leaving a retry to encounter an already completed operation.
For consequential effects, use an appropriate stable application operation identifier and duplicate-handling design. A timeout means the outcome may be unknown; it is not proof that nothing happened. Expiry also needs an application interpretation: removing an old message from a queue does not undo work already started by a consumer.
Ordering needs a named scope. One publisher’s ordered topic stream, a queue’s delivery sequence and the order in which multiple workers finish are different things. MQTT defines ordered-topic rules for non-shared subscriptions, with qualifications around retransmission. That does not create one global completion order across different publishers, topics and subscribers.
Include useful timestamps, source identity, sequence or operation identifiers and a schema version where the application requires them. A timestamp alone is not a perfect total ordering mechanism when clocks differ. Consumers should have a deliberate policy for stale state, gaps and duplicate events rather than treating arrival order as a complete history of reality.
Secure both publishing and subscribing
Authentication identifies a connecting client; authorisation determines what it may do. A sensor may need permission to publish its own readings but no permission to issue commands to every controller. A dashboard may need read access without publish access. Broker access controls should reflect those separate responsibilities.
Broad wildcard subscriptions can expose more information than intended as a topic tree grows. Avoid placing secrets or unnecessary personal information in topic names, which may appear in logs and monitoring tools. Encrypt the network connections with an appropriate TLS configuration and protect stored data according to its sensitivity. Connection encryption normally protects each client-to-service path; it does not automatically hide readable payloads from the broker itself.
Operational controls matter too: manage credentials, maintain software, limit message sizes and queue growth, and make denied subscriptions or publications visible. A rejected permission or an incompatible payload can resemble a missing-message network fault unless the application records the relevant results.
Where the broker sits changes the broadband dependency
A broker on the local network can route between local devices without sending every message over an internet connection, provided those functions and services are genuinely local. A cloud-hosted broker introduces a WAN path. A local publisher uploading once to a remote broker and three remote consumers receiving copies do not necessarily put all three copies back across the publisher’s broadband line.
If several subscribers are also behind that same home or business connection, their cloud deliveries can use its download path. Other cloud APIs, remote access and authentication services may create additional dependencies even where the main broker is local. Draw the actual paths before attributing traffic or resilience benefits to the architecture.
Reconnection Handling explains why recovering connectivity and recovering useful application state are different tasks. For UK broadband diagnosis, establish a suitable wired baseline and distinguish Wi-Fi loss, an access-line outage, a broker-side queue and a consumer that has stopped processing. Latency under load can delay feedback on a busy path, but upgrading line speed does not repair a wrong topic filter or an expired session.
Separate publisher acceptance, subscriber delivery and application completion in monitoring.
Set retention and queue limits for the value and lifetime of the information.
Give equivalent workers a shared-work mechanism when they should divide tasks.
Keep topic permissions and message contracts aligned as consumers change.
A practical trace for a message that did not produce a result
Record the actual broker, protocol and versions, the publisher’s concrete topic and the subscriber’s accepted filter or binding.
Check authentication and separate publish and subscribe permissions. Inspect subscription results and any rejection or capability messages.
Trace one authorised test message using a stable identifier, recording publication, broker routing, subscriber receipt and application completion separately.
Check whether the subscriber was present, whether its session or queue survived, and whether retention, expiry or a missing binding explains the gap.
Compare arrival and completion rates, queue depth and oldest-message age. Inspect duplicate handling, parsing errors and any shared-group membership.
Retest on a suitable wired path and then in a controlled interruption scenario. Verify the resulting application state rather than only a connected indicator or publish callback.
Choose the communication behaviour the job needs
Requirement | Design question |
|---|---|
Several independent uses of one observation | Does each consumer have its own subscription or delivery state? |
Several equivalent workers for one job | Is a shared group or competing-consumer mechanism configured? |
Recovery after absence | What exactly is stored, for how long, and how is it replayed? |
Immediate confirmation of an action | Is a request/reply or explicit application-result flow needed? |
Pub/sub works well when information should reach independently interested consumers and the application can manage asynchronous results. Direct request/response can be clearer when a caller needs one immediate answer. The two can coexist: a service can accept a request, publish subsequent state changes and provide a separately correlated completion result. Choose from the actual interaction, not from the popularity of a pattern.
Frequently asked questions
Is publish subscribe the same thing as MQTT?
No. Publish subscribe is a messaging pattern. MQTT is one protocol that implements it, with specified topic, session and delivery behaviour. Other products can use different addressing, retention and consumer rules.
Does every subscriber receive every message?
Only relevant eligible subscriptions receive a publication under the service’s rules. Independent matching subscriptions can each receive a copy, while shared groups or competing consumers divide work among members. Permissions, connection state and delivery policies also matter.
Will an offline subscriber automatically receive old messages?
No. Recovery requires a suitable storage, session or replay mechanism and sufficient retention. Live-only systems may discard messages for absent subscribers, while a retained latest value is different from a complete event history.
Does publishing once mean the network carries only one copy?
No. A publisher can send one input copy while the intermediary creates several outgoing subscriber deliveries. The actual paths, protocols and number of matching consumers determine where the extra traffic occurs.
What to remember
Publish subscribe separates the act of announcing information from the list of applications interested in it. Its practical value comes from explicit interests and independent consumers. Reliable operation still needs a compatible message contract, deliberate storage and delivery rules, sensible access control and evidence that the intended application work actually completed.

