Quick revision
The short answer
Storing several phone numbers in one comma-separated column breaks first normal form, so searches need LIKE scans that cannot use a normal index, and two concurrent edits that read, change and write back the string overwrite each other and drop numbers. The fix is a child table user_phones(user_id, phone, type) with an index on phone and the constraints we need, migrated by backfilling from the split strings and then switching reads and writes.
What to remember
In this answer, we traced both support problems to one modeling mistake: a list stored in one string column breaks first normal form. Searches cannot use an index and match partial numbers, and read-modify-write updates overwrite each other. We replaced it with a user_phones child table with an index and constraints, saw when a PostgreSQL array or jsonb column with a GIN index is a reasonable alternative, and migrated by backfilling, dual writing, switching reads and finally dropping the old column.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Storing several phone numbers in one comma-separated column breaks first normal form, so searches need LIKE scans that cannot use a normal index, and two concurrent edits that read, change and write back the string overwrite each other and drop numbers. The fix is a child table user_phones(user_id, phone, type) with an index on phone and the constraints we need, migrated by backfilling from the split strings and then switching reads and writes.
Why this question is asked
A list packed into one column is one of the first shortcuts a growing product takes, and support tickets like these two are how it usually comes back. Interviewers use it to check that we can connect a symptom (lost updates, failed searches) to a modeling rule (atomic values) and plan a safe migration. In this answer, we will recap first normal form, reproduce both bugs, design the child table, look at when an array or JSON column is acceptable, and walk through a migration that does not break the running application.
1A Quick Recap of First Normal Form
First normal form asks that each column hold one atomic value, meaning a value the database treats as a single thing. '555-1234' is atomic. '555-1234,555-9876' is two values glued into a string, and the database has no idea it is a list: it cannot index the second number, cannot check that each part is a valid phone, and cannot change one part without rewriting the whole string.
That is the whole problem in one sentence. Both symptoms support reported are consequences of it.
2Why Searching by the Second Number Fails
A lookup by exact value cannot match the second number, so people fall back to pattern matching.
A B-tree index on phone_numbers is useless for '%...%' patterns because the value we want can start anywhere inside the string, so every search reads the whole table. The pattern also matches partial numbers, and formatting differences such as spaces after commas make exact matching fragile. The support tool most likely did an equality search or a prefix search, which finds only the first number.
3Why Updates Drop a Number
Adding a number to a string column means reading the string, appending in the application, and writing the whole string back. When two of these run at the same time, the second write overwrites the first.
5 messages in order. Play them, or step through them one at a time.
A read-modify-write on one string column: the last writer wins and the other change disappears.
Nothing failed and no error was raised, which is why the bug is reported as 'sometimes'. With a child table, adding a number is an INSERT of a new row, and two inserts of different numbers never overwrite each other.
4The Child Table
We give each phone number its own row, linked to the user.
Now the search uses the phone index and returns in milliseconds. UNIQUE (user_id, phone) stops the same number being listed twice for one user. If the business rule is that a phone number can belong to only one user, we would make phone unique on its own instead. It is also worth storing numbers in one normalized format, such as E.164 ('+15555551234'), so that '555 9876' and '555-9876' are not treated as different values.
5When an Array or JSON Column Is Acceptable
PostgreSQL does have real list types. A text[] column or a jsonb column is not a string; the database knows the elements, and a GIN index (an index type that indexes the elements inside a value) supports searches like phones @> ARRAY['555-9876']. For data that is always read and written together with the user and never queried on its own, that can be fine.
But the child table is still simpler here. Element-level constraints (a CHECK per number, uniqueness across users) are awkward or impossible on arrays, joins and per-number metadata such as type or verified_at are natural in a table, and an update to an array column is still a rewrite of the whole value, so concurrent edits need care. JPA also maps a child table with an ordinary @OneToMany or @ElementCollection.
6Migrating Without Downtime
We cannot switch everything at once, so we move in steps. First we create user_phones and backfill it from the existing strings, splitting on commas and trimming spaces.
Then the application writes to both places for a release, reads switch to user_phones (search first, since that is where the pain is), we run a comparison query to confirm both sources agree, and finally we stop writing the old column and drop it in a later release. Rows that fail to parse during the backfill go to a review list instead of being silently dropped.
7Follow-up questions
Why not just use a lock or a version column to fix the lost updates?
Optimistic locking with a version column would turn the silent overwrite into an error that the second editor can retry, so it does fix the data loss. But it leaves the search problem, keeps the validation problem, and makes two people editing different numbers conflict with each other. The child table fixes the cause, so most of these problems never arise.
How would you search for numbers typed in different formats?
Normalize on the way in: strip spaces and punctuation and store an E.164 value in the phone column, keeping the original text in another column if needed for display. Searches normalize the input the same way, so the index on phone still works with a plain equality.
What happens to the old column during the transition?
It stays and is kept in sync by the application until reads have moved and the comparison check shows no differences. Dropping it is the last step, done in a separate release, so we can roll back the code without losing data.
8Conclusion
In this answer, we traced both support problems to one modeling mistake: a list stored in one string column breaks first normal form. Searches cannot use an index and match partial numbers, and read-modify-write updates overwrite each other. We replaced it with a user_phones child table with an index and constraints, saw when a PostgreSQL array or jsonb column with a GIN index is a reasonable alternative, and migrated by backfilling, dual writing, switching reads and finally dropping the old column.
Open with
The model breaks first normal form: the column holds a list glued into a string, so the database sees one opaque value. That explains both reports. Searching for the second number only works with LIKE percent patterns, which cannot use a normal B-tree index, scan the whole table and can match partial numbers, so the support tool's exact or prefix search misses it.
Then, if they want more
And adding or removing a number is a read-modify-write of the whole string, so if an agent and the app edit the same user at the same time, the last write wins and the other number silently disappears.
I would move to a child table, user_phones with user_id, phone and type, a foreign key to users, a unique constraint on user_id and phone, or on phone alone if a number can belong to only one user, and an index on phone. I would also store numbers in a normalized format like E.164 so searches can be exact.
PostgreSQL arrays or jsonb with a GIN index would make search work, and that is acceptable for simple cases, but constraints and joins are easier with a child table. To migrate, I backfill user_phones by splitting the strings, dual write for a release, switch reads, verify both agree, and drop the old column last.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A users table has a column phone_numbers storing values like '555-1234,555-9876'....": https://scrivio-interview-library.netlify.app/databases/data-modeling/ecd4fe5c24/