Guide to Elasticsearch Cluster Scaling Strategies for Growth
Master the art of scaling your Elasticsearch cluster for exponential growth. This guide details crucial strategies for both horizontal (scaling out) and vertical (scaling up) expansion. Learn how to optimize node roles, calculate ideal shard allocation for performance, and implement best practices for maintaining high availability and handling increased query and indexing loads effectively.
Guide to Elasticsearch Cluster Scaling Strategies for Growth
Elasticsearch cluster scaling gets urgent when searches slow down, indexing queues back up, or disks start filling faster than expected. As data volumes and query loads grow, you need to know whether to add resources to existing nodes, add more nodes, change shard strategy, or redesign hot indices.
This guide covers vertical and horizontal scaling, node roles, shard sizing, and practical steps for growing a cluster without guessing.
Understanding Elasticsearch Scaling Fundamentals
Scaling an Elasticsearch cluster primarily involves two strategies: Vertical Scaling (scaling up) and Horizontal Scaling (scaling out). The optimal strategy often involves a careful balance of both, dictated by your workload characteristics.
Vertical Scaling (Scaling Up)
Vertical scaling involves increasing the resources of existing nodes. This is the simplest approach but hits physical limits quickly.
When to use Vertical Scaling:
- When latency is the primary concern and you need faster query responses from the existing data set.
- For short-term pressure where adding and rebalancing new nodes would take longer than the relief you need.
Primary Resource Upgrades:
- RAM (Memory): Elasticsearch needs JVM heap and a large OS filesystem cache. A common starting point is to set heap near 50% of system RAM while staying below the compressed ordinary object pointer threshold, often around 26-32GB depending on the JVM.
- CPU: Necessary for complex aggregations, heavy indexing, and high query concurrency.
- Storage (Disk I/O): Faster SSDs or NVMe drives significantly improve indexing throughput and search speed, especially for heavy I/O workloads.
Warning on Vertical Scaling: Very large JVM heaps can lose compressed ordinary object pointer benefits and may suffer longer garbage collection pauses. Extra RAM is still useful for the filesystem cache, but pushing heap size upward is not a long-term scaling plan.
Horizontal Scaling (Scaling Out)
Horizontal scaling involves adding more nodes to the cluster. This distributes the data and the query load across more machines, offering near-linear scalability and high availability.
When to use Horizontal Scaling:
- When data volume exceeds the capacity of existing nodes.
- When you need to improve overall indexing throughput or query concurrency.
- As the primary strategy for long-term, sustainable growth.
Horizontal scaling is achieved by adding new data nodes. Coordinating nodes can also be added, but typically, data node expansion drives capacity growth.
Architectural Best Practices for Scalability
Scaling is more than just adding hardware; it requires a well-structured index and node topology.
Node Roles and Specialization
Modern Elasticsearch deployments benefit greatly from assigning dedicated roles to nodes, especially in larger clusters. This prevents resource contention between heavy tasks (like indexing) and critical tasks (like coordinating searches).
| Node Role | Primary Responsibility | Best Practice Consideration |
|---|---|---|
| Master Nodes | Cluster state management, stability. | Dedicated set of 3 or 5 nodes. Should not handle data or ingest requests. |
| Data Nodes | Storing data, indexing, searching. | Scale these aggressively based on data volume and load. |
| Ingest Nodes | Pre-processing documents before indexing (using ingest pipelines). | Offload CPU-intensive pre-processing from data nodes. |
| Coordinating Nodes | Handling large search requests, gathering results from data nodes. | Add these when search requests become complex or frequently overload data nodes with coordination overhead. |
Shard Allocation Strategy
Shards are the fundamental unit of distribution and parallelism in Elasticsearch. Poor shard allocation is the number one cause of scaling pain points.
1. Primary Shard Count Optimization
Choosing the right number of primary shards (index.number_of_shards) is critical and cannot be changed easily after index creation (unless using index aliases or reindexing).
- Too Few Shards: Limits parallelism during searches and prevents effective horizontal scaling.
- Too Many Shards: Adds cluster-state overhead, increases memory use, and creates the "small shard" problem where coordination costs dominate useful work.
Best Practice: For many time-series and logging workloads, target shard sizes in the tens of gigabytes, often roughly 10GB to 50GB. Treat this as a starting range, then test with your own indexing rate, retention window, and query pattern.
2. Replica Shards for High Availability and Read Throughput
Replica shards (index.number_of_replicas) provide redundancy and increase read capacity.
- Setting
number_of_replicas: 1means every primary shard has one copy, ensuring high availability (HA). - Increasing replicas can improve read capacity because searches may be served by primary or replica copies, but it also increases storage use and indexing work.
Example of HA Setup:
If you have 10 primary shards and set number_of_replicas: 1, the cluster requires at least 20 total shard copies (10 primary + 10 replica) distributed across nodes.
PUT /my_growing_index
{
"settings": {
"index.number_of_shards": 20,
"index.number_of_replicas": 1
}
}
Preventing Hotspots with Awareness
When adding new nodes, make sure shards are spread across failure domains. Elasticsearch rebalances automatically, but zone or rack awareness only works if you configure node attributes and allocation awareness settings.
Use the Cluster Allocation Explainer API to diagnose why shards might not be moving to new nodes or why a node is overloaded.
Practical Scaling Steps: Handling Growth
When your cluster performance degrades (high JVM heap pressure, slow queries, slow indexing), follow these steps in order:
Step 1: Monitor and Diagnose
Before making changes, diagnose the bottleneck. Common indicators:
- High CPU/Low Free Memory: Indicates compute or memory starvation (potential vertical scale need).
- Excessive Disk Queue Length: Indicates I/O bottleneck (need faster disks or node addition).
- Search Latency Spikes: Often due to insufficient caching or too few shards/replicas (needs more memory or horizontal scale).
Step 2: Address Immediate Resource Needs (Vertical Tweaks)
If memory pressure is high, increase the JVM heap size within safe limits (max 32GB) and ensure adequate RAM is available for the OS filesystem cache.
Step 3: Scale Out (Horizontal Expansion)
If adding nodes, follow this procedure:
- Provision new data nodes with identical or superior hardware.
- Configure them with the correct roles. For capacity growth, this usually means data roles such as
data_hot,data_content, ordatadepending on your deployment. - Point them to the existing cluster using
discovery.seed_hosts. - Once the new nodes join, Elasticsearch will automatically begin rebalancing existing shards to utilize the new capacity.
Step 4: Future-Proofing Indices (Reindexing)
If existing indices have suboptimal shard counts, they cannot fully utilize the new nodes. You must rebuild them:
- Create a new index template or use the Create Index API with the desired number of shards and replicas.
- Use the Reindex API to migrate data from the old, poorly-sized index to the new one.
- Once migration is complete, swap traffic over using an alias.
Example Reindex Command:
POST _reindex
{
"source": {
"index": "old_index_bad_shards"
},
"dest": {
"index": "new_index_optimized_shards"
}
}
Best Practices Checklist
Scaling Elasticsearch works best when you monitor first, change one variable at a time, and keep shard layout aligned with your growth pattern.
Key Takeaways:
- Prioritize Horizontal Scaling: It offers the best path for continuous growth and resilience.
- Dedicated Master Nodes: Keep cluster management stable by separating master roles.
- Shard Sizing is Permanent: Aim for 10GB-50GB primary shard size upon index creation.
- Monitor JVM Heap: Keep heap below the compressed pointer threshold for your JVM and leave enough RAM for the OS cache.
- Use Reindexing: Rebuild crucial indices when scaling out requires a change in the primary shard count.