ApexAdvancedplatform-cacheperformancecaching
Design Apex cache stampede protection for hot reference data
Real World Scenario
Org cache partition for product catalog expires at noon. Thousand concurrent users hit Apex simultaneously causing SOQL storm and CPU limit errors.
Expected Answer
• TTL jitter: stagger expiry not all keys at same second
• Mutex pattern: first miss rebuilds cache others wait or serve stale
• Scheduled job warms cache 5 minutes before peak expiry
• Org cache partition size adequate for full catalog payload
• Fallback serve stale with X-Stale header flag to LWC for refresh UX
• Monitor cache miss rate spike as alert threshold
• Consider Custom Metadata for rarely changing catalog slices
Follow-Up Questions & Answers
Click to expand — each follow-up includes a direct, interview-ready answer
Main difference: use case and scale. TTL jitter: stagger expiry not all keys at same second. Mutex pattern: first miss rebuilds cache others wait or serve stale. Pick based on your integration pattern and team capability. Cache expiry without warm-up is scheduled outage—architect stampede protection at design time. Optimize for scale and operational observability.
Architect Perspective
Cache expiry without warm-up is scheduled outage—architect stampede protection at design time.