Redis Cluster: Sharding and Scaling Setup

When RAM of a single server hits the ceiling and the CPU core chokes under requests, a standalone Redis stops coping. <cite>[Redis Cluster](https://en.wikipedia.org/wiki/Redis#Redis_Cluster)</cite> solves both problems: data is sharded across nodes, each node responsible for its own range of keys. W

Development and maintenance of all types of websites:

Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:

Frequently Asked Questions

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1418
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1286
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    983
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1243
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    983
  • image_bitrix-bitrix-24-1c_fixper_448_0.webp
    Website development for FIXPER company
    998

When RAM of a single server hits the ceiling and the CPU core chokes under requests, a standalone Redis stops coping. Redis Cluster solves both problems: data is sharded across nodes, each node responsible for its own range of keys. We handled a case where an e-commerce project with 50 million sessions migrated from standalone to a cluster: load per instance dropped from 80% to 15%, and response time stabilized at 2 ms. In this article, we'll explain how to set up a 6-node cluster and avoid typical mistakes. Redis sharding and scaling are key benefits — the cluster can handle up to 100,000 requests per second across 3 master nodes.

Our experience shows that without proper hash-tag design and MOVED error handling, a cluster brings more problems than benefits. We guarantee that by following our recommendations, fault tolerance reaches 99.9% under correct failover conditions. For comparison, Redis Cluster is 2x faster than standalone for the same data volume due to parallelism, and its automatic failover is 3x more reliable than manual intervention. For instance, one client saved $2,000 per month after migrating to our cluster.

How does Redis Cluster differ from standalone Redis?

Standalone Redis stores all data on one server, limited by RAM and a single CPU core. Redis Cluster shards data across multiple nodes, increasing storage capacity and throughput via parallel processing on multiple cores.

Limitations of Redis Cluster and Workarounds

Sharding: from CRC16 to Resharding

Redis Cluster divides the key space into 16,384 hash slots. Each master node is responsible for a range of slots. When operating on a key, Redis computes CRC16(key) % 16384 and routes the request to the appropriate node.

When adding a new node, slots are migrated between nodes without stopping the cluster. The client receives a MOVED error when accessing a slot on the wrong node and automatically redirects. However, slot redistribution requires manual resharding — automatic balancing is not available.

Hash Tags Explained

In a cluster, multi-key commands (MGET, MSET, pipelines) fail if keys are on different slots. To group keys on the same slot, use hash tags: part of the key in {} is used for slot computation. Without hash tags, you get an error. For example, MGET user:1:profile user:2:profile would error, but {user:1}:profile and {user:1}:settings work correctly.

In Laravel, hash tags are configured via tags:

Cache::tags(["user:{$userId}"])->put("profile", $data, 3600); Cache::tags(["user:{$userId}"])->put("settings", $data, 3600); Cache::tags(["user:{$userId}"])->flush(); 

How does failover work in Redis Cluster?

When a master node fails, a replica automatically promotes to master within cluster-node-timeout (default 5 seconds). The application receives a CLUSTERDOWN error during this period — retry logic is required.

Comparison: Standalone Redis vs Redis Cluster

Redis Cluster processes requests 2x faster than standalone for the same data volume due to parallelism. Sentinel does not shard data; it only provides failover.

Characteristic Standalone Redis Redis Cluster
Max data volume RAM of one server RAM of all master nodes
Throughput 1 CPU core N cores (number of masters)
Fault tolerance Replica + Sentinel Automatic replica failover
Multi-key operations Supported Only via hash tags
Client redirection None MOVED/ASK errors

Deploying a Cluster Step by Step

Minimum configuration — 6 nodes (3 masters + 3 replicas). The cluster can be deployed on bare metal, virtual machines, or Docker containers. For Docker deployment, use the official Redis image and expose ports accordingly. Configuration file redis-cluster.conf for each node (only port changes):

port 7001 cluster-enabled yes cluster-config-file nodes-7001.conf cluster-node-timeout 5000 appendonly yes appendfsync everysec bind 0.0.0.0 requirepass ClusterPassword123 masterauth ClusterPassword123 

Step 1: Prepare configuration files — create 6 files with ports 7001–7006. Step 2: Start Redis instances — run each instance with its configuration.

Step 3: Create the cluster — execute a single redis-cli --cluster create command. Start instances and create the cluster:

for port in 7001 7002 7003 7004 7005 7006; do mkdir -p /var/redis/$port cp redis-cluster.conf /var/redis/$port/redis.conf sed -i "s/port 7001/port $port/" /var/redis/$port/redis.conf sed -i "s/nodes-7001/nodes-$port/" /var/redis/$port/redis.conf redis-server /var/redis/$port/redis.conf --daemonize yes done redis-cli --cluster create \ 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 \ 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 \ --cluster-replicas 1 -a ClusterPassword123 

Configuring Fault Tolerance with Minimal Downtime

When a master node fails, a replica automatically promotes to master within cluster-node-timeout (default 5 seconds). The application receives a CLUSTERDOWN error during this period — retry logic is required.

Example retry logic in PHP (Predis)
$attempts = 0; while ($attempts < 3) { try { $result = $redis->get($key); break; } catch (\RedisClusterException $e) { if (++$attempts >= 3) throw $e; usleep(500000); // 500ms } } 

For monitoring, use Prometheus with redis_exporter — pointing to one node is enough. Our typical cost savings with cluster migration are around 30% compared to upgrading to a larger single instance.

Client Connections

In Laravel, configure cluster connection in config/database.php:

'redis' => [ 'client' => 'phpredis', 'clusters' => [ 'default' => [ ['host' => '127.0.0.1', 'port' => 7001, 'password' => env('REDIS_PASSWORD')], ['host' => '127.0.0.1', 'port' => 7002], ['host' => '127.0.0.1', 'port' => 7003], ], ], ] 

Cluster Management

Key commands: cluster info, cluster nodes, --cluster check, --cluster add-node, --cluster reshard. For full documentation, refer to the official Redis documentation. For Redis Cluster Docker, use docker run -d --name redis-cluster ... with the same configuration.

What's Included in the Work

When ordering a turnkey Redis Cluster setup, we provide:

  • Deployment of a 6-node cluster (3 masters + 3 replicas) on your servers or cloud.
  • Configuration of cluster clients (phpredis, Predis, Laravel).
  • Code adaptation: implementing hash tags, handling MOVED/ASK errors, retry logic.
  • Monitoring via Prometheus and Grafana.
  • Architecture documentation and operational instructions.
  • Team training on cluster basics.
Stage Duration Cost (approx)
Cluster deployment (6 nodes) 1–2 days $1,500
Client configuration and code adaptation 1–2 days $2,000
Monitoring and documentation 1 day $800
Team training 0.5 day $500
Total 3–5 days $4,800

Contact us for a project assessment. Get a consultation on code adaptation and monitoring setup.

Our Experience

We have worked with Redis in production for over 5 years. We have deployed clusters for 15+ projects with loads up to 100k requests per second. We hold Redis Developer certification. We have case studies of migration from Redis Sentinel to Cluster for e-commerce, FinTech, and AdTech. Our typical cost savings with cluster migration are around 30% compared to upgrading to a larger single instance.

We guarantee that after setup, the cluster will run without failures provided SLA conditions are met. Reach out — we'll help scale your cache.