Skip to content
HIPAA Compliant AppSecure healthcare engineering

Guide

HIPAA-Compliant Database Design: Schema, Encryption and Access Patterns

HIPAA compliant database design is about controlling who can read which rows and columns of PHI, proving who did, and making sure the data can be recovered, retained and eventually removed according to policy. The Security Rule does not prescribe a database engine or schema, so these decisions come from your risk analysis.

This guide covers the patterns we use for relational and document stores that hold PHI: layered encryption, key management, row-level security, separating identifiers from clinical data, audit tables, retention and deletion, backups and de-identification under 45 CFR 164.514.

Key takeaway

A HIPAA-compliant database encrypts PHI at rest with managed keys, adds field-level encryption for the most sensitive attributes, enforces least-privilege and tenant or patient-level access through roles and row-level security, records access in tamper-resistant audit storage, and follows documented retention, backup and de-identification rules. The database runs on a BAA-covered, HIPAA-eligible service in a private network.

Last reviewed November 17, 2026

Start with a data classification in the schema

Before choosing encryption or access patterns, classify every table and column. Mark direct identifiers (name, address, phone, email, MRN, SSN), quasi-identifiers (dates, ZIP codes), clinical content (diagnoses, notes, results, images) and operational data with no PHI. Store the classification as metadata, for example in column comments or a data catalog, so tools and reviewers can use it.

This classification drives every later decision: which columns get field-level encryption, which are excluded from search indexes and analytics exports, and which are removed during de-identification.

Layered encryption: storage, envelope and field level

Encryption at rest is an addressable specification under 164.312(a)(2)(iv), and for a cloud database it is almost always reasonable and appropriate. Most teams use several layers, each protecting against a different threat.

LayerProtects againstLimitations
Storage or volume encryption (managed database encryption at rest)Lost disks, decommissioned hardware, raw snapshot accessTransparent to anyone with database credentials; does not limit what queries can read
Envelope encryption with KMSKey exposure; enables key rotation and access policies on keysRequires KMS availability; adds design work for rotation and re-encryption
Field-level or application-level encryptionDatabase administrators, SQL injection and over-broad service roles reading sensitive columnsEncrypted fields cannot be indexed or searched normally; needs careful key scoping
Backup and snapshot encryptionExposure of backups copied to other accounts or regionsKeys must be available in the recovery region; test restores with keys

Key management with a KMS

Envelope encryption uses a data encryption key to encrypt the data and a key encryption key, held in a key management service or HSM, to encrypt the data key. The application never stores the master key, and access to decrypt is controlled and logged by the KMS.

Separate keys by environment and, where customers require it, by tenant. Restrict decrypt permissions to the specific service roles that need plaintext, enable automatic rotation where the service supports it, and alert on unusual decrypt volumes. A KMS audit trail is also valuable evidence during an incident investigation.

  • Production keys live only in the production account; developers cannot use them.
  • Key deletion is protected by a waiting period and requires multiple approvals.
  • Searchable fields such as MRN can use a keyed hash (blind index) alongside the encrypted value.

Access control in the database: roles and row-level security

Application code should enforce authorization, but the database is a useful second line. Create separate database roles for each service, grant only the tables and operations each one needs, and never let applications connect as a superuser or owner.

Row-level security, available in PostgreSQL and several managed databases, filters rows by a session attribute such as tenant ID or care team. If a developer forgets a WHERE clause, the policy still prevents cross-tenant reads. Combine it with column-level grants so reporting roles cannot select identifier columns.

Service roles

One role per service with least privilege. Migrations run under a separate role that applications cannot assume.

Tenant isolation policies

Row-level security keyed on a tenant identifier set per connection or transaction, with tests that prove cross-tenant queries return nothing.

Human access

No standing human access to production PHI. Break-glass access is approved, time-bound and recorded.

Read replicas and analytics

Replicas inherit the same data; apply the same access controls or replicate only de-identified or tokenized data.

Separate identifiers from clinical data

A common pattern stores demographics and direct identifiers in a patient identity table or service, and clinical records keyed by an internal surrogate ID. Clinical tables then contain no names, contact details or MRNs. Joining the two requires access to both, which can be restricted to specific services.

This separation also simplifies de-identification, data exports and analytics, and limits what a single compromised query or role can reveal. Note that clinical data keyed by a surrogate ID is generally still PHI if your organization can link it back to an individual.

Audit tables and access history

Audit controls (164.312(b)) require mechanisms that record and examine activity in systems containing ePHI. Database-level audit features capture queries, but application-level audit events are more meaningful because they record which user, acting in which role, viewed which patient.

Store audit events in an append-only table or, better, in separate write-once storage that application roles cannot update or delete. Include actor, action, resource, patient identifier, timestamp, source IP or device, and outcome. Avoid copying PHI values into audit records; reference them by identifier.

