Overview
Tif1’s architecture is designed for performance and reliability. Data flows through multiple layers with caching, validation, and lazy loading to ensure fast access while maintaining data integrity.Architecture Overview
Data Flow Layers
1. User Layer
The entry point where users request data:2. Lazy Loading Layer
Data is only loaded when accessed:core.py:3491-3547 - the laps property:
3. Cache Layer
Two-level caching system:Level 1: In-Memory Cache (LRU)
Fast, process-local cache using an LRU (Least Recently Used) strategy:- Speed: Instant (memory access)
- Scope: Current process only
- Capacity: Limited by
MAX_CACHE_SIZE(default: 1000 items) - Persistence: Lost when process exits
Level 2: SQLite Cache
Persistent cache stored on disk:- Speed: Fast (disk I/O, ~1-10ms)
- Scope: Persistent across sessions
- Capacity: Limited by disk space
- Persistence: Survives process restarts
Cache Hit Performance:
- In-Memory: Instant (< 1ms)
- SQLite: Fast (~1-10ms)
- CDN: Slow (~200-1000ms)
4. Network Layer
CDN Data Source
Tif1 fetches data from TracingInsights GitHub repositories served through jsDelivr CDN:Async HTTP Fetching
Tif1 uses parallel async fetching with HTTP/2 vianiquests:
- HTTP/2: Multiplexing, header compression
- Connection Pooling: Reuse TCP connections
- Parallel Fetching: Load multiple files simultaneously
- Result: 4-5x faster than sequential loading
Retry Logic
Automatic retry with exponential backoff:- Attempt 1: Immediate
- Attempt 2: Wait ~2 seconds
- Attempt 3: Wait ~4 seconds
- Attempt 4: Fail with exception
5. Processing Layer
JSON Parsing and Validation
DataFrame Construction
Transform JSON to optimized DataFrames:Type Optimization
Optimize memory usage with proper dtypes:Type Optimization Benefits:
- Categorical types: 50% memory reduction for repeated strings
- Proper numeric types: Faster computations
- Timedelta types: Native time operations
Data Flow Scenarios
Scenario 1: Cold Start (First Load)
No cached data available:Scenario 2: Warm Start (SQLite Cache)
Data exists in SQLite cache:Scenario 3: Hot Start (In-Memory Cache)
Data already loaded in current process:Scenario 4: Telemetry Loading
Telemetry has a more granular flow:- Cold: ~200-500ms per lap
- Cached: ~1-10ms
Scenario 5: Batch Telemetry Loading
Optimized parallel loading:- Cold: ~0.4s for 20 drivers (parallel)
- Sequential would be: ~10s (25x slower)
Ultra-Cold Mode
For maximum performance on first load, tif1 offers ultra-cold mode:- Skip Validation: Parse JSON without schema validation
- Skip Retries: Fail fast on errors
- Background Caching: Fetch data, return immediately, cache in background
Data Flow Diagrams
Complete Data Flow
Telemetry-Specific Flow
Performance Characteristics
Operation Latencies
| Operation | Cold (No Cache) | Warm (SQLite) | Hot (Memory) |
|---|---|---|---|
| Load laps (20 drivers) | 400-1000ms | 10-50ms | <1ms |
| Load single telemetry | 200-500ms | 1-10ms | <1ms |
| Load 20 telemetry (parallel) | 400-1000ms | 10-50ms | <1ms |
| Load 20 telemetry (sequential) | 10-15s | 200-500ms | <1ms |
| Load weather | 200-400ms | 1-5ms | <1ms |
| Load race control | 200-400ms | 1-5ms | <1ms |
Cache Effectiveness
- Development: 90-95% (iterating on same data)
- Production: 60-80% (varied data access)
- CI/CD: 0-20% (fresh environments)
Configuration
Cache Configuration
Network Configuration
Troubleshooting
Slow Initial Load
Problem: First data access takes too long Solutions:Cache Issues
Problem: Cache not being used Check:Network Errors
Problem: Frequent network failures Solutions:Related Topics
Sessions
Understanding session objects and lazy loading
Laps and Telemetry
Working with lap and telemetry data structures
Caching
Detailed cache configuration and management
Performance
Performance optimization tips and benchmarks