(Side project · backend engineering)

EHR Ingestion Platform

A hospital sends a patient record. The network drops. The client retries.

Now there are two records. Or none. And nobody finds out until it matters.

So I built a backend where that can’t happen. Then I broke it on purpose, 11 different ways, to prove it.

  • Java 21
  • Spring Boot
  • PostgreSQL
  • RabbitMQ
  • Docker Compose
  • Testcontainers
  • GitHub Actions

View the code on GitHub ↗CI passing on every push

POSTpublishdeliver job + outbox,one transaction result + receipt+ outbox after 3 attempts Client Intake API:8080 RabbitMQ0 ready Normalization:8081 PostgreSQLjobs · keys · outbox Dead letterspoison only PostgreSQLresults · receipts · outbox SIGKILL 202 Accepted Retry, same key → same job SUCCEEDED ✓ once

The whole idea in one loop. The worker dies mid-job, the message waits, the job still finishes once.

60Java unit tests, all passing
19integration tests on real PostgreSQL
11/11fault-injection scenarios against live containers
0%errors across 200 end-to-end jobs
Role
Solo: architecture, implementation, testing, CI
Shape
2 services, 2 databases, 1 broker, 5 containers
Data
FHIR R4 and HL7 v2, synthetic patients only

(Why build this at all?)

I’m pivoting harder into backend engineering. And software is going AI-native fast.

AI can write a service in an afternoon now. What it can’t do is decide what “correct” means, or prove the thing stays correct when a container dies at the worst possible moment.

That part is still the job. So that’s the part I wanted to get good at.

I picked healthcare on purpose. A duplicated record in a demo is a bug. A duplicated record in a hospital is somebody’s medication list, twice. If I was going to practise reliability, I wanted a domain where it obviously matters.

I used AI as a pair to move faster. The design calls, the failure cases and the proof were mine.

Three gaps where records go missing.

Hospital systems talk over unreliable networks. Every one of these happens in real life, and every one is a chance to lose a record or store it twice.

The client retries after the server already saved.

Stored twice.

The worker saves its result, then crashes before telling the queue.

Processed twice.

The broker goes down mid-delivery.

Lost.

The obvious fix is “just retry”.
Retries are exactly how you get duplicates.

One request, end to end.

  1. SubmitThe client POSTs a record with an idempotency key.
  2. CommitThe job and its outbox event are saved in one transaction, and 202 is returned.
  3. PublishThe outbox publisher sends to RabbitMQ and waits for the confirm.
  4. NormalizeThe worker converts FHIR or HL7 into one patient model.
  5. Commit, then ackThe result is saved before the message is acknowledged.
  6. CompleteA completion event updates the job to SUCCEEDED.

Two services that deploy separately, each owning its own database, joined only by durable queues. Intake keeps accepting work even when the worker is down. Clients read normalized results straight from the Normalization service, scoped to their own API key.

Six decisions that close the gaps.

Closes: stored twice

Idempotent intake

A unique constraint on client and key settles racing retries in the database. 32 simultaneous requests with one key produced exactly one job. A changed payload under the same key returns 409.

INSERT … ON CONFLICT (client_id, idempotency_key) DO NOTHING
Closes: lost

Transactional outbox

The business write and the message to send commit together, so a crash can never strand an accepted job. Publishers claim rows without blocking each other and back off up to 60 seconds.

SELECT … FOR UPDATE SKIP LOCKED
Closes: lost

Confirmed publishing

A message only counts as sent when the broker acks it and it was routable. Checking both catches messages that would otherwise silently vanish.

if (!confirm.isAck() || returned != null) retry
Closes: processed twice

Commit before ack

The worker saves its result, a receipt and the completion event before acknowledging. If it dies in between, redelivery hits the receipt and becomes a no-op: exactly-once effect on at-least-once delivery.

Keeps the line moving

Dead-lettering

Three attempts, then poison messages move to a dead-letter queue so the worker keeps going. A bad record in a 100-patient bundle rolls back the whole bundle.

Keeps data private

Tenant isolation

Identity comes from the API key on the server, never from a header the caller sets. Every read is owner-scoped, so another client's job returns 404.

Broken on purpose.

A recovery suite stops, kills and restarts real containers, then checks nothing was lost or duplicated. All 11 scenarios pass locally and in CI.

A replay of the suite’s output. See the real runs in CI ↗

Two race conditions, found and fixed.

Infrastructure

RabbitMQ crashed on first boot

Symptom
On a fresh volume the broker died with .erlang.cookie: eacces.
Cause
The Docker healthcheck ran the CLI as root and created the cookie file before the broker could, locking the broker out of its own file.
Fix
One line: run the healthcheck as the rabbitmq user. Verified with three cold boots on fresh volumes, zero restarts.

Test harness

A chaos test hung on CI

Symptom
The abrupt-worker-restart scenario stalled on GitHub's slower runners but passed locally.
Cause
The test restarted the SIGKILLed container before it had fully exited.
Fix
Wait for the exit, then restart, without loosening a single assertion. Passed CI twice in a row.

Measured, not guessed.

200 jobs, concurrency 8
Metricp50p95p99
End to end: submit → normalized → complete569 ms1.16 s1.18 s
HTTP acceptance8.6 ms27 ms37 ms

Closed-loop run on an Apple M1 laptop, 200 of 200 jobs succeeded with zero errors. Most end-to-end time is the deliberate 500 ms outbox poll interval on each hop, a tunable trade-off rather than processing cost.

Four layers of tests, every push.

Unit60 tests covering domain rules, retry backoff and the API contract
Integration19 tests on real PostgreSQL covering locking, rollback and crash windows
Recovery11 black-box scenarios against the running stack
BenchmarkAn end-to-end load run with latency percentiles

Making it work once is easy.
Making it work again, right after it crashed, is the job.

Hiring for backend? Email me ↗See the rest of my work