Online resharding for Redis OSS (cluster mode enabled) - Amazon ElastiCache (Redis OSS)
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Online resharding for Redis OSS (cluster mode enabled)

By using online resharding and shard rebalancing with Amazon ElastiCache (Redis OSS) version 3.2.10 or newer, you can scale your Redis OSS (cluster mode enabled) cluster dynamically with no downtime. This approach means that your cluster can continue to serve requests even while scaling or rebalancing is in process.

You can do the following:

  • Scale out – Increase read and write capacity by adding shards (node groups) to your Redis OSS (cluster mode enabled) cluster (replication group).

    If you add one or more shards to your replication group, the number of nodes in each new shard is the same as the number of nodes in the smallest of the existing shards.

  • Scale in – Reduce read and write capacity, and thereby costs, by removing shards from your Redis OSS (cluster mode enabled) cluster.

  • Rebalance – Move the keyspaces among the shards in your Redis OSS (cluster mode enabled) cluster so they are as equally distributed among the shards as possible.

You can't do the following:

  • Configure shards independently:

    You can't specify the keyspace for shards independently. To do this, you must use the offline process.

Currently, the following limitations apply to ElastiCache (Redis OSS) online resharding and rebalancing:

  • These processes require Redis OSS engine version 3.2.10 or newer. For information on upgrading your engine version, see Version Management for ElastiCache.

  • There are limitations with slots or keyspaces and large items:

    If any of the keys in a shard contain a large item, that key isn't migrated to a new shard when scaling out or rebalancing. This functionality can result in unbalanced shards.

    If any of the keys in a shard contain a large item (items greater than 256 MB after serialization), that shard isn't deleted when scaling in. This functionality can result in some shards not being deleted.

  • When scaling out, the number of nodes in any new shards equals the number of nodes in the smallest existing shard.

  • When scaling out, any tags that are common to all existing shards are copied to the new shards.

  • When scaling out a Global Data Store cluster, ElastiCache will not automatically replicate Functions from one of the existing nodes to the new node(s). We recommend loading your Functions in the new shard(s) after scaling out your cluster so that every shards have the same functions.

Note

In ElastiCache (Redis OSS) version 7 and above: When scaling out your cluster, ElastiCache will automatically replicate the Functions loaded in one of the existing nodes (selected at random) to the new node(s). If your application uses Redis OSS Functions, we recommend loading all of your functions to all the shards before scaling out so that your ElastiCache (Redis OSS) cluster does not end up with different function definitions on different shards.

For more information, see Online cluster resizing.

You can horizontally scale or rebalance your Redis OSS (cluster mode enabled) clusters using the Amazon Web Services Management Console, the Amazon CLI, and the ElastiCache API.

Adding shards with online resharding

You can add shards to your Redis OSS (cluster mode enabled) cluster using the Amazon Web Services Management Console, Amazon CLI, or ElastiCache API. When you add shards to a Redis OSS (cluster mode enabled) cluster, any tags on the existing shards are copied over to the new shards.

