| name | opensearch-personalize-caching-strategies |
| description | Caching strategies in front of AWS OpenSearch (Elasticsearch) or AWS Personalize โ search, recommenders, multi-recommender pages, anon vs logged-in traffic. Covers ROI decision (TPS/minProvisionedTPS, Zipf, amplification), key design (canonicalisation, cohort vs user, solution-version pinning, bucketing), personalisation boundary (anon/logged split, fan-out coalescing), strategies (cache-aside, refresh-ahead, write-through, batch precompute, L1+L2), TTL (volatility, soft/hard, jitter, event-driven invalidation), stampede protection (single-flight, XFetch, stale-while-revalidate, circuit breaker), observability (hit-rate, cost-per-1k, cardinality drift, log-replay), defensive caching (negative, Bloom filter), and tier composition (LRU, ElastiCache Redis, CloudFront, OpenSearch request/filter cache). Triggers on cache hit rate, Personalize throttling, stampede, single-flight, L1/L2, ElastiCache sizing. Complements opensearch-function-scoring-algorithms. |
Marketplace-Research OpenSearch + Personalize Caching Best Practices
A reference distillation of caching strategies for two-sided marketplaces running AWS OpenSearch (search) and AWS Personalize (recommendations behind a microservice). Contains 52 rules across 9 categories, ordered by cascade effect โ from the upstream decision of whether to cache, through key design, personalisation boundary, strategy selection, TTL design, stampede protection, observability, and the lower-cascade categories of negative caching and tier composition. Each rule explains the WHY (the cost, latency, or correctness mechanism), shows incorrect-vs-correct code (TypeScript/Node for the microservice layer, Python for batch and analytics, OpenSearch JSON for OS-specific queries, YAML for CDN/Kubernetes), and cites the canonical source โ AWS Personalize/OpenSearch/ElastiCache documentation, the XFetch paper (Vattani et al. VLDB 2015), RFC 5861 (stale-while-revalidate), and the engineering blogs of cache infrastructure teams (Netflix EVCache, Pinterest Cachelib, Twitter Twemcache, Cloudflare).
This is the complement to opensearch-function-scoring-algorithms โ that skill answers "what should the ranking compute?", this skill answers "how do you scale it to production traffic without burning down OpenSearch or Personalize?"
When to Apply
Reach for this skill when:
- Adding caching to a search or recommendation surface for the first time โ start with decide-cache-roi-calculation and decide-hot-key-distribution
- A homepage or category page renders 5+ recommenders and Personalize bills are growing faster than traffic โ decide-amplification-multiplier, pers-recommender-fan-out-coalescing, pers-cohort-precomputation
- Cache hit rate is suspiciously low (under 30-40%) and you don't know why โ key-canonicalize-query, key-strip-volatile-params, key-bucket-numerical-ranges, obs-key-cardinality-tracking
- Personalize is throttling (HTTP 429) during traffic spikes โ decide-personalize-quota-budget, neg-cache-throttled-personalize, stamp-circuit-breaker-on-origin-error
- p99 spikes at TTL boundaries โ stamp-coalesce-concurrent-misses, stamp-probabilistic-early-expiration, stamp-serve-stale-on-rebuild, ttl-soft-and-hard, ttl-jitter-to-prevent-thundering
- Recommendations stay stale after a model retrain โ key-version-the-model, ttl-personalize-solution-version, strat-async-warm-up
- A read-after-write surface shows stale data (user favourites, saved searches) โ strat-write-through-mutations, ttl-event-driven-invalidation
- Cache decisions need to be defensible to finance โ decide-cache-roi-calculation, obs-cost-attribution, obs-cache-simulation-from-logs
- Anonymous and logged-in traffic mix on the same routes โ pers-anonymous-vs-logged-split,
The rules apply to any AWS-based marketplace with OpenSearch and Personalize fronted by an application microservice, regardless of vertical โ accommodation, food delivery, fashion, services, jobs, secondhand goods, real estate. Triggers include "cache hit rate", "cache miss storm", "Personalize throttling", "Personalize cost", "multi-recommender page", "cohort caching", "single-flight", "stale-while-revalidate", "XFetch", "OpenSearch slow queries", "ElastiCache sizing", "CloudFront search caching", "Bloom filter cache penetration", and "thundering herd".
The Caching Pipeline
Categories are derived from the request-time caching pipeline. Earlier stages cascade: a wrong "should we cache?" decision wastes everything below; un-canonicalised keys cap hit rate at a fraction of the achievable ceiling; without observability you can't tell whether any of the rules helped.
Request โ [1] Decide โ [2] Key construction โ [3] Personalisation boundary
โ [4] Strategy (read/write path) โ [5] TTL/freshness โ [6] Stampede protection
โ [8] Negative/defensive โ [9] Tier composition (L1/L2/CDN/OS-internal) โ Response
โ
[7] Observability (meta-layer applied to all stages:
hit rate by key class, latency-with-and-without,
cost-per-1k, cardinality, staleness, log-replay)
Rule Categories by Priority
| Priority | Category | Impact | Prefix | Rules |
|---|
| 1 | Decision & Cost Calculus | CRITICAL | decide- | 7 |
| 2 | Cache Key Design | CRITICAL | key- | 7 |
| 3 | Personalisation Boundary | HIGH | pers- | 6 |
| 4 | Strategies & Write Paths | HIGH | strat- | 6 |
| 5 | TTL & Freshness | HIGH | ttl- | 6 |
| 6 | Stampede Protection | HIGH | stamp- | 5 |
| 7 | Observability & Empirical Measurement | HIGH | obs- | 6 |
| 8 | Negative & Defensive Caching | MEDIUM-HIGH | neg- | 4 |
| 9 | Tiered & Edge Caching | MEDIUM-HIGH | tier- | 5 |
Quick Reference
1. Decision & Cost Calculus (CRITICAL)
2. Cache Key Design (CRITICAL)
3. Personalisation Boundary (HIGH)
4. Strategies & Write Paths (HIGH)
5. TTL & Freshness (HIGH)
6. Stampede Protection (HIGH)
7. Observability & Empirical Measurement (HIGH)
8. Negative & Defensive Caching (MEDIUM-HIGH)
9. Tiered & Edge Caching (MEDIUM-HIGH)
How to Use
For a focused question ("should I cache this?", "why is my hit rate low?", "how do I survive Personalize throttling?"), jump directly to the relevant rule โ each is self-contained with the WHY, code, and citation.
For a full caching-design review of a new or struggling surface, work the categories top-to-bottom. The cascade is real: a wrong decide-cache-roi-calculation wastes engineering effort on a cache that doesn't pay; a leaky key-canonicalize-query caps the achievable hit rate; a missing pers-cohort-precomputation keeps Personalize bills proportional to MAU. Stampede and observability are mandatory once hit rate exceeds 90% โ the 10% miss in a thundering herd kills the origin, and without per-class hit-rate dashboards you can't tell.
For tuning an existing cache empirically, start with obs-cache-simulation-from-logs (replay your logs through what-if configs) and pair with obs-hit-rate-by-key-class, obs-cost-attribution, and obs-stale-served-ratio for the dashboards. The trio answers: is the cache doing its job, what does it cost, and are users seeing stale data?
For the multi-recommender homepage problem specifically (the most common Personalize cost-explosion pattern), the priority order is: decide-amplification-multiplier โ pers-cohort-precomputation โ pers-recommender-fan-out-coalescing โ pers-anonymous-vs-logged-split. These four typically cut Personalize spend by 70-90% on consumer marketplaces.
For the "Personalize is throttling under load" incident, the priority is: stamp-circuit-breaker-on-origin-error โ neg-cache-throttled-personalize โ decide-personalize-quota-budget. The first two stabilise the user-facing impact; the third right-sizes minProvisionedTPS so it doesn't happen again.
For sibling-skill cross-reference, see opensearch-function-scoring-algorithms โ that skill covers what to compute in OpenSearch (function_score, kNN, RRF, rank_feature, decay, LTR, MMR, evaluation). This skill covers how to cache it so the cluster survives production traffic.
Read section definitions for the cascade-impact rationale, or the rule template when adding a new rule.
Related Skills
Reference Files