Feed Caching & Staleness
Why it matters
A feed endpoint with no Cache-Control header or client-side staleTime triggers a full database query on every page visit, every back-navigation, and every tab focus. For a social feed, this means re-fetching 20 posts with author joins and like counts every few seconds per active user — a multiplier that kills database throughput under modest concurrent load. ISO 25010:2011 performance-efficiency requires that repeated reads of slowly-changing data not incur full round-trip costs each time. Without cache invalidation on post creation, you also risk serving stale feeds, but that is a secondary concern relative to the cost of zero caching.
Severity rationale
Low because the impact accumulates gradually with user count and does not cause correctness failures, but the fix is low-effort and the cost of omission scales linearly with engagement.
Remediation
Add a short stale-while-revalidate cache header to the feed API response, and configure staleTime on the client-side query so back-navigation reuses cached data rather than re-fetching.
// app/api/feed/route.ts
export async function GET(req: Request) {
const feed = await getFeed(getCurrentUserId())
return Response.json(feed, {
headers: {
'Cache-Control': 'private, max-age=30, stale-while-revalidate=120'
}
})
}
// hooks/useFeed.ts
export function useFeed() {
return useQuery({
queryKey: ['feed'],
queryFn: () => fetch('/api/feed').then(r => r.json()),
staleTime: 60 * 1000, // treat data as fresh for 60s
gcTime: 10 * 60 * 1000 // keep in cache for 10 min
})
}
// After creating a post, invalidate so the new item appears
queryClient.invalidateQueries({ queryKey: ['feed'] })
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Social Features & Engagement Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- iso-25010:2011 · performance-efficiency — Resource Utilisation
Taxons
History
- 2026-04-18·v1.0.0·Initial import from community-social-engagement·automated