Multi-Tier Caching for Read-Heavy Workloads
HeliosProxy offloads read-heavy workloads from HeliosDB Lite with an opt-in query-result cache: repeated SELECT results are served from in-process L1 and L2 tiers, an entry is refused once a write through the proxy commits to a table it read, writes that bypass the proxy are bounded by the configured time-to-live, and results above a size limit bypass the cache.
Problem Being Solved
Core Problem Statement
Read-heavy workloads suffer from the tension between data consistency and performance, forcing organizations to choose between fast but stale external caches or slow but consistent database queries.
Who Suffers Most
SaaS Multi-Tenant Application Architects: Building B2B platforms where each tenant has isolated data but common queries (dashboards, reports, analytics). They struggle with cache key namespacing, tenant isolation in shared cache clusters, and the impossibility of invalidating complex aggregated query results without rebuilding entire cache layers.
Concrete Examples with Code, Config & Architecture
Example 1: Embedded Configuration for E-Commerce Product Catalog
HeliosDB Lite Configuration (heliosdb-lite.toml):
[database]
name = "ecommerce_catalog"
port = 5432
unix_socket = "/var/run/heliosdb/heliosdb.sock"
[storage]
data_dir = "/var/lib/heliosdb/data"
wal_dir = "/var/lib/heliosdb/wal"
page_size = "8KB"
# L1: In-Memory Hot Data Cache
[cache.l1]
enabled = true
max_size = "8GB" # Cache ~1M product rows in memory
eviction_policy = "adaptive_lru" # Promotes frequently accessed items
warm_on_startup = true # Load hot data from previous session
hotspot_threshold = 100 # Access count to be considered "hot"
# L2: Disk-Based Page Cache
[cache.l2]
enabled = true
cache_dir = "/mnt/nvme/heliosdb/l2cache" # Fast NVMe SSD
max_size = "100GB" # Store ~12M product pages
prefetch_strategy = "sequential_scan_detection"
compression = "lz4" # Fast compression for page storage
# L3: Semantic Query Result Cache
[cache.l3]
enabled = true
max_size = "10GB" # Store result sets
max_result_size = "50MB" # Don't cache extremely large results
ttl = "5m" # Safety TTL (invalidation is primary mechanism)
cache_select_queries = true
cache_analytical_queries = true # Aggregations, GROUP BY, etc.
invalidate_on_write = true # Automatic invalidation
[cache.l3.invalidation]
# Table-level dependency tracking
track_tables = true
# Fine-grained column tracking for complex invalidation
track_columns = false # Simpler but broader invalidation
async_invalidation = true
invalidation_queue_size = 10000
[proxy]
enabled = true
max_connections = 1000
query_timeout = "30s"
[proxy.routing]
# Route reads to cache layers, writes directly to storage
read_strategy = "cache_first" # L3 → L2 → L1 → Storage
write_strategy = "write_through" # Write + invalidate
[metrics]
enabled = true
export_prometheus = true
prometheus_port = 9090
cache_hit_rate_by_tier = true
Example 2: Language Binding Integration for Multi-Tenant SaaS (Python)
Scenario: B2B SaaS platform with 10K tenants, each with isolated data. Dashboard queries are repetitive per tenant but results must be fresh.
Example 3: Infrastructure & Container Deployment for Content Platform
Scenario: Social media platform with 50M users, 500M posts, feed generation requires complex queries joining users, posts, likes, comments.
Dockerfile:
FROM debian:bookworm-slim
# HeliosDB-Lite binary, built from the licensed source distribution
# (https://www.heliosdb.com/docs/lite/getting-started/installation/)
COPY heliosdb-lite /usr/local/bin/heliosdb-lite
RUN apt-get update && apt-get install -y \
ca-certificates \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Create directories for L1/L2/L3 caching
RUN mkdir -p \
/var/lib/heliosdb/data \
/var/lib/heliosdb/wal \
/mnt/nvme/heliosdb/l2cache \
/var/run/heliosdb
# Copy configuration
COPY heliosdb-content-platform.toml /etc/heliosdb/heliosdb.toml
# Expose PostgreSQL port and metrics
EXPOSE 5432 9090
# Health check using pg_isready equivalent
HEALTHCHECK --interval=10s --timeout=5s --retries=3 \
CMD heliosdb-lite health-check || exit 1
# Run as non-root user
RUN useradd -r -u 999 heliosdb && \
chown -R heliosdb:heliosdb /var/lib/heliosdb /mnt/nvme/heliosdb /var/run/heliosdb
USER heliosdb
CMD ["heliosdb-lite", "start", "--config", "/etc/heliosdb/heliosdb.toml"]
Docker Compose (with NVMe volume for L2 cache):
version: '3.8'
services:
heliosdb-content:
build: .
container_name: heliosdb-content-platform
ports:
- "5432:5432" # PostgreSQL protocol
- "9090:9090" # Prometheus metrics
volumes:
# Main data storage (SSD)
- heliosdb-data:/var/lib/heliosdb/data
- heliosdb-wal:/var/lib/heliosdb/wal
# L2 cache on fast NVMe (host-mounted for performance)
- type: bind
source: /mnt/nvme-pool/heliosdb-l2
target: /mnt/nvme/heliosdb/l2cache
# Configuration
- ./heliosdb-content-platform.toml:/etc/heliosdb/heliosdb.toml:ro
environment:
HELIOSDB_LOG_LEVEL: "info"
HELIOSDB_CACHE_L1_SIZE: "16GB"
HELIOSDB_CACHE_L2_SIZE: "200GB"
HELIOSDB_CACHE_L3_SIZE: "20GB"
# Resource limits to prevent OOM
deploy:
resources:
limits:
cpus: '8'
memory: 24G # 16GB for L1 + 8GB overhead
reservations:
cpus: '4'
memory: 20G
restart: unless-stopped
# Ensure L2 cache volume is mounted before starting
depends_on:
- init-l2-cache
init-l2-cache:
image: busybox
volumes:
- type: bind
source: /mnt/nvme-pool/heliosdb-l2
target: /cache
command: chown -R 999:999 /cache
# Prometheus for metrics collection
prometheus:
image: prom/prometheus:latest
ports:
- "9091:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus-data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
restart: unless-stopped
# Grafana for cache metrics visualization
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
volumes:
- grafana-data:/var/lib/grafana
- ./grafana-dashboards:/etc/grafana/provisioning/dashboards:ro
environment:
GF_SECURITY_ADMIN_PASSWORD: "admin"
restart: unless-stopped
volumes:
heliosdb-data:
driver: local
heliosdb-wal:
driver: local
prometheus-data:
driver: local
grafana-data:
driver: local
Kubernetes Deployment (with local NVMe for L2):
apiVersion: v1
kind: ConfigMap
metadata:
name: heliosdb-config
namespace: content-platform
data:
heliosdb.toml: |
[database]
name = "content_platform"
port = 5432
[storage]
data_dir = "/var/lib/heliosdb/data"
wal_dir = "/var/lib/heliosdb/wal"
[cache.l1]
enabled = true
max_size = "16GB"
eviction_policy = "adaptive_lru"
[cache.l2]
enabled = true
cache_dir = "/mnt/nvme/heliosdb/l2cache"
max_size = "200GB"
compression = "lz4"
[cache.l3]
enabled = true
max_size = "20GB"
ttl = "10m"
invalidate_on_write = true
[metrics]
enabled = true
export_prometheus = true
prometheus_port = 9090
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: heliosdb-content
namespace: content-platform
spec:
serviceName: heliosdb-content
replicas: 1 # Single primary (read replicas can be added)
selector:
matchLabels:
app: heliosdb-content
template:
metadata:
labels:
app: heliosdb-content
spec:
# Node affinity to ensure deployment on NVMe-equipped nodes
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: storage-tier
operator: In
values:
- nvme
containers:
- name: heliosdb
image: registry.example.com/heliosdb-lite:<version> # licensed image from HeliosDB sales, or built from the Lite Dockerfile
ports:
- containerPort: 5432
name: postgresql
- containerPort: 9090
name: metrics
env:
- name: HELIOSDB_LOG_LEVEL
value: "info"
resources:
requests:
cpu: "4"
memory: "20Gi"
limits:
cpu: "8"
memory: "24Gi"
volumeMounts:
- name: config
mountPath: /etc/heliosdb
readOnly: true
- name: data
mountPath: /var/lib/heliosdb/data
- name: wal
mountPath: /var/lib/heliosdb/wal
- name: l2-cache
mountPath: /mnt/nvme/heliosdb/l2cache
livenessProbe:
exec:
command:
- heliosdb-lite
- health-check
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
exec:
command:
- heliosdb-lite
- ready-check
initialDelaySeconds: 10
periodSeconds: 5
volumes:
- name: config
configMap:
name: heliosdb-config
- name: l2-cache
hostPath:
path: /mnt/nvme-pool/heliosdb-l2
type: DirectoryOrCreate
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "fast-ssd"
resources:
requests:
storage: 500Gi
- metadata:
name: wal
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "fast-ssd"
resources:
requests:
storage: 50Gi
---
apiVersion: v1
kind: Service
metadata:
name: heliosdb-content
namespace: content-platform
spec:
selector:
app: heliosdb-content
ports:
- name: postgresql
port: 5432
targetPort: 5432
- name: metrics
port: 9090
targetPort: 9090
clusterIP: None # Headless service for StatefulSet
---
apiVersion: v1
kind: Service
metadata:
name: heliosdb-content-lb
namespace: content-platform
spec:
type: LoadBalancer
selector:
app: heliosdb-content
ports:
- name: postgresql
port: 5432
targetPort: 5432
Example 4: Microservices Integration with API Gateway (Rust + Axum)
HeliosDB Lite Configuration for API Gateway:
[database]
name = "api_gateway"
port = 5432
[cache.l1]
enabled = true
max_size = "4GB" # Cache hot API keys in memory
eviction_policy = "adaptive_lru"
hotspot_threshold = 50 # API keys accessed 50+ times = hot
[cache.l2]
enabled = false # Not needed for API key lookups (small dataset)
[cache.l3]
enabled = true
max_size = "1GB"
cache_select_queries = true
# Aggressive TTL since rate limit counts change frequently
ttl = "1s"
invalidate_on_write = true
[proxy.routing]
read_strategy = "cache_first"
write_strategy = "write_through"
Example 5: Edge Computing & IoT Deployment for Offline-First Apps
Scenario: Retail point-of-sale system with 5000 stores, each running local HeliosDB Lite instance.
Edge Device Configuration (edge-pos-terminal.toml):
[database]
name = "pos_edge_store_4523"
port = 5432
unix_socket = "/var/run/heliosdb/heliosdb.sock"
[storage]
data_dir = "/mnt/local-ssd/heliosdb/data"
wal_dir = "/mnt/local-ssd/heliosdb/wal"
# Smaller page size for edge devices with limited RAM
page_size = "4KB"
# L1: Aggressive in-memory caching for product catalog
[cache.l1]
enabled = true
max_size = "2GB"
eviction_policy = "adaptive_lru"
warm_on_startup = true # Pre-load hot products on boot
hotspot_threshold = 10
# L2: SSD cache for warm products
[cache.l2]
enabled = true
cache_dir = "/mnt/local-ssd/heliosdb/l2cache"
max_size = "20GB"
compression = "lz4"
prefetch_strategy = "sequential_scan_detection"
# L3: Cache computed queries (price calculations, promotions)
[cache.l3]
enabled = true
max_size = "500MB"
ttl = "1h" # Promotions change hourly
cache_select_queries = true
cache_analytical_queries = false # Not needed for POS
invalidate_on_write = true
[cache.l3.invalidation]
track_tables = true
# Edge-specific: batch invalidations when syncing from central
async_invalidation = true
# Edge replication settings
[replication]
mode = "edge"
central_hub = "postgresql://central:5432/pos_central"
sync_interval = "5m" # Sync product updates every 5 minutes
conflict_resolution = "central_wins" # Central catalog is source of truth
offline_mode = true # Continue operating if central is unreachable
[proxy]
enabled = true
max_connections = 50 # Limited for edge device
[metrics]
enabled = true
export_prometheus = true
prometheus_port = 9090
# Send metrics to central for monitoring
remote_write_url = "https://monitoring.retailcorp.com/api/v1/push"
Adoption Strategy
Phase 1: Proof of Value (Weeks 1-4)
Benchmark Read-Heavy Workloads: Deploy HeliosDB Lite in dev/staging environment alongside existing PostgreSQL + Redis infrastructure. Run production traffic replay or synthetic benchmark simulating read-heavy patterns (95:5 read/write ratio). Measure L1/L2/L3 cache hit rates, query latency distribution (P50/P95/P99), and infrastructure resource utilization.
TCO Analysis: Calculate total cost of ownership for current infrastructure (database instances, Redis clusters, invalidation workers, monitoring, engineering time debugging cache bugs) versus HeliosDB Lite single-component deployment. Include hard costs (cloud infrastructure bills) and soft costs (engineering hours on cache management, incident response for stale data bugs).
Migration Complexity Assessment: Identify application code that would need changes during migration. For applications using Redis-specific features (Pub/Sub, Lua scripts), identify workarounds or SQL equivalents. Create migration runbook. Target: < 40 engineering hours for migration effort.
Phase 2: Production Rollout (Weeks 5-12)
Canary Deployment: Deploy HeliosDB Lite for a single low-risk service or tenant (e.g., internal dashboard, small subset of SaaS tenants). Configure multi-tier caching for service-specific read patterns. Monitor cache hit rates, latency, error rates, and database load for 2 weeks. Compare to baseline metrics from Phase 1. Target: Match or exceed baseline performance with zero production incidents.
Gradual Traffic Migration: Use feature flags or load balancer rules to gradually shift read traffic to HeliosDB Lite while keeping writes dual-written to both old and new systems.
Phase 3: Optimization & Expansion (Months 4-12)
Cache Tuning: Analyze cache hit rates by tier (L1/L2/L3) and adjust sizing based on workload patterns. Use HeliosDB Lite built-in observability to identify hotspots and tune eviction policies. Experiment with different L2 compression algorithms (LZ4 vs. Zstd) for optimal performance/space tradeoff.
Expand to Additional Services: Migrate remaining services to HeliosDB Lite based on lessons learned. Prioritize services with highest read-heavy workloads (most cost savings) or most cache invalidation bugs (most reliability improvement). Build internal best practices documentation and training for engineering teams.
Advanced Features: Explore HeliosDB Lite advanced caching features like semantic query result caching for complex analytical queries, custom eviction policies for domain-specific access patterns, and geo-distributed edge replication for global low-latency reads.
Conclusion
Multi-tier caching for read-heavy workloads represents a fundamental architectural advantage of HeliosDB Lite over traditional database solutions. By integrating L1 in-memory, L2 disk-based, and L3 semantic query result caching directly into the database engine via HeliosProxy, HeliosDB Lite eliminates the operational complexity, consistency challenges, and cost burden of external caching infrastructure.
HeliosDB Lite's integrated approach, built on PostgreSQL compatibility for easy adoption, combines ACID correctness with cache-level read performance, single-binary deployment and built-in observability.
The business value is immediate and measurable: faster user experiences drive higher conversion rates, reduced infrastructure costs improve margins, and eliminated cache coherency bugs restore engineering focus to product innovation rather than infrastructure firefighting. As organizations increasingly demand both performance and simplicity in their data infrastructure, HeliosDB Lite's multi-tier caching positions it as the embedded database for the next decade of read-heavy, cloud-native applications.
Performance depends on workload and hardware. Published figures are measured on representative fixtures; see the benchmarks page and reproduce them on your own workload.