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. Swytch keeps all data in memory — when the cache is full, the eviction algorithm removes infrequently accessed keys to make room.

Identifying Memory Pressure

Use these metrics to understand whether your working set fits in memory:

MetricMeaning
swytch_redis_cache_hits_totalSuccessful cache lookups
swytch_redis_cache_misses_totalCache misses (key not found)
swytch_redis_cache_hit_rateHit rate (0-1)
swytch_redis_evictions_totalKeys evicted from cache

Working set fits in memory when:

  • Hit rate is high (>90%)
  • Evictions are infrequent
  • p99 latency is stable

Working set exceeds memory when:

  • Hit rate is dropping
  • Consistent eviction pressure
  • Frequently accessed keys are being evicted and re-populated

Calculating Hit Rate

Hit Rate = cache_hits / (cache_hits + cache_misses)

Or use the pre-computed gauge:

swytch_redis_cache_hit_rate

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

When to Scale

Scale Memory When

SignalAction
Hit rate < 80%Increase --maxmemory
Evictions > 1000/sec sustainedIncrease --maxmemory
p99 latency increasingCheck eviction rate and hit rate
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 Nodes When (Cluster Mode)

SignalAction
Single node cannot hold working setAdd nodes to distribute load
High cluster_reads_remote_fetch_totalData is spread across nodes; add memory or review key distribution
Network bandwidth saturatedAdd nodes to reduce per-node traffic

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. Size Memory

Swytch is an in-memory cache. All active data must fit in --maxmemory. When the limit is reached, the eviction algorithm removes infrequently accessed effects automatically.

maxmemory = data_size × 1.2  (20% headroom)

If your total dataset is larger than available memory, Swytch functions as a cache — frequently accessed keys stay in memory while cold keys are evicted. In this case, size for your working set:

maxmemory = working_set_size × 1.2

If unknown, start generous and monitor hit rate.
Reduce gradually until hit rate drops below your target.

3. Set Resource Limits

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

The extra memory beyond --maxmemory accounts for connection buffers, Lua scripting overhead, the Go runtime, and cluster replication state (if clustered).

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: swytch_redis_cache_hit_rate < 0.8
        for: 15m
        labels:
          severity: warning
        annotations:
          summary: "Cache hit rate below 80%"

Quick Reference

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