All articles
SEO & GrowthOctober 22, 2026 6 min read

Hreflang at Scale: The Sitemap Pattern That Stops Google Swapping Your Locales

Hreflang breaks quietly on programmatic sites — wrong locale served in SERPs, cannibalisation, lost revenue. Here's the sitemap-driven pattern we use to keep thousands of locale variants in sync.

Hreflang at Scale: The Sitemap Pattern That Stops Google Swapping Your Locales

Hreflang is the tag everyone implements once and then quietly forgets. On a static five-page site that's fine. On a programmatic site with 40,000 URLs across 11 locales, it's the difference between German users landing on /de-de/ and Google serving them a confused mash of /en-gb/ with a currency switcher they'll bounce from.

This is the pattern we land on after cleaning up hreflang on a handful of large multilingual catalogues. It's boring on purpose.

Why inline hreflang breaks on programmatic sites

The canonical advice — put <link rel="alternate" hreflang="..."> tags in the <head> of every page — works until it doesn't. On a programmatic site, each page needs to know about every one of its siblings in every other locale. That's an N×M problem baked into your render path.

Three things tend to go wrong:

  1. Partial coverage. A page exists in en-us and de-de but not fr-fr, and your template still emits a broken fr-fr link because the data layer assumes full coverage.
  2. Stale references. A slug changes in one locale (say /shoes/ becomes /footwear/ in en-gb) and the other 10 locales keep pointing at the old URL for months.
  3. Self-reference drift. The spec requires each page to reference itself. Miss that on even 5% of pages and Google starts ignoring the cluster.

Google Search Console will cheerfully tell you "no return tags" for thousands of URLs and you'll have no obvious place to start debugging, because the problem is distributed across your entire template layer.

The symptom you'll see first

Usually it's a drop in impressions for one locale while another locale's impressions mysteriously climb for queries in the wrong language. In GSC's Performance report, filter by country, then by page, and look for pages ranking in markets they shouldn't. That's hreflang telling you it's given up.

The pattern: move hreflang out of the page

Instead of emitting hreflang in every page's <head>, we emit it in XML sitemaps. Google treats sitemap-level and page-level hreflang as equivalent, and sitemaps give you three massive wins:

  • Single source of truth. One build job generates the cluster definitions. No template has to know about siblings.
  • Diffable. Sitemaps are files. You can version them, diff them in CI, and alert on unexpected changes.
  • Decoupled from render. A slug change in one locale updates one row in your URL table, and the next sitemap build propagates it everywhere.

Here's the shape of a sitemap entry:

<url>
  <loc>https://example.com/en-us/running-shoes/</loc>
  <xhtml:link rel="alternate" hreflang="en-us"
    href="https://example.com/en-us/running-shoes/"/>
  <xhtml:link rel="alternate" hreflang="en-gb"
    href="https://example.com/en-gb/running-shoes/"/>
  <xhtml:link rel="alternate" hreflang="de-de"
    href="https://example.com/de-de/laufschuhe/"/>
  <xhtml:link rel="alternate" hreflang="x-default"
    href="https://example.com/en-us/running-shoes/"/>
</url>

Every URL in the cluster gets its own <url> entry with the full set of alternates — including a self-reference. That's non-negotiable.

The data model that makes this cheap

The pattern falls apart without a clean data layer. What we want is a single table — call it url_cluster — where every row ties a canonical entity to its locale and its live URL.

CREATE TABLE url_cluster (
  entity_id      BIGINT NOT NULL,
  locale         TEXT   NOT NULL,  -- e.g. 'en-us', 'de-de'
  url            TEXT   NOT NULL,
  is_indexable   BOOLEAN NOT NULL DEFAULT true,
  last_verified  TIMESTAMPTZ NOT NULL,
  PRIMARY KEY (entity_id, locale)
);

CREATE INDEX ON url_cluster (entity_id) WHERE is_indexable;

The entity_id is whatever ties localised versions together — a product ID, a category code, an article slug stem. The is_indexable flag matters because out-of-stock products, unpublished translations, or noindexed pages must be excluded from clusters. If you include a noindex URL in an hreflang set, Google will drop the whole cluster.

Sitemap generation becomes a straightforward query: group by entity_id, emit one <url> per row, with alternates sourced from the sibling rows in the same group.