HIPAA does not set a specific retention period for audit logs. Many organizations align log retention with the six-year documentation retention requirement in 164.316(b)(2); decide your period in policy and document the rationale.

Soft delete, retention and disposal

Soft delete (marking rows inactive) supports undo and investigations, but it is not disposal. Medical record retention periods are generally set by state law and by the covered entity's policies, not by HIPAA itself, and they vary. Your schema should support the policy the organization adopts.

  1. 1

    Model retention explicitly

    Store a retention category and dates per record so automated jobs can apply the policy.

  2. 2

    Separate logical and physical deletion

    Soft delete for user actions; scheduled hard delete or cryptographic erasure when retention ends.

  3. 3

    Handle backups

    Document how deleted data ages out of backups, since restoring an old backup can reintroduce it.

  4. 4

    Support legal holds

    Allow specific records to be exempted from deletion when litigation or investigations require it.

  5. 5

    Record disposal

    Log what was disposed of and when, supporting the device and media controls in 164.310(d).

Backups and recovery

Data backup and disaster recovery plans are required parts of the contingency plan (164.308(a)(7)(ii)(A) and (B)). Use automated, encrypted backups with point-in-time recovery, copy them to a separate account and region, and protect at least one copy with immutability or retention locks so ransomware or a compromised admin role cannot delete it.

A backup that has never been restored is an assumption. Schedule restore tests, measure how long they take against your recovery time objective, and record the results as evidence.

De-identification under 45 CFR 164.514

De-identified data is not PHI, which makes it far easier to use for analytics, testing and research. HIPAA recognizes two methods in 164.514(b).

  • Free-text fields such as clinical notes often contain identifiers and need specialized handling.
  • Re-identification codes are allowed under 164.514(c) only if they are not derived from identifiers and the mechanism is not disclosed.
  • A limited data set (164.514(e)) is different: it is still PHI and requires a data use agreement.

Safe Harbor

Remove 18 types of identifiers of the individual and of relatives, employers and household members, and have no actual knowledge that the remaining information could identify the individual. The identifiers include names; geographic subdivisions smaller than a state (with a limited exception for the first three ZIP code digits); all elements of dates except year directly related to the individual, and ages over 89; telephone and fax numbers; email addresses; Social Security numbers; medical record numbers; health plan beneficiary numbers; account numbers; certificate and license numbers; vehicle identifiers; device identifiers and serial numbers; URLs; IP addresses; biometric identifiers; full-face photographs and comparable images; and any other unique identifying number, characteristic or code.

Expert Determination

A person with appropriate statistical and scientific expertise determines and documents that the risk of re-identification is very small, given the data and the anticipated recipient. This method can preserve more useful detail, such as partial dates or finer geography, but requires a qualified expert and documented methods.

This page is general information about software engineering for healthcare, not legal advice. HIPAA compliance depends on your organization's risk analysis, policies, workforce practices, vendor agreements and how PHI is actually handled. No software, hosting provider or development partner can make an organization compliant on its own, and there is no official HIPAA certification for applications.

Frequently Asked Questions

Does HIPAA require database encryption?

Encryption at rest is an addressable specification under the current Security Rule, so you must implement it if reasonable and appropriate or document an equivalent alternative. For cloud databases it is almost always reasonable, and encrypted PHI consistent with HHS guidance can fall under the breach notification safe harbor.

Which databases are HIPAA compliant?

No database is HIPAA compliant on its own. Managed databases from AWS, Azure and Google Cloud can be used for ePHI when they are listed as HIPAA-eligible under the provider's BAA and are configured with encryption, access controls, private networking and logging.

What is the difference between envelope encryption and field-level encryption?

Envelope encryption describes how keys are managed: data keys encrypt data and a master key in a KMS encrypts the data keys. Field-level encryption describes what is encrypted: specific columns are encrypted by the application so even database users cannot read them. They are often used together.

How long must PHI be retained in a database?

HIPAA does not set a medical record retention period; that comes mainly from state law and organizational policy. HIPAA does require retaining required documentation, such as policies and risk analyses, for six years.

Is de-identified data still subject to HIPAA?

No. Data de-identified under Safe Harbor or Expert Determination (45 CFR 164.514(b)) is not PHI. A limited data set is different: it is still PHI and requires a data use agreement.

Should I use soft delete for PHI?

Soft delete is useful for undo and investigations, but it does not dispose of data. Pair it with scheduled hard deletion or cryptographic erasure that follows your retention policy, and account for copies in backups.

Can developers use production data for testing?

It is far safer not to. Use synthetic or properly de-identified data in non-production environments. Copying production PHI to test systems extends the scope of your safeguards, BAAs and audit obligations to those environments.

Plan your HIPAA-compliant app with engineers who start from the data flow.

Tell us what you are building. We will respond with questions about scope, integrations and PHI handling, then a structured estimate. Please do not include patient information.