fix: revert buggy recommendation cache causing memory bloat and latency spike#8
Merged
AlexanderWert merged 1 commit intoai-demofrom Mar 11, 2026
Merged
Conversation
…cy spike The get_recommendations_ids function introduced in commit 375a36e contains a critical bug: on every cache miss, it extends ids_to_add with the entire cached_ids list for each product, causing O(n²) memory growth. This bloats cached_ids up to MAX_CACHED_IDS (2,000,000) entries very quickly, leading to severe latency degradation on GET /api/recommendations. Reverts to the original direct product catalog lookup.
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.
Problem
An active latency alert fired for
frontend-proxyon transactionGET /api/recommendations:Root Cause
Commit
375a36eb40eb812fa6b1110585cd863e3daf8535introduced aget_recommendations_ids()caching function insrc/recommendation/recommendation_server.pythat contains a critical bug:On every cache miss,
ids_to_addis extended with the entirecached_idslist for each product in the catalog. This causes O(n²) memory growth, rapidly bloatingcached_idsup toMAX_CACHED_IDS(2,000,000 entries). The resulting memory pressure and list operations cause severe latency degradation on therecommendationservice, which propagates up throughfrontend→frontend-proxy.Fix
Reverts
recommendation_server.pyto the original direct product catalog lookup, removing the faulty caching logic entirely.Impact
GET /api/recommendations(616 ms vs 200 ms threshold)git.shaattribute in latency distribution analysis