Topics

    You can use the Amazon Web Services Management Console to add one or more shards to your Redis OSS (cluster mode enabled) cluster. The following procedure describes the process.

    To add shards to your Redis OSS (cluster mode enabled) cluster
    1. Open the ElastiCache console at https://console.amazonaws.cn/elasticache/.

    2. From the navigation pane, choose Redis OSS clusters.

    3. Locate and choose the name, not the box to the left of the cluster's name, of the Redis OSS (cluster mode enabled) cluster that you want to add shards to.

      Tip

      Redis OSS (cluster mode enabled) show Clustered Redis OSS in the Mode column

    4. Choose Add shard.

      1. For Number of shards to be added, choose the number of shards you want added to this cluster.

      2. For Availability zone(s), choose either No preference or Specify availability zones.

      3. If you chose Specify availability zones, for each node in each shard, select the node's Availability Zone from the list of Availability Zones.

      4. Choose Add.

    The following process describes how to reconfigure the shards in your Redis OSS (cluster mode enabled) cluster by adding shards using the Amazon CLI.

    Use the following parameters with modify-replication-group-shard-configuration.

    Parameters
    • --apply-immediately – Required. Specifies the shard reconfiguration operation is to be started immediately.

    • --replication-group-id – Required. Specifies which replication group (cluster) the shard reconfiguration operation is to be performed on.

    • --node-group-count – Required. Specifies the number of shards (node groups) to exist when the operation is completed. When adding shards, the value of --node-group-count must be greater than the current number of shards.

      Optionally, you can specify the Availability Zone for each node in the replication group using --resharding-configuration.

    • --resharding-configuration – Optional. A list of preferred Availability Zones for each node in each shard in the replication group. Use this parameter only if the value of --node-group-count is greater than the current number of shards. If this parameter is omitted when adding shards, Amazon ElastiCache selects the Availability Zones for the new nodes.

    The following example reconfigures the keyspaces over four shards in the Redis OSS (cluster mode enabled) cluster my-cluster. The example also specifies the Availability Zone for each node in each shard. The operation begins immediately.

    Example - Adding Shards

    For Linux, OS X, or Unix:

    aws elasticache modify-replication-group-shard-configuration \ --replication-group-id my-cluster \ --node-group-count 4 \ --resharding-configuration \ "PreferredAvailabilityZones=us-east-2a,us-east-2c" \ "PreferredAvailabilityZones=us-east-2b,us-east-2a" \ "PreferredAvailabilityZones=us-east-2c,us-east-2d" \ "PreferredAvailabilityZones=us-east-2d,us-east-2c" \ --apply-immediately

    For Windows:

    aws elasticache modify-replication-group-shard-configuration ^ --replication-group-id my-cluster ^ --node-group-count 4 ^ --resharding-configuration ^ "PreferredAvailabilityZones=us-east-2a,us-east-2c" ^ "PreferredAvailabilityZones=us-east-2b,us-east-2a" ^ "PreferredAvailabilityZones=us-east-2c,us-east-2d" ^ "PreferredAvailabilityZones=us-east-2d,us-east-2c" ^ --apply-immediately

    For more information, see modify-replication-group-shard-configuration in the Amazon CLI documentation.

    You can use the ElastiCache API to reconfigure the shards in your Redis OSS (cluster mode enabled) cluster online by using the ModifyReplicationGroupShardConfiguration operation.

    Use the following parameters with ModifyReplicationGroupShardConfiguration.

    Parameters
    • ApplyImmediately=true – Required. Specifies the shard reconfiguration operation is to be started immediately.

    • ReplicationGroupId – Required. Specifies which replication group (cluster) the shard reconfiguration operation is to be performed on.

    • NodeGroupCount – Required. Specifies the number of shards (node groups) to exist when the operation is completed. When adding shards, the value of NodeGroupCount must be greater than the current number of shards.

      Optionally, you can specify the Availability Zone for each node in the replication group using ReshardingConfiguration.

    • ReshardingConfiguration – Optional. A list of preferred Availability Zones for each node in each shard in the replication group. Use this parameter only if the value of NodeGroupCount is greater than the current number of shards. If this parameter is omitted when adding shards, Amazon ElastiCache selects the Availability Zones for the new nodes.

    The following process describes how to reconfigure the shards in your Redis OSS (cluster mode enabled) cluster by adding shards using the ElastiCache API.

    Example - Adding Shards

    The following example adds node groups to the Redis OSS (cluster mode enabled) cluster my-cluster, so there are a total of four node groups when the operation completes. The example also specifies the Availability Zone for each node in each shard. The operation begins immediately.

    https://elasticache.us-east-2.amazonaws.com/ ?Action=ModifyReplicationGroupShardConfiguration &ApplyImmediately=true &NodeGroupCount=4 &ReplicationGroupId=my-cluster &ReshardingConfiguration.ReshardingConfiguration.1.PreferredAvailabilityZones.AvailabilityZone.1=us-east-2a &ReshardingConfiguration.ReshardingConfiguration.1.PreferredAvailabilityZones.AvailabilityZone.2=us-east-2c &ReshardingConfiguration.ReshardingConfiguration.2.PreferredAvailabilityZones.AvailabilityZone.1=us-east-2b &ReshardingConfiguration.ReshardingConfiguration.2.PreferredAvailabilityZones.AvailabilityZone.2=us-east-2a &ReshardingConfiguration.ReshardingConfiguration.3.PreferredAvailabilityZones.AvailabilityZone.1=us-east-2c &ReshardingConfiguration.ReshardingConfiguration.3.PreferredAvailabilityZones.AvailabilityZone.2=us-east-2d &ReshardingConfiguration.ReshardingConfiguration.4.PreferredAvailabilityZones.AvailabilityZone.1=us-east-2d &ReshardingConfiguration.ReshardingConfiguration.4.PreferredAvailabilityZones.AvailabilityZone.2=us-east-2c &Version=2015-02-02 &SignatureVersion=4 &SignatureMethod=HmacSHA256 &Timestamp=20171002T192317Z &X-Amz-Credential=<credential>

    For more information, see ModifyReplicationGroupShardConfiguration in the ElastiCache API Reference.

    Removing shards with online resharding

    You can remove shards from your Redis OSS (cluster mode enabled) cluster using the Amazon Web Services Management Console, Amazon CLI, or ElastiCache API.

    Removing shards (Console)

    The following process describes how to reconfigure the shards in your Redis OSS (cluster mode enabled) cluster by removing shards using the Amazon Web Services Management Console.

    Before removing node groups (shards) from your replication group, ElastiCache makes sure that all your data will fit in the remaining shards. If the data will fit, the specified shards are deleted from the replication group as requested. If the data won't fit in the remaining node groups, the process is terminated and the replication group is left with the same node group configuration as before the request was made.

    You can use the Amazon Web Services Management Console to remove one or more shards from your Redis OSS (cluster mode enabled) cluster. You cannot remove all the shards in a replication group. Instead, you must delete the replication group. For more information, see Deleting a replication group. The following procedure describes the process for deleting one or more shards.

    To remove shards from your Redis OSS (cluster mode enabled) cluster
    1. Open the ElastiCache console at https://console.amazonaws.cn/elasticache/.

    2. From the navigation pane, choose Redis OSS clusters.

    3. Locate and choose the name, not the box to the left of the cluster's name, of the Redis OSS (cluster mode enabled) cluster you want to remove shards from.

      Tip

      Redis OSS (cluster mode enabled) clusters have a value of 1 or greater in the Shards column.

    4. From the list of shards, choose the box to the left of the name of each shard that you want to delete.

    5. Choose Delete shard.

    Removing shards (Amazon CLI)

    The following process describes how to reconfigure the shards in your Redis OSS (cluster mode enabled) cluster by removing shards using the Amazon CLI.

    Important

    Before removing node groups (shards) from your replication group, ElastiCache makes sure that all your data will fit in the remaining shards. If the data will fit, the specified shards (--node-groups-to-remove) are deleted from the replication group as requested and their keyspaces mapped into the remaining shards. If the data will not fit in the remaining node groups, the process is terminated and the replication group is left with the same node group configuration as before the request was made.

    You can use the Amazon CLI to remove one or more shards from your Redis OSS (cluster mode enabled) cluster. You cannot remove all the shards in a replication group. Instead, you must delete the replication group. For more information, see Deleting a replication group.

    Use the following parameters with modify-replication-group-shard-configuration.

    Parameters
    • --apply-immediately – Required. Specifies the shard reconfiguration operation is to be started immediately.

    • --replication-group-id – Required. Specifies which replication group (cluster) the shard reconfiguration operation is to be performed on.

    • --node-group-count – Required. Specifies the number of shards (node groups) to exist when the operation is completed. When removing shards, the value of --node-group-count must be less than the current number of shards.

    • --node-groups-to-remove – Required when --node-group-count is less than the current number of node groups (shards). A list of shard (node group) IDs to remove from the replication group.

    The following procedure describes the process for deleting one or more shards.

    Example - Removing Shards

    The following example removes two node groups from the Redis OSS (cluster mode enabled) cluster my-cluster, so there are a total of two node groups when the operation completes. The keyspaces from the removed shards are distributed evenly over the remaining shards.

    For Linux, OS X, or Unix:

    aws elasticache modify-replication-group-shard-configuration \ --replication-group-id my-cluster \ --node-group-count 2 \ --node-groups-to-remove "0002" "0003" \ --apply-immediately

    For Windows:

    aws elasticache modify-replication-group-shard-configuration ^ --replication-group-id my-cluster ^ --node-group-count 2 ^ --node-groups-to-remove "0002" "0003" ^ --apply-immediately

    Removing shards (ElastiCache API)

    You can use the ElastiCache API to reconfigure the shards in your Redis OSS (cluster mode enabled) cluster online by using the ModifyReplicationGroupShardConfiguration operation.

    The following process describes how to reconfigure the shards in your Redis OSS (cluster mode enabled) cluster by removing shards using the ElastiCache API.

    Important

    Before removing node groups (shards) from your replication group, ElastiCache makes sure that all your data will fit in the remaining shards. If the data will fit, the specified shards (NodeGroupsToRemove) are deleted from the replication group as requested and their keyspaces mapped into the remaining shards. If the data will not fit in the remaining node groups, the process is terminated and the replication group is left with the same node group configuration as before the request was made.

    You can use the ElastiCache API to remove one or more shards from your Redis OSS (cluster mode enabled) cluster. You cannot remove all the shards in a replication group. Instead, you must delete the replication group. For more information, see Deleting a replication group.

    Use the following parameters with ModifyReplicationGroupShardConfiguration.

    Parameters
    • ApplyImmediately=true – Required. Specifies the shard reconfiguration operation is to be started immediately.

    • ReplicationGroupId – Required. Specifies which replication group (cluster) the shard reconfiguration operation is to be performed on.

    • NodeGroupCount – Required. Specifies the number of shards (node groups) to exist when the operation is completed. When removing shards, the value of NodeGroupCount must be less than the current number of shards.

    • NodeGroupsToRemove – Required when --node-group-count is less than the current number of node groups (shards). A list of shard (node group) IDs to remove from the replication group.

    The following procedure describes the process for deleting one or more shards.

    Example - Removing Shards

    The following example removes two node groups from the Redis OSS (cluster mode enabled) cluster my-cluster, so there are a total of two node groups when the operation completes. The keyspaces from the removed shards are distributed evenly over the remaining shards.

    https://elasticache.us-east-2.amazonaws.com/ ?Action=ModifyReplicationGroupShardConfiguration &ApplyImmediately=true &NodeGroupCount=2 &ReplicationGroupId=my-cluster &NodeGroupsToRemove.member.1=0002 &NodeGroupsToRemove.member.2=0003 &Version=2015-02-02 &SignatureVersion=4 &SignatureMethod=HmacSHA256 &Timestamp=20171002T192317Z &X-Amz-Credential=<credential>

    Online shard rebalancing

    You can rebalance shards in your Redis OSS (cluster mode enabled) cluster using the Amazon Web Services Management Console, Amazon CLI, or ElastiCache API.

    Online Shard Rebalancing (Console)

    The following process describes how to reconfigure the shards in your Redis OSS (cluster mode enabled) cluster by rebalancing shards using the Amazon Web Services Management Console.

    To rebalance the keyspaces among the shards on your Redis OSS (cluster mode enabled) cluster
    1. Open the ElastiCache console at https://console.amazonaws.cn/elasticache/.

    2. From the navigation pane, choose Redis OSS clusters.

    3. Choose the name, not the box to the left of the name, of the Redis OSS (cluster mode enabled) cluster that you want to rebalance.

      Tip

      Redis OSS (cluster mode enabled) clusters have a value of 1 or greater in the Shards column.

    4. Choose Rebalance.

    5. When prompted, choose Rebalance. You might see a message similar to this one: Slots in the replication group are uniformly distributed. Nothing to do. (Service: AmazonElastiCache; Status Code: 400; Error Code: InvalidReplicationGroupState; Request ID: 2246cebd-9721-11e7-8d5b-e1b0f086c8cf). If you do, choose Cancel.

    Online shard rebalancing (Amazon CLI)

    Use the following parameters with modify-replication-group-shard-configuration.

    Parameters
    • -apply-immediately – Required. Specifies the shard reconfiguration operation is to be started immediately.

    • --replication-group-id – Required. Specifies which replication group (cluster) the shard reconfiguration operation is to be performed on.

    • --node-group-count – Required. To rebalance the keyspaces across all shards in the cluster, this value must be the same as the current number of shards.

    The following process describes how to reconfigure the shards in your Redis OSS (cluster mode enabled) cluster by rebalancing shards using the Amazon CLI.

    Example - Rebalancing the Shards in a Cluster

    The following example rebalances the slots in the Redis OSS (cluster mode enabled) cluster my-cluster so that the slots are distributed as equally as possible. The value of --node-group-count (4) is the number of shards currently in the cluster.

    For Linux, OS X, or Unix:

    aws elasticache modify-replication-group-shard-configuration \ --replication-group-id my-cluster \ --node-group-count 4 \ --apply-immediately

    For Windows:

    aws elasticache modify-replication-group-shard-configuration ^ --replication-group-id my-cluster ^ --node-group-count 4 ^ --apply-immediately

    Online shard rebalancing (ElastiCache API)

    You can use the ElastiCache API to reconfigure the shards in your Redis OSS (cluster mode enabled) cluster online by using the ModifyReplicationGroupShardConfiguration operation.

    Use the following parameters with ModifyReplicationGroupShardConfiguration.

    Parameters
    • ApplyImmediately=true – Required. Specifies the shard reconfiguration operation is to be started immediately.

    • ReplicationGroupId – Required. Specifies which replication group (cluster) the shard reconfiguration operation is to be performed on.

    • NodeGroupCount – Required. To rebalance the keyspaces across all shards in the cluster, this value must be the same as the current number of shards.

    The following process describes how to reconfigure the shards in your Redis OSS (cluster mode enabled) cluster by rebalancing the shards using the ElastiCache API.

    Example - Rebalancing a Cluster

    The following example rebalances the slots in the Redis OSS (cluster mode enabled) cluster my-cluster so that the slots are distributed as equally as possible. The value of NodeGroupCount (4) is the number of shards currently in the cluster.

    https://elasticache.us-east-2.amazonaws.com/ ?Action=ModifyReplicationGroupShardConfiguration &ApplyImmediately=true &NodeGroupCount=4 &ReplicationGroupId=my-cluster &Version=2015-02-02 &SignatureVersion=4 &SignatureMethod=HmacSHA256 &Timestamp=20171002T192317Z &X-Amz-Credential=<credential>