Yusuf Ramadhan

16 November 2026

Migrating a login system when the usernames look like ๐–—๐–†๐–’๐–†

A neat grey rack of identical rectangular slots, most filled with matching violet tags. A star-shaped tag is being pushed at one slot and does not fit. Beside the rack lies a pile of tags in odd shapes and sizes.

I have moved a platform between clouds and rewritten its backend in another language. Neither was the hard one. The hard one was moving its database, because of what people had been allowed to call themselves.

How it got that way

When the platform started, the CTO chose Firebase Realtime Database for everything. It stores whatever you give it. Nobody added rules on top, so a username could be anything at all:

Username What is wrong with it
xy Two characters
r@m@! Special characters
๐–—๐–†๐–’๐–† Styled Unicode letters that only look like โ€œramaโ€

The first two are examples of the kind. The last one is real.

Why PostgreSQL makes it a problem

A relational database is where you finally get to say what a username is: how long, which characters, and that no two people share one. The moment you switch those rules on, the existing users break them.

That leaves two bad options:

And the one requirement that did not bend: every existing user had to keep logging in.

What we shipped

The CTO wanted every user to log in exactly as before, with the username they already had. So the old database stayed, as a fallback for login:

  1. Look for the user in PostgreSQL.
  2. If they are not there, look in Firebase.
  3. Log them in either way.
The login flow that shipped. The user logs in with the username they have always had. The system looks in PostgreSQL, the new database. If the user is found they are logged in. If not, the system looks in Firebase, the old database that was kept, and logs them in through that fallback.

It worked, and nobody was locked out. It also meant the migration never finished:

I built it, and I think it was the wrong call.

What I would do as the CTO

Clean the usernames once, then help people find their new one:

  1. Clean up every username by rule, and keep a record of what each one became.
  2. Run PostgreSQL only, with validation switched on.
  3. Add a โ€œForgot my username?โ€ step to login: the user enters their email.
  4. Email them their cleaned-up username.
What I would do now, from top to bottom: clean up every username once by rule, run PostgreSQL only with validation switched on, add a forgot my username step where the user enters their email, and email them the cleaned-up username, which they log in with from then on.

Some people would have to look up their username once. In exchange there is one database, the rules hold for everyone, and the migration is over.

What I took from it

Validation is cheapest on the day you create the field.

Every month without a rule adds accounts that will break it later. By the time the rule is obviously needed, enforcing it means choosing which users to inconvenience.

I would rather inconvenience a few people once than carry two databases for good.

Back to all notes