What is Broker?

A broker is an intermediary that receives messages from one system and delivers them to the systems interested in them. In MQTT and the Internet of Things, the broker is the server that accepts client connections, matches published topics to subscriptions and manages the relevant delivery state. A temperature sensor can publish once while a dashboard, an alerting service and a recorder each receive the reading independently.
This guide focuses on the MQTT broker used in smart homes, monitoring and home labs. The important distinction is that routing a message is different from storing its history or proving that an automation completed. Those outcomes need their own configuration and evidence.
Where does the broker sit in an MQTT system?
MQTT clients connect to the broker rather than opening a separate MQTT connection to every other device. A client can publish, subscribe or do both. The broker may run on a home server, a small computer, a hosted virtual machine or a managed service. It is software, even when supplied inside a dedicated appliance.
The MQTT protocol defines the conversation between those clients and the server. MQTT is not the name of the broker product. Eclipse Mosquitto is one implementation; other implementations and hosted services have their own supported features, operational limits and management tools.
Component | Responsibility |
|---|---|
Publisher | Creates a message, chooses its topic and sends it to the broker. |
Broker | Accepts connections, applies permissions, matches subscriptions and handles onward delivery. |
Subscriber | Requests matching messages and receives them under its subscription settings. |
Automation or storage application | Interprets the payload and performs the useful action, such as raising an alert or saving a reading. |
A router forwards network packets. An IoT gateway may translate sensor protocols into MQTT. An automation engine decides what to do with an event. These roles can share hardware, but installing a broker does not automatically provide the other functions. Our broader message broker guide compares messaging systems beyond this MQTT-focused use case.
Follow one sensor reading through the broker
Imagine a garage sensor reporting 18.6 °C on the topic home/garage/temperature. Its payload might contain the temperature, unit, device identifier and observation time. The topic selects interested subscriptions; the application still needs to understand what the payload means.
The sensor establishes its connection and presents the required identity or credentials.
The broker accepts or rejects that connection and the requested operations according to its configuration.
The sensor publishes its topic and payload. The broker checks its publish permission.
The broker finds eligible matching subscriptions and handles delivery to those clients.
Each receiving application validates the reading and performs its own work. A recorder saves data; an alerting service evaluates a rule.
Publishing does not require the sensor to know the dashboard’s address or whether the recorder is online. That separation is the publish/subscribe model. It reduces direct dependencies, but applications still share topic names, units, payload formats and expectations about freshness.
How topics determine who receives a message
A topic name identifies a publication. A subscription uses a topic filter to select names. MQTT uses slash-separated levels, case-sensitive matching and specific wildcard rules. A perfectly healthy network can deliver nothing if the topic filter is wrong.
Subscription filter | Illustrative matching behaviour |
|---|---|
home/garage/temperature | Matches that exact topic, not home/Garage/temperature. |
home/+/temperature | Matches one room level, such as garage or kitchen, but not home/garage/upper/temperature. |
home/# | Matches home and its descendant topics. The multi-level wildcard is placed last. |
These are ordinary independent subscriptions. Three separate clients with matching subscriptions can each receive the same publication. They do not automatically share three readings between them. Work-sharing arrangements, such as supported MQTT shared subscriptions, are a separate configuration choice.
The illustration below shows that separation: the publisher sends to the broker, and the broker sends to matching clients. Neither a retained value nor the broker’s location removes the need to define what happens during an outage.

