MQTT 5 Topic Aliases reduce repeated wire bytes without changing the topic model seen by applications. A sender first associates a small nonzero integer with a full Topic Name. Later PUBLISH packets on that same network connection can carry the alias and an empty Topic Name, allowing the receiver to reconstruct the full name from the connection-local mapping.

The optimization is useful for robot telemetry with long hierarchical names, but its lifetime is deliberately narrow. An alias is neither a broker-wide dictionary entry nor durable Session State. It disappears when the network connection ends, even if the client resumes an MQTT Session that still contains subscriptions and queued messages.

## Establish before abbreviating

The OASIS MQTT 5.0 specification defines Topic Alias as a Two Byte Integer property on PUBLISH. The sender creates or replaces a mapping by sending a PUBLISH that contains both a nonempty Topic Name and a Topic Alias. The receiver processes that publication normally and records the mapping for future packets from that sender on that connection.

After the mapping exists, the sender may transmit the same alias with a zero-length Topic Name. The receiver treats the packet as if it contained the mapped Topic Name. An empty Topic Name without a Topic Alias is a Protocol Error, so a sender cannot use omission as a general compression trick.

A sender can remap an alias by sending it again with a different nonempty Topic Name. That feature makes aliases a mutable connection cache. Logging only the integer without recording when the mapping changed can therefore produce misleading diagnostics.

## Reconnect clears the table

The most important boundary is the Network Connection. The specification requires receivers not to carry Topic Alias mappings from one connection to another. A reconnect starts with no aliases, regardless of Client Identifier, Clean Start value, Session Present flag, or Session Expiry Interval.

This differs from stored MQTT Session State. A broker can retain subscriptions and queued QoS messages for a reconnecting client, but it must not treat the old connection's alias table as part of that state. The first post-reconnect publication that wants an alias must establish the mapping again with the complete Topic Name.

Consider a robot gateway that maps alias 7 to `factory/line-4/robot-12/joints/temperature`. It disconnects and reconnects with Session Present set. If its first new PUBLISH sends alias 7 with an empty Topic Name, the receiver has no valid mapping. The retained Session does not rescue that packet. The gateway must first send the full Topic Name with alias 7 on the new connection.

## Direction creates two independent namespaces

Client-to-server and server-to-client aliases are independent. Alias 1 selected by a robot client may refer to motor current, while alias 1 selected by the broker for deliveries to that same client may refer to a safety-controller heartbeat. Neither side can infer the other direction's mapping.

The usable range is negotiated separately in each direction. A client advertises Topic Alias Maximum in CONNECT to limit aliases sent by the server. A server advertises its maximum in CONNACK to limit aliases sent by the client. A maximum of zero, including the default when the property is absent, means the receiver does not accept Topic Aliases in that direction.

Alias zero is always prohibited. Values above the relevant maximum are Protocol Errors. Implementations should validate these rules before touching their mapping table so an invalid packet cannot corrupt the cache used by later messages.

## Aliases do not alter routing meaning

Topic Alias changes the encoding of a PUBLISH, not its logical destination. Subscription matching still operates on the reconstructed Topic Name. Retained-message storage is indexed by the Topic Name, access-control decisions still need the resolved name, and application consumers should receive the meaningful topic rather than a connection-specific integer.

A broker may also choose different aliases for outbound delivery. An inbound alias is not an instruction to forward that same number to subscribers. The server resolves the incoming name, performs normal routing, and may establish an independent alias on each outbound connection if its implementation and the receiving client's advertised maximum allow it.

This distinction matters for observability. A packet capture from one side of a broker cannot decode aliases seen on another connection. Diagnostic tools need the mapping history for the exact connection and direction being inspected.

## A safe client state machine

Create two maps per active connection: outbound alias-to-topic and inbound alias-to-topic. Clear both when the transport connection closes or is replaced. For outbound traffic, send the full Topic Name whenever establishing or remapping an alias. Use an empty name only after the mapping packet has been sent successfully on the current connection.

For inbound traffic, reject alias zero, out-of-range values, duplicate Topic Alias properties, and an empty Topic Name whose alias has no current mapping. When a valid packet contains both fields, update the map before exposing the resolved publication to routing or application code.

Connection generations help prevent asynchronous reconnect bugs. Tag queued send work with the connection generation that created its alias assumption. If a new generation becomes active, regenerate the PUBLISH with a full Topic Name instead of transmitting stale abbreviated bytes.

## Test the failure boundaries

A useful conformance test first publishes a long robot topic with alias 3, then publishes several packets with alias 3 and an empty Topic Name. Verify that all resolve identically. Remap alias 3 to a second topic and confirm subsequent empty-name packets follow the new mapping.

Next reconnect while preserving the MQTT Session. Confirm that the old alias is rejected or otherwise treated as a protocol violation until the full name establishes it again. Test independent alias 3 mappings in each direction, maximum values of zero and one, alias zero, and an alias above the negotiated maximum.

Topic Aliases are most effective when software treats them as disposable encoding state. They save bandwidth for repetitive robot telemetry, but they do not provide durable naming, Session continuity, or cross-connection identity. Clear the table on every reconnect, negotiate each direction independently, and keep the full Topic Name authoritative for routing, authorization, and diagnostics.