A hiring tool holds people's personal data for a limited time, then has to let it go. The hard part is not the delete statement. It is making deletion complete, making billing survive it, and making sure a failure in one place never stops the rest.

What we promise is written down in the privacy notice and the data processing terms. This post is how the code keeps it.

Deleting a candidate is a hard delete

There is no soft-delete flag. Removing a candidate cascades through everything held about them, including their email log rows and any support requests. What survives is a deletion_log row with a count and a reason, nothing else:

check('deletion_log_reason_valid', sql`${table.reason} IN ('employer_request', 'retention')`), check('deletion_log_count_positive', sql`${table.candidate_count} > 0`), 

The reason is one of two values, enforced by the database, so the log can say whether an employer asked or the clock did, and cannot carry free text that someone might put a name in.

Billing must not depend on the person still existing

The product counts a candidate against the allowance when they start, and invoices come from that count. If the count were derived from candidate rows, deleting a candidate would silently lower someone's bill, and a retention job would rewrite last year's invoices.

So usage is a separate ledger, usage_events, with an organisation, a timestamp and two opaque identifiers that are deliberately not foreign keys:

// Opaque references. Deliberately not foreign keys. assessment_id: uuid('assessment_id'), candidate_invite_id: uuid('candidate_invite_id').notNull(), 

A unique index on the invite and the kind makes a double count impossible. The ledger holds no personal data, so it can outlive the candidate it counts without keeping anything it should not.

The retention job

Each organisation's owner sets how long candidate records are kept. A job runs daily:

  • for every organisation, delete candidates with no activity past that period, in batches of 500, with a stated reason of retention;
  • on a fixed 365-day schedule, clear old email logs, closed support requests, handled demo requests, and team invites that expired long ago;
  • last, and on its own, check for members whose account has been closed.

It also has a dryRun mode that only counts, which is how I look at what a change would do before it can do anything.

One failure must not stop the rest

Each organisation is wrapped in its own try/catch. A bad row in one account is logged and the next organisation proceeds. The housekeeping steps run after, and the account check runs last and separately, so an outage in the auth service cannot stop the deletions above it. In a compliance job the failure mode that matters is "it stopped halfway and nobody noticed".

Closed accounts: only a definite no counts

Employer team members sign in through a shared account system. If someone deletes their account, they can no longer sign in, and the job takes their membership off the team and out of notification emails. The rule I am happiest with is what counts as "gone":

if (error && (error.status === 404 || error.code === 'user_not_found')) { gone.push(member.id); } else if (error) { logError(`Could not check the account of member ${member.id}`, error); } 

Only a definite "user not found" removes anyone. A timeout, a 500 or a rate limit leaves the member alone until the next run. Removing a real person because a lookup failed would be far worse than leaving a deleted one in place for a day. Lookups are made ten at a time, and anything that is not a UUID, such as the development sign-in's ids, is never looked up.

Every reference to a member is set null, so roles, invites and decisions they made keep their history without them.

Who may call it

The job runs on a schedule from the host. Its route accepts only a bearer secret, compared with timingSafeEqual on equal-length buffers, and a secret shorter than 24 characters counts as unset, so a misconfigured environment refuses everything rather than allowing everything.

What it adds up to

Deletion is complete, billing is unaffected, the log holds nothing personal, and a failure degrades to "try again tomorrow". The security page has the rest of the commitments, and the help centre explains to a candidate what happens to their data.