Blog

    Healthcare Integration Architecture With Mirth Connect and Kafka: Edge, Backbone, Ordering and Replay

    By GauravNovember 27, 20269 mins read
    On this page

    Hospital feeds rarely stay with one consumer. The ADT feed that once updated a single patient table now has to reach a scheduling service, an analytics warehouse, a care team alert service and whatever the product team builds next. Wiring each new consumer into the interface engine turns it into a tangle of channels that nobody wants to touch.

    This post is for architects and integration engineers who run Mirth Connect and are considering Kafka behind it. It covers what each tool should do, when to acknowledge, topic design, ordering, delivery guarantees, replay and monitoring.

    What is a Mirth and Kafka integration architecture?

    Planning Kafka behind your interface engine?

    Our Apache Kafka consulting team designs topics, keys, retention and consumers for healthcare event streams.

    A Mirth and Kafka integration architecture uses Mirth Connect at the edge to receive and acknowledge HL7 v2 over MLLP, and Apache Kafka behind it as the event backbone that stores messages and feeds every consuming service. Agnotic Technologies uses this split when many internal services need the same hospital feeds.

    Each tool does what it is good at. Mirth speaks the hospital's protocols and handles acknowledgments, while Kafka keeps an ordered, replayable log that any number of services can read at their own pace.

    When does adding Kafka make sense?

    Adding Kafka makes sense when several services consume the same feeds, when you need to replay history, or when consumers must be able to fall behind without blocking the hospital. For one feed and one consumer, Mirth alone is simpler.

    • Many consumers: three or more services need the same ADT or result events.
    • Replay: a new service or a bug fix needs past events without a hospital resend.
    • Isolation: a slow consumer must not stop the interface from acknowledging.
    • Existing platform: the product already runs Kafka for its own events.

    Kafka adds a cluster to run, secure and monitor. If nobody on the team will own it, a managed Kafka service or a simpler queue may be the better answer.

    What stays in Mirth?

    Mirth keeps everything that faces the hospital: MLLP listeners, acknowledgments, light parsing checks and outbound messages back to hospital systems. Business logic moves out to the consuming services.

    Mirth Connect and Kafka architecture: hospital systems send ADT, ORU and SIU over MLLP to a Mirth edge that listens, checks and acknowledges after a durable write, then Kafka holds raw topics per source and message type keyed by patient id with a dead-letter topic, then consuming services read independently, with a retention and replay bar
    • MLLP listener: one channel per inbound feed, named for the source and message type.
    • Light checks: the message parses and carries the fields needed to route and key it.
    • Publish: the raw message and a few headers written to the right Kafka topic.
    • Outbound: results, documents or orders sent back to hospitals through their own channels.

    Keeping Mirth channels thin makes them easy to read and test. Mapping, enrichment and decisions belong in services that can be versioned and deployed like any other code.

    When should Mirth send the ACK?

    Mirth should send the acknowledgment only after Kafka confirms the write. If Mirth acknowledges first and the publish then fails, the hospital believes the message was delivered and will never resend it.

    Configure the producer to wait for all in-sync replicas before treating a write as done. This adds a little latency to each acknowledgment, but it means an ACK always reflects a message that is safely stored, which is the promise the hospital is relying on.

    If Kafka is unreachable, let Mirth queue or return an error acknowledgment according to the interface agreement. Never fall back to acknowledging and dropping.

    Topic design per message type

    Create raw topics per source and message type, such as one for hospital A's ADT and one for its results. Raw topics keep the message exactly as received, which is what you need for audits and replays.

    • Raw topics: source plus message type, holding the original HL7 text and headers.
    • Canonical topics: optional, holding parsed events in your own format for most consumers.
    • Dead-letter topics: events that a consumer could not process, with the error attached.
    • Naming: a fixed pattern, so access rules and retention can be set by prefix.

    Put a small header on every event: source, message type, message control id, patient key and receive time. Consumers can then filter and deduplicate without parsing the HL7 body.

    Choose partition counts with growth in mind, since adding partitions later changes which partition a key maps to. A modest count sized for expected consumer parallelism is usually enough for hospital feed volumes.

    How do you keep a patient's messages in order?

    Keep a patient's messages in order by using the patient identifier as the event key. Kafka sends all events with the same key to one partition, and each partition is read in write order.

    The Apache Kafka documentation says events with the same event key are written to the same partition, and that any consumer of a given topic partition always reads that partition's events in exactly the order they were written.

    Choose the key carefully. A source medical record number works for one hospital, while an enterprise identifier suits several. Plan for merges: after a patient merge, events for the surviving and retired identifiers may sit on different partitions, so consumers must apply the merge before trusting order.

    What delivery guarantees do you get?

    By default you get at-least-once delivery, so consumers must expect to see some events twice. That is acceptable as long as every consumer is idempotent.

    The Apache Kafka design documentation says Kafka guarantees at-least-once delivery by default, and that exactly-once delivery to destination systems outside Kafka generally requires cooperation from those systems.

    The simplest idempotency key in HL7 v2 is the source plus the message control id from MSH-10. Consumers record processed keys, or write in a way where applying the same event twice gives the same result.

    Replay and retention

    Replay is one of the main reasons to add Kafka. A new consumer can start from the oldest retained event, and a fixed consumer can reprocess the period its bug affected.

    The Apache Kafka documentation says events in a topic can be read as often as needed and are not deleted after consumption; a per-topic setting defines how long Kafka retains them.

    Retention is also a data protection decision, because raw topics hold PHI. Set retention per topic from your record retention and minimum necessary policies, restrict who can read raw topics, and keep long-term archives in a store designed for them rather than in Kafka.

    Mirth and Kafka failure points

    Most failures come from treating the two tools as one system with one set of guarantees.

    • Early ACKs: the hospital is told a message arrived before Kafka stored it.
    • Wrong key: events keyed by message id, so a patient's updates arrive out of order.
    • Logic in channels: mapping in Mirth and again in consumers, with two versions of the truth.
    • Endless retries: a poison message blocks a partition because no dead-letter path exists.
    • Open raw topics: every service can read full HL7 messages it does not need.

    A worked example: one ADT feed, five consumers

    A care management company receives ADT from a hospital through Mirth. Five services need it: the patient index, a care team alert service, scheduling, the warehouse and an audit store.

    Mirth listens on MLLP, checks each message parses and has a patient identifier, publishes to the hospital's raw ADT topic keyed by that identifier, and acknowledges after the write. A small service parses raw events into a canonical topic that four services read.

    When the alert service ships a bug that drops some transfer events, the team fixes it and replays the affected days from the canonical topic. The hospital never knows anything happened.

    Later, the company adds a second hospital. It builds one new Mirth channel and one new raw topic, extends the parser, and none of the five consumers needs a change.

    Who owns what?

    This architecture splits responsibilities that used to sit with one interface team.

    • Interface team: Mirth channels, MLLP connections, acknowledgments and hospital contacts.
    • Platform team: the Kafka cluster, topics, retention, access control and capacity.
    • Service teams: consumers, idempotency, dead-letter handling and their own data stores.
    • Privacy and security: which services may read raw topics and how long data is kept.

    Write the hand-offs down. When a hospital reports a missing message, the interface team should be able to show the ACK and the Kafka offset, and the service team should be able to show whether its consumer processed that offset.

    How do you monitor the pipeline?

    Monitor each hop separately, because a healthy Mirth channel says nothing about a consumer that fell behind an hour ago.

    • Mirth: inbound rate, error count, queue depth and time to acknowledge.
    • Kafka: produce errors, under-replicated partitions and disk use per broker.
    • Consumers: lag per consumer group and partition, and dead-letter topic growth.
    • End to end: time from hospital send to consumer processing for sampled messages.

    Alert on lag and dead-letter growth, not just on errors. A consumer that silently stops reading shows no errors at all.

    What are Mirth and Kafka architecture best practices?

    Keep Mirth thin and hospital-facing, acknowledge only after Kafka confirms a durable write, and key events by patient so order holds where it matters. Make every consumer idempotent using the message control id.

    Keep raw topics for audit and replay, set retention from policy, restrict access to PHI topics and monitor consumer lag as closely as interface errors.

    How Agnotic can help

    Agnotic designs and builds Mirth and Kafka integration platforms: thin edge channels, topic and key design, canonical event services, idempotent consumers, replay procedures and monitoring. We work with your interface team and your platform team so each owns a clear part.

    Design your healthcare event backbone

    We connect hospital feeds to internal services through an architecture your teams can run.

    Sources

    Frequently Asked Questions

    Mirth works well for a few feeds and consumers. When many services need the same events, or you need replay, Kafka gives each consumer its own pace without adding channels.

    Talk to an engineer about your project

    Share your current feeds and the services that need them. We will sketch the topics, keys and acknowledgment rules.

    Go deeper

    Services and solutions on this topic