Design an Enterprise Healthcare Record Ingestion Engine
System DesignModel answerLast updated
Architect a resilient, HIPAA-compliant ETL pipeline capable of ingesting 500 million daily sensitive records with strict partner fault isolation and replayability.
You are asked to design an enterprise-grade record processing and ingestion framework for a medical data network. The platform collects daily updates across hundreds of external healthcare facilities (e.g., hospitals, clinics, labs).
The system must ingest 500 million patient updates per day while addressing four core operational challenges:
- Data Quality & Schema Drift: External updates frequently contain bad formatting, duplicated entries, or out-of-order state mutations.
- Security & Regulatory Compliance: Datasets contain Protected Health Information (PHI/PII). All records must be encrypted at rest and in transit with complete audit trail immutability under HIPAA guidelines.
- Partner Fault Isolation: A corrupt feed or bug in one provider's format must never degrade pipeline availability or throughput for other clinical providers.
- Lineage & Audit Replay: The architecture must guarantee end-to-end lineage tracking and allow re-processing of raw historical inputs when parser definitions or business rules are revised.
Pipeline Requirements & Target Scale
- Average Ingestion Rate: ~5,800 records/sec.
- Peak Load: Up to 20,000 records/sec during heavy batch windows.
- End-to-End SLA: Maximum end-to-end processing latency under 5 minutes from upload to searchability.
- Data Lifecycle: Raw payloads must remain queryable/replayable for 7 years; refined database records are updated daily via point-in-time upserts.
Design the end-to-end platform from client ingress to the structured storage layer, detailing the component architecture, stream routing, duplicate/ordering control, fault isolation boundaries, and compliance mechanisms.
Hints
Hint 1
Calculate throughput and bandwidth constraints first. Does throughput or data integrity dictate the architectural pattern?
Hint 2
Separate raw immutable ingestion from business validation logic. How does writing raw payloads directly to an immutable object layer unlock historical replay capabilities?
Hint 3
To prevent high-volume hospital partners from starving smaller providers during backfills, design a dedicated topic partition and worker bulkhead model based on partner tiers.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Requirement & Capacity Estimation
Non-Functional Targets
- SLA: End-to-end latency $\le 5\text{ minutes}$.
- Durability & Lifecycle: 7 years of immutable raw storage.
- Security: Encryption key isolation per partner, zero unencrypted PHI in application logging, full WORM (Write Once, Read Many) compliance.
Capacity & Throughput Math
- Total Daily Volume: $500\text{ million records / day}$.
- Average Rate: $\frac{500 \times 10^6}{86,400\text{ seconds}} \approx 5,787\text{ records/sec}$.
- Peak Rate: $20,000\text{ records/sec}$.
- Payload Envelope: Average record size $\approx 2\text{ KB}$ (JSON/FHIR/HL7 wrapped).
- Peak Ingress Bandwidth: $20,000\text{ rec/sec} \times 2\text{ KB} = 40\text{ MB/sec} = 320\text{ Mbps}$.
- Daily Raw Storage (uncompressed): $500 \times 10^6 \times 2\text{ KB} = 1\text{ TB/day}$.
- 7-Year Retention: $1\text{ TB/day} \times 2,555\text{ days} \approx 2.55\text{ PB}$. Compressed with Zstandard ($\sim 4:1$), actual cold storage is $\approx 640\text{ TB}$.
Takeaway
Peak traffic ($40\text{ MB/sec}$) is straightforward for standard message brokers (e.g., Apache Kafka). The primary engineering difficulty lies in correctness (ordering and deduplication), multi-tenant isolation, and compliance enforcement at scale.
2. System Architecture
┌────────────────────────────────────────────────────────┐
│ INGRESS LAYER │
└────────────────────────────────────────────────────────┘
│
Partner Feeds ── (mTLS / TLS 1.3) ───────────►│ Ingress Gateway API / SFTP Landing
│ ├─ Checksum verification
│ └─ Write byte stream
▼
┌────────────────────────────────────────────────────────┐
│ RAW ZONE │
└────────────────────────────────────────────────────────┘
│
▼
Cloud Object Store
(WORM Lock, Per-Partner KMS)
│
│ Emits "Object Created" event
▼
┌────────────────────────────────────────────────────────┐
│ PROCESSING ZONE │
└────────────────────────────────────────────────────────┘
│
▼
Kafka Event Streaming Hub
(Tiered Topics: High / Standard)
│
├──► File Extractor & Splitter
│
├──► Validation & Parsing Workers
│ ├─ Schema check
│ ├─ Malformed ──► Quarantine / DLQ Topic
│ └─ Valid ─────► Deduplication Stream
│
▼
Stateful Version Resolver
(RocksDB / Kafka Streams State Store)
│
┌────────────────────────────────────────────────────────┐
│ CURATED ZONE │
└────────────────────────────────────────────────────────┘
│
▼
Open Table Format (Apache Iceberg)
MERGE INTO / Conditional Upsert
│
├──► Operational Serving DB (PostgreSQL / DynamoDB)
└──► Immutable Audit Log (WORM)
Flow Breakdown
-
Ingress & Raw Immutable Storage (Raw Zone)
- External data arrives via HTTPS (FHIR REST API) or SFTP batch uploads.
- The Gateway calculates an payload SHA-256 hash, stores the raw payload immediately into a cloud Object Storage bucket configured with Object Lock (WORM mode), and returns an acknowledgement with a generated
ingest_batch_id. - No validation or parsing occurs at ingress. This guarantees raw byte preservation for historical replay.
-
File Decomposition & Streaming
- Storing a raw file triggers an object creation event to a Kafka manifest topic (
raw.manifest). - A fleet of Splitter Workers streams the raw payload from Object Storage, divides batched files into granular records, and publishes each record to a partitioned Kafka topic (
raw.records).
- Storing a raw file triggers an object creation event to a Kafka manifest topic (
-
Validation & Pipeline Parsing
- Parser Workers consume from
raw.records. Validation occurs across three stages:- Syntactic: JSON/HL7 payload structure integrity.
- Structural: Schema requirement matching (presence of mandatory fields).
- Semantic: Valid standard clinical codes (ICD-10, LOINC) and plausible date ranges.
- Failures route directly to a Dead Letter Queue (DLQ) and Quarantine Store with attached context metadata. Valid events stream to
valid.records.
- Parser Workers consume from
-
Version Control & State Settlement
- The Deduplication Engine uses a local state store (Kafka Streams / RocksDB) to evaluate incoming record versions against recorded history.
- Records stream into the Curated Zone, built on open table formats like Apache Iceberg, executing idempotent conditional upserts (
MERGE INTO).
3. Handling Quality, Duplicates, and Out-of-Order Records
Data Processing Matrix
| Data Issue | Identification Strategy | Resolution Mechanism |
|---|---|---|
| Malformed Payload | Schema validation failure during parsing phase. | Redirect payload pointer to DLQ Stream; write failure reason to Quarantine DB. Emits metric alert. |
| Exact Payload Duplicate | Identical SHA-256(payload) within ingestion window. | Drop duplicate at Deduplication stage; log idempotency key skip event. |
| Redelivered Message | Kafka consumer retry emitting identical business ID. | Target database executes idempotent write (MERGE INTO matching record hash). |
| Out-of-Order Update | Record event timestamp source_ts < existing record timestamp in state store. | Conditional Write: Update append-only historical log table (SCD Type 2), but do not mutate the active operational state. |
Deduplication and Version Resolution Logic
def process_incoming_record(incoming_record, state_store, storage_layer):
# Construct business identity key
entity_key = hash_key(
incoming_record.provider_id,
incoming_record.patient_id,
incoming_record.clinical_event_id
)
existing_state = state_store.get(entity_key)
if existing_state:
# Check payload duplicate
if existing_state.payload_hash == incoming_record.payload_hash:
log_metrics("duplicate_dropped", entity_key)
return
# Check temporal order based on source generation time, NOT ingress system time
if incoming_record.source_ts < existing_state.source_ts:
# Store in audit history (SCD Type 2), skip active state overwrite
storage_layer.write_historical_only(incoming_record)
log_metrics("out_of_order_archived", entity_key)
return
# Record is valid and newer: update state store and perform downstream write
state_store.put(entity_key, incoming_record.to_state())
storage_layer.upsert_active_state(incoming_record)
4. Partner Fault Isolation Architecture
To prevent a rogue partner system sending corrupt payloads or massive backfill volumes from starving other pipelines, isolation boundaries are set at messaging, execution, and rate limiting stages.
┌─────────────────────────────────────────────────┐
│ PARTNER INGRESS TIER │
└─────────────────────────────────────────────────┘
│
┌─────────────────────┴─────────────────────┐
▼ ▼
[ High-Volume Tier ] [ Standard Tier ]
(Partner A, Partner B) (Partners C through Z)
│ │
▼ ▼
Kafka Dedicated Topics Kafka Pooled Topics
`raw.records.partner_a` `raw.records.pooled_1`
`raw.records.partner_b` `raw.records.pooled_2`
│ │
▼ ▼
Dedicated Pod Pool Shared Pod Pool
(Strict CPU/Mem Limits) (Fair-Share Scheduling)
-
Topic Partitioning & Tiered Routing
- Incoming records use Kafka message keys set to
partner_id:patient_id. Partitioning guarantees strict order per patient while balancing across nodes. - High-throughput partners (Tier 1) are given dedicated Kafka topics. Smaller institutions share pooled multi-tenant topics.
- Incoming records use Kafka message keys set to
-
Compute Bulkheads
- Kubernetes processing pods are deployed in isolated worker pools. Heavy partner backfills are scheduled on dedicated worker deployments bound by resource quotas (CPU/Memory resource requests and limits).
-
Circuit Breakers & Automatic Quarantine
- Each partner pipeline tracks parsing error rates over sliding 5-minute windows.
- If a partner’s error rate exceeds 5%, the circuit breaker trips. Records for that specific
partner_idbypass processing and route directly to apartner_quarantinebucket without halting execution for compliant providers.
5. Security, Lineage, and Compliance (HIPAA)
Data Encryption Framework
- In Transit: All traffic enforces TLS 1.3. Internal node-to-node streaming over Kafka uses TLS with mTLS client authentication.
- At Rest: Envelopes encrypted via AWS KMS / HashiCorp Vault. Each medical provider partner uses a distinct KMS Key. If a partner contract terminates, their specific key is revoked (crypto-shredding), instantly rendering their raw data unreadable without affecting historical records of other tenants.
Data Lineage Structure
Every curated database record maintains metadata tracking its full processing history:
{
"curated_record_id": "rec_9938217",
"patient_id": "pat_38210",
"provider_id": "prov_hospital_alpha",
"source_version_ts": "2024-10-12T08:30:00.000Z",
"ingest_timestamp": "2024-10-12T08:31:12.420Z",
"parser_version": "v2.1.4",
"raw_object_uri": "s3://raw-zone-bucket/prov_hospital_alpha/2024/10/12/batch_9921.json.gz",
"raw_object_offset": 48192,
"payload_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
}
Audit Logging & PII Protection
- Application loggers enforce regex masks filtering out SSNs, phone numbers, and names.
- DLQs contain pointer payloads (
raw_object_uriand byte offset) rather than plaintext PHI strings, preventing developers from accessing sensitive records in troubleshooting tooling. - Audit trails are appended to a dedicated write-once ledger (e.g., QLDB or S3 Object Lock) recording every access attempt, processing execution, and manual replay operation.
6. Historical Replay Architecture
When parser bug fixes or structural schema changes require reprocessing past records, the pipeline leverages its raw-zone data store:
Replay Command ──► Trigger Replay Job (specify partner_id, date range, target_parser_version)
│
▼
Read Immutable Raw Zone Objects (S3 WORM)
│
▼
Publish to `replay.records` Topic
│
▼
Execute Isolated Processing Pipeline (Replay Worker Pool)
│
▼
Conditional Upsert to Curated Zone (Iceberg MERGE)
- Non-Disruptive Triggering: Replays operate over a dedicated Kafka topic (
replay.records) using isolated worker pods to avoid starving real-time feeds. - Deterministic Processing: Raw bytes are parsed using the updated parser rules. The output is processed through the state resolver.
- Idempotent Merge: Updates upsert cleanly into the Apache Iceberg curated tables. If the re-parsed record matches an existing version, the write evaluates as a no-op; if it corrects an older parsed state, the curated state updates automatically.