Building HIPAA-Compliant Software: A Practical Engineering Guide
Senior engineers building AI-native software for clients worldwide
HIPAA compliance is an engineering discipline, not a legal checkbox. Here is how we actually implement technical safeguards, audit logging, BAAs, and PHI handling patterns in production healthcare software — and the mistakes that sink audits.
HIPAA compliance is mostly an engineering problem wearing a legal costume. The regulation itself is short on technical specifics — it says 'implement audit controls' without telling you what to log, and 'encrypt where appropriate' without defining appropriate. That vagueness is why so many teams either over-build (encrypting things three times while leaving PHI in application logs) or under-build (assuming their cloud provider's compliance page means their app is compliant). We have shipped patient portals, clinical workflow tools, and health-data integrations, and this is the practical engineering guide we wish someone had handed us before the first one.
One thing before we start: this is engineering guidance, not legal advice. HIPAA obligations depend on your specific role — covered entity, business associate, or neither — and you need a healthcare attorney to confirm yours. What follows is how we implement the technical side once that question is answered.
First, Know Whether You Are Actually Handling PHI
Protected Health Information is health data plus an identifier — name, email, IP address, device ID, dates, anything on the 18-identifier list. This creates surprises in both directions. A symptom-checker app with no accounts and no identifiers may not be handling PHI at all. Meanwhile, an appointment-reminder service that only stores a phone number and an appointment time absolutely is, because a phone number linked to the fact of receiving care from a specific provider is PHI. Map your data flows before writing any code: what enters the system, where it is stored, where it is transmitted, and what leaves. Every downstream decision hangs off this map, and auditors will ask for it.
BAAs: The Chain Must Be Unbroken
A Business Associate Agreement is required with every vendor that touches PHI on your behalf — and 'touches' includes stores, transmits, or could access. In practice, for a typical modern stack, that means signed BAAs with:
- Your cloud provider — AWS, Google Cloud, and Azure all sign BAAs, but only specific services are covered. AWS lists eligible services explicitly; using a non-eligible service for PHI voids your position regardless of the signed agreement.
- Your email and SMS providers — this is where most startups get burned. Standard tiers of many popular email APIs and SMS gateways are not BAA-eligible; you often need an enterprise plan or a healthcare-specific vendor like Paubox or Twilio's HIPAA-eligible offerings.
- Error tracking and analytics — Sentry, Datadog, and similar tools will happily ingest PHI in stack traces and breadcrumbs. Either sign a BAA with them or scrub PHI before it leaves your infrastructure (do both).
- Your LLM provider, if AI features touch PHI — several major providers now offer BAA coverage on specific tiers or via cloud-hosted versions of their models. Verify the exact product surface covered; a BAA for the enterprise API does not cover developers pasting patient notes into a consumer chat interface.
The rule we enforce: no PHI flows to any third party until a countersigned BAA is filed and the specific service is confirmed eligible. We keep a spreadsheet of every vendor, the BAA date, and the covered services. Auditors love it, and so do we.
The Technical Safeguards That Actually Matter
Encryption: table stakes, done specifically
TLS 1.2+ everywhere in transit, AES-256 at rest — your cloud provider's managed encryption (RDS encryption, S3 SSE, encrypted EBS) covers the storage layer with a checkbox. The parts that require actual thought: encrypt database backups and snapshots (frequently forgotten), encrypt data in message queues and caches (Redis with PHI in it is still PHI at rest), and manage keys through KMS with rotation enabled rather than environment variables.
Access control: role-based, least-privilege, and real
Every user and every service gets the minimum access required. Concretely: clinicians see only their own patients (enforced in queries, not just UI), support staff get a break-glass mechanism that grants temporary elevated access and pages a supervisor, and no engineer has standing read access to production PHI. For debugging, we build de-identified data paths or time-boxed, logged, approval-gated access. Unique accounts for everyone — a shared admin login is an automatic audit finding.
Automatic logoff and session discipline
Required by the Security Rule and genuinely useful in clinical settings where machines are shared. We implement 15-minute idle timeouts for clinical users, shorter for admin panels, with re-authentication that preserves in-progress work so users do not revolt and start propping sessions open.
Audit Logging: The Safeguard Everyone Underbuilds
HIPAA requires you to record and be able to review activity around PHI. Interpreted practically, every access to PHI — reads included, not just writes — needs an immutable log entry answering: who, what record, what action, when, and from where. Our standard implementation:
- Structured JSON events emitted at the data-access layer (not sprinkled through controllers, where new endpoints will forget them)
- Written to append-only storage — S3 with Object Lock or a dedicated logging service — separate from the application database, so a compromised app cannot rewrite history
- Six-year retention, matching the HIPAA documentation retention period
- Alerting on anomalies: one user reading 500 patient records in an hour, access at 3 a.m. from a new location, repeated failed access attempts
Two hard-won specifics. First, log record identifiers, never the PHI itself — an audit log full of patient names is a second PHI store you now have to protect. Second, the read-logging requirement is the one that breaks naive architectures: if your ORM lazily fetches patient rows all over the codebase, you cannot bolt on access logging later. Put PHI access behind a repository layer from day one. Retrofitting this on one inherited codebase cost a client roughly six weeks; designing it in costs nearly nothing.
PHI Handling Patterns We Use in Every Build
- Segregate PHI at the schema level. Keep identifiers and clinical data in clearly marked tables or a separate database. This shrinks the audit surface and makes it possible to answer 'where is all our PHI?' — a question you will be asked.
- Tokenise for internal references. Internal services, queues, and URLs pass opaque record IDs, never names or MRNs. A patient ID in a URL ends up in browser history, proxy logs, and analytics — that is a breach vector.
- Scrub logs and error reports at the source. We run a redaction middleware that strips known PHI fields before anything reaches log aggregation, and we ban PHI in log statements at code review. The most common breach pattern we have seen in inherited codebases is not hackers — it is patient data sitting in plaintext application logs shipped to a third-party log service with no BAA.
- De-identify for analytics and lower environments. Staging environments seeded with production PHI are astonishingly common and completely indefensible. We generate synthetic datasets or run a de-identification pipeline following the Safe Harbor method — strip all 18 identifier categories — before data leaves production.
Infrastructure Patterns Worth Standardising
Beyond the application layer, a few infrastructure decisions do disproportionate compliance work. Network segmentation first: PHI databases live in private subnets with no public route, reachable only from application services through security groups scoped to specific ports — an auditor's first question is often a network diagram, and 'the database is publicly addressable but password-protected' is a losing answer. Second, MFA on everything with production access: cloud console, VPN, deployment tooling. Credential compromise is the leading root cause in published breach reports, and MFA is the cheapest control in this entire article. Third, disaster recovery with teeth: the Security Rule expects a contingency plan, which we implement as automated encrypted backups, a documented restore procedure, and — the part everyone skips — an actual annual restore test. A backup you have never restored is a hope, not a plan. Finally, infrastructure as code: when your environment is Terraform rather than console clicks, you can prove what your security posture was on any given date, which converts several audit questions from archaeology into a git log.
The Mistakes That Sink Audits
- Believing 'HIPAA-compliant hosting' makes the app compliant. The BAA covers the infrastructure layer only. Your access controls, your logging, your session handling — that is all on you.
- No risk assessment on paper. The Security Rule requires a documented risk analysis. Doing the engineering without documenting the reasoning fails audits that the engineering itself would have passed.
- PHI in third-party tools nobody thought about. Calendar invites with patient names, support tickets with screenshots, Slack messages pasting a record — policy plus tooling (DLP scanning, redaction) has to cover the humans, not just the servers.
- No breach response plan. HIPAA has notification deadlines measured in days. Deciding who does what during the incident is far too late. Write the runbook, name the owners, and rehearse it once a year.
- Treating compliance as a launch milestone. Every new feature, vendor, and integration re-opens the question. We run a lightweight PHI-impact check in every design review — five minutes that regularly catches things.
What This Costs, Honestly
On our healthcare projects, HIPAA engineering adds roughly 15–25% to build cost when designed in from the start: the audit layer, access-control rigour, environment segregation, and vendor vetting. Retrofitting the same controls onto an existing product has cost our clients 2–4× that. If there is any chance your product touches PHI within two years, build the repository layer, the audit log, and the data map now — they are cheap early and brutal late.
If you are building in healthcare, our engineering team has shipped these patterns in production and can either build your product on them or audit what you have.
Ready to put these insights into practice? The team at Fajarix builds exactly these solutions. Book a free consultation to discuss your project.
Ready to build something like this?
Talk to Fajarix →