Prompt
How do I integrate a headless CMS with commerce and search?
Latest observation
Integrating a headless CMS with commerce and search usually means treating each system as a specialized source of truth, then connecting them through APIs and an orchestration layer.
Typical architecture
- Headless CMS: stores editorial content, landing pages, blog posts, guides, product storytelling, SEO fields, etc.
- Commerce platform: stores products, prices, inventory, carts, promotions, orders, customer data.
- Search engine: indexes content and products for fast faceted search, autocomplete, and relevance ranking.
- Frontend: a headless storefront or app that fetches from all three.
Common integration pattern
1. Define ownership of data
Decide which system owns which fields:
- CMS owns:
- Marketing copy
- Category pages
- Landing pages
- SEO metadata
- Rich media
- Commerce owns:
- SKU/product catalog
- Pricing
- Availability
- Inventory
- Variants
- Search owns:
- Indexable copies of CMS and commerce data
- Facets
- Synonyms
- Ranking rules
This prevents duplicate editing and inconsistent data.
2. Model relationships between content and products
In the CMS, add references to commerce objects:
- Product blocks referencing product IDs/SKUs
- Collection pages referencing category IDs
- Guides/articles referencing related products
- Campaign pages referencing bundles or featured items
This lets editors build rich pages while commerce stays authoritative for product data.
3. Sync data into search
Search usually needs a denormalized index that combines CMS and commerce data.
Example indexed document:
{
"id": "prod_123",
"type": "product",
"name": "Trail Running Shoe",
"description": "Lightweight shoe for long runs",
"category": "Shoes",
"cms_content": {
"hero_copy": "Built for rugged terrain",
"features": ["Breathable mesh", "Carbon plate"]
},
"price": 129.99,
"in_stock": true,
"tags": ["running", "outdoor"]
}
Usually:
- Commerce events update product index documents
- CMS publishing events update content index documents
- Search merges them into the same experience, but not necessarily the same record type
4. Use webhooks or event-driven sync
When content changes in the CMS or commerce platform, trigger updates to search and frontend caches.
Typical events:
content.publishedcontent.unpublishedproduct.updatedinventory.changedprice.changed
These events can go to:
- Search reindexer
- Cache invalidation service
- Preview/build pipeline
- Personalization system
5. Build a composition layer
Use a backend-for-frontend, API gateway, or orchestration service to assemble data at request time.
This layer can:
- Fetch CMS page structure
- Resolve product references from commerce
- Pull search suggestions or related results
- Normalize data shapes for the frontend
- Handle caching and fallback logic
This is often better than having the frontend call every service directly.
Search-specific considerations
Faceted search
Index fields like:
- Brand
- Price
- Category
- Color
- Size
- Availability
- Content type
Content + commerce blending
You may want search results that include both:
- Products
- Editorial content
- Guides/how-tos
Use result types and ranking rules to control mix.
Relevance tuning
Add:
- Synonyms
- Boosting for popularity or margin
- Merchandising rules
- Zero-results handling
- Typo tolerance
Commerce-specific considerations
Don’t duplicate authoritative product data in CMS
Instead of copying price/stock into CMS, store references and render live values from commerce.
Handle variant complexity
If products have variants:
- Index variant-level fields for search
- Render product-level pages in CMS
- Show variant selectors via commerce API
Practical implementation steps
-
Choose systems:
- CMS: Contentful, Sanity, Strapi, Prismic, etc.
- Commerce: Shopify, commercetools, BigCommerce, Magento, etc.
- Search: Algolia, Elasticsearch/OpenSearch, Meilisearch, Typesense, etc.
-
Define schemas:
- CMS content types
- Product references
- Search index fields
-
Set up sync:
- Webhooks from CMS and commerce
- Reindex jobs
- Retry/idempotency handling
-
Build frontend integrations:
- Page renderer from CMS
- Product components from commerce
- Search UI from search API
-
Add caching and preview:
- Draft preview from CMS
- Staging indexes for search
- Cache invalidation on publish
A good rule of thumb
- CMS = storytelling
- Commerce = transactions
- Search = discovery
- Frontend = composition
If you want, I can also give you:
- a reference architecture diagram,
- an example data model,
- or a stack-specific integration guide for something like Shopify + Contentful + Algolia.