I noticed reading the FAQ that HN users can change their names now:
> Can I change my username?
> Yes. Email hn@ycombinator.com and we'll help.
How on earth did you pull this off? Can you please allocate some time someday to talk about this on a technical level? It’s probably one of the more impressive refactorings I’ve ever seen.
HN was originally designed so that usernames were the primary key in HN’s database schema. They appear in dozens of places, and each of those places would need to be mutated by a username change. But that would be hard for obvious reasons — examining up to 37 million items and updating them atomically isn’t so easy, especially when there are external systems involved like Algolia and Firebase.
The only other way I can think of would be to create a second “shadow” user. E.g. if user foo wants to change their name to bar, then create bar and set it as the shadow of foo. But now everywhere in the code that looks up usernames needs to perform this indirection. Is that how it works? It would also have other benefits, e.g. if someone visits /user?id=foo then you can redirect them to bar. But there must be dozens of places where this indirection needs to happen, so I’m leaning towards the “update all 37 million items atomically” design rather than shadow users.
I suppose the third option is to punt: create bar, set bar’s karma to foo’s, change foo’s profile to “I switched to bar,” and lock foo. That’s entirely valid, and seems like the most likely approach for a name change. (It would certainly sidestep a mountain of complexity…)
As someone who’s studied the HN codebase for well over a decade, I have to know. It’ll torment me if it remains a mystery. Sorry for the off topic question.