MLLP
The framing protocol that carries HL7v2 messages over a TCP connection.
The HL7v2 standard defines what a message contains, its segments, fields, and delimiters, but not how the message travels between systems. The Minimal Lower Layer Protocol (MLLP) is the transport most commonly used for that purpose. It carries messages over a TCP connection (opens in a new tab) and marks where each message begins and ends, so that the destination can separate one message from the next. This marking is called framing, and MLLP defines little else: the connection, the acknowledgment, and the security of the exchange are left to other layers.
Specification
MLLP is not part of the HL7v2 standard. HL7 publishes it as a separate transport specification, in two releases. Release 1 defines the framing described below; Release 2 adds an acknowledgment at the frame level.
Framing
TCP (Transmission Control Protocol) connects two systems and delivers the bytes that one sends to the other, complete and in order. TCP has no concept of a message: it carries a stream of bytes, and which bytes form a message is left to the protocol built on top of it. As a result, two messages can arrive at the destination in a single piece, or one message can arrive split across several pieces, and one piece can contain the end of one message and the beginning of the next.
Every protocol built on TCP therefore defines how its messages are delimited in the stream. Some state the length of each message before the message: HTTP, for example, usually gives the length of each message body in a Content-Length header. Others place a marker at the end of each message: SMTP, which carries email, ends each message with a line that contains a single period. The destination reads the stated number of bytes, or reads until it finds the marker.
MLLP uses markers. The source places a start byte before each message and a two-byte end sequence after it. The destination reads bytes until it finds the end sequence, treats the bytes between the markers as one message, and then reads the next frame.
Because the destination finds each message by reading to its end sequence, the messages on a connection travel one after another, never in parallel: one frame must end before the next begins.
Sequential delivery
A source that also waits for each acknowledgment sends one message at a time, so the rate of an interface depends on how quickly the destination processes and acknowledges each message. Interfaces that need more throughput open several connections, at the cost of the order between them.
Frame
A frame is one message with its markers. It has three parts:
End FS 0x1C CR 0x0D Payload HL7v2 message bytes Start VT 0x0B
| Part | Bytes | Name |
|---|---|---|
| Start | 0x0B | Vertical tab (<VT>) |
| Payload | Variable | The HL7v2 message |
| End | 0x1C 0x0D | File separator (<FS>) followed by carriage return (<CR>) |
<VT> and <FS> are ASCII control characters (opens in a new tab). Neither character occurs in the content of an HL7v2 message, so each marks a frame boundary without ambiguity. The final <CR> is the same character that HL7v2 uses to end each segment.
The payload is the message exactly as the standard defines it: segments end with <CR>, and fields are separated by |. MLLP adds bytes around the message and changes nothing inside it.
Example
The following frame carries an ADT^A04 message. The control characters are shown by name, and each segment is shown on its own line:
<VT>MSH|^~\&|SendingApp|SendingFacility|ReceivingApp|ReceivingFacility|20230630120000||ADT^A04^ADT_A01|MSG000001|P|2.5.1<CR>
EVN|A04|20230630120000<CR>
PID|1||12345^^^HOSP^MR||Doe^John||19700101|M<CR>
PV1|1|O<CR>
<FS><CR>The last segment ends with its own <CR>, so a frame ends with three control characters: the segment's <CR>, then <FS> and the <CR> of the end sequence.
Character encoding
The markers are single bytes, so the payload must not contain the bytes 0x0B or 0x1C except as those characters. ASCII and UTF-8 meet this condition. In encodings such as UTF-16, the same bytes can occur inside other characters and end the frame early, so MLLP interfaces use ASCII or UTF-8. Character encoding describes how a message declares its encoding.
Connection
MLLP runs over a TCP connection that is opened once and then used for many messages. On the connection, the exchange is a sequence of frames: the source sends a frame, and the destination processes the message and sends back an acknowledgment, which is itself an HL7v2 message in its own frame. The source then sends the next frame. The connection remains open until either system closes it.
The connection is long-lived because opening a TCP connection has a cost: a handshake between the two systems, and a second negotiation when the connection is encrypted. An interface that carries a thousand messages an hour would pay that cost a thousand times if it opened a connection for each message. A connection that stays open pays it once.
A long-lived connection also has consequences that MLLP does not address. A frame can arrive in several pieces, a connection can stay idle for hours, and a connection can close before a frame is complete. The specification leaves the handling of these cases, such as how long an idle connection stays open, to each system.
Port
A TCP connection is opened to a port, a number that identifies one service on a system. One system listens on the port, and the other connects to it. Port 2575 is registered with IANA (opens in a new tab) (the Internet Assigned Numbers Authority) for HL7 and is the conventional default.
In practice, a system that receives messages from several sources, such as an interface engine, usually assigns each source its own port. The port then identifies the source and its interface. Each source also has its own connection, so a busy source does not delay the messages of the others.
Acknowledgments
MLLP does not define an acknowledgment of its own. The destination confirms each message with an HL7v2 acknowledgment: a message of type ACK whose MSA segment carries the result code, such as AA for a message that was accepted. The destination sends the acknowledgment as a new frame on the same connection, with its own start byte and end sequence.
The source usually waits for the acknowledgment of each message before it sends the next one. Waiting keeps the messages in order and pairs each acknowledgment with the message just sent. A source that sends several messages without waiting must match each acknowledgment with its message by control ID: the acknowledgment carries the MSH-10 of the original message in MSA-2. Acknowledgments describes the acknowledgment message and its codes.
Release 2
MLLP Release 2 adds an acknowledgment at the frame level, separate from the HL7v2 acknowledgment. After each frame, the destination returns a frame that contains a single byte instead of a message:
| Frame | Bytes | Meaning |
|---|---|---|
| Commit acknowledgment | <VT> 0x06 <FS><CR> | The destination has stored the frame's content. |
| Negative commit acknowledgment | <VT> 0x15 <FS><CR> | The frame arrived but its content could not be stored. |
0x06 and 0x15 are the ASCII characters ACK and NAK. With these acknowledgments, Release 2 guarantees that messages are delivered in order and at least once: the source resends a frame until it receives a commit acknowledgment, and it does not send the next frame before then. The destination can therefore receive the same message twice, and recognizes the duplicate by its control ID.
Release 2 is uncommon in production. Most interfaces use the framing of Release 1 and rely on the HL7v2 acknowledgment, including the commit acknowledgments of enhanced mode, to confirm delivery.
Security
MLLP provides no security of its own. It sends messages in cleartext, so anyone who can observe the network can read them. It does not authenticate either system, so any system that can reach the port can open a connection and send messages. A message names its sending application and facility in MSH-3 and MSH-4, but nothing verifies those values. Because HL7v2 messages carry protected health information (opens in a new tab), the security of an MLLP interface depends entirely on the layers beneath the protocol.
Cleartext
Many MLLP interfaces on hospital networks remain unencrypted. Cleartext is acceptable only on a network that the organization fully controls, and even there every system on the network can read the messages.
TLS
The usual method is to run the TCP connection over TLS (Transport Layer Security), the protocol that also secures HTTPS. TLS encrypts the connection and authenticates the systems at each end with certificates. The destination presents a certificate to prove its identity to the source. With mutual TLS, the source presents a certificate as well, and the destination accepts connections only from systems that it recognizes.
The frames are unchanged: TLS encrypts the connection that carries them, not the messages themselves. Both systems must be configured for TLS, because a system that expects TLS cannot read frames sent in cleartext. The IHE Audit Trail and Node Authentication (opens in a new tab) (ATNA) profile specifies that connections between systems that exchange health data be authenticated and encrypted, usually with TLS, and many implementation guides refer to it.
Network controls
When a system cannot use TLS, the network protects the connection instead. A virtual private network (VPN) encrypts the traffic between two sites, and is common for interfaces between organizations. Within a site, firewalls limit each port to the addresses of the systems that are expected to connect. These controls protect the path between networks, but they do not authenticate the systems at each end.
Limits
TLS and VPNs protect a message only while it travels over one connection. An interface engine that forwards a message ends one connection and opens another, so the message is decrypted, processed, and often stored in cleartext between them. Each connection along the route must therefore be secured separately. HL7v2 defines no mechanism to sign or encrypt the content of a message: MSH-8, the security field, exists, but the standard does not specify its use.
Alternatives
MLLP is the most common transport for HL7v2, and most integration within hospitals is built on it. It suits systems on the same network that exchange messages continuously, at high volume and low latency. Two other transports are also common.
HTTP
HTTP carries each message as the body of a POST request, and the destination returns the acknowledgment in the response. Unlike MLLP, HTTP pairs each response with its request, so the source does not need to match acknowledgments with messages. Over HTTPS, TLS encrypts the connection, as it does for MLLP.
HTTP fits the gateways, load balancers, and monitoring that organizations already operate for other services. It is therefore common between organizations, where opening a dedicated port for a long-lived TCP connection is difficult. Its cost per message is higher than that of MLLP, because each request carries headers and connections are reused less often.
File transfer
File transfer writes messages to files, usually grouped into batches, and delivers each file to a location from which the destination retrieves it: a shared directory, or a server reached over FTP or SFTP. SFTP, the SSH File Transfer Protocol, encrypts the transfer; FTP does not. The destination processes each file when it retrieves it, and any acknowledgments are returned as files as well.
File transfer suits periodic exchanges that do not need an immediate response, such as billing and reporting. It remains common in older interfaces and between systems that do not share a network.
The systems on an interface usually determine its transport. When one of them supports only one transport, the interface uses it.
Trade-offs
MLLP's strengths and weaknesses both follow from how little it defines:
- Simplicity. The protocol consists of a TCP connection and three bytes of framing. It has no versions to negotiate and no options to configure, so systems built decades apart can exchange messages over it.
- Security. The protocol provides no encryption and no authentication. Both depend on TLS or the network beneath it.
- Reliability. Release 1 adds nothing to the reliability of TCP. A destination that acknowledges a message before storing it can still lose it, as described in Message flow.
- Visibility. The protocol carries no metadata, such as headers or content types, so monitoring an interface requires reading the HL7v2 messages themselves.
MLLP remains in use for the same reasons as HL7v2. Replacing the transport of an interface in production carries cost and risk, and each alternative improves on MLLP in some respects and adds costs in others.
Further reading
- Message flow — how transmission fits into the exchange between source and destination.
- Acknowledgments — the content of the acknowledgment message.
- Interface engines — the systems that usually send and receive MLLP on behalf of each application.
- HL7 Transport Specification: MLLP, Release 2 (opens in a new tab) — the specification.