Skip to content

Deployment

Choose the right Redis topology for your availability and scalability needs.

Topology Comparison

TopologyHAScalabilityComplexityUse Case
SingleNoVerticalLowDev, small apps
SentinelYesVerticalMediumProduction HA
ClusterYesHorizontalHighLarge scale

Single Node

Best for: Development, small applications, non-critical workloads

typescript
RedisModule.forRoot({
  clients: {
    host: 'redis',
    port: 6379,
  },
})

Limitations:

  • No automatic failover
  • Memory limited to single machine
  • Single point of failure

Best for: Production with high availability needs

typescript
RedisModule.forRoot({
  clients: {
    sentinels: [
      { host: 'sentinel-1', port: 26379 },
      { host: 'sentinel-2', port: 26379 },
      { host: 'sentinel-3', port: 26379 },
    ],
    name: 'mymaster',
    password: process.env.REDIS_PASSWORD,
  },
})

Failover behavior:

  1. Sentinel detects master failure
  2. Sentinels elect new master
  3. Client redirected to new master
  4. ~30 seconds failover time

Cluster

Best for: Large-scale applications needing horizontal scaling

typescript
// ioredis cluster mode
import { Cluster } from 'ioredis';

const cluster = new Cluster([
  { host: 'node-1', port: 6379 },
  { host: 'node-2', port: 6379 },
  { host: 'node-3', port: 6379 },
], {
  redisOptions: {
    password: process.env.REDIS_PASSWORD,
  },
  scaleReads: 'slave',
});

Key hashing:

  • Keys distributed across 16384 slots
  • Use {hash_tag} to co-locate related keys
  • Some commands limited to single slot
typescript
// These keys will be on same shard
'user:{123}:profile'
'user:{123}:settings'
'user:{123}:orders'

Decision Matrix

FactorSingleSentinelCluster
Data size<10GB<100GB>100GB
Availability needsLowHighHigh
Operations teamSmallMediumLarge
BudgetLowMediumHigher
Failover timeManual~30s~15s

Cloud Managed Options

ProviderServiceTopology Support
AWSElastiCacheSingle, Cluster
GCPMemorystoreSingle, Cluster
AzureAzure CacheSingle, Cluster
Redis LabsRedis CloudAll

Benefits of managed:

  • Automatic patching
  • Backup/restore
  • Monitoring included
  • Simplified operations

High Availability Architecture

Persistence Configuration

ModeDurabilityPerformance
NoneLowestHighest
RDBMediumHigh
AOFHighMedium
RDB + AOFHighestLower

For caching: RDB or none For queues/locks: AOF recommended

# redis.conf
appendonly yes
appendfsync everysec

Next Steps

Released under the MIT License.