Contentful and algolia search cache edge
Site search with dual upstream cache
Cache composed search hits for popular queries. For "contentful and algolia search cache edge", store CONTENTFUL_ACCESS_TOKEN, ALGOLIA_API_KEY in Secret Vault, call https://cdn.contentful.com/spaces/{{query.spaceId}}/entries from a Worker, and let Next.js / React hit only https://realcomposer.com/v1/workspace/contentful-algolia-search-cache-edge with an rc_live_ client token. POST upstream calls are not stored in caches.default; clients must send JSON bodies and headers forward unchanged.
Uncached Contentful and Algolia spikes cost and latency
Every Next.js / React visitor can trigger a fresh Contentful and Algolia call. Bursts exhaust per-minute quotas even when data changes slowly.
- Thundering herds after cache expiry on the origin
- Analytics skewed by client-side retry storms
- Support tickets blaming "API downtime" during spikes
How RealComposer Solves This at the Edge
Bind vault keys to the Worker
Store CONTENTFUL_ACCESS_TOKEN, ALGOLIA_API_KEY in the vault. Next.js / React never embeds the raw secret, only a revocable rc_live_ client token.
Target the real upstream URL
Configure headersTemplate to inject vault secrets, target https://cdn.contentful.com/spaces/{{query.spaceId}}/entries, and Add output mapping fields that mirror the JSON contract your screen already expects.
Call from Next.js / React
Call https://realcomposer.com/v1/workspace/contentful-algolia-search-cache-edge with a restricted rc_live_ client token. Next.js / React never sends upstream secrets.
// app/api route or client component
const res = await fetch('https://realcomposer.com/v1/workspace/contentful-algolia-search-cache-edge', {
cache: 'no-store',
headers: { Authorization: 'Bearer rc_live_your_token' }
});
{
"requestId": "req_contentf",
"upstreamLatencyMs": 142,
"audit": {
"region": "edge",
"trace": "contentful-algolia-search-cache-edge"
},
"payload": {
"id": "sample_id",
"status": "active",
"nested": {
"tags": [
"demo"
],
"internal": true
},
"unused_blob": {
"foo": "bar",
"bar": "baz"
}
}
}
{
"contentful_entryId": "sample",
"contentful_title": "sample",
"algolia_hitCount": "sample",
"algolia_firstHit": "sample"
}
Recipe Specs
- HTTP method
- POST
- Upstream calls
- 2
- Edge cache TTL
- No caching
- Client auth
- Restricted client token
- Mapped output fields
- 4
- Payload
- 255 B to 115 B (-55%)
curl -X POST "https://realcomposer.com/v1/workspace/contentful-algolia-search-cache-edge" \
-H "Authorization: Bearer rc_live_client_token" \
-H "Content-Type: application/json" \
-d '{"model":"example"}'Developer Questions & Troubleshooting
Can Next.js / React call Contentful without holding the production key?
Store CONTENTFUL_ACCESS_TOKEN, ALGOLIA_API_KEY for contentful-algolia-search-cache-edge. Next.js / React never sees decrypted values.
Does POST traffic get cached?
contentful-algolia-search-cache-edge forwards client JSON to POST upstreams unchanged; secrets interpolate only in URLs and header templates.
How do I rotate upstream credentials?
Rotate vault secrets for contentful-algolia-search-cache-edge anytime; clients keep the same rc_live_ token.
Sources & Definitions Used in This Answer
Deploy this Next.js / React + Contentful, Algolia Recipe
Clone this pre-configured pipeline into your RealComposer workspace in one click. We pre-populate upstream URLs, headers, and mapping rules.