CNAME, short for "canonical name", is a unique name used to identify a singular object in the database, such as a game or a company.
Important objects in the Database, such as games, tags or hardware, have their own unique CNAME.
They are also used in the URL to identify resources and navigate the website.
Importance
The reason we use CNAMEs is to have an intuitive, easy-to-read, rule-based identifier that could be re-used throughout various systems (rather than rely on numbers or text strings that are generated sequentially or randomly).
We use various internal types of IDs, from numeric sequences to randomly-generated UUIDs, each filling their own niche. However, CNAMEs are generally given more importance for their ease-of-use.
That said, they also have their downsides: they are somewhat hard to generate, and sometimes they will to be changed - to keep consistency or because their initial value was bad - which is not exactly great for an identifier.
Thus, choosing a good CNAME when creating an object is very important.
Generating CNAMEs
The basic rules for generating CNAMEs is as follow:
- Take the official English name of the object. If no official name in English exists, use the romanized version of the official name.
- If the name contains any roman numbers (like VII), convert them into arabic numbers (these are the usual numbers, like 123). Be careful not to convert uppercase letters into numbers.
- If the name contains any & character, replace it with the word "and".
- Make it lower-case.
- Convert all diacritics into their ASCII equivalent (for example, çüñá becomes cuna).
- Remove all characters that are not spaces, hyphens, letters or numbers.
- Convert all hyphens into spaces.
- Remove all duplicated spaces, as well as any spaces at the start and end of the name.
- Convert all spaces into hyphens.
We do most of those steps automatically, so focus on choosing a good name!
At this point you might have wondered what happens when 2 different objects have the same name, and thus generate the same CNAME. That's what we call a CONFLICT, and it often must be manually resolved using specific rules.
Resolving conflicts
Using Dates
The most standard way to solve a CNAME conflict is by adding a date, usually just the year, to the end of the the CNAME. For example, both Doom and DOOM have the same base CNAME, doom. To solve this issue, we append the earliest release date to the CNAME of any conflicting CNAME, except the earliest one. So we'd have doom and doom-2016.
The date should be a relevant date to the object. In particular, we use the following dates for each object type:
- Company: founding date
- People: date of birth
- Games: first release (worldwide)
- Hardware: first release (worldwide)
- Franchises: first release (worldwide)
- Stores: date opened
You might have noticed that Tags are missing, and that's because tags are always unique, there is no point in have 2 different tags with the same name.
If appending the year doesn't solve the issue, e.g., there are 2 people called "John Doe" that were both born in 1970, then add the month and, if necessary, the day, always in the format YYYY-MM-DD. For example, john-doe-1970-02-01 and john-doe-1970-02-28.
If using a full date still doesn't solve it, e.g., both people were born on the same day, or the date of birth of one is unknown, then we use qualifiers.
Using Qualifiers
A qualifier is simply a word or expression used to make sure the CNAME is unique. It can be anything, as long as it remains relevant to the object. It could be a location, a product or work that the object's known for, the profession or area that the object works in. For example, we could have john-doe-us-california and john-doe-us-florida.
Just try to keep it relevant and simple, and it's will probably be fine.
Final Note
Coming up with names and meaningful words is surprisingly hard, and oftentimes hard to tell if the name or naming scheme you came up with is actually any good. At the end of the day, CNAMEs are just a "best effort" - sometimes they'll be poor or just wrong - and though it's a pain in the ass, making mistakes is part of the journey, so we'll update them accordingly.
So at the end of the day, CNAMEs might end up changing in order to make more sense. That's a bit sketchy for an identifier, but it's all in the name of better organization.
Previous
Types of IDs |
Next
Adding Content In Bulk |