Both address the stateful/presence gaps in a pure pub/sub model. A retained message solves the "I just subscribed, what's the current value?" problem: normally a subscriber only sees messages published after it subscribes, so a device joining late would wait for the next publish to learn, say, the current temperature or a config value. When a publisher marks a message retained, the broker stores the last retained message per topic and immediately delivers it to any new subscriber, so late joiners get current state instantly, ideal for status and configuration topics. Last Will and Testament (LWT) solves presence/failure detection: a client registers a "will" message and topic when it connects, and if it disconnects ungracefully, a crash, a dropped link, or a missed keepalive, the broker publishes that will on its behalf, for example setting device/123/status to offline. This lets the rest of the system detect dead devices without polling, because a normally-disconnecting client clears its will but a vanished one triggers it. Together they make pub/sub practical for representing device state and liveness, not just transient events. A common pattern combines them: publish a retained online status on connect and register a retained offline LWT, so any subscriber always sees the device's current presence.
Networking & IoT · Interview question
What are retained messages and Last Will, and what problems do they solve?
A strong answer
What a weak answer sounds like
You know the answer. Do you know what gets you dinged?
Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.
From the lesson
MQTT
The IoT publish/subscribe workhorse: a broker decouples publishers and subscribers over topics, devices dial out (NAT-friendly), and QoS, retained messages, and Last Will handle lossy links.