Handling partial coverage honestly

When a product exists in 7 locales but not the other 4, the cluster only contains 7 entries. Don't fabricate the missing four. Don't 302 them to a fallback locale either — Google treats that as a soft signal that the fallback is the real page and will often index it for queries in the missing language.

For the missing locales, serve a proper 404 or an unlinked holding page with noindex. Then plug the gap with translated content when you have it.

Validation in CI

The reason inline hreflang breaks is that nothing catches drift. A sitemap-based approach makes drift catchable, because sitemaps are static artefacts you can lint before deploy.

We run four checks on every sitemap build:

  1. Self-reference present. Every <url> must include an <xhtml:link> to itself.
  2. Reciprocity. If A points to B, B must point to A. Build a graph in memory and assert symmetry.
  3. Status codes. Every URL in the cluster returns 200. Any 3xx, 4xx, or 5xx fails the build. We sample this against a small subset in CI and run the full crawl nightly.
  4. Locale format. hreflang values match the ISO 639-1 / ISO 3166-1 pattern. de_DE and de-DE both work; german doesn't.

Here's the reciprocity check in rough Python:

from collections import defaultdict

def check_reciprocity(clusters):
    graph = defaultdict(set)
    for cluster in clusters:
        for url, alternates in cluster.items():
            for alt_locale, alt_url in alternates.items():
                graph[url].add(alt_url)

    errors = []
    for url, targets in graph.items():
        for target in targets:
            if url not in graph.get(target, set()):
                errors.append((url, target))
    return errors

Fail the build if errors is non-empty. We've caught more problems with this one function than with any GSC report.

Monitoring once it's live

GSC's International Targeting report was deprecated, but the Pages report in Search Console still surfaces hreflang issues under the "Why pages aren't indexed" breakdown. More usefully, pull the GSC Search Analytics API into your warehouse and watch two metrics per locale:

  • Impressions by country for the wrong-locale URL. If /en-us/ pages are picking up impressions from DACH countries, your de-de cluster is probably broken for those entities.
  • CTR delta between locales. A locale with a sudden CTR drop is often being served to the wrong audience. Users bounce from checkout when the currency's wrong.

We wrote more about the GSC-to-warehouse loop on the blog — same instinct applies here. Treat SEO signals as telemetry, not a dashboard you check on Fridays.

A word on x-default

x-default is for the page you'd show someone whose language or region doesn't match any of your locales. For most catalogues, that's the English homepage or a locale picker. Pick one and stick with it. Don't omit it — Google uses it as a tiebreaker, and sites without an x-default tend to see more wrong-locale swaps for long-tail queries.

Common failures we still see in 2026

  • Mixing hreflang in HTML and sitemaps. Pick one. If both are present and they disagree, Google picks whichever it feels like and your cluster behaves unpredictably.
  • Pointing hreflang at canonicalised-away URLs. Hreflang targets must be the canonical URL for that locale. If /en-gb/shoes/ canonicals to /en-gb/footwear/, your hreflang must point at /en-gb/footwear/.
  • Protocol or trailing-slash mismatches. http vs https, www vs apex, / vs no / — all count as different URLs. Normalise ruthlessly at the data layer.
  • CDN edge cases. If your CDN strips or rewrites the xhtml namespace in XML, hreflang in sitemaps silently stops working. Fetch a sitemap through the CDN and diff it against origin.

Where we'd start

If you've inherited a multilingual programmatic site and you're not sure where you stand, do this in order:

  1. Pull a sample of 500 URLs across all locales and run them through a hreflang validator. Count the error rate.
  2. Build the url_cluster table from your CMS or product data. Even as a view, this is the artefact everything else hangs off.
  3. Generate a single sitemap for one high-value entity type (say, your top category pages) and ship it alongside your existing setup. Measure.
  4. Add the four CI checks above before you expand coverage.

Hreflang isn't glamorous. But on a site with real international revenue, getting it right is worth more than a quarter's worth of content work — and once the pattern's in place, it maintains itself. If you want a hand mapping this to your stack, our SEO engineering work usually starts exactly here.

#SEO#Programmatic SEO#Internationalisation#Technical SEO

Want a team like ours?

72Technologies builds production software for the kind of teams who actually read this blog.

Start a project