Message replay and idempotency answer different questions in a healthcare interface engine. Replay asks whether a message can be executed again from a stored copy or redelivered after an interruption. Idempotency asks whether executing that message more than once changes the downstream system state. A replay mechanism without idempotency can create duplicate patient records, repeated orders, or double-posted charges. An idempotency mechanism without replay still leaves the team unable to recover a lost transaction. The practical design problem is therefore not choosing one control, but defining the stable identifier, the deduplication window, and the ownership boundary that make replay safe for a specific HL7 v2, FHIR, or webhook path. Vendor documentation describes these mechanisms in different layers, and the distinctions matter when an interface spans a broker, a transformation engine, and a receiving EHR.
Replay is a recovery action; idempotency is a state guarantee
Replay in an integration engine means re-executing a previously received or transformed message without asking the source system to transmit it again. CASRAI's healthcare integration guide describes end-to-end message auditing and replay as logging the raw inbound payload, transformed intermediate state, outbound payload, and remote ACK or NACK response with cryptographic timestamps. That record lets interface engineers inspect failed transactions and replay messages without requesting a retransmission from the source EHR [7]. The replay action itself does not prevent duplicate effects. It only makes the original message available for another execution attempt.
Idempotency, by contrast, is a property of the operation or the consumer. Microsoft's Idempotent Consumer pattern defines it as keeping a record of successfully processed messages and skipping any message already processed, based on a stable identifier that survives redelivery [1]. AWS Durable Execution documentation states that an operation with a side effect repeats the side effect on every run, while idempotency describes operations where the effect remains the same regardless of how many times they run [4]. These are distinct concerns: replay supplies the repeated input, and idempotency determines whether the repeated input produces a repeated effect.
Where the deduplication key lives changes the failure surface
The stable identifier can be owned by the producer, the broker, the consumer, or the receiving API. Redis Streams, beginning with Redis 8.6, supports idempotent message processing at the producer side through XADD parameters IDMP or IDMPAUTO. The producer supplies a producer ID and an idempotency ID, and Redis retains those IDs for a configured duration or maximum count [3]. This prevents duplicate entries when a producer resends after a network disconnect or crash, but it does not address a consumer that processes the same entry twice after a checkpoint failure.
Inngest places deduplication at either the event producer or the function consumer. A stable event ID for one business occurrence prevents duplicate function starts within 24 hours, while a function-level CEL expression generates a key from the event payload to prevent duplicate execution for the same period [8]. The choice of boundary is consequential. An event ID that represents one checkout suppresses work when reused for a genuinely new occurrence, so the documentation warns teams to choose the boundary carefully [8]. In a healthcare interface, the equivalent question is whether the key represents one ADT message, one patient encounter, or one logical business event that may span multiple messages.
Choosing the key and window for an HL7 v2 to FHIR path
For an HL7 v2 message translated to a FHIR resource, the engine should not silently reuse the HL7 message control ID as the FHIR idempotency key unless the receiving API documents that contract. CASRAI's guide notes that FHIR ingestion can use conditional PUT or POST requests with business identifiers such as medical record numbers in Patient.identifier to prevent duplicate patient creation [7]. The stable key should therefore be chosen at the boundary where the duplicate would occur. If the receiving EHR deduplicates on Patient.identifier, the engine should preserve that identifier across replays. If the receiving API requires an Idempotency-Key header, the engine should generate that key once per logical event and reuse it on every retry, as AWS documentation warns that a key generated outside a step changes on replay and defeats deduplication [4].
Delivery semantics determine whether idempotency is mandatory
At-least-once delivery makes idempotency necessary because retries can cause duplicate delivery. Microsoft's Retry pattern documentation states that retrying operations to handle transient faults makes idempotent processing necessary [1]. AWS Durable Execution describes at-least-once per retry as the default semantic, where an interrupted step runs again on replay and is safe only for idempotent operations [4]. Kafka's transactional delivery, starting with version 0.11.0.0, lets a producer resend with idempotency so existing messages are overwritten rather than duplicated, at the cost of higher latency [5].
The receiving system's API semantics also shape the requirement. Stripe's API supports idempotency keys for safely retrying requests without performing the same operation twice. For API v1, retries with the same key return the saved status code and body of the first request, including 500 errors. For API v2, retries do not repeat successful operations, and Stripe retries failed or partially failed work to completion when possible [2]. A healthcare interface engine that posts FHIR resources to a vendor API inherits whatever idempotency contract that API documents, which may differ from the engine's internal queue semantics.
Deduplication windows and retention are operational contracts
Every idempotency mechanism has a finite memory. Redis Streams retains idempotency IDs until either a time-based duration expires or a capacity-based maximum is reached. The default IDMP-DURATION is 100 seconds and the default IDMP-MAXSIZE is 100 entries per producer, with the maximum size taking precedence over the duration [3]. Redis documentation calls the duration an operational guarantee: Redis will not discard a previously sent ID for the specified duration unless the maximum size is reached [3]. A producer that crashes and stops sending will have its IDs discarded after the duration elapses.
The IETF Internet-Draft on event and webhook delivery semantics recommends a minimum deduplication window of 24 hours, based on a survey of vendor documentation where reported windows range from approximately one hour to seven days [6]. The draft also states that an idempotency identifier must remain stable across retries of the same logical event and must be scoped to the producer-consumer context [6]. For healthcare interfaces, the window must cover the longest plausible retry or replay delay, including manual intervention after a weekend outage. A 100-second broker window is insufficient for a message that an engineer replays three days later from an audit log.
A hypothetical validation scenario for an ADT replay path
A useful validation scenario, suggested here rather than drawn from any tested deployment, would exercise an ADT^A01 admission message through a store-and-forward engine. The team would first send the message normally and confirm the downstream patient record is created. Then they would replay the identical message from the engine's audit log without changing the message control ID or the business identifier. The expected result is that the downstream system either rejects the duplicate or returns the existing record, and no second patient is created.
The second test would send two distinct ADT^A01 messages for the same patient with different message control IDs but the same medical record number. This distinguishes a true duplicate from a legitimate update. The third test would simulate a downstream API that succeeds just before the engine records a failure, then confirm that the retry with the same idempotency key is accepted as success rather than creating a duplicate [8]. These tests would reveal whether the deduplication key is the message control ID, the patient identifier, or a separate idempotency token, and whether the retention window covers the replay delay.
Sources & references
- Idempotent Consumer Pattern - Azure Architecture Center | Microsoft Learn · learn.microsoft.com
- Idempotent requests · docs.stripe.com
- Idempotent message processing · redis.io
- Idempotency and retries - AWS Durable Execution SDK Developer Guide · docs.aws.amazon.com
- Kafka Message Delivery Guarantees | Confluent Documentation · docs.confluent.io
- Event and Webhook Delivery Semantics · www.ietf.org
- Healthcare Integration Engine: HL7 & FHIR Guide — CASRAI · casrai.org
- Idempotency | Prevent Duplicate Runs - Inngest Docs · www.inngest.com