feat: Add BigQuery caching with 30-minute freshness - #12
Merged
Conversation
Implements intelligent caching system to avoid expensive BigQuery queries on container restarts, reducing costs and improving restart performance. New capabilities: - Smart cache system with 30-minute freshness threshold - Automatic fallback to BigQuery when cache is stale or missing - Configuration options for cache control (CACHE_MAX_AGE_MINUTES, FORCE_BIGQUERY_REFRESH) - Race condition fixes in file operations for production reliability - Comprehensive test coverage for all caching scenarios Performance benefits: - Container restarts: ~30 seconds (cached) vs ~5 minutes (BigQuery) - Cost savings: Eliminates ~500GB queries on rapid restarts - Maintains full reliability with graceful degradation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
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.
Summary
Implements intelligent caching system to avoid expensive BigQuery queries on container restarts, reducing costs and improving restart performance while maintaining full system reliability.
Motivation and Context
Container restarts were triggering full ~500GB BigQuery queries every time, causing:
Since BigQuery results are deterministic for the same time period, we can safely cache processed data for short periods to optimize restart performance without affecting data integrity.
Changes Made
🚀 feat: Smart Caching System
🚀 feat: Configuration Options
CACHE_MAX_AGE_MINUTES=30- Configurable freshness thresholdFORCE_BIGQUERY_REFRESH=false- Override cache for debugging/manual runs🚀 feat: Cache Management Methods
has_fresh_processed_data()- Checks data existence and freshnessload_eligible_indexers_from_csv()- Loads cached eligible indexersget_data_age_minutes()- Calculates cache age in minutes🔧 fix: Race Condition Hardening
✅ test: Comprehensive Test Coverage
Performance Impact
Cost Optimization
Reliability Improvements
Risk Assessment
Low Risk Changes
Potential Considerations
Future Enhancements
Notes for Reviewers
Key Files to Review
src/models/service_quality_oracle.py- Main caching logic integrationsrc/models/eligibility_pipeline.py- New caching methods implementationtests/test_service_quality_oracle.py- Test coverage for caching scenariosTesting Strategy
Configuration Changes
[caching]section toconfig.toml.example🤖 Generated with Claude Code