Idempotent EDI processing with an inbox and outbox makes claim submission behave as if each claim is sent exactly once, even when servers crash, uploads time out or workers retry. The outbox records what must be sent in the same database transaction as the claim change; the inbox records every inbound acknowledgment file once, so it is never applied twice.
Startup founders and product or engineering leaders building claim submission into billing or revenue cycle software will find where duplicates and lost claims come from, how the two tables work and how to test the failure cases.
What is idempotent EDI processing with an inbox and outbox?
Idempotent EDI processing with an inbox and outbox stores every outbound claim file as an outbox row written in the same transaction as the claim's status change, and every inbound acknowledgment as an inbox row keyed by a unique identifier. Any step can then be retried without creating a second claim or applying a file twice.
Building claim submission that must not double-bill?
We design the outbox, inbox, claim states and recovery paths for your claims workflow.
The pattern is plain database engineering. It needs no special messaging product, only careful transactions, unique keys and a clear state for every claim.
Why does claim submission need exactly-once behavior?
Claim submission needs exactly-once behavior because both failure directions cost money. A claim sent twice can be denied as a duplicate, confuse payment posting and waste staff time; a claim never sent quietly loses revenue until someone notices the missing payment.
The danger sits in the gap between two systems. Your database can commit a change, and the clearinghouse can receive a file, but no single transaction covers both, so a crash at the wrong moment leaves them disagreeing.
Where do duplicates and lost claims come from?
- Crash after upload: the file reaches the clearinghouse, but the server dies before marking the claim as sent, so it is sent again.
- Crash before upload: the claim is marked as sent, then the upload never happens.
- Timeouts: the upload times out on your side, but the file actually arrived.
- Competing workers: two processes pick up the same claim at the same moment.
- Repeated inbound files: the same 999 or 277CA is downloaded twice and its results applied twice.
- User actions: a submit button pressed twice, or a batch rerun by hand.
Is exactly-once delivery really possible?
Exactly-once delivery over a network cannot be guaranteed; what you can build is exactly-once effect. Send at least once, give each submission a stable identity, and make every receiver, including your own inbox, ignore repeats of something it has already handled.
That framing changes the design questions. Instead of asking how to avoid retries, ask how each step recognizes work it has already done.
For claims, that means three checks: the relay knows which submissions it has already uploaded, the clearinghouse can recognize a resent file, and the inbox knows which acknowledgment files it has already applied.
How does the outbox work?
The outbox works by writing the intent to send in the same transaction as the business change, then letting a separate relay do the sending.
- Claims service: marks the claim ready and inserts an outbox row with the claim, its version and a submission key, in one transaction.
- Relay: reads pending outbox rows, builds or loads the 837 file, uploads it and marks the row sent.
- Clearinghouse: receives the file and later returns acknowledgments.
- Inbox: stores each returned file once, then updates claim statuses from it.
If the claims transaction rolls back, no outbox row exists, so nothing is sent. If it commits, the row survives any crash until the relay finishes.
How do relays pick up work safely?
Relays pick up work safely by locking the outbox rows they take, so two relays never send the same submission at once.
PostgreSQL's SELECT documentation says that with SKIP LOCKED, selected rows that cannot be locked immediately are skipped. It warns that this gives an inconsistent view of the data, so it does not suit general work, but it avoids lock contention when several consumers read a queue-like table.
With that clause, each relay selects a few pending rows, locks them and skips rows another relay already holds. If a relay crashes, its locks are released when the transaction ends, and another relay picks the rows up.
What makes each submission identifiable?
Each submission becomes identifiable when its key, file and control numbers are fixed before the first upload attempt and reused on every retry.
- Submission key: the claim identifier plus a version, so a corrected claim gets a new key and a retry does not.
- Stored file: the generated 837 bytes saved with the outbox row, so a retry resends the same file.
- Control numbers: assigned once and stored, never regenerated on retry.
- Deterministic file name: built from the submission key, so a repeated upload is recognizable.
Many clearinghouses check for duplicate files and claims. Confirm with yours how it treats a resent file with identical control numbers, and rely on your own records first.
How does the inbox work?
The inbox works by recording each inbound file under a unique key before acting on it, so a second copy of the same file is stored once and processed once.
PostgreSQL's INSERT documentation says ON CONFLICT DO NOTHING simply avoids inserting a row as its alternative action, and that ON CONFLICT DO UPDATE guarantees an atomic insert or update outcome even under high concurrency, provided there is no independent error.
- Key: a hash of the file content, or the sender's control numbers where they are reliable.
- Insert: write the raw file to the inbox with that key, ignoring conflicts.
- Process: a worker takes unprocessed inbox rows, parses the 999, 277CA or 835 and updates claims.
- Mark: the inbox row and the claim updates commit together, so a crash means the whole file is processed again from the start.
Claim updates from an inbox file should be idempotent as well. Setting a claim to accepted twice has the same result as setting it once.
What happens when an upload result is unknown?
When an upload result is unknown, such as a timeout after the file was sent, mark the submission as uncertain and reconcile before retrying.
- Check the clearinghouse's file listing or status interface for the file name.
- Wait for a 999 that references the stored control numbers.
- Retry only when the file is confirmed missing, resending the same stored bytes.
- Alert a person when a submission stays uncertain past the agreed window.
Where should the inbox and outbox tables live?
The inbox and outbox tables should live in the same database as the claims they describe. The whole point is that the claim change and the outbox row commit in one transaction, which is only possible when they share a database.
Keep the raw files in object storage if they are large, with the table holding the key, the storage location and a checksum. Encrypt both, since claim files and remittances carry PHI, and apply the same retention rules your compliance lead sets for claims.
How do you monitor the pipeline?
Monitor the pipeline by watching for work that stops moving, because a healthy inbox and outbox drain steadily.
- Oldest pending outbox row: a growing age means the relay is down or the clearinghouse is unreachable.
- Uncertain submissions: any count above zero needs a person to reconcile it.
- Sent without a 999: files past the agreed window with no acknowledgment.
- Unprocessed inbox rows: files downloaded but not yet applied to claims.
- Parse failures: inbound files the processor could not read, held for review.
Which claim states does the design need?
| State | Entered when | Next step |
|---|---|---|
| Ready | Claim passes internal edits | Outbox row written in the same transaction |
| Queued | Outbox row exists | Relay uploads the stored file |
| Sent | Upload confirmed | Wait for 999 |
| Uncertain | Upload outcome unknown | Reconcile before any retry |
| Acknowledged | 999 accepts the transaction set | Wait for 277CA |
| Accepted or rejected | 277CA reports the claim's status | Await 835, or correct and resubmit |
How do corrections differ from retries?
A correction is a new submission and a retry is the same submission again, and the design must never confuse the two.
A rejected claim that is fixed gets a new claim version, a new submission key and a new outbox row. A retry after a failed upload reuses the existing row, file and control numbers. Mixing them up either blocks a valid correction as a duplicate or sends the same claim twice.
How do you test the failure cases?
- Kill the relay after upload and before it marks the row sent, then confirm the retry is recognized.
- Kill it before upload and confirm the claim is still queued, not sent.
- Run several relays at once and confirm each row is sent once.
- Drop the same 999 and 277CA files into the inbox twice and confirm claims change once.
- Simulate an upload timeout and confirm the submission becomes uncertain.
Automate these cases against a real database rather than mocks, because the guarantees depend on actual transactions, locks and unique constraints behaving as documented.
What are the common mistakes with idempotent EDI processing?
The common mistakes with idempotent EDI processing undo the guarantees in small ways.
- Sending inside the business transaction: a rollback after upload leaves a sent file with no record.
- Regenerating files on retry: new control numbers turn a retry into a new submission.
- Inbox without a unique key: repeated downloads apply results twice.
- Retrying on timeout without reconciling: the uncertain case becomes a duplicate.
- Treating corrections as retries: fixed claims are blocked or duplicates slip through.
What does this mean for your build plan?
The inbox and outbox add two tables, a relay, an inbox processor and reconciliation tooling. They are cheaper to build at the start than to retrofit after duplicates reach payers, so include them in the first claims release.
- Model claim states and transitions before writing the relay.
- Decide the submission key and how claim versions work with your billing team.
- Build the failure tests into CI so later changes keep the guarantees.
How does Agnotic build exactly-once claim submission?
Agnotic Technologies designs the claim states, outbox and inbox tables, relays, reconciliation and failure tests for your claims workflow, and connects them to your clearinghouse. Your billing team gets one clear status for every claim and every file.
Send each claim once, and know it
Outbox, inbox and reconciliation built into the claims workflow.
Related reading on Agnotic
Claims, EDI and service reliability.


