<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title><![CDATA[Andrei Dan - Elasticsearch Labs]]></title>
    <description><![CDATA[Articles and tutorials from the Search team at Elastic]]></description>
    <copyright><![CDATA[© 2026. Elasticsearch B.V. All Rights Reserved]]></copyright>
    <image>
      <title><![CDATA[Andrei Dan - Elasticsearch Labs]]></title>
      <url>https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt1121c0bf0e8a6e65/6a88da6340a1841030ef456f/search-labs-thumbnail.png</url>
      <link>https://www.elastic.co/search-labs/author/andrei-dan</link>
    </image>
    <link>https://www.elastic.co/search-labs/author/andrei-dan</link>
    <atom:link href="https://www.elastic.co/search-labs/rss/author/andrei-dan.xml" rel="self" type="application/rss+xml"/>
    <language><![CDATA[en]]></language>
    <lastBuildDate>Fri, 18 Sep 2026 17:51:22 GMT</lastBuildDate>
  <item>
    <title><![CDATA[Elasticsearch replicas for load balancing in Serverless]]></title>
    <description><![CDATA[Learn how Elastic Cloud Serverless automatically adjusts index replicas based on search load, ensuring optimal query performance without manual configuration.]]></description>
    <content:encoded><![CDATA[<p>In Elastic Cloud Serverless, we automatically adjust the number of replicas for your indices based on search load, ensuring optimal query performance without any manual configuration. In this blog, we’ll explain how replicas are scaled, when the system adds or removes them, and what this means for your indices.</p><h2>The party is getting crowded</h2><p>You're hosting a pizza party. You've got a few friends helping you serve, each stationed at different spots around the room. You give each friend a pizza, and they start handing out slices to hungry guests as they arrive.</p><p>At first, things run smoothly. A few guests trickle in, your friends serve slices, everyone's happy. But then word spreads about your sourdough pizzas. The doorbell keeps ringing. Guests pour in. Soon, there's a crowd forming around one of your friends, the one holding the pepperoni pizza, which everyone seems to want.</p><p>Your friend with the pepperoni pizza is overwhelmed. Guests are waiting, getting impatient, and a large queue has formed. Meanwhile, your friend holding the margherita pizza is standing around with barely anyone asking for a slice.</p><p>What do you do?</p><p>You order a couple more pepperoni pizzas and hand them to other friends. Now three friends are holding pepperoni instead of one. The crowd spreads out, and suddenly you can serve three times as many guests at once.</p><p>A few things become clear as you host more parties:</p><ul><li><p><strong>Not all pizzas are equally popular.</strong> Some are in high demand, others have fewer takers. You don't need extra "copies" of the unpopular ones. You need extras of the ones with queues.</p></li><li><p><strong>Order more pizzas before the queue gets too long.</strong> If you wait until your friend is completely overwhelmed and guests are leaving angry, you've waited too long. Better to get an extra pizza when you see a crowd forming.</p></li><li><p><strong>Don't throw away pizzas too quickly.</strong> Just because the crowd around the pepperoni thinned out for five minutes doesn't mean the rush is over. Maybe they're just refilling drinks, or even talking among themselves (is that still a thing?). Keep the extra pizzas ready. If the lull continues for a while, then you can put them away.</p></li><li><p><strong>You can only hand out as many pizzas as you have friends who are helping.</strong> If you've only got four friends helping, ten pizzas won’t change the outcome. Only four can be served at once. Match your pizza count to your available hands.</p></li><li><p><strong>When a friend leaves, take their pizza.</strong> If one of your friends needs to head out, grab their pizza immediately. You can't have pizzas sitting unattended. Hand it to someone else, or put it away.</p></li></ul><h2>From pizzas to replicas</h2><p>Let's map this back to Elasticsearch.</p><p>In our analogy, pizzas are replicas (copies of your index shards), your friends helping serve are search nodes, hungry guests are search queries, and that popular pizza with a crowd around it is a hot index with high search load.</p><p>When search traffic increases on a particular index, we create additional replicas and distribute them across your search nodes. Any replica can serve any query for that index, just like any friend holding pepperoni can hand out pepperoni slices. More replicas means higher throughput: Three replicas can handle three times the queries per second of a single replica.</p><h2>Measuring the hunger</h2><p>Before we decide how many pizzas to order, we need to know how hungry the crowd is.</p><p>Elasticsearch tracks the <strong>search load</strong> for every shard. It's a metric that captures how much search activity a shard is handling. We aggregate this across all shards of an index to understand the total search demand.</p><p>What matters most is the <strong>relative search load</strong>: What proportion of your project's total search traffic is hitting each index? If one index is receiving 60% of all searches while another gets 5%, we know where to add capacity.</p><h2>The math behind the pizzas</h2><p>We calculate the optimal number of replicas following this formula:</p>desired_replicas = min(ceil(L × N / (S × X)), N)<p>Where:</p><ul><li><p><strong>L</strong> = the index's relative search load (between 0 and 1).</p></li><li><p><strong>N</strong> = the number of desired search nodes in your project.</p></li><li><p><strong>S</strong> = the number of shards in the index.</p></li><li><p><strong>X</strong> = a threshold to avoid hot spots (default: 0.5).</p></li></ul><p>An example: four search nodes, one index with two primary shards receiving 80% of search traffic:</p>desired_replicas = min(ceil(0.8 × 4 / (2 × 0.5)), 4)
                 = min(4, 4)
                 = 4<p>This hot index gets four replicas distributed across the search nodes.</p><p>The threshold X (defaulting to 0.5) is important. We don't wait until a replica is completely overwhelmed; we scale up when it's at half capacity. Hand out the extra pizza when you see the crowd forming, not when guests are already leaving.</p><h2>Scale up fast, scale down slow</h2><p>When search load increases, we add replicas immediately. No reason to make users wait.</p><p>When search load drops, we wait a bit before taking any action. We need to see consistent low demand for about 30 minutes before reducing replicas. (This is to deal with spiky traffic where a quiet moment doesn't mean the party is over.)</p><p>This matters because adding a replica has a cost. The new replica copies data and warms its caches before serving queries efficiently. Removing replicas too eagerly means constantly paying this startup cost as traffic naturally fluctuates.</p><h2>Respecting topology bounds</h2><p>Replicas can never exceed the number of search nodes. Having more replicas than nodes provides no benefit (you can only serve as many pizzas as you have friends who are helping to serve slices).</p><p>When nodes are removed from your project, we reduce replicas immediately to match. No waiting for the cooldown, as you can't have unassigned replicas. The moment a friend leaves, we remove their pizza.</p><h2>The bigger Serverless picture</h2><p>Replicas for search load balancing works alongside other autoscaling systems:</p><ul><li><p><strong>Search autoscaling</strong> adjusts the number of search nodes (how many friends are helping).</p></li><li><p><strong>Replicas for search load balancing</strong> distribute traffic by adjusting replica counts per index (how many pizzas of each kind we need).</p></li><li><p><strong>Data stream autosharding</strong> optimizes shard counts for writes (how to slice each pizza, covered in the <a href="https://www.elastic.co/search-labs/blog/datastream-autosharding-serverless">previous post</a>).</p></li></ul><p>An important design principle: Replicas for load balancing don't directly trigger search autoscaling. Instead, by distributing search requests across more replicas, it enables increasing resource utilization across your search nodes. This higher utilization then triggers our existing autoscaling logic to add capacity if needed. Replicas for load balancing enables autoscaling to do its job, making sure your search nodes are actually being used, rather than having all traffic bottlenecked on a single replica while other nodes sit idle.</p><h2>What this means for you</h2><p>You don't need to predict which indices will be popular. You don't need to manually adjust replicas when traffic patterns change. You don't need to wake up at 3 a.m. because a surge overwhelmed your busiest index.</p><p>The system watches where queues are forming and orders more pizzas for those spots. Cold indices don't waste resources on unnecessary replicas. Hot indices get the capacity they need. Your budget goes where it matters.</p><h2>Conclusion</h2><p>In the <a href="https://www.elastic.co/search-labs/blog/datastream-autosharding-serverless">autosharding post</a>, we made sure your pizzas are sliced right. Now, with replicas for search load balancing, we make sure you have enough pizzas, in the right hands, when the hungry crowds arrive.</p><p>Try <a href="https://www.elastic.co/cloud/serverless">Elastic Cloud Serverless</a> and let us handle the pizza logistics.</p>]]></content:encoded>
    <link>https://www.elastic.co/search-labs/blog/elasticsearch-replicas-load-balancing-serverless</link>
    <guid isPermaLink="true">https://www.elastic.co/search-labs/blog/elasticsearch-replicas-load-balancing-serverless</guid>
    <category><![CDATA[Elastic Cloud Serverless]]></category>
    <dc:creator><![CDATA[Andrei Dan]]></dc:creator>
    <enclosure url="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blte3b371b70b12b9ef/6a170f240e2e49999441a1de/3c4c1e99b892f026b7aba098973593f8298e2ea6-1280x717.png" length="0" type="image/png"/>
    <pubDate>Tue, 24 Mar 2026 00:00:00 GMT</pubDate>
  </item>
  <item>
    <title><![CDATA[Autosharding of data streams in Elasticsearch Serverless]]></title>
    <description><![CDATA[In Elastic Cloud Serverless we spare our users from the need to fiddle with sharding by automatically configuring the optimal number of shards for data streams based on the indexing load.]]></description>
    <content:encoded><![CDATA[<h2>How Elastic Cloud Serverless autosharding works</h2><ol><li><p><strong>Monitors indexing write load: </strong>Elasticsearch continuously tracks the <code>write_load </code>metric, representing the average number of write threads used for indexing. This metric informs sharding decisions.</p></li><li><p><strong>Calculates optimal shard count: </strong>The system uses a formula that considers the current <code>write_load</code>, the minimum and maximum write threads available per node, to determine the ideal number of shards. This balances performance with overhead.</p></li><li><p><strong>Triggers rollover based on write load:</strong> When the <code>write_load</code> necessitates a shard increase, a rollover operation is triggered. This creates a new index in the data stream with the calculated optimal number of shards. Regular rollover conditions (like shard size) also trigger rollovers, potentially leading to shard reduction if the <code>write_load</code> is lower.</p></li><li><p><strong>Applies cooldown periods: </strong>To prevent rapid shard adjustments, cooldown periods are enforced. There's a 4.5-minute wait before increasing shards and a 3-day wait before reducing them.</p></li><li><p><strong>Autoscaling integration: </strong>Autosharding works in conjunction with autoscaling. By dynamically adjusting shard counts, autosharding enables autoscaling to more effectively increase resources as needed, preventing the system from being constrained at low capacity during high indexing workloads. It also enables autoscaling to more effectively increase resources as needed, preventing the system from being constrained at low capacity during high indexing workloads.</p></li></ol><h2>Background</h2><p>Traditionally, users change the sharding configuration of data streams in order to deal with various workloads and make the best use of the available resources. In <a href="https://www.elastic.co/docs/current/serverless">Elastic Cloud Serverless</a> we've introduced autosharding of data streams, enabling them to be managed and scaled automatically based on indexing load. </p><p>This post explores the mechanics of autosharding, its benefits, and its implications for users dealing with variable workloads. The autosharding philosophy is to increase the number of shards aggressively and reduce them very conservatively, such that an increase in shards is not followed prematurely by a reduction of shards due to a small period of reduced workload.</p><h2>Autosharding of data streams in Serverless Elasticsearch</h2><p>Imagine you have a large pizza that needs to be shared among your friends at a party. If you cut the pizza into only two slices for a group of six friends, each slice will need to serve multiple people. This will create a bottleneck, where one person hogs a whole slice while others wait, leading to a slow sharing process. Additionally, not everyone can enjoy the pizza at the same time; you can practically hear the sighs from the friends left waiting. If more friends show up unexpectedly, you’ll struggle to feed them with just two slices and find yourself scrambling to reshape those slices on the spot.</p><p>On the other hand, if you cut the pizza into 36 tiny slices for those same six friends, managing the sharing becomes tricky. Instead of enjoying the pizza, everyone spends more time figuring out how to grab their tiny portions. If the slices are too small, the pizza might even fall apart.</p><p>To ensure everyone enjoys the pizza efficiently, you’d aim to cut it into a number of slices that matches the number of friends. If you have six friends, cutting the pizza into 6 or 12 slices allows everyone to grab a slice without long waits. By finding the right balance in slicing your pizza, you’ll keep the party running smoothly and everyone happy.</p><p>You know it’s a good analogy when you immediately follow-up with the explanation; the pizza represents the data, the slices represent the index shards, and the friends are the Elasticsearch nodes in your cluster.</p><p>Traditionally, users of Elasticsearch had to anticipate their indexing throughput and manually configure the number of shards for each <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/data-streams.html">data stream</a>. This approach relied heavily on predictive heuristics and required ongoing adjustments based on workload characteristics whilst also balancing <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/size-your-shards.html">data storage, search analytics, and application performance</a>.</p><p>Businesses with seasonal traffic, like retail, often deal with spikes in data demands, while IoT applications can experience rapid load increases at specific times. Development and testing environments typically run only a few hours a week, making fixed shard configurations inefficient. New applications might struggle to estimate workload needs accurately, leading to potential over- or under-provisioning.</p><p>We've introduced autosharding of data streams in <a href="https://www.elastic.co/docs/current/serverless">Elastic Cloud Serverless</a>. Data streams in <a href="https://www.elastic.co/docs/current/serverless">Serverless</a> are managed and scaled automatically based on indexing load - automatically slicing your pizza as friends arrive to your party or finish eating.</p><h2>The promise of autosharding</h2><p>Autosharding addresses these challenges by automatically adjusting the number of shards in response to the current indexing load. This means that instead of users having to manually tweak configurations, Elasticsearch will dynamically manage shard counts for the data streams in your project based on real-time data traffic.</p><p>Elasticsearch keeps track of the indexing load for every index as part of a metric named write load, and exposes it for on-prem and ESS deployments as part of the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-stats.html">index stats API</a> under the indexing section.</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltbf8a17014280842a/6a170cf55091687333e1bb3e/b83c902ebadc04d7e0e0a794b6b2ec925b0f4cb4-1200x1600.png" alt="Autosharding in Elasticesarch:  indexing load " /><p>The <code>write_load</code> represents the average number of write threads used while indexing documents.</p><p>For an index with one shard the maximum possible value of the <code>write_load</code> metric is the number of write threads available (e.g. all write threads are busy writing in the same shard).</p><p>For indices with multiple shards the maximum possible value for the write load is the number of write threads available in a node times the number of indexing nodes in the project. (e.g. all write threads on all the indexing nodes that host a shard for our index are busy writing in the shards belonging to our index, exclusively)</p><p>To get a sense of the values allowed for <code>write_load</code> let’s look at index <code>logs</code> with one shard running on one Elasticsearch machine with 2 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-threadpool.html#node.processors%60">allocated processors.</a> The <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-threadpool.html">write thread pool</a> will be sized to 2 threads. This means that if this Elasticsearch node is exclusively and constantly writing to the same index <code>logs</code>, the <code>write_load</code> we’ll report for index <code>logs</code> will be <strong>2.0</strong> (i.e. 2 write threads fully utilized for writing into index <code>logs</code>).</p><p>If <code>logs</code> has 2 primary shards and we’re now running on two Elasticsearch nodes, each with 2 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-threadpool.html#node.processors">allocated processors</a> we’ll be able to get a maximum reported <code>write_load</code> of <strong>4.0 </strong>if all write threads on both Elasticsearch nodes are exclusively writing into the <code>logs</code> index.</p><h3>Serverless autoscaling</h3><p>We just looked at how the write load capacity doubled when we increased the number of shards and Elasticsearch nodes. <a href="https://www.elastic.co/docs/current/serverless">Elastic Cloud Serverless</a> takes care automatically of both these operations using data stream autosharding and <a href="https://www.elastic.co/search-labs/blog/elasticsearch-ingest-autoscaling">ingest autoscaling</a>. Autoscaling refers to the process of dynamically adjusting resources - like memory, CPU, and disk - based on current demands.</p><p>In our serverless architecture, we start with a small 2GB memory server and use a step-function scaling approach to increase capacity efficiently. We scale up memory incrementally and then scale out by adding servers. This cycle continues, increasing memory per server incrementally up to 64GB while managing the number of servers.</p><h4>Linking autoscaling and autosharding</h4><p>The connection between auto<strong>scaling</strong> and auto<strong>sharding</strong> is essential for optimizing performance. When calculating the optimal number of shards for a data stream, we consider the minimum and maximum number of available write threads per node in our scaling setup.</p><ul><li><p>For small projects, the system will move from 1 to 2 shards when the data stream uses more than half the capacity of a node (i.e., more than one indexing thread).</p></li><li><p>For medium-sized projects, as the system scales across multiple nodes, it will not exceed 3 shards to avoid excessive overhead.</p></li><li><p>Once we reach the largest node sizes, further sharding is enabled to accommodate larger workloads.</p></li></ul><p>Autosharding also enables autoscaling to increase resources as needed, preventing the system from staying at low capacity during high indexing workloads, by enabling projects to reach higher ingestion load values.</p><h3>Auto sharding formula</h3><p>To determine the number of shards needed, we use the following formula:</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt93cb63543b31d1b3/6a170cf660084b4d273c45c4/2185640ab125aaf4cd300fbaff74b3d83cf0de31-667x275.png" alt="Autosharding formula in Elasticsearch" /><p>This equation balances the need for increasing shards based on <code>write_load</code> while capping the number of shards to prevent oversharding. The division by 2 reflects the strategy of increasing shards only after exceeding half the capacity of a node. The min/max write threads represent the minimum and maximum number of write threads available in the autoscaling step function (i.e. the number of write threads available on the smallest 2GB step and the number of write threads available on the largest server)</p><p>Let’s visualize the output of the formula:</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltd5ebade9321a608b/6a170cf8ab7f085179db9ef7/ca928d959397c42a57311a91269d5418e983609a-1600x986.png" alt="Output of autosharding formula formula in Elasticsearch" /><p>On the Y axis we have the <strong>number of shards</strong>. And on the X axis we have the<strong> write load</strong>. We start with 1 shard and we get to 3 shards when the write load is just over 3.0. We remain with 3 shards for quite some time until the write load is about 48.0.</p><p>This covers us for the time we scale up through the nodes but haven’t really got to 2 or more or the largest servers, at which point we unlock auto sharding to more than 3 shards, as many as needed to ingest data.</p><p>While adding shards can improve indexing performance, excessive sharding in an Elasticsearch cluster can have negative repercussions - imagine that pizza with 56 slices being shared by only 7 friends. Each shard carries overhead costs, including maintenance and resource allocation. Our algorithm accounts for and avoids the peril of excessive sharding until we get to the largest workloads where adding more than 3 shards makes a material difference to indexing performance and throughput.</p><h3>Implementing autosharding with rollovers</h3><p>The implementation of autosharding relies on the concept of <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-rollover-index.html">rollover</a>. A rollover operation creates a new index within the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/data-streams.html">data stream</a>, promoting it to the write index while designating the previous index as a regular backing index, which no longer accepts writes. This transition can occur based on specific conditions, such as exceeding a shard size of 50GB. We take care of configuring the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/data-stream-lifecycle-settings.html#_cluster_level_settings_3">optimal rollover conditions</a> for data streams in <a href="https://www.elastic.co/docs/current/serverless">Serverless</a>.</p><p>In <a href="https://www.elastic.co/docs/current/serverless">Serverless</a> alongside the usual rollover conditions that relate to maintaining healthy indices and shards we introduce a new condition that evaluates whether the current write load necessitates an increase in shard count. If this condition is met, a rollover will be triggered and the new resulting data stream <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/data-streams.html#data-stream-write-index">write index</a> will be configured with the optimal number of shards.</p><p>For downscaling, the system will monitor the workload and will not trigger a rollover solely for reducing shards. Instead, it will wait until a regular rollover condition, like the primary shard size, triggers the rollover. The resulting write index will be configured with a lower number of shards.</p><h3>Cooldown periods for shard adjustments</h3><p>To ensure stability during shard adjustments, we implement cooldown periods:</p><ul><li><p><strong>Increase shards cooldown</strong>: A minimum wait time of 4.5 minutes is enforced before increasing the number of shards since the last adjustment. The 4.5 minutes cooldown might seem peculiar but the interval has been chosen to make sure we <strong>can </strong>increase the number of shards every time <a href="https://www.elastic.co/search-labs/blog/data-lifecycle-simplified-for-data-streams">data stream lifecycle</a> checks if data streams should rollover (currently, every 5 minutes) but not more often than 5 minutes, covering for internal Elasticsearch cluster reconfiguration.</p></li><li><p><strong>Decrease shards cooldown</strong>: We maintain a 3-day minimum wait time before reducing shards to ensure that the decision is based on sustained workload patterns rather than temporary fluctuations.</p></li></ul><h2>Conclusion</h2><p>The data streams autosharding feature in <a href="https://www.elastic.co/docs/current/serverless">Serverless</a> Elasticsearch represents significant progress in managing data streams effectively. By automatically adjusting shard counts based on real-time indexing loads, this feature simplifies operations and enhances scalability.</p><p>With the added benefits of <a href="https://www.elastic.co/search-labs/blog/elasticsearch-ingest-autoscaling">autoscaling</a>, users can expect a more efficient and responsive experience, whether they are handling small projects or large-scale applications. As data workloads continue to evolve, the adaptability provided by auto sharding ensures that Elasticsearch remains a robust solution for managing diverse indexing needs.</p><p>Try out our <a href="https://www.elastic.co/docs/current/serverless">Serverless</a> Elasticsearch offering to take advantage of data streams auto sharding and observe the indexing throughput scaling seamlessly as your data ingestion load increases.</p><p>Your pizzas will be optimally sliced as more friends arrive at your party, keen to try those sourdough craft pizzas you prepared for them.</p>]]></content:encoded>
    <link>https://www.elastic.co/search-labs/blog/datastream-autosharding-serverless</link>
    <guid isPermaLink="true">https://www.elastic.co/search-labs/blog/datastream-autosharding-serverless</guid>
    <category><![CDATA[Elastic Cloud Serverless]]></category>
    <dc:creator><![CDATA[Andrei Dan]]></dc:creator>
    <enclosure url="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt84da396c370b06ec/6a170cfa6234e00dd3db1a55/d92e2e9fbae1dca1f18e623b2f5eb2a835307130-1600x1066.jpg" length="0" type="image/jpeg"/>
    <pubDate>Tue, 10 Dec 2024 00:00:00 GMT</pubDate>
  </item>
  </channel>
</rss>