Skip to main content
Swytch Documentation
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Sizing and Capacity Planning

This guide helps you estimate memory requirements, plan for growth, and understand when to scale your Swytch deployment.

Memory Estimation

Per-Key Overhead

Every key stored in Swytch has fixed overhead beyond the key and value bytes:

ComponentBytesNotes
Key storagelen(key)Your key string
Value storagelen(value)Your value bytes
Entry metadata~64Timestamps, flags, hash, etc.
Index entry~24In-memory hash table slot

Rule of thumb: Each key-value pair uses len(key) + len(value) + 90 bytes of memory.

Estimation Formula

Total Memory = (num_keys × 90) + total_key_bytes + total_value_bytes

Example: 10 million keys with average 20-byte keys and 200-byte values:

Memory = (10,000,000 × 90) + (10,000,000 × 20) + (10,000,000 × 200)
       = 900MB + 200MB + 2000MB
       = 3.1GB

Add 20% headroom for runtime overhead: ~3.7GB recommended maxmemory

Data Type Overhead

Different Redis data types have additional per-element overhead:

TypePer-element overheadNotes
String0Stored as raw bytes
List~16 bytesDoubly-linked list nodes
Hash~24 bytes per fieldField name + value + metadata
Set~16 bytes per memberHash set entry
Sorted Set~32 bytes per memberScore + skip list nodes
Stream~48 bytes per entryEntry ID + field overhead

Example: A hash with 100 fields averaging 10-byte names and 50-byte values:

Hash overhead = 100 × (24 + 10 + 50) = 8,400 bytes per hash

Working Set Analysis

What is Working Set?

Your working set is the subset of data actively accessed within a time window. In tiered storage mode, the L1 cache holds your working set while L2 holds everything.

Identifying Working Set Size

Use these metrics to understand your working set:

MetricMeaning
swytch_redis_cache_hits_totalL1 (memory) cache hits
swytch_redis_l2_hits_totalL2 (disk) hits (working set exceeded L1)
swytch_redis_evictions_totalKeys evicted from L1

Working set fits in memory when:

  • L2 hit rate is low (<5%)
  • Evictions are infrequent
  • p99 latency is stable

Working set exceeds memory when:

  • L2 hit rate is high (>20%)
  • Consistent eviction pressure
  • Latency spikes during cache misses

Calculating Hit Rate

L1 Hit Rate = cache_hits / (cache_hits + l2_hits + l2_misses)
L2 Hit Rate = l2_hits / (l2_hits + l2_misses)
Overall Hit Rate = (cache_hits + l2_hits) / (cache_hits + l2_hits + l2_misses)

Target: L1 hit rate > 90% for latency-sensitive workloads.

When to Scale

Scale Memory When

SignalAction
L1 hit rate < 80%Increase --maxmemory
Evictions > 1000/sec sustainedIncrease --maxmemory
p99 latency increasingCheck L2 hit rate; may need more memory
OOM killsIncrease container memory limit

Scale CPU When

SignalAction
CPU utilization > 80% sustainedAdd cores or optimize queries
Command queue backing upCheck INFO for blocked clients
Lua script timeoutsOptimize scripts or add CPU

Scale Disk When (Persistent Mode)

SignalAction
Disk usage > 70%Add storage or run defragmentation
Write latency spikesMove to faster storage (NVMe)
Recovery time too longConsider data lifecycle policies

Capacity Planning Worksheet

Use this worksheet to plan your deployment:

1. Estimate Data Size

Current keys:           ____________
Average key size:       ____________ bytes
Average value size:     ____________ bytes
Growth rate (monthly):  ____________ %

Current data size = keys × (key_size + value_size + 90)
                  = ____________ GB

6-month projection = current × (1 + growth_rate)^6
                   = ____________ GB

2. Determine Mode

QuestionIf YesIf No
Must data survive restarts?Persistent modeIn-memory mode
Is all data equally important?Persistent modeConsider TTLs
Can data be regenerated from source?In-memory modePersistent mode

3. Size Memory

In-memory mode:

maxmemory = data_size × 1.2  (20% headroom)

Persistent mode:

maxmemory = working_set_size × 1.2

If unknown, start with:
maxmemory = data_size × 0.3  (assume 30% is hot)

4. Size Disk (Persistent Mode)

disk_size = data_size × 2.5  (growth + defrag headroom)

5. Set Resource Limits

container_memory = maxmemory + max(512MB, maxmemory × 0.2)
container_cpu = based on expected ops/sec (see Deployment guide)

Monitoring for Capacity

Set up alerts for proactive scaling:

# Prometheus alerting rules
groups:
  - name: swytch-capacity
    rules:
      - alert: SwytchMemoryPressure
        expr: swytch_redis_memory_bytes / swytch_redis_memory_max_bytes > 0.9
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "Swytch memory usage above 90%"

      - alert: SwytchHighEvictionRate
        expr: rate(swytch_redis_evictions_total[5m]) > 1000
        for: 10m
        labels:
          severity: warning
        annotations:
          summary: "High eviction rate indicates memory pressure"

      - alert: SwytchLowHitRate
        expr: |
          rate(swytch_redis_cache_hits_total[5m]) /
          (rate(swytch_redis_cache_hits_total[5m]) + rate(swytch_redis_l2_hits_total[5m]) + rate(swytch_redis_l2_misses_total[5m]) + 0.001) < 0.8
        for: 15m
        labels:
          severity: warning
        annotations:
          summary: "L1 cache hit rate below 80%"

Note: Monitor disk usage at the OS level using standard tools like df or node_exporter metrics, as Swytch does not currently expose disk usage metrics.

Quick Reference

ScenarioRecommended maxmemoryNotes
Small app (<1M keys)256MB - 1GBStart small, scale up
Medium app (1-10M keys)1GB - 8GBMonitor working set
Large app (10-100M keys)8GB - 64GBProfile access patterns
Very large (>100M keys)64GB+Consider app-level sharding