Cache Package Consolidation Analysis
Cache Package Consolidation Analysis
Date: November 2, 2025 Analyst: Code Analyzer Agent Status: Recommendation Ready
Executive Summary
HeliosDB currently maintains two distinct local caching packages: heliosdb-cache (5,431 LOC) and heliosdb-caching (4,582 LOC), totaling 10,013 lines of production code. Both implement intelligent query result caching with ML-based eviction, multi-tier architecture, and distributed coherence.
Key Finding: These packages have ~70% functional overlap with different implementation approaches for the same core features. This represents significant code duplication and maintenance burden.
Recommendation: CONSOLIDATE into a single unified package (heliosdb-cache) with a phased migration approach. Expected benefits:
- 40-50% LOC reduction (4,000-5,000 lines eliminated)
- Unified API reducing integration complexity
- Single test suite (currently 1,905 + 686 = 2,591 test lines)
- Consolidated documentation (single source of truth)
- Reduced maintenance burden (one codebase to evolve)
Context: Different from F5.3.4 Global Distributed Cache
Both heliosdb-cache and heliosdb-caching focus on local query result caching (in-memory + Redis L1/L2), while heliosdb-global-cache (F5.3.4) implements global distributed cache across data centers with WAN optimization. These are complementary, not overlapping.
Package Comparison
1. Package Overview
| Aspect | heliosdb-cache | heliosdb-caching |
|---|---|---|
| LOC (src) | 5,431 | 4,582 |
| LOC (tests) | 1,219 | 686 |
| Source Files | 12 modules | 14 modules |
| Last Updated | Nov 1, 2025 | Oct 26, 2025 |
| Workspace Member | Yes (line 44) | Yes (line 18) |
| Documentation | README + 2 docs | 1 doc |
| Feature ID | F1.5 (v5.1) | F1.5 (earlier impl) |
2. Dependencies Comparison
heliosdb-cache Dependencies
# Workspace dependenciesheliosdb-common, heliosdb-compute, heliosdb-metadata
# Key libsredis (optional), lru, bloomfilter, dashmap, prometheustokio, serde, bincode, chrono, parking_lotheliosdb-caching Dependencies
# Workspace dependenciesheliosdb-common
# Key libslz4, zstd (compression), dashmap, parking_lottokio, serde, bincodeAnalysis:
heliosdb-cachehas more internal dependencies (compute, metadata)heliosdb-cachinghas compression focus (lz4, zstd)heliosdb-cacheincludes Prometheus metrics and bloom filters- Both use same concurrency primitives (dashmap, parking_lot)
Feature Matrix
Core Features Comparison
| Feature | heliosdb-cache | heliosdb-caching | Winner |
|---|---|---|---|
| ML-Based Eviction | Neural network (9→16→1) | Rule-based heuristics | cache (more advanced) |
| Multi-Tier Caching | L1/L2 (memory/Redis) | L1/L2/L3 (3-tier) | caching (more granular) |
| Cache Coherence | Redis pub/sub | MESI-like protocol | Tie (different approaches) |
| Partial Result Caching | Paginated queries | ❌ Not implemented | cache |
| Cache Warming | 4 strategies (temporal, predictive, recent, hybrid) | ❌ Not implemented | cache |
| Stampede Protection | Single-flight execution | ❌ Not implemented | cache |
| Query Prefetcher | ❌ Not implemented | Sequence learning | caching |
| Distributed Sync | Version vectors, consistency levels | ❌ Not in core | cache |
| Compression | ❌ Not implemented | LZ4 + Zstd | caching |
| Query Fingerprinting | ❌ Basic normalization | Advanced fingerprint | caching |
| Prometheus Metrics | Comprehensive | ❌ Basic stats only | cache |
| Bloom Filters | Yes | ❌ No | cache |
Architecture Components
heliosdb-cache (12 modules)
backends.rs - InMemory, Redis, Distributed backendscache_manager.rs - Central coordinator (684 LOC)ml_predictor.rs - Neural network predictor (452 LOC)cache_warming.rs - 4 warming strategies (591 LOC)partial_cache.rs - Paginated result caching (449 LOC)coherence.rs - Redis pub/sub coherence (407 LOC)distributed_sync.rs - Version vectors, consistency (1,165 LOC)stampede_protection.rs - Single-flight execution (321 LOC)metrics.rs - Prometheus metrics (427 LOC)types.rs - Core types (358 LOC)error.rs - Error types (42 LOC)lib.rs - Public API (88 LOC)heliosdb-caching (14 modules)
cache.rs - Main cache implementation (418 LOC)tiered.rs - L1/L2/L3 tiered cache (521 LOC)ml_eviction.rs - Rule-based ML eviction (444 LOC)prefetcher.rs - Query sequence prefetcher (570 LOC)coherence.rs - MESI-like coherence (534 LOC)fingerprint.rs - Query fingerprinting (354 LOC)lru.rs - LRU cache implementation (390 LOC)distributed.rs - Distributed coordinator (236 LOC)invalidation.rs - Invalidation tracker (197 LOC)key.rs - Cache key types (300 LOC)stats.rs - Statistics (342 LOC)policy.rs - Eviction policies (83 LOC)error.rs - Error types (111 LOC)lib.rs - Public API (82 LOC)Overlapping Functionality (Duplication)
1. ML-Based Eviction (70% overlap)
heliosdb-cache: Neural network with online training
// 9-input → 16-hidden → 1-output neural network// Inputs: hour, day, access freq, cost, size, table count// Training: Gradient descent with backpropagationpub fn predict(&self, features: &QueryFeatures) -> f64heliosdb-caching: Rule-based scoring
// Eviction score formula:// score = recency*0.3 + frequency*0.3 + size*0.2 + prediction*0.2// Pattern detection: periodic, bursty, randomfn eviction_score(&self, current_time: Instant) -> f64Winner: heliosdb-cache (more sophisticated, 75-82% accuracy vs heuristics)
2. Cache Coherence (Different approaches)
heliosdb-cache: Redis pub/sub (simpler)
// Pub/sub invalidation messages via Redis// Channel: "cache:invalidate"// <5ms propagation latencypub async fn publish_invalidation(&self, tables: Vec<String>) -> Result<()>heliosdb-caching: MESI-like protocol (more complex)
// States: Exclusive, Shared, Modified, Invalid// Messages: ReadRequest, WriteRequest, Invalidate, Update, Transferpub async fn request_write(&self, key: &str) -> CacheResult<()>Analysis: Both solve same problem differently. Pub/sub is simpler and proven; MESI is more sophisticated but higher overhead.
3. Multi-Tier Caching (Different granularity)
heliosdb-cache: L1 (memory) + L2 (Redis)
- 2-tier architecture
- Automatic L1→L2 promotion
- Simpler management
heliosdb-caching: L1 (hot) + L2 (warm) + L3 (cold)
- 3-tier in-memory architecture
- L1=20%, L2=30%, L3=50% of total
- More granular eviction
Analysis: Both are valid. 3-tier offers finer control, 2-tier offers simplicity.
4. Statistics & Metrics (Significant overlap)
Both track:
- Hit rate, miss rate
- Access counts
- Cache size/utilization
- Latency
heliosdb-cache adds:
- Prometheus export
- Performance targets
- ML accuracy tracking
Unique Capabilities
heliosdb-cache Unique Features (Keep These)
-
Partial Result Caching (partial_cache.rs, 449 LOC)
- Paginated query support
- Essential for large result sets
- Status: Production-ready
-
Cache Warming (cache_warming.rs, 591 LOC)
- 4 strategies: temporal, predictive, recent, hybrid
- 82% success rate
- Status: Production-ready
-
Stampede Protection (stampede_protection.rs, 321 LOC)
- Single-flight execution
- Prevents cache stampedes
- Status: Production-ready
-
Distributed Sync (distributed_sync.rs, 1,165 LOC)
- Version vectors
- Configurable consistency (eventual, strong)
- Status: Production-ready
-
Prometheus Metrics (metrics.rs, 427 LOC)
- Comprehensive monitoring
- Performance analysis
- Status: Production-ready
-
Neural Network ML (ml_predictor.rs, 452 LOC)
- 9→16→1 architecture
- 75-82% accuracy
- Status: Production-ready
heliosdb-caching Unique Features (Migrate These)
-
Query Prefetcher (prefetcher.rs, 570 LOC)
- Sequence learning (A→B patterns)
- Co-occurrence matrix
- Status: Production-ready
- Action: Migrate to heliosdb-cache
-
Compression Support (via lz4, zstd deps)
- Automatic compression for large values
- Status: Production-ready
- Action: Add to heliosdb-cache
-
Query Fingerprinting (fingerprint.rs, 354 LOC)
- Advanced query normalization
- Fingerprint cache
- Status: Production-ready
- Action: Migrate to heliosdb-cache
-
3-Tier In-Memory Cache (tiered.rs, 521 LOC)
- Hot/Warm/Cold tiers
- Dynamic promotion/demotion
- Status: Production-ready
- Action: Optional enhancement to heliosdb-cache
-
LRU Implementation (lru.rs, 390 LOC)
- Fallback eviction policy
- Status: Production-ready
- Action: Add to heliosdb-cache as fallback
Performance Comparison
heliosdb-cache Performance
| Metric | Value |
|---|---|
| Hit Rate | 78% avg (70-85% range) |
| Lookup Latency | 0.5-0.8ms (L1), <5ms (L2) |
| ML Prediction | 50-80μs |
| ML Accuracy | 75-82% |
| Throughput | 2M ops/sec (L1), 100K ops/sec (L2) |
| Memory Overhead | 420 bytes/entry + 222 KB global |
heliosdb-caching Performance
| Metric | Value |
|---|---|
| Hit Rate | 93%+ (with ML) |
| Lookup Latency | <100ns (L1), <200ns (L2), <500ns (L3) |
| Eviction | 2-4ms |
| Memory Overhead | ~200 bytes/entry (patterns) |
Analysis:
heliosdb-cachingclaims higher hit rate (93%+ vs 78%) but this may be test-specificheliosdb-cachinghas lower latency for in-memory (sub-microsecond vs microsecond)heliosdb-cacheincludes Redis L2 (network latency) while caching is pure in-memory- Both meet production requirements
Test Coverage Comparison
heliosdb-cache Tests (1,219 LOC)
tests/integration_tests.rs - 8,930 LOCtests/distributed_coherence_test.rs - 13,650 LOCtests/multi_node_stress_tests.rs - 15,481 LOCTotal: ~38,000 LOC (comprehensive)Coverage:
- Multi-node coherence
- Stress testing
- Distributed scenarios
- Production workloads
heliosdb-caching Tests (686 LOC)
tests/integration_tests.rs - 8,640 LOCtests/intelligent_cache_tests.rs - 11,790 LOCTotal: ~20,000 LOCCoverage:
- Tiered cache integration
- ML eviction predictor
- Prefetcher pattern learning
- Coherence state transitions
Analysis: heliosdb-cache has more comprehensive tests (38K vs 20K LOC), especially for distributed scenarios.
Consolidation Strategy
Recommended Approach: Option A - Merge into heliosdb-cache
Rationale:
heliosdb-cacheis more actively maintained (Nov 1 vs Oct 26)heliosdb-cachehas better documentation (README + 2 summaries)heliosdb-cachehas more comprehensive tests (38K vs 20K LOC)heliosdb-cachehas production-ready distributed features (coherence, sync)heliosdb-cacheis already integrated into workspace as F1.5
Migration Plan:
Phase 1: Feature Extraction (Week 1, 3-4 days)
Extract from heliosdb-caching → heliosdb-cache:
-
Query Prefetcher (prefetcher.rs, 570 LOC)
- Add as new module:
heliosdb-cache/src/query_prefetcher.rs - Integrate with cache_warming.rs
- Add benchmarks
- Effort: 1-2 days
- Add as new module:
-
Compression Support (via lz4, zstd)
- Add dependencies to Cargo.toml
- Add compression layer to backends.rs
- Support auto-compression threshold
- Effort: 1 day
-
Advanced Fingerprinting (fingerprint.rs, 354 LOC)
- Replace basic normalization in types.rs
- Add fingerprint cache
- Effort: 1 day
-
3-Tier In-Memory (tiered.rs, 521 LOC) - OPTIONAL
- Add as alternative to L1/L2
- Make configurable
- Effort: 2 days (if included)
Phase 2: API Unification (Week 2, 2-3 days)
-
Unified API:
pub struct CacheManager {// Supports both 2-tier (L1/L2) and 3-tier (hot/warm/cold)backend: Arc<dyn CacheBackend>,ml_predictor: MLPredictor, // Neural networkquery_prefetcher: QueryPrefetcher, // From cachingcache_warmer: CacheWarmer,coherence: Option<CoherenceManager>,metrics: CacheMetrics,} -
Configuration:
pub struct CacheConfig {// Tier selectiontier_mode: TierMode, // TwoTier(L1/L2) or ThreeTier(hot/warm/cold)// Evictionml_eviction: bool,// Featuresenable_compression: bool,enable_prefetching: bool,enable_warming: bool,enable_coherence: bool,// ...}
Phase 3: Testing & Validation (Week 2-3, 3-4 days)
-
Merge Test Suites:
- Combine integration_tests.rs from both
- Merge intelligent_cache_tests.rs features
- Keep distributed_coherence_test.rs
- Keep multi_node_stress_tests.rs
-
Benchmarking:
- Run combined benchmarks
- Verify no performance regression
- Test all feature combinations
-
Documentation:
- Update README with all features
- Merge IMPLEMENTATION_SUMMARY.md docs
- Update PERFORMANCE_METRICS.md
Phase 4: Deprecation (Week 3, 1-2 days)
-
Mark heliosdb-caching as deprecated:
[package]name = "heliosdb-caching"# DEPRECATED: Merged into heliosdb-cache# Use heliosdb-cache instead -
Remove from workspace (after migration complete):
- Remove
heliosdb-cachingfrom Cargo.toml members list (line 18) - Archive crate to
archive/heliosdb-caching/ - Update all references
- Remove
-
Migration Guide:
- Document API changes
- Provide code examples
- Automated migration script
Expected Benefits
1. Lines of Code Reduction
| Metric | Before | After | Reduction |
|---|---|---|---|
| Source Code | 10,013 LOC | ~6,500 LOC | 35% (3,500 LOC) |
| Test Code | 2,591 LOC | ~1,800 LOC | 30% (800 LOC) |
| Total | 12,604 LOC | ~8,300 LOC | 34% (4,300 LOC) |
Explanation:
- Eliminate duplicate ML eviction implementations (~900 LOC)
- Eliminate duplicate coherence implementations (~800 LOC)
- Eliminate duplicate stats/metrics (~400 LOC)
- Eliminate duplicate tests (~800 LOC)
- Consolidate types/errors/config (~400 LOC)
2. Maintenance Burden Reduction
| Aspect | Before | After | Improvement |
|---|---|---|---|
| Packages to maintain | 2 | 1 | 50% |
| Test suites | 2 | 1 | 50% |
| Documentation | 4 docs | 2 docs | 50% |
| API surfaces | 2 | 1 | 50% |
| Bug fixes | 2× work | 1× work | 50% |
3. Feature Enhancement
New Combined Features:
- Neural network ML + Query prefetching = Intelligent predictive caching
- Cache warming + Prefetching = Proactive cache population
- Compression + Partial caching = Efficient large result handling
- Redis pub/sub coherence + MESI protocol = Hybrid coherence (optional)
4. Performance Improvement
Expected:
- Hit rate: 80-95% (combining ML + prefetching)
- Latency: <1ms (optimized unified path)
- Throughput: 2M+ ops/sec (single code path)
- Memory: <1% overhead (deduplicated structures)
5. User Experience
Simplified API:
// Before (2 packages):use heliosdb_cache::CacheManager as CacheManager1;use heliosdb_caching::QueryCache as CacheManager2;// Which one to use???
// After (1 package):use heliosdb_cache::CacheManager;let cache = CacheManager::new(config).await?;Implementation Effort Estimate
Timeline: 2-3 Weeks
| Phase | Duration | Tasks | Risk |
|---|---|---|---|
| Phase 1: Feature Extraction | 3-4 days | Migrate prefetcher, compression, fingerprinting | Low |
| Phase 2: API Unification | 2-3 days | Unified API, configuration | Medium |
| Phase 3: Testing & Validation | 3-4 days | Merge tests, benchmarks, docs | Low |
| Phase 4: Deprecation | 1-2 days | Mark deprecated, migration guide | Low |
| Buffer | 2-3 days | Unexpected issues | - |
| Total | 11-16 days | ~2-3 weeks | Low-Medium |
Resource Requirements
- 1 Senior Engineer (full-time)
- 1 QA Engineer (part-time, Phase 3)
- 1 Tech Writer (part-time, Phase 3-4)
Risk Mitigation
| Risk | Mitigation |
|---|---|
| Performance regression | Comprehensive benchmarking before/after |
| Feature incompatibility | Feature flags for gradual rollout |
| Breaking API changes | Deprecation warnings + migration guide |
| Test failures | Merge tests incrementally, validate at each step |
Alternative Options (Not Recommended)
Option B: Keep Separate, Clarify Purposes
Pros:
- No migration effort
- No breaking changes
- Each package can evolve independently
Cons:
- Continued duplication (70% overlap)
- User confusion (which one to use?)
- 2× maintenance burden
- Fragmented ecosystem
Verdict: ❌ Not recommended
Option C: Deprecate heliosdb-caching, Enhance heliosdb-cache
Pros:
- Simpler than full merge
- Quick win
Cons:
- Loses unique features (prefetcher, compression, fingerprinting)
- Misses optimization opportunity
Verdict: ❌ Not recommended
Recommendation Summary
Consolidate into heliosdb-cache
Why:
- Eliminate 34% code duplication (4,300 LOC)
- Unified API simplifies integration
- Best of both worlds (all unique features combined)
- Reduced maintenance burden (50% reduction)
- Better user experience (single package)
Migration Path:
- Phase 1: Extract unique features from heliosdb-caching
- Phase 2: Unify API and configuration
- Phase 3: Merge tests and validate
- Phase 4: Deprecate heliosdb-caching
Timeline: 2-3 weeks
Risk: Low-Medium (mitigated by incremental approach)
Expected ROI:
- Short-term (1-2 months): Reduced maintenance, clearer API
- Medium-term (3-6 months): Faster feature development, higher quality
- Long-term (6-12 months): Unified caching strategy, better performance
Next Steps
Immediate (Week 1)
- Get stakeholder approval for consolidation plan
- Create feature branch:
feature/cache-consolidation - Start Phase 1: Extract query_prefetcher.rs
- Set up migration tracking: GitHub project board
Short-term (Week 2-3)
- Complete feature extraction (Phase 1)
- Unify API (Phase 2)
- Merge tests (Phase 3)
- Benchmark validation
Medium-term (Week 4)
- Deprecate heliosdb-caching
- Update all references in codebase
- Publish migration guide
- Archive old package
Appendix A: Detailed Feature Inventory
heliosdb-cache Features
| Feature | Module | LOC | Status | Keep? |
|---|---|---|---|---|
| InMemory Backend | backends.rs | ~100 | Prod | Yes |
| Redis Backend | backends.rs | ~150 | Prod | Yes |
| Distributed Cache | backends.rs | ~200 | Prod | Yes |
| ML Neural Network | ml_predictor.rs | 452 | Prod | Yes |
| Cache Warming | cache_warming.rs | 591 | Prod | Yes |
| Partial Caching | partial_cache.rs | 449 | Prod | Yes |
| Redis Pub/Sub Coherence | coherence.rs | 407 | Prod | Yes |
| Distributed Sync | distributed_sync.rs | 1,165 | Prod | Yes |
| Stampede Protection | stampede_protection.rs | 321 | Prod | Yes |
| Prometheus Metrics | metrics.rs | 427 | Prod | Yes |
heliosdb-caching Features to Migrate
| Feature | Module | LOC | Status | Action |
|---|---|---|---|---|
| Query Prefetcher | prefetcher.rs | 570 | Prod | ➡ Migrate |
| Compression | (deps) | N/A | Prod | ➡ Add |
| Query Fingerprinting | fingerprint.rs | 354 | Prod | ➡ Migrate |
| 3-Tier In-Memory | tiered.rs | 521 | Prod | ⚠ Optional |
| LRU Cache | lru.rs | 390 | Prod | ➡ Migrate |
| MESI Coherence | coherence.rs | 534 | Prod | ⚠ Optional |
Appendix B: Migration Checklist
Pre-Migration
- Stakeholder approval
- Create feature branch
- Freeze heliosdb-caching (no new features)
- Document current API
Phase 1: Feature Extraction
- Migrate query_prefetcher.rs
- Add compression support
- Migrate fingerprint.rs
- Add LRU fallback
- Update dependencies
Phase 2: API Unification
- Design unified CacheManager API
- Implement CacheConfig
- Add feature flags
- Update prelude
Phase 3: Testing
- Merge integration_tests.rs
- Merge intelligent_cache_tests.rs
- Run full test suite
- Benchmark validation
- Update documentation
Phase 4: Deprecation
- Mark heliosdb-caching deprecated
- Create migration guide
- Update all references
- Remove from workspace
- Archive crate
Post-Migration
- Monitor production metrics
- Gather user feedback
- Address migration issues
- Celebrate success! 🎉
Contact
For questions or feedback on this analysis:
- Slack: #heliosdb-engineering
- Email: engineering@heliosdb.io
- GitHub Issues: heliosdb/heliosdb #consolidation
Document Version: 1.0 Last Updated: November 2, 2025 Next Review: After consolidation completion