What does an acknowledgement actually prove?
MQTT delivery has two relevant legs: publisher to broker, then broker to subscriber. An acknowledgement on the first leg does not prove that a dashboard displayed the value or that a pump physically stopped. Application completion sits beyond that protocol boundary.
QoS 0 provides at-most-once delivery on the relevant MQTT exchange, with no MQTT acknowledgement or retry for that publication.
QoS 1 provides at-least-once delivery and can produce duplicates, so repeated handling must be safe.
QoS 2 uses additional protocol state to provide exactly-once delivery on its exchange. It does not make an unrelated database write and physical action one atomic operation.
The OASIS MQTT 5.0 standard, approved in March 2019, defines these mechanisms and the server’s responsibilities. Publication QoS and the subscription’s granted QoS both affect onward delivery. The separate guide to MQTT QoS levels explains the exchanges in more detail.
For an important command, give the application a stable command identity and define its response. “Broker accepted the command”, “device received it” and “requested state reached” are three different observations. Avoid treating the MQTT Packet Identifier as a permanent business identifier; it belongs to protocol delivery state and can be reused.
Retained messages, sessions and persistence are different
Mechanism | What it is for |
|---|---|
Retained message | Makes the latest stored retained publication for a topic available to eligible new subscriptions. It is not a sequence of historical readings. |
Session state | Can preserve subscriptions and qualifying pending deliveries across a client disconnect, subject to protocol settings, expiry and resource policy. |
Broker persistence | Defines how the implementation stores state so it can recover after a process restart. Check its storage and flush behaviour. |
History database | Stores the readings or events an application needs to query later. This is an additional recording function. |
A newly opened dashboard may receive yesterday’s retained temperature immediately, such as the illustrative 22.4 °C value in the infographic. That tells it which value is stored, not whether the sensor is currently healthy. Include the measurement time and decide when a value becomes stale. Be especially careful with retained commands that a newly subscribing actuator could receive later.
MQTT 3.1.1 uses the Clean Session setting. MQTT 5 separates Clean Start from Session Expiry Interval. Keeping the same client identity matters when resuming a session; starting fresh or letting the session expire changes what can be recovered. MQTT 5 also has message expiry, which can remove a pending reading before the client returns.
A preserved client session is not a promise that every abrupt power failure preserves every accepted message. The Mosquitto configuration manual documents persistence and queue controls separately. Check the installed version, persistence backend, storage location, save policy and limits instead of assuming all broker installations behave alike.
How does the broker detect an offline device?
MQTT Keep Alive helps detect a broken client connection. When an enabled keep-alive interval would otherwise pass without another MQTT control packet, the client sends PINGREQ and expects PINGRESP. This checks the connection to the broker; it does not prove that the sensor is producing fresh measurements or that its physical input is healthy.
A client can also configure a Will Message for the broker to publish when it detects a qualifying loss of that client’s connection. An offline status topic can help an automation distinguish an old retained reading from a currently connected source. Detection and delivery are not instantaneous: keep-alive rules, network behaviour and MQTT 5 Will Delay or session settings affect the timing. Monitor the broker separately, because its own failure can prevent it issuing timely notifications.
Local broker or cloud broker: follow the dependency
A local broker can keep sensor-to-dashboard exchanges on your LAN. A cloud broker puts the WAN path between local participants, even when both devices are in the same building. Neither location is inherently right for every system: decide which conversations must continue when each dependency fails.
Event | Local broker with local clients | Cloud broker reached over broadband |
|---|---|---|
WAN connection fails | Local delivery can continue if power, LAN, broker and required services remain available. | Clients lose the cloud path. New readings need client-side or local buffering if they must survive. |
Local broker host fails | Its clients lose the messaging service until it recovers or another configured service takes over. | Cloud service may remain available, but local clients still need working power and networking. |
One subscriber disconnects | Its recovery depends on session, message and storage settings. | The same delivery questions apply; hosting does not replace configuration. |
Remote monitoring is required | Needs an authorised remote path, bridge or other integration. | Remote clients can use the hosted endpoint, subject to access controls and service availability. |
A broker cannot queue a sensor reading it never received. During a broadband outage, a cloud broker might preserve existing subscriptions and messages already accepted, but that does not recover measurements still stranded at home. A local gateway, publisher buffer or local broker-and-bridge design must accept that responsibility explicitly.
In a UK FTTP setup, the cloud path can include WiFi or Ethernet, the customer router, the ONT, the access network, the ISP and the remote host. Faster headline broadband does not remove a failed DNS lookup, incorrect listener, expired certificate or unavailable cloud service. Local broker placement removes the WAN from local exchanges, but not from remote subscribers or bridges.
Techie Broadband calculation: what crosses the WAN?
Consider an illustrative installation with 100 sensors. Each publishes one 300-byte application payload every 10 seconds. Three independent subscribers, all at the same premises, each receive every reading. Assume no local aggregation and exclude protocol headers, topic names, TLS, acknowledgements, keep-alives, retries and replication.
Quantity | Calculation | Payload-only result |
|---|---|---|
Publications | 100 ÷ 10 seconds | 10 messages per second |
Home publishers to cloud broker | 10 × 300 bytes × 8 | 24 kbit/s upstream |
Cloud broker to three home subscribers | 10 × 300 bytes × 3 × 8 | 72 kbit/s downstream |
Local broker, same local exchanges | All participating traffic stays on the LAN | No WAN payload for those exchanges |
These are Techie Broadband calculations, not measured traffic or a bandwidth recommendation. The combined payload rate on the two WAN directions is 96 kbit/s, but upstream and downstream are separate capacities. Actual network traffic is higher, and remote subscribers or a cloud bridge change the result.
The main decision here is resilience, not saving an impressive number of megabits. A low-rate stream can still matter if missing a reading breaks an alert or if a WAN round trip delays a local control decision. Conversely, a broker handling many connections can run out of memory or processing capacity even when payload bandwidth looks modest.
Outage storage and recovery need headroom
Keep the same 10-message-per-second example and assume a 20-minute WAN outage. If the design must preserve every reading for later upload, the local buffering requirement begins with 10 × 1,200 = 12,000 messages. At 300 bytes each, that is 3,600,000 payload bytes, or 3.6 MB using decimal units, before any metadata or storage overhead.
Suppose the restored upstream processing path can accept 25 messages per second while 10 new messages per second continue arriving. Only 15 messages per second drain the old backlog. The theoretical recovery time is 12,000 ÷ 15 = 800 seconds, or 13 minutes 20 seconds. At a sustained capacity of 10 messages per second, the backlog would not shrink at all.
This model assumes all readings remain eligible for delivery, sufficient storage, a steady arrival rate and constant processing capacity. Real expiry rules, reconnections, batching, throttling or slow consumers can change it. Configure and test the actual queue limit and overflow policy; a calculated payload total is not a suitable disk-allocation figure by itself.
Secure the broker’s identity and topic permissions
Authentication decides who can connect. Authorisation decides what that identity may publish or subscribe to. A temperature sensor should not gain access to actuator command topics simply because it has a valid account. Restrict wildcard subscriptions and separate device credentials where the system supports that design.
Use protected transport for connections that need confidentiality and validate the broker’s certificate against its hostname and trusted issuer.
Limit listener exposure to the intended network. A listener on loopback is different from one reachable across the LAN or internet.
Protect credentials, retained data, persistence files and administrative interfaces. Review them when replacing devices or restoring backups.
Bound message sizes, client activity and queued deliveries. An authenticated but malfunctioning device can still exhaust resources.
Ports 1883 and 8883 are commonly associated with MQTT and MQTT over TLS respectively. The port number alone does not prove encryption or safe access. Check the actual listener and client settings. A home broker usually does not need a publicly exposed inbound port merely to let local sensors talk to local applications.
Home Assistant’s MQTT integration is a client of a broker; an automation service and a broker remain distinct components. Its documentation also explains certificate validation. Where the broker runs in a container, remember that 127.0.0.1 inside a client container refers to that container, not automatically to a neighbouring broker container or the host.
A controlled publish-and-subscribe check
The following is an example procedure, not a test performed against your network. It assumes the Mosquitto command-line clients are installed and an isolated test broker is already listening on 127.0.0.1:1883 with permission for this synthetic topic. Use an existing approved test environment; do not weaken a production broker’s authentication to run it.
Open a subscriber terminal first. Run the command below and wait for its subscription acknowledgement before publishing. The debug output makes that boundary visible.
In a second terminal, publish the synthetic reading using the second command. Both commands explicitly select MQTT 3.1.1.
Confirm that the subscriber prints the exact topic and broker-check payload. The subscriber exits after one received message, or times out after 30 seconds.
If delivery works, move to the affected application’s approved connection settings and test its precise topic and payload contract. Do not substitute a wildcard production subscription for a permission check.
Subscriber: mosquitto_sub -h 127.0.0.1 -p 1883 -V mqttv311 -t 'techiebroadband/test/broker' -q 1 -v -d -C 1 -W 30
Publisher: mosquitto_pub -h 127.0.0.1 -p 1883 -V mqttv311 -t 'techiebroadband/test/broker' -q 1 -m 'broker-check'
The Mosquitto subscriber manual documents the subscription, diagnostic and timeout options. Its publisher manual documents the matching publish options. Real deployments may require TLS and credentials supplied through protected configuration. Keep passwords out of shared command history and diagnostic screenshots.
A successful result proves this publication reached this subscriber through this broker under these conditions. It does not test restart recovery, an absent subscriber, WAN connectivity, permissions for every device or whether an automation performed its action.
Troubleshoot the first boundary that fails
Symptom | Useful next check |
|---|---|
Connection refused | Confirm that the broker is running and listening on the expected address and port. Check container and firewall boundaries. |
Connection times out | Check hostname resolution, selected IP family, route and filtering. Compare local reachability with the cloud path. |
TLS handshake fails | Check hostname, certificate trust, expiry and device clock. Do not treat disabling validation as the repair. |
Connected but cannot publish or subscribe | Inspect authentication results, topic permissions and protocol reason codes or broker logs. |
Publication accepted but nothing arrives | Confirm the subscription was accepted first, then check topic case, levels, filters and subscriber connectivity. |
Clients repeatedly disconnect each other | Check for duplicate client identifiers. MQTT 5 closes the existing connection when another client takes over its identity. |
Old values appear after reconnect | Separate retained state, queued deliveries and application caching. Compare the original measurement time with receipt time. |
Live messages work but restart loses state | Inspect persistence, writable storage, recovery logs and save policy. Client session settings alone do not establish restart durability. |
After a connection problem, test the broker path before changing the broadband package or replacing the router. If message delivery succeeds but the dashboard remains wrong, trace payload parsing, units, timestamps and application rules. Repeatedly reconnecting the client does not repair a mismatched data contract.
Monitor the quantities that expose failure: active connections, rejected operations, reconnect rate, queued messages or bytes, dropped or expired deliveries, persistence errors and the age of the last valid reading. Also record the application outcome. “Broker running” is less useful than knowing that the required recorder is current and the expected alert was evaluated.
Frequently asked questions
Is a broker the same as MQTT?
No. MQTT is a messaging protocol. A broker is the server implementing the intermediary role between MQTT clients. Different broker products can support the same protocol.
Does an MQTT broker need the internet?
A broker and clients on the same local network can exchange messages without internet access when their required services remain local and available. A cloud broker, remote client or bridge needs its relevant external connection.
Is Home Assistant itself an MQTT broker?
The MQTT integration connects Home Assistant to a broker. A Mosquitto app or another separately installed broker can provide that service, even when it runs on the same physical machine.
Does a broker save every message?
No. Retained state, pending session deliveries and storage across restarts are separate mechanisms. A historical archive needs a suitable recording application or service.
Will QoS 2 make an automation run exactly once?
It provides an MQTT delivery guarantee on the relevant protocol exchange. It does not automatically guarantee exactly one external action or make the action and its completion record atomic.
Why can a cloud broker not recover all readings after an outage?
It cannot recover readings it never received unless another part of the system buffered them and uploads them later. Broker-side sessions and local publisher buffering address different sides of the interrupted path.
Key takeaway
Treat a broker as the meeting point for messages, then check the responsibilities around it. Who may publish? Which subscription should receive the event? What survives a disconnect, a WAN outage or a restart? Which observation proves the application finished? Those answers determine whether a working connection becomes a dependable system.
Use the broadband terminology guide to explore the networking concepts underneath the broker, from routing and latency to secure transport and remote access.

