Sub topic 3
Store each fact once and render it everywhere
This chapter assumes you can read basic HTML and JSON, have edited a content or e-commerce site, and know that crawlers fetch pages and extract text and structured data. It covers the single source of truth: the practice of storing each fact in exactly one place and generating every other appearance of that fact from it.
The problem: one fact, many copies
Take one price: 89.00 EUR for the Trail Runner 2. On a typical shop that number appears in several places:
- The visible price on the product page.
- The
offers.pricevalue in JSON-LD. - A price in a category listing card.
- A product feed sent to a merchant platform.
- A promotional banner or a blog post that mentions the shoe.
- A cached copy at a CDN.
If an editor changes the price by hand in each place, some copies will be missed. A crawler or an AI answer system may then see two prices on the same page, or see a price in the markup that differs from the one in the text. Systems that quote your pages cannot tell which copy is right, so they may quote the wrong one or trust none of them.
The fix is structural, not a matter of being more careful. If each fact has one stored value and every other place is generated from it, the copies cannot disagree.
What a single source of truth means
A single source of truth (SSOT) is one authoritative record for each fact. Everything else is a rendering of that record. Three rules define it:
- One write location. A fact is edited in exactly one place, such as a product database, a CMS field, or a content file.
- Derived outputs. HTML, JSON-LD, sitemaps, feeds, and snippets are produced by code or templates that read the record. Nobody types them in.
- Visible ownership. Each fact type has a named owner who is allowed to change it. Later chapters cover owners and review schedules.
The source does not have to be one system for the whole site. Prices might live in a commerce platform, article dates in a CMS, and opening hours in a settings file. The rule applies per fact: each one has exactly one home.
Worked example: one record, two outputs
The Python below builds the visible price label and the JSON-LD from the same dictionary. Because both functions read p['price'] and p['currency'], they cannot drift apart.
from decimal import Decimal
import json
def product_jsonld(p):
availability = 'https://schema.org/InStock' if p['in_stock'] else 'https://schema.org/OutOfStock'
return {
'@context': 'https://schema.org',
'@type': 'Product',
'name': p['name'],
'sku': p['sku'],
'offers': {
'@type': 'Offer',
'price': str(p['price']),
'priceCurrency': p['currency'],
'availability': availability,
},
}
def price_label(p):
return ' '.join([str(p['price']), p['currency']])
product = {'name': 'Trail Runner 2', 'sku': 'TR2-BLK-42', 'price': Decimal('89.00'), 'currency': 'EUR', 'in_stock': True}
print(price_label(product))
print(json.dumps(product_jsonld(product), indent=2))Running it prints 89.00 EUR followed by the JSON-LD object. Change price to Decimal('79.00') and both outputs change together. There is no second edit to forget.
Two details matter here:
- Decimal, not float.
Decimal('89.00')keeps the exact value and the two decimal places. A float such as89.0would print as89.0, and arithmetic on floats can produce values like88.99999999999999. - Convert to a string in one place. The function
str(p['price'])is the only place the number becomes text for the markup. If you format prices differently in different outputs (for example89,00for display), do it in a dedicated formatting function, and keep the machine-readable value in the markup as a plain number with a dot.
Where to put the render layer
A render layer is the code that turns a record into an output. You have several options, and the right one depends on your stack.
| Approach | How it works | Strength | Risk |
|---|---|---|---|
| Server-side templates | The page template reads the record and writes both HTML and JSON-LD in one request | Simple, markup and text always match | Each template must include the JSON-LD block |
| Build-time generation | A static site generator reads data files and writes pages | Fast pages, easy to review in version control | A data change needs a rebuild and deploy before it is visible |
| Client-side rendering | JavaScript fetches data and fills in the page | Flexible UI | Crawlers may not run the script, so they may see an empty or stale shell |
| Shared component library | A `<Price>` component or helper used by every template | One place to fix formatting bugs | Teams that bypass it reintroduce copies |
For facts you want crawlers and answer systems to read reliably, prefer server-side or build-time rendering. Then the facts are in the HTML the first time it is fetched, and you do not depend on a crawler running your scripts.
Common ways copies sneak back in
Even a site with a database can end up with duplicate facts. Watch for these:
- Hard-coded text in prose. A blog post says "now only 89 EUR". The price is in an editor's paragraph, not in the record. Replace it with a reference or a shortcode that reads the record, or remove the number and link to the product.
- Manual JSON-LD in a CMS field. Someone pastes a JSON-LD snippet into a page's custom field. It is now a second copy with no connection to the product record.
- Duplicated fields in a plugin. An SEO plugin has its own "price" or "date" fields that default to blank and are filled in by hand.
- Cached fragments. A rendered snippet is stored for days. The source changed, but the fragment did not. Cache invalidation is covered in a later chapter.
- Exports that become inputs. A spreadsheet exported for the feed is edited by hand and imported back. Now the spreadsheet is a rival source.
- Free-text fields with structured meaning. A "specs" text box holds "Weight: 280 g". If the weight is also a structured field, the two can differ.
A useful test: for any fact on the site, ask "if this changes, how many places must I edit?" The answer should be one.
Designing the record
A good record makes it hard to create inconsistent output. A few design choices help.
Store values in a machine form, format at render time. Keep price as a decimal and currency as an ISO 4217 code such as EUR. Keep dates as ISO 8601 timestamps with an offset, such as 2026-11-20T08:00:00+00:00. Format them for people (20 November 2026) in the template.
Store the state, not a derived label. Keep in_stock as a boolean or an enumerated status. Do not store the string "Only 3 left!" as a field. Generate it from a quantity.
Keep one field per meaning. If the site shows a regular price and a sale price, store both as separate fields with names that say what they are. Do not overload one field with "price" that sometimes means the sale price.
Record when the fact changed. A price_updated_at timestamp, set by the system when the price changes, gives later chapters a reliable input for modified dates and sitemap lastmod values. It should be set by code, not typed by a person.
Validate on write. Reject a negative price, a missing currency, or an availability value outside your allowed list before it is saved. Errors caught at the source never reach any of the copies.
Checking that outputs agree
Generating from one source removes most drift, but a test still pays off. A simple check renders a page and compares the visible price with the JSON-LD price.
import json
import re
def extract_jsonld_price(html):
match = re.search(r'<script type="application/ld\+json">(.*?)</script>', html, re.S)
data = json.loads(match.group(1))
return data['offers']['price']
def extract_visible_price(html):
match = re.search(r'<span class="price">([\d.]+) [A-Z]{3}</span>', html)
return match.group(1)
html = '''
<span class="price">89.00 EUR</span>
<script type="application/ld+json">
{"@context": "https://schema.org", "@type": "Product", "name": "Trail Runner 2",
"offers": {"@type": "Offer", "price": "89.00", "priceCurrency": "EUR"}}
</script>
'''
assert extract_jsonld_price(html) == extract_visible_price(html)
print('price agrees')This sample uses regular expressions to stay short. In a real test, use an HTML parser, and run it against rendered pages from a staging build. Chapter 15 returns to automated audits at scale.
Trade-offs and edge cases
- Legitimately different values. A page can show a price including tax while a feed requires it with or without tax, depending on the merchant platform's rules. Store the base values once, and compute each variant in the render layer. Do not store two separate prices.
- Facts from several systems. Price comes from the commerce platform and stock from a warehouse system. Pick one system as authoritative for each fact, and sync into a read model rather than editing both.
- Latency. A source of truth is only useful if changes reach the outputs quickly. Decide how long a change may take to appear, and design the build, caches, and feed schedule to meet it.
- Historical content. A dated article ("prices in March 2026") is a record of the past. It should keep its date and its old value, clearly labelled, instead of reading the live record.
Exercise
A product page shows "79.00 EUR" in the visible text, but its JSON-LD still says "89.00". The editor says they updated the price in the CMS. Name two likely causes that relate to the single source of truth, and say where you would fix the problem.
Show answer
Likely causes: (1) the JSON-LD is a manually pasted block in a page field, so it is a second copy that the CMS price field never updates; (2) the visible price is rendered live while the JSON-LD comes from a cached fragment or an older build. Fix it at the source and the render layer: make the template generate the JSON-LD from the same product record as the visible price, remove the pasted block, and invalidate or shorten the cache for that fragment. Do not just edit the JSON-LD number by hand.
Exercise
You store price as a Python float and render it with str(). Give one problem this can cause, and what you should store instead.
Show answer
Floats can cause rounding artefacts (for example 88.99999999999999 after arithmetic) and drop trailing zeros (89.0 instead of 89.00). Store the price as a Decimal (or as integer minor units such as cents) together with an ISO 4217 currency code, and format it in one dedicated place.