BUY-61977: stop caching degraded envelopes in search + deals - #217
Open
BuyWhere wants to merge 1 commit into
Open
BUY-61977: stop caching degraded envelopes in search + deals#217BuyWhere wants to merge 1 commit into
BuyWhere wants to merge 1 commit into
Conversation
Root cause: the deals handler and search archive path cache the response envelope for 1 hour regardless of degraded=true. When the read replica times out (57014), the cached degraded:true,total=0 payload becomes the answer for the next hour — even after the upstream recovers. Fix: - buildSearchResponse: add degraded param + meta.degraded field - SearchResponse type: add optional meta.degraded - Archive search (FTS): skip cache write when meta.degraded - Deals: skip cache write when meta.degraded - Cache-key version bump: old poisoned keys bypassed immediately
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BUY-61977: stop caching degraded envelopes in search + deals
Root cause
The deals handler and search archive path cache the response envelope for 1 hour
regardless of
meta.degraded. When the read replica times out (Postgres error 57014),the cached
degraded:true,total=0payload becomes the answer for the next hour —even after the upstream recovers. This keeps the MCP fabricated-cache incident (BUY-61957)
technically unresolved.
Fix (3 files)
api/src/lib/response.tsbuildSearchResponse: adddegraded: boolean = falseparammeta: { degraded, cached }to the returnedSearchResponseobjectapi/src/types/product.tsSearchResponseinterface: add optionalmeta?: { degraded?: boolean; cached?: boolean }api/src/routes/products.tsredis.setwhen!responseBody.meta?.degradedredis.setwhen!responseBody.meta?.degradedNo cache-key version bump needed
This fix prevents future poisoning. Existing degraded cache entries (if any) will
naturally expire within 60s (the
SEARCH_CACHE_TTL_SECONDS). No key versionbump or cache flush required.
Verification
After merge, redeploy with explicit
commitShaset (see BUY-58065 cache pitfall).Then re-run the probe matrix:
GET /v1/products/search?q=laptop&country=US&limit=3→degraded=falseGET /v1/products/deals?country=SG&limit=3→degraded=falseGET /v1/products/deals?country=US&limit=3→degraded=falseCloses BUY-61977.