All posts
Product

Every company gets an id that never changes

Every company is keyed by a random co_ id. Why a name can't be a key, what a merge looks like on the wire, and the one line to add.

HyperJobs Team5 min read

Every company profile is identified by an id like co_7Hk2p9Qx: co_ followed by eight letters and digits. It's the key of the Company object, it's what /v1/companies/{id} takes, and company_id= / exclude_company_id= filter /v1/jobs by it.

The id is random: not derived from a name, a board or a website. That property is the point.

A name is a terrible key

A derived key is a promise that the thing it was derived from never changes. Company names fail that promise constantly, and in every direction:

  • They change. A rebrand, an acquisition, a legal-name cleanup. A key built from the old name either changes with it, breaking every id you stored, or doesn't, and stops describing the company it names.
  • They collide. There are a lot of companies called Apex. A key built from a name needs a tiebreaker, and the tiebreaker is usually whichever one we saw first, which is not a fact about either company.
  • They're wrong at first. The first time we see an employer it's often a board token or a careers-site domain, not the company's real name. The key gets minted from the worst information we will ever have about it.

The last one matters most. Resolving postings to companies is ongoing work: we learn that a careers domain belongs to a company we already know, that two profiles are the same employer, that a board belongs to a parent rather than a subsidiary. Every one of those discoveries is good for the data, and under a derived key, every one of them is a key change you'd have to absorb.

A key derived from what we know changes when we learn something. A random key changes never.

What the id promises

PropertyWhat it means for you
RandomNot built from the name, the domain, or the board. You can't construct one: read it from a job or from /v1/companies.
PermanentIt doesn't change while the company exists. Store it as a foreign key.
Never reusedAn id that stops naming a company never names a different one.
Present only on a profilecompany.id is how you tell a full profile from the minimal fallback, which has no id.

The last row is worth a second look. A job's company can be a full profile, a four-field fallback built from the employer name the posting declared, or null. id is the one field guaranteed on the first and impossible on the second, so it's the test:

JS
const isProfile = job.company?.id != null;

A merge is a redirect

Random keys raise the obvious question: if we discover that co_A and co_B are the same company, what happens to the one that goes away?

It keeps its id, and the id becomes a pointer.

  1. Two profiles

    co_A and co_B

  2. Same employer

    we merge them

  3. co_B survives

    jobs move to it

  4. co_A answers 301

    → /v1/companies/co_B

A merged id is never deleted and never reassigned. It answers with the company it was folded into.

Concretely:

  • /v1/companies/co_A answers 301 with a Location pointing at the survivor. One hop, always to a company that exists.
  • company_id=co_A on /v1/jobs matches the survivor's jobs. A saved search keyed on the old id keeps returning the right postings; it doesn't go quietly empty.
  • exclude_company_id=co_A excludes the survivor, for the same reason. Jobs with no resolved company survive the exclusion.

So nothing you stored breaks when a merge happens. It just gets one redirect further from the truth than it needs to be.

The one line to add

Most HTTP clients follow a 301 without telling you. That's fine for reading (you get the survivor's profile), but it means the stale id stays in your database forever, and every lookup pays a hop. Notice the redirect and store where it landed:

JS
const res = await fetch(`https://api.hyperjobs.io/v1/companies/${id}`, {
  headers: { Authorization: `Bearer ${process.env.HYPERJOBS_KEY}` },
});
const company = await res.json();
 
if (res.redirected) {
  // The id we held was merged into another company. company.id is the survivor's.
  await db.companies.repoint(id, company.id);
}

With curl, pass -L to follow it, or leave it off and read the Location header yourself, which is the cheaper way to sweep a list of stored ids for merges: a 301 bills no jobs.

Don't parse the id

There's nothing in it to read: the eight characters are random, so they say nothing about the company, its age, or its source. Store it as text and compare it as an opaque string.

Building on it

  1. Key your companies table on id

    Store company.id as the primary key, as text. Names, domains and LinkedIn pages are attributes that can change; the id is the one column that won't.

  2. Filter by id, not by name

    company_id= and exclude_company_id= on /v1/jobs take a comma list. A saved search keyed on ids keeps matching through a rebrand.

  3. Detect the fallback with id

    job.company?.id != null is a profile. A job without one carries the minimal shape: a name and little else, so don't upsert it into your companies table as if it were a profile.

  4. Handle the 301

    Follow it, and repoint the stored id when you see one. It's the only part that needs code of its own, and it's the part that keeps your data clean for good.

The ids you store keep working for as long as the company does, whatever we find out about it next.