Sub topic 3
Store each fact once and render it everywhere
This chapter assumes you understand basic HTML, JSON, web servers, and content or e-commerce systems. The key design problem is keeping the same fact consistent when it appears in several outputs: visible page text, JSON-LD, sitemaps, product feeds, and API responses.
What a single source of truth means
A single source of truth is one authoritative record for a fact. For a product, that record might contain its name, SKU, price, currency, stock status, and important dates. Other representations are generated from that record.
For example, the product database should own the price. A page template should not contain a second hard-coded price, and a JSON-LD template should not contain a third copy. If someone changes the price in the database, every output should read the new value.
This arrangement prevents drift. Drift occurs when two copies of a fact slowly become different.
Separate stored facts from derived output
Store facts that people or business systems manage. Derive formatting and transport-specific output in code.
A product record might store price as a decimal value and currency as an ISO currency code. The page can format these values as 89.00 EUR, while JSON-LD receives the same numeric price and currency separately.
Do not store only a formatted string such as €89. That string is harder to validate, convert, compare, or reuse in a feed. Also avoid deriving important facts from unrelated text. For example, do not infer stock status by searching for the word “available” in a product description.
from decimal import Decimal
import json
def visible_price(product):
return f"{product['price']:.2f} {product['currency']}"
def product_jsonld(product):
availability = (
"https://schema.org/InStock"
if product["in_stock"]
else "https://schema.org/OutOfStock"
)
return {
"@context": "https://schema.org",
"@type": "Product",
"name": product["name"],
"sku": product["sku"],
"offers": {
"@type": "Offer",
"price": str(product["price"]),
"priceCurrency": product["currency"],
"availability": availability,
},
}
product = {
"name": "Trail Runner 2",
"sku": "TR2-BLK-42",
"price": Decimal("89.00"),
"currency": "EUR",
"in_stock": True,
}
print(visible_price(product))
print(json.dumps(product_jsonld(product), indent=2))The formatting functions are different, but both read the same product object. In a real application, the object would come from a database or catalog service rather than being declared in the page template.
Define ownership at the data boundary
A single source of truth works only when ownership is explicit. Decide which system controls each field:
- The catalog system owns product names, SKUs, prices, and stock status.
- The publishing system owns article text and editorial dates.
- The deployment system may own build metadata, but it should not overwrite content dates.
- Rendering code owns presentation, not business facts.
Keep identifiers stable across outputs. A product SKU and canonical URL let you compare the page, structured data, and feed during audits.
Common failure modes
A common error is updating the visible price but forgetting the JSON-LD or merchant feed. Another is letting a cache serve an old page after the catalog has changed. A third is allowing multiple teams to edit the same field in different systems.
Treat generated outputs as disposable. Regenerate them from the authoritative record after a change instead of manually patching each copy.
Exercise
A product page shows 89 EUR, but its JSON-LD shows 99 EUR. Which representation should you edit first?
Show answer
Edit the authoritative product record, then regenerate the page and JSON-LD. Do not patch only the visible text or only the markup.