When sharding Prometheus scrape targets is the right fix
Sharding is the right fix when one Prometheus server cannot keep up with the number of scrape targets or the volume of series it has to ingest, and the server's CPU, memory or scrape duration shows that load is the cause. Before you split anything, confirm which of three problems you have. If the server is slow to scrape because too many targets share one process, sharding spreads the scrape work. If it is running out of memory because of high series counts from a few noisy jobs, splitting by function or reducing cardinality may help more. If the real need is a single query view across many servers or keeping data longer than one server's disk allows, you need long-term storage, which is a different decision from sharding.
Sharding means running several Prometheus servers, each scraping a deterministic subset of the same target list. In open-source Prometheus this is usually done with hashmod relabeling on the __address__ label, where each server keeps only the targets whose hash modulo the shard count equals its own shard number. Each shard then stores only the series it scraped. The storage docs describe local storage as not clustered or replicated and to be managed like any other single-node database, so the shards do not share data and no server holds the full picture. Any query that spans shards, and any alert rule that depends on series from more than one shard, has to be designed for that split. A shard that fails takes its targets with it until it is restored, so you also need to decide whether each shard gets a standby.
Sharding is not the answer when the workload is a few very large series sets, when the problem is one expensive metric, or when you want a single global query view without extra components. Splitting does not reduce the cardinality of a single job, and it multiplies the number of servers you must back up, upgrade and watch. Before committing, ask your team to measure active series per server, scrape duration, and the rule evaluation and query load on the current server, and to write down which alerts and dashboards would need to query more than one shard. Confirm these numbers with your own environment, because a sizing exercise on your metrics will say more than a general rule.
Sharding configuration options and when each fits
This table compares the main sharding choices for splitting scrape targets across Prometheus servers, from the hashing inputs and modulus to Operator-managed shards and site placement. Read each row for the condition that makes the option fit and the trade-off it brings, then confirm exact configuration key behavior against the Prometheus documentation for your version.
| Option | What it controls | When it fits | Trade-off to weigh |
|---|---|---|---|
| Number of shards | How many Prometheus servers share the scrape load, each owning a slice of targets | One server is consistently short on CPU, memory or scrape time, and series growth is spread across many jobs | Each shard adds a server to run, patch, back up and alert on, and queries must now reach every shard |
| Source labels hashed with hashmod | The label values (often __address__) that feed the hash deciding which shard owns each target | Targets are numerous and similar, so a stable hash spreads them evenly without manual assignment | Adding or removing a shard changes ownership for many targets at once, and uneven target sizes can still load one shard heavily |
| Modulus and shard index per server | The modulus equals the shard count, and each server keeps only the hash result that matches its index | You want deterministic ownership that a configuration management tool can generate for each server | Changing the modulus later reshuffles targets, so plan the count before the estate grows and test the change on staging |
| Operator shards setting | The Prometheus Operator's shard count on a Prometheus resource, which it uses to split scrape work for you | The estate runs on Kubernetes with the Operator and you want the Operator to manage relabeling and scaling | You depend on the Operator's behavior and release cycle, and you must confirm how the version you run handles shards and any related fields |
| Manual target assignment by job or team | Which jobs or owners land on which server, set by hand in separate configuration files | Teams own distinct services, or targets have very different scrape intervals or sizes | Balance drifts as services change, so someone must review load per server regularly |
| Shards in the same site | Shards run in one network zone, close to targets and to the query and alerting path | Latency to targets is low, and the goal is to relieve load rather than to isolate failure domains | A site outage stops every shard, so pair shards with replicas or a global query layer for resilience |
| Shards across sites | Each site runs its own shard set, scraping only local targets | Data residency, network boundaries or wide-area latency keep metrics close to where they are produced | Cross-site queries and alerts need a federated or remote storage design, and each site adds operating effort |
| Pairing shards with Thanos or remote storage | Each shard keeps local data for short retention and forwards or uploads samples for one global view | Queries and long retention must span every shard without a single overloaded server | Adds object storage, sidecars or receivers to run, and the query layer must deduplicate series that overlap across shards |
How to set up sharded Prometheus servers step by step
This sequence takes a single overloaded Prometheus to a set of shards that each own a fixed slice of targets, with identical rules and a check that every target is scraped exactly once. Each step ends with a check you can run before moving on.
Measure the bottleneck before splitting
Confirm which limit the current server is hitting: ingestion rate, active series count, memory use, or query load. Read the server's own metrics for scrape duration, head series and memory, and check whether remote write is falling behind if you use it. Sharding only helps when the pressure comes from the number of targets or series a single server must scrape, so if memory is driven by expensive queries or high label churn, fix those first. Done when you have a written baseline per metric and a clear reason to split, which you can compare against the same metrics after the change.
Choose a stable shard key
Pick a label or target attribute that is present on every target and spreads load evenly, such as the target address or a hash of it. Ask the platform team which labels are reliable across your service discovery sources, and avoid keys that change when a pod restarts or a host is renamed, because a changing key moves targets between shards and breaks continuity of series. Record the shard count you intend to run. Done when you can state the key, the number of shards, and the expected behavior when a target disappears.
Write hashmod relabel rules for each shard
In each shard's configuration, add a
hashmodaction on the chosen key with the shard count as the modulus, then akeepaction that retains only the shard's own remainder. Use the same source labels and modulus on every shard, and change only the remainder value. Keep these rules in the scrape job'srelabel_configsso they run before scraping. Done when you can dry-run the rules against a sample list of targets and see each target assigned to exactly one remainder.Deploy shards with identical rules and alerts
Deploy each shard from the same configuration source, with the same recording rules, alerting rules, external labels that identify the shard, and scrape settings. Only the shard index and its remainder should differ. Give each shard a distinct external label so that downstream queries and alerts can tell which server produced a series. Confirm the rule files load without errors on every shard. Done when the configuration diff between shards is limited to the shard identifier and remainder, and each server reports its rule groups as loaded.
Verify each target is scraped by exactly one shard
Compare the target lists from all shards in the Prometheus targets view or API, then check that the union equals the full target inventory from service discovery. Count targets per shard and confirm that no target appears on two shards and none is missing. Confirm that the
upmetric exists with a value for every target on the shard that owns it. Repeat this check after any change to the target inventory. Done when the counts sum to the full inventory and no target is reported by two shards.Confirm alerts and queries work across shards
Because each shard only holds its own series, an alert that depends on targets from several shards needs a global view, either through a query layer over all shards or by moving that rule to a server that can see the data. Test one alert on each shard by stopping a test target and confirming the alert fires on the owning shard only. Check that dashboards that combine shards return complete results. Done when each alert rule has a named shard or query layer that evaluates it, and a test firing has been observed.
Pair shards with long-term storage or a query layer
Decide how users query across shards before production use. Options include Thanos with a Querier across sidecars, Grafana Mimir, VictoriaMetrics, or remote write to a shared store. Each option changes how the external labels from the previous step are used, and each adds operating effort. Ask the vendor or project docs to confirm the exact configuration for your version. Done when one option is chosen, a test query returns series from every shard, and the team knows who operates the query layer.
Monitor the shards and rehearse a target move
Add alerts for the
upmetric dropping on any shard, for scrape failures, and for a shard that stops reporting. Then test a target reassignment in a non-production environment by changing the shard count or removing a target, and confirm the series move as expected with no duplicates. Document the procedure for adding a shard, since changing the modulus reshuffles targets and will create a gap in data for moved series. Done when the monitoring alerts fire in the test and the reassignment runbook has been walked through once.
How queries and alerts behave when metrics live on several shards
Each shard only holds the series its own Prometheus scraped, so a PromQL query sent to one shard returns a partial view of the estate. A query for total request rate across a service, for example, will undercount if its instances are split between shards, and nothing in the result tells the reader that series are missing. Before sharding, decide how global queries will be answered. The usual options are a federation layer, a remote storage backend that receives every shard's samples, or Thanos, which queries across shards at read time. Each option changes where the global view lives and what it costs to run, so pick one before the shards go live rather than discovering the gap during an incident.
Alert rules behave the same way. A rule evaluated on one shard only sees that shard's series, so an alert that compares services across shards, or that depends on a metric scraped elsewhere, can stay silent when it should fire. The reverse also happens: when two shards both evaluate the same rule, or a replicated pair both fire, the same problem arrives as duplicate notifications. Review every rule for its data dependencies and move cross-shard conditions to a layer that sees all the series. Alertmanager should receive alerts from every Prometheus instance, as its documentation describes, so each shard should list every Alertmanager in its configuration rather than sitting behind a load balancer. Confirm in a test environment that a deliberately broken target on one shard produces exactly one notification with the expected labels.
Security and operational risks of a sharded Prometheus estate
Each shard is a separate Prometheus server with its own web UI, API, credentials and configuration, so a sharded estate multiplies the attack surface and the places where things can drift. The cards below cover the risks that tend to appear first and what to check on each shard before the estate goes live.
Exposed web UI and API
Prometheus has no built-in single sign-on and no built-in CSRF protection on mutating endpoints, so each shard's web UI and API depend on whatever sits in front of them. Put an authenticating reverse proxy in front of every shard, and terminate TLS there or on the server. Basic authentication sends credentials in cleartext unless TLS is in use, so confirm that TLS is enforced on every shard endpoint, that TLS 1.2 is the minimum, and that no shard is reachable directly from a user network.
Security model docsAdmin APIs and lifecycle flags
Admin HTTP APIs are disabled by default, but the --web.enable-admin-api flag enables destructive operations and --web.enable-lifecycle enables reload and shutdown endpoints. Teams often enable these on one shard during troubleshooting and forget the others, so each shard can behave differently. Audit the startup flags of every shard, keep both flags off unless a documented task needs them, and restrict any enabled endpoint to the automation account that uses it.
SSRF through exporter targets
Exporters such as SNMP and Blackbox take their targets from URL parameters. The Prometheus security model warns that anyone with HTTP access to these exporters can make them send requests to arbitrary endpoints. In a sharded estate, each shard may run its own exporters, so each one is a potential request forwarder inside your network. Restrict which hosts can reach each exporter, limit the targets it may probe, and record which scrape jobs supply those parameters.
Secrets and certificate sprawl
Every shard needs its own basic auth hashes, TLS certificates, client certificates and remote write credentials, and each one has an expiry date and an owner. Multiplied across shards, these items are easy to lose track of and hard to rotate on schedule. Keep a single inventory of every credential per shard, store the bcrypt-hashed passwords and keys in a managed secret store, and set rotation dates that cover all shards together rather than one at a time.
Alert routing gaps on shard failure
Each shard evaluates its own alert rules, so when a shard stops scraping or crashes, the alerts it would have raised disappear without a notification. Alertmanager can run as a cluster for high availability, and Prometheus should point at every Alertmanager instance. Confirm that a watchdog alert from every shard reaches a receiver outside the estate, that someone is paged when that watchdog stops, and that shard down conditions are alerted independently of the shard itself.
Configuration drift between shards
Shards that were configured by hand at different times tend to diverge in scrape intervals, relabeling rules, retention settings and the flags listed above. Drift can also hide a security problem, such as one shard that still accepts unauthenticated requests. Keep the configuration for all shards in version control, generate each shard's file from the same template with only the shard number changed, and run a periodic comparison of the running configuration and flags against that source.
Questions teams ask before sharding Prometheus
Can our own team shard Prometheus without a partner?
Yes, many teams do, provided they have someone who understands PromQL, relabeling and how their scrape configuration is generated. Sharding itself is a configuration pattern: each Prometheus server scrapes a subset of targets, usually selected with a hashmod relabeling rule on the target address, and the rest of the estate is unchanged. The harder part is everything around it: which shard owns which job, how dashboards and alerts reach series that now sit on several servers, and how a shard failure is noticed. A partner is most useful when the team has no spare capacity to design and verify that layer, or when the estate spans Kubernetes, multiple sites and a query layer at once.
What makes the sharding effort larger or smaller?
The main drivers are the number of targets and series per shard, how many rule groups and alerts depend on series that will now be split across servers, whether targets come from Kubernetes service discovery or a static list, and what query layer sits on top. A small estate with static targets and one Grafana data source is a contained change. A large estate with cross-job alert rules, several clusters and a global query requirement involves more design, more testing of alert behavior and more change control. Ask any provider to break its quote down along these lines rather than giving a single number.
What skills does the team need to run a sharded setup?
The team needs working knowledge of PromQL, because queries that aggregate across all targets will return partial results once series are split, and of relabeling, because the hashmod rule and the keep rules that go with it decide which shard scrapes each target. Configuration should live in version control and be rendered or reviewed like code, since a single mistyped modulus can silently drop or duplicate targets. Engineers also need to read the Prometheus runtime and target status pages to confirm that every target is scraped exactly once across the shard set.
How long does planning and verification usually take?
Duration depends on the same drivers as cost: estate size, the number of alert rules and dashboards that must keep working, and how many environments need to be validated before production. Planning usually covers an inventory of targets and series, a shard layout, an alert and dashboard review and a rollback plan. Verification means checking that each target appears on exactly one shard, that alert rules evaluate against the expected series and that queries return complete results. Ask for the planned phases and the acceptance checks in writing, then compare them against your change calendar. The fixed-scope agreement sets these timelines before work begins.
Should we pair sharding with Thanos, Mimir or remote storage?
Sharding splits scraping across servers, but it does not give you one query endpoint or long-term retention. Each shard still keeps its own local data, and the local storage documentation notes that it is not clustered or replicated. Teams that need a single global view or retention beyond a local server typically add a long-term store fed by remote write, or a query layer that reads across shards. Choosing between Thanos, Grafana Mimir, VictoriaMetrics or a plain remote write target depends on your operating model and on how much of the estate needs a global query path. Decide this before the shard layout is finalized, because it changes where the query and alerting logic lives.
What does a fixed-scope sharding engagement cover?
A fixed-scope engagement covers the agreed deliverables in writing before work starts, which for sharding typically include the target inventory and shard design, the Prometheus configuration changes as code, the alert and dashboard review for cross-shard behavior, verification checks and handover documentation. Items that are often outside a sharding scope include changes to exporters, application instrumentation, new alert receivers and the long-term storage platform itself unless it is named in the scope. Ask for the scope list, the exclusions, the acceptance checks and the handover items, and confirm how ongoing upgrades or support would be handled after the work ends.
What should we ask for in a sharding quote?
Ask for a breakdown of the work into discovery, design, implementation, verification and handover, with the effort for each. Ask which environments are in scope, how many targets, jobs and alert rules are assumed, whether Kubernetes and the query layer are included, and what the team must provide, such as access, configuration repositories and a change window. Also ask what is one-time and what recurs, for example support or a retainer for upgrades, and how rollback is handled. Any figure you receive should trace back to these assumptions so you can see what would change the price.
Limits to confirm in your environment before you shard
Sharding changes how targets, series, alerts and retention are divided, so a few facts about your current setup decide whether the split is worth making. The six checks below cover the version you run, how your targets are discovered, the load each shard will carry, where rules live, how disk fills, and how a global view will be built.
Current version and support window
Confirm which Prometheus minor release you run and whether it still receives bug fixes. The release cycle page says a minor release generally stops receiving bug fixes after six weeks, and long-term support lines get fixes for one year. Sharding multiplies the number of servers you must upgrade, so an unsupported version on every shard is a risk to settle before the split. Check the release notes for the version you plan to move to.
- Minor release window
- 6 weeks
Target discovery supports the relabel approach
Hashmod sharding works by hashing a label such as the target address in relabeling, then keeping only the targets whose hash matches each shard's number. Confirm that your service discovery exposes the labels you want to hash and that every shard's configuration is generated from the same source. If targets are created and removed often, confirm that each shard keeps the same assignment after changes, or that you accept targets moving between servers.
Cardinality and churn per shard
Sharding divides targets, not series, so one noisy job can still overload a single shard. Measure active series and series churn for each job before choosing the split, and confirm which shard receives the highest-cardinality exporters. Ask whether any target produces labels that change on every deploy, because those labels increase head series even when the target count is small.
Alert and recording rule placement
Each shard evaluates only the series it scrapes, so an alert that compares metrics from two shards cannot run on either one alone. Confirm which alert and recording rules need series from several jobs, and decide whether they run on a central Prometheus, in Thanos Ruler, or in another place that can query all shards. Also confirm which Alertmanager receives alerts from each shard, so duplicate pages and missing routes are caught before go-live.
Retention per shard against disk
Each shard stores its own local time series database, and local storage is not clustered or replicated. Confirm the disk size, retention setting and expected ingestion for every shard separately, not as one pooled figure. The storage docs describe how disk use follows from ingestion rate and retention. Check that each shard can keep its data for the period your queries and alerts need.
- Default retention
- 15 days
Thanos or remote write configuration
A global query view across shards needs a plan for how their data is combined. Confirm whether you will use Thanos sidecars and a Querier, or send samples with remote write to a long-term store, and who owns the object storage or receiver. Confirm how external labels identify each shard, because duplicate or unlabeled series make global queries hard to read. Decide before the split whether this setup is required or only planned for later.
Pairing sharding with Thanos or remote storage
Sharding solves scrape capacity, while long-term storage and global queries solve retention and cross-shard views. Each shard is an ordinary Prometheus server with its own scrape load and its own local storage, so splitting targets lets each server keep up with its share of series. It does not, by itself, give you a single place to query all metrics, keep data beyond the local retention window, or see one alert picture across shards. Those needs are usually handled by a second layer, and the two are often combined.
The second layer is usually remote write. Prometheus can send samples to an external system through the remote write protocol, and it can read back through remote read. The storage docs are explicit that local storage is not clustered or replicated and should be managed like any other single-node database, so a shard does not replicate its neighbors and losing a shard's disk loses that shard's local history. Confirm which samples each shard forwards, whether the receiver deduplicates data from paired servers, and how a failed shard is detected and replaced before you decide whether remote storage is a backup or the primary copy.
Several sibling topics cover the receiving side in detail: a Thanos setup that adds a sidecar, querier and object storage, a Grafana Mimir cluster that accepts remote write with tenant headers, and VictoriaMetrics used as remote storage while Prometheus keeps scraping and alerting. Choose among them by the query and operating model your teams need, not by the sharding layout alone. Whichever you pick, verify three things in a test environment: that the same metric name and labels reach the long-term store from every shard, that rule evaluation and alerting stay on the Prometheus servers or move deliberately, and that queries spanning shards return the same results they would from a single server. Record the shard label scheme as well, because it determines how series are deduplicated and how you find the shard that owns a target.
How DeployOpen scopes, delivers and supports Prometheus sharding
DeployOpen approaches sharding Prometheus scrape targets as a scoped engagement: first confirming why one server cannot keep up, then designing the shard layout, the query and alerting path across shards, and the storage pairing. Work runs inside infrastructure you control, with the written scope agreed before any change is made to your servers.
How we scope
- The written scope lists the target inventory, the shard count, and the Prometheus servers that will carry each shard.
- We confirm how queries and alert rules will reach series that now live on several servers before any split begins.
- The scope names the long-term storage pairing, such as Thanos, Grafana Mimir or VictoriaMetrics, or states that none is included.
How we build
- We write the hashmod relabeling rules or Operator shard settings, then test that every target lands on exactly one shard.
- We check that each shard keeps its own alerting and that duplicate or missing series are caught before cutover.
- We run the sharded layout in a staging copy of your scrape configuration and record the load on each server before production changes.
How we hand over
- You receive the relabeling or Operator configuration as versioned files, with a note on how each shard was assigned.
- The handover documents the query path, the alert routing, and the steps to add a shard or move a target between shards.
- Your team runs a walkthrough of the failure cases, including what happens when one shard server stops scraping.
How we support
- Engagements are fixed-scope, and ongoing support, upgrades and continuous testing are available as a retainer.
- Retainer work can cover Prometheus version upgrades, shard rebalancing as the target count grows, and retesting after changes.
- Ask any partner to confirm in writing who owns on-call response, upgrade windows and the evidence you will receive after each change.

