Design a Patient Record Database Next to a Legacy One
- Model patients, visits and clinical entries in plain words, with an identity scheme that survives duplicates and merges
- Change a schema while years of existing records keep reading correctly
- Move off a legacy database in stages, and adjust calmly each time the interviewer adds a requirement
Understanding the problem
Something like this: design a new database that holds realistic patient data. An old database already stores patient records and is still in use, so your design has to deal with it. Expect the interviewer to add requirements as you talk.
Two firsthand 2026 reports describe this case study. A Madison candidate in May 2026 said the session "became a design for a new database with realistic patient data while still dealing with the old database," and that "the question kept changing as the discussion continued." A developer who accepted an offer in July 2026 called it a "relaxed, non-technical design for creating a record system for patients." Neither report lists the requirements the interviewer added. So when this lesson talks about likely pushes, read them as prep advice built from the shape of the prompt. Your interviewer may go somewhere else entirely.
The prompt is small on purpose. There's no traffic to estimate and no global fleet to draw. What's being tested is whether you can model medical records cleanly, and whether that model holds up when someone changes the rules halfway through. The legacy database makes it harder in a realistic way. You can't design on a blank page, because years of records already exist and somebody is still using them.
Requirements
Functional requirements
Agree on a small surface first. Staff register a patient and look them up again later. A clinician records a visit and adds entries to it: a diagnosis, an allergy, a medication, a measurement like blood pressure. Anyone allowed to see the chart can open it and see everything in order. And the records already sitting in the old database have to show up in the new one, correctly attached to the right person. Ask a couple of questions out loud before you commit. Is the old database being replaced, or will both live on? Do other apps still read the old one? Is this one clinic or several? The answers shape the rest of the conversation.
In scope
- Register a patient and find them again by name and date of birth
- Record visits and the clinical entries made during them
- Open a patient's full chart in time order
- Bring the old database's records across without losing or duplicating anyone
- Keep working while the old database is still in use
Below the line (call it out, then skip)
- Billing, insurance claims and scheduling
- The clinician's screens beyond what they need from the data
- Exchanging records with other hospitals
- Reporting and analytics, unless the interviewer brings them up
Non-functional requirements
Correctness comes first, and it outranks speed by a long way. A lab result attached to the wrong patient is worse than a slow page. So every write that touches identity, like registering a patient or merging two records, needs a transaction and a unique key behind it. Nothing is ever really deleted. A clinician who entered a wrong allergy needs to fix it, and anyone reviewing the chart later needs to see that it was fixed, when, and by whom. That pushes the design toward corrections that add a new version rather than overwrite the old one. The old system has to keep working throughout. Other apps, reports and people depend on it, and you won't control their timeline. Privacy matters too. Every read of a chart should be logged with who looked, because in healthcare that question gets asked.
- Never: mix up two patients. Identity writes are transactional and keyed. A wrong attachment is the worst bug this system can have.
- Never: silently overwrite. Corrections add a new version and keep the old one, so the chart always shows what changed.
- Always: keep the old system working. Apps that read the legacy database move on their own schedule, so both stores run side by side for a while.
- Always: log who opened a chart. Every read and write of a patient record leaves an audit entry with the user and the time.
The records, in words
Four records carry the design. Name them before you draw boxes, since most of the follow-ups will land on this model and not on the architecture.
Patient
One real person. It holds who they are: name, date of birth, sex, contact details. Its key is an internal patient_id the new system mints itself, and that id never changes or gets reused, even if the person changes their name or gets merged with a duplicate.
Patient identifier
Every outside number that points at a patient: the medical record number each clinic assigns, the id the old database used, an insurance member number. Each row says which system issued the number. The old database's ids land here too, right next to the new ones.
Visit
One encounter between a patient and care: an office visit, an admission, a phone call. It records the patient, where it happened, who saw them and when. Clinicians call this an encounter, and saying so once shows you know the domain.
Clinical entry
One thing written into the chart during a visit: a diagnosis, an allergy, a medication, a blood pressure reading. It records the visit, the kind of entry, the value, who entered it and when. A correction is a new entry that replaces an old one, and the old one stays.
| Table | Fields |
|---|---|
| patients | patient_id · name · date_of_birth · sex · contact · merged_into · created_at |
| patient_identifiers | issuing_system · identifier · patient_id |
| visits | visit_id · patient_id · location · clinician · started_at · kind |
| clinical_entries | entry_id · visit_id · patient_id · kind · value · entered_by · entered_at · replaces_entry_id · status |
| audit_log | user · action · patient_id · at |
Two choices here are worth saying out loud. The first is the key. A social security number or a name plus birthday looks tempting, and the identity deep dive shows how each one fails. A number the system mints itself, the internal patient_id, is the only key that stays stable.
The second is the identifier table. The old database's ids, each clinic's record numbers and anything that comes later all live in one place, each tagged with the system that issued it. When the interviewer adds a second hospital with its own numbering, nothing in the patient table changes.
Clinical entries sit in one table with a kind field, rather than a table each for allergies, diagnoses and medications. That keeps the chart one query away and makes a new kind of entry cheap. The trade is weaker checking per kind. A medication needs a dose and an allergy needs a reaction, and one generic value column can't enforce either. A fair middle ground: shared columns for what every entry has, plus a small table per kind for the details that need rules. Say the trade and pick one. The interviewer cares more about the reasoning than the choice.
The API
Five calls are enough to anchor the conversation. Keep it this thin. In a relaxed case study the interviewer wants to see that reads and writes have a clear shape, and won't ask for a full spec.
The design end to end
The architecture is mostly about living next to the old database. At the start, the legacy database stays the system of record, the one place whose version wins if the two disagree. The new database fills up as a faithful copy and serves the new screens. Later, ownership moves across one clinic at a time, which the migration deep dive covers. In the diagram, blue is people and apps outside the design, violet is a service we run, amber is a stream of changes, and green is stored data.
1) Copy the history. The Backfill job reads the Legacy database in batches of patients, oldest first, and hands each record to the Sync worker. The worker looks the old patient key up in the ID crosswalk, mints an internal id if this person is new, translates the record into patients, visits and entries, and writes them to the New patient database. Backfill and live sync use the same translation code on purpose. Two copies of the mapping rules would drift apart, and the reconciler would spend its life reporting the difference.
2) Keep up with live changes. While the backfill runs, people keep using the old system. Every change they commit lands on the Change feed, and the sync worker applies it to the new database within seconds. Because each write is keyed on the legacy id, it doesn't matter if the backfill and the feed both deliver the same record, or if a change arrives twice after a crash. The second write lands on the same row. The order still matters for a single patient, so the feed has to keep each patient's changes in sequence.
3) Serve the new screens. The Clinician app calls the Record service, which reads charts from the new database. Writes take more care. While legacy owns a patient, the service writes there, and the change arrives in the new database a moment later through the feed. A nurse who saves an allergy and refreshes might not see it yet. The service can close that gap by waiting until the change shows up before it answers. Raise the gap before the interviewer finds it.
4) Check the copy. Every night the Reconciler compares both sides and reports differences. This is what lets you say "the new database is right" with evidence. When a clinic's numbers have matched for a few weeks, it's a candidate to move across. How that move works, and how to change the new schema once it's live, are the deep dives.
Technology choices
In a relaxed case study, naming the kind of tool and why is usually enough. Brand names help when the interviewer asks.
- The New patient database is Postgres. Patient data is full of relationships: entries belong to visits, visits belong to patients, identifiers point at patients. A relational database enforces those links and the unique keys that stop duplicates, and it runs a merge of two patients in one transaction. A document store would make "one chart as one document" easy, and every cross-patient question hard.
- The Change feed is change data capture, with a tool like Debezium reading the old database's transaction log into Kafka. Reading the log means the old apps don't change at all. Kafka keeps each patient's changes in order if you key the messages by patient, and it keeps them for days, so a sync worker that falls behind or crashes picks up from where it stopped. If the old database has no readable log, poll a last-modified column instead and accept a slower feed.
- The Sync worker and Backfill job are plain services sharing one translation library. The worker commits its position in the feed only after the write to Postgres succeeds, so a crash repeats a little work and loses none. Repeats are safe because every write is an upsert keyed on the legacy id.
- The ID crosswalk is a Postgres table inside the new database, with a unique key on the issuing system plus the number. It lives in the same database as the patients so registering a patient and recording its old id happen in one transaction.
- The Reconciler is a scheduled job. It compares counts and checksums per patient rather than every row, which keeps a nightly run cheap even across years of history.
Potential deep dives
How do we know two records are the same patient?
Copy the old data across and you'll find the same person three times: "Jon Smith" registered at one clinic, "Jonathan Smith" at another, and a third record with the birthday typed wrong. Healthcare calls these duplicates, and they're dangerous. A doctor who opens one of the three sees a third of the history, and might miss the allergy on another.
Approach
Use name plus date of birth as the primary key, or the social security number, so the same person can't be registered twice.
Challenges
Two different people share a name and a birthday more often than you'd guess, and the key forces them into one chart. That's the worst error the system can make. Names change after a marriage. Many patients have no social security number, newborns and visitors among them, and some give a wrong one. And a key built from personal data spreads that data into every table that refers to the patient.
Approach
Every patient gets an internal id the system mints and never reuses. Outside numbers live in the identifier table. When the front desk registers someone, the service searches for likely matches on name, date of birth and phone number, and shows them before creating a new patient. The clerk picks one or confirms this is someone new.
Challenges
Most new duplicates get stopped at the desk, where the person is standing there to ask. The duplicates already in the old data slip straight through, and a migration brings every one of them across. This tier also leaves no way to fix a duplicate after the fact without losing which record said what.
Approach
Score each pair of candidate records: matching date of birth and phone counts a lot, a similar name a little, a different sex counts against. High scores merge automatically, low scores stay separate, and the middle band goes to a review queue for a person to decide. A merge never deletes. The losing patient row gets a merged_into pointer to the survivor, and its identifiers and entries stay where they are. Reads follow the pointer.
Challenges
Merges sometimes turn out to be wrong, and in healthcare you must be able to undo one. Linking makes that possible: clear the pointer and both patients reappear with their own history. The cost is that every lookup follows a pointer, sometimes a chain of them. Keep chains short by pointing each merged record straight at the final survivor.
The thresholds are a judgment call, so say which mistake is worse. Wrongly merging two people puts one person's medications in another's chart. Wrongly keeping one person split hides part of their history. Both hurt, which is why the uncertain middle goes to a human. The coding problem at the end of this lesson is the linking part of this tier.
How does a schema change land without breaking existing data?
Say the interviewer asks for something the model doesn't have. A patient's preferred name, separate from their legal name, is a common example in prep. The new database already holds years of records, and the record service, the sync worker and maybe a report all read the patients table. Some of them will be on the old code for a while after the change ships.
Approach
Rename the name column to legal name, add preferred name, and rewrite every existing row in one big update during a deploy.
Challenges
Any code still reading the old column name breaks the moment the rename lands, and in a running system some always is. A rewrite of every row in one statement can lock a busy table for a long time. If the release has to be rolled back, the old code can't read the renamed column either.
Approach
Add a new optional column for preferred name and leave everything else alone. Old code ignores the column it doesn't know about. New code reads it and falls back to the legal name when it's empty. Existing rows don't need touching at all.
Challenges
It's safe and fast, and it covers most requests. But it can't handle a change of meaning. If the interviewer says a patient can now have several addresses, one address column on the patient can't be extended into that. And a schema that only ever grows ends up full of columns nobody trusts.
Approach
Make the change in three releases. Expand: add the new shape next to the old one, such as an addresses table, and have new code write both. Migrate: copy old rows into the new shape in small batches, in the background. Contract: once every reader uses the new shape and the counts match, stop writing the old column, and later drop it.
Challenges
It takes longer, and for a while two shapes hold the same fact. The double write has to happen in one transaction so they can't disagree. The reward is that every step can be rolled back on its own, and no step ever breaks a reader still on the old code.
release 1 add addresses table; write both; read the old columnrelease 2 backfill old addresses in batches; read the new tablerelease 3 stop writing the old column; drop it a release laterHow do we move off the legacy database without a big bang?
This is the heart of the reported prompt. The old database is in use while you work, so whatever you propose has to keep it correct for the people still on it. A clinic can't stop seeing patients for a weekend while you copy data.
Approach
Pick a weekend. Stop all writes to the old database, copy everything into the new one, point every app at the new database on Monday morning.
Challenges
Everything has to work on the first try, for every clinic, every record and every app at once. Any translation bug found on Monday affects every patient, and going back means losing every record written since the switch. Hospitals don't close, so "stop all writes" means paper charts and someone typing them in later. Some older apps may not be able to move by Monday at all.
Approach
Copy history in the background. Change the app so every save writes to the old database and to the new one. When the copy finishes and new writes go to both, switch reads over.
Challenges
Two separate writes can't be one transaction. If the first succeeds and the second fails, or the app crashes in between, the two databases disagree, and nothing notices. It also means changing every app that writes to the old database, including the ones you don't control.
Approach
Keep legacy as the system of record and fill the new database from its change feed, as in the diagram. When a clinic's data has matched for a few weeks, move that clinic. Its writes now go to the new database. A reverse sync copies them back to legacy in the old shape for apps that still read there. At any moment each clinic has exactly one owner.
Challenges
Syncing both ways needs care so a change doesn't bounce forever. Each change carries its origin, and the sync worker skips changes that came from itself. Patients seen at clinics on both sides need a rule, such as "the clinic that registered them owns them." Old apps keep working until the last one moves, and only then does legacy retire.
What earns the Great tier its complexity is reversibility. If a moved clinic hits a problem, it moves back, and the old database still has every record because the reverse sync kept it current. Compare that with the weekend switch, where a bug found on Monday has no safe way back. If the interviewer pushes on the cut-over moment itself, describe it plainly: pause that clinic's writes for a minute, let the feed drain, flip the owner flag, resume.
Shadow reads first
Before a clinic moves, have the record service read each chart from both databases and log any difference, while still showing the legacy version. Real traffic finds translation bugs that test data never does.
Quarantine, never drop
Old records that fail translation, like an allergy stored as unreadable free text, go to a review queue with the original attached. Dropping a medical record quietly is the one thing this migration can't do.
Keep the old ids forever
The crosswalk keeps every legacy key, even after legacy retires. Scanned letters, lab printouts and other hospitals will quote those numbers for years.
What happens when the interviewer adds a requirement?
The Madison candidate described a prompt that "kept building on itself." The actual add-ons weren't reported, so the table below is prep: requirements that commonly come up in patient-record designs, and the smallest change to this model that handles each. Practising the move matters more than the list. Restate the new requirement, say which record it touches, change that, and say what stays the same.
| If the interviewer adds | What changes in the model |
|---|---|
| A second hospital joins with its own record numbers | New rows in the identifier table, tagged with the new issuing system. Patients and visits are untouched. |
| A wrong entry has to be fixed | A new entry that names the one it replaces, and the old one marked entered in error. The chart shows the current one and keeps both. |
| Show what the chart said last Tuesday | Already possible: entries are never overwritten, so filter by entered time. Patient details need the same versioning. |
| A patient can have several addresses or phone numbers | A child table off the patient, landed with expand, migrate, contract. |
| Only the care team may see a chart | A check in the record service against who is treating the patient, plus the audit log on every read. |
| Two records turn out to be the same person | A merge by link, as in the identity dive, which can be undone. |
Nothing in that table needs a redesign from scratch. If an add-on forces you to rebuild the whole model, say so honestly, but it usually means a record was doing two jobs. The visit and the entry are separate for exactly this reason. When a requirement really does conflict with an earlier choice, say which choice and why you're changing it. "I put allergies in the generic entry table; now we need a severity rule on each one, so I'll add a small allergy details table" is a good sentence to be able to say calmly mid-interview.
Practice the core in code
The case study is a conversation, so you won't be asked to code this. Writing it once still makes the identity design concrete. The class below is the ID crosswalk with merge by link. Records from different systems map to one internal patient id, and a replayed record gets the id it already has. Merging two patients leaves both ids pointing at the survivor.
Patient index with an id crosswalk and merges
Problem
Write a class
PatientIndex. add(system, local_id) registers a record and returns its patient id. A new record gets the next internal id, counting up from 1. A record seen before returns its current id and changes nothing. find(system, local_id) returns the current patient id, or null for an unknown record.link(system_a, id_a, system_b, id_b) merges the two records' patients and returns the survivor, which is the smaller of the two current ids. It returns null if either record is unknown. records(patient_id) returns every record of the patient that id now belongs to, as strings sorted alphabetically. Each string is the system name and the local id joined by a colon. An id that was merged away still works there, and an id never given out returns an empty list.Input encoding. A test case is a JSON array of operations. The first entry is
["PatientIndex", []] and each later entry is [method, [args]]. The expected array holds each operation's return, with null for the constructor.- PatientIndex()
- add("legacy", "A17")→ 1
- add("new", "p-1")→ 2
- link("legacy", "A17", "new", "p-1")→ 1
- find("new", "p-1")→ 1
- records(2)→ ["legacy:A17","new:p-1"]
The two records get ids 1 and 2. The link makes 1 the survivor, so the new record now finds patient 1, and asking about the merged-away id 2 still returns the whole chart.
Map each record to the id it was first given, and keep a "merged into" pointer per id. Following pointers to the end gives the current patient. The structure is called union-find.
Patient index with an id crosswalk and merges
Click "Run" to execute your code
unlink to undo a merge, which is why the pointer lives per id and not per record. Then talk about persistence: the record map is the identifier table with a unique key, and the pointer is the merged_into column on patients.Follow-ups to be ready for
Privacy and access. Who may open a chart? Anyone on the patient's care team covers the normal case, checked in the record service on every read. Emergencies need a "break the glass" override that lets a clinician in with a stated reason, and that access gets reviewed later. Either way the audit log records every read.
Reports without slowing the clinic. Someone will want counts across all patients: how many diabetics, how many flu shots this month. Running those on the live database competes with nurses charting. Copy data into a separate reporting store on a schedule and point the reports there.
A patient asks for their own records. The chart query already returns everything in time order, so the work is in the format and in checking identity before handing it over. Keep the response in the audit log like any other read.
Retiring the old database. Once the last app moves off, stop the reverse sync, keep a read-only copy for as long as records must be retained, and keep the crosswalk forever.
What a strong answer shows
Epic posts one developer job, Software Developer, and that single posting covers every experience level. No report describes a harder design round for experienced candidates. The bar below is advice built from the prompt, split by what each group tends to miss.
New grads and interns
Lean toward breadth. You name patients, identifiers, visits and entries, pick an internal key and say why, and keep the old database working while the new one fills up. When a requirement lands you change one part of the model and explain the change. Naming Kafka or change data capture is a bonus at this level. The bar: a clean model with a stable patient id, a migration that never stops the old system, and calm, spoken reasoning through every new requirement.
Developers with experience
Here the interviewer expects depth, and expects you to raise the hard parts yourself. Bring up duplicates in the old data and how a merge gets undone, and the gap between writing to legacy and seeing the change in the new database. Then cover schema changes that ship over several releases, and moving clinic by clinic with a way back. The bar: you find the failure cases before the interviewer does, and every step of your migration can be reversed.
Common questions
Is the Epic Systems case study technical?
Lightly. The July 2026 report called the patient record version "relaxed, non-technical," and a May 2026 candidate guessed it tests communication and reasoning more than system design. You still need a sound data model. You don't need capacity numbers.
Do I need to write SQL in the case study?
No report mentions writing queries. Describe the records and how they link in words, and sketch tables only if it helps the conversation.
What if my prompt isn't the patient record database?
Other 2026 case studies include a calendar UI for doctors and a system to cut clinic wait times. The same habits carry over: model the records, protect existing data, and talk through each change. The case study overview lists every reported prompt.
Key Takeaways
- ✓Key patients on an internal id the system mints, and merge duplicates by linking so a wrong merge can be undone.
- ✓Change the schema by expanding, migrating, then contracting, so old rows and old code keep working.
- ✓Move off legacy one clinic at a time, with exactly one owner per clinic and a way back.
- ✓When a requirement lands, say what it touches, change that one part, and say what stays.
Epic Systems interview guideKnow what Epic Systems asks before you walk in.
28 coding · 4 system design · 20 behavioral questions
Get their questions first.
InterviewLegend is independent and not affiliated with or endorsed by any company it covers.