JACOB PARK
SOFTWARE / DATA

One opening, several sources: deduplicating job listings

A runnable Python and SQLite example for deduplicating job listings with scoped posting IDs, conservative URLs, source provenance, and saved state.

A job search can return the same opening from an employer’s careers page, a job board, and a search result. Counting those sightings as three opportunities makes the queue look productive while giving the person reviewing it more work.

The harder failure runs in the other direction: merging two different openings because they share a title. A useful deduplication policy needs to explain both why records belong together and when there is too little evidence to merge them.

Start with the strongest identity

An employer-scoped posting ID is usually more useful than a title. Scope matters: an ID such as 4821 can exist in more than one employer’s system. Treat the source, employer, and posting ID as a tuple.

posting_key = (source, employer_id, posting_id)
# Illustrative records, not real job listings:
("ats", "example-labs", "4821")
("ats", "another-company", "4821")  # different opening

When a connector does not provide a stable ID, a canonical posting URL can be the next useful clue. A title-and-company match is weaker evidence. Large employers can advertise several “Data Analyst” openings at once, with different locations, teams, or seniority.

Normalize URLs conservatively

Removing a known tracking parameter can make two sightings easier to compare. Removing every query parameter can destroy the identity you are trying to preserve: ?job_id=4821 may be the only part of a URL that identifies the opening.

A conservative policy removes only tracking keys that it recognizes. Keep the original URL too, so a reviewer can follow the source and a later parser can revisit the decision.

from urllib.parse import parse_qsl, urlencode, urlsplit, urlunsplit

TRACKING = {"utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"}

def comparison_url(url):
    parts = urlsplit(url)
    query = [(key, value) for key, value in
             parse_qsl(parts.query, keep_blank_values=True)
             if key.lower() not in TRACKING]
    return urlunsplit((parts.scheme.lower(), parts.netloc.lower(),
                      parts.path, urlencode(query), parts.fragment))

This example intentionally keeps the path, fragment, and remaining query parameters. Some careers sites use fragments for routing. Lowercasing an entire URL or removing every trailing slash would make assumptions that do not hold for every provider. A source-specific rule can be more precise once its URL format is understood. Python’s URL parsing documentation explains the components; parsing alone does not validate that a URL is safe or trustworthy.

Keep the sightings behind the match

One opening can have several source records. Keeping those records separate from the opening makes it possible to preserve where the information came from, when it was seen, and which source supplied each field.

  • Opening: the entity shown in the review queue.
  • Sighting: one source’s version, including its URL and retrieval time.
  • Match decision: the rule or evidence that connected the sighting to the opening.

If two sources disagree about salary or location, overwriting one value hides the disagreement. Retaining provenance lets the interface show the conflict and prefer the employer’s posting when that policy is appropriate.

A refresh should preserve the person’s work

Deduplication also protects saved state. Discovering a posting again should update its source information without erasing a saved flag, an application stage, or a note written by the user.

Keep source-owned fields separate from user-owned fields. Enforce stable source identity with a database uniqueness constraint, and update only the fields that a source refresh is allowed to change. SQLite’s UPSERT support can handle those conflicts, but the application still has to choose the identity and update policy.

Test the merges you should refuse

The example below turns those identity rules into a small SQLite database. It has two tables: openings owns the saved flag and user note; sightings owns each source's title, location, description, and original URL.

Six input rows become five source sightings and four distinct openings, with saved state stored on the opening.
Refreshes update source information while the person's saved state stays with the opening.

A useful check set includes the same posting with tracking parameters, two employers reusing an ID, two locations with the same title, and a posting that changes its description. Verify that repeat sightings converge and genuinely distinct openings stay separate.

This is a design companion to Job Applier, not a claim that every source supplies clean identifiers. When the match is uncertain, keeping two records available for review can be better than silently losing an opportunity. Once identity is settled, ranking rules can decide which openings deserve attention.

Run the Python and SQLite example

Six records. Four openings.

Python 3.10+ with its standard-library SQLite module. The database lives in memory; nothing is scraped or submitted.

Download the deduplication example ↗Inspect the complete Python source ↗Read the fictional listings ↗

Extract the folder and run:

python deduplicate.py

The fixture contains an employer posting and its board copy, a different employer reusing the same ID, a second location, another requisition with the same title and location, and an updated version of the first posting. The script saves the first opening, imports the other rows, and imports everything again.

{
  "input_rows": 6,
  "openings": 4,
  "sightings": 5,
  "openings_after_replay": 4,
  "saved_state": [
    1,
    "Review tomorrow"
  ],
  "latest_description": "Updated description"
}

The counts should remain at four openings and five source sightings after replay. The saved flag and “Review tomorrow” note survive, while the source description becomes “Updated description.” This is the behavior the example's checks exercise.

Know where this identity rule stops

A cross-source merge here requires the same employer and a verified employer posting URL. That URL is supplied explicitly in the fixture; the script does not discover or verify it. Each source's own posting identity is scoped by source and employer. A repeated sighting updates its source fields without touching the opening's saved state.

Titles and locations do not trigger a merge. The URL comparison removes only known tracking keys and preserves job IDs, path case, fragments, and other parameters. Missing identity fields produce an error so the record can be reviewed instead of guessed into an existing opening.

This deliberately small model assumes a provider does not reuse a posting ID for a new opening. A real connector needs a policy for reused IDs, expired posts, redirects, and contradictory employer destinations. It also needs retrieval timestamps and a review path for ambiguous matches. The example makes one conservative policy inspectable; it does not solve every provider's identity problem.

See Python's sqlite3 documentation for connection behavior and SQLite's UPSERT reference for conflict handling. Once records retain their identity, partial source failures become easier to report without losing the work already done.

BACK TO THE NOTEBOOK
IN THIS NOTE
  1. Start with the strongest identity
  2. Normalize URLs conservatively
  3. Keep the sightings behind the match
  4. A refresh should preserve the person’s work
  5. Test the merges you should refuse
  6. Run the Python and SQLite example
  7. Know where this identity rule stops