This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: prom3-otlp-ingestion-sharding-backpressure

Prometheus 3.0 Native OTLP Sharded Backpressure and TSDB Ingestion Boundary

Establishes a resilient boundary for Prometheus 3.0 native OTLP ingestion under high-cardinality multi-cluster surges. Mandates consistent metric series-affinity sharding, explicit upstream backpressure propagation (gRPC ResourceExhausted/HTTP 429), and strict TSDB out-of-order ingestion alignment to eliminate Head-of-Line WAL blocking and out-of-order sample eviction.

Prohibited Anti-Pattern: Unpartitioned direct OTLP stream dumping into Prometheus 3.0 endpoints, triggering Head chunk lock contention, out-of-order drops, and WAL write stalls.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Prometheus 3.0 Native OTLP Sharded Backpressure and TSDB Ingestion Boundary - Establishes a resilient boundary for Prometheus 3.0 native OTLP ingestion under high-cardinality multi-cluster surges. Mandates consistent metric series-affinity sharding, explicit upstream backpressure propagation (gRPC ResourceExhausted/HTTP 429), and strict TSDB out-of-order ingestion alignment to eliminate Head-of-Line WAL blocking and out-of-order sample eviction.
globs: src/telemetry/**/*.ts, src/gateway/**/*.ts, deploy/k8s/**/*.yaml, config/prometheus/**/*.yml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/prom3-otlp-ingestion-sharding-backpressure"
---

# Prometheus 3.0 Native OTLP Sharded Backpressure and TSDB Ingestion Boundary

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unpartitioned direct OTLP stream dumping into Prometheus 3.0 endpoints, triggering Head chunk lock contention, out-of-order drops, and WAL write stalls.

## System Constraints
You are a Principal Telemetry & TSDB Architect enforcing Prometheus 3.0 Native OTLP Ingestion boundaries. You must reject raw unpartitioned ingestion topologies, enforce strict series-affinity sharding before OTLP reaches TSDB Head chunks, mandate gRPC/HTTP backpressure propagation (ResourceExhausted/429), and ensure out-of-order timestamp windows match boundary buffer capabilities to prevent Head-of-Line WAL stalls.

## Strict Guidelines
- Engineers MUST ALWAYS route OTLP metrics through an affinity-sharding gateway using consistent hashing on series fingerprints (metric name + sorted normalized label pairs) to prevent split-brain chunk allocation across Prometheus replicas.
- Engineers MUST propagate downstream TSDB backpressure immediately to callers using standard gRPC Status 8 (RESOURCE_EXHAUSTED) or HTTP 429 (Too Many Requests) with explicit 'Retry-After' jitter intervals, NEVER silently dropping or unbounded queuing in memory.
- Services MUST explicitly configure Prometheus 3.0 with '--storage.tsdb.out-of-order-time-window' tuned strictly to the ingestion edge buffer's maximum clock skew and transit latency; samples arriving outside this window MUST trigger alertable gateway rejections.
- Engineers MUST enforce strict maximum batch size and message size limits (e.g., maximum 2MB per uncompressed OTLP payload) and mandate zstd or gzip decompression validation prior to TSDB parsing.
- Components NEVER bypass the sharding boundary with direct multi-cluster ingress routing straight to Prometheus stateful pods without concurrency and semaphore controls.

## Bad vs Good Implementations
### OTLP Ingestion Gateway Sharder & Backpressure Boundary

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Round-robin distribution of raw metric batches sends data points for identical series to different Prometheus instances, breaking series locality, causing out-of-order timestamp collisions, TSDB chunk contention, and memory exhaustion under burst traffic without upstream backpressure.
```typescript
// BAD: Direct unbuffered round-robin forwarding of OTLP payloads without series
// hashing or backpressure signaling, causing TSDB lock contention and dropped samples.
import { Request, Response } from 'express';
import axios from 'axios';

const PROMETHEUS_TARGETS = ['http://prom-1:9090', 'http://prom-2:9090'];
let counter = 0;

export async function handleOtlpMetrics(req: Request, res: Response): Promise<void> {
  const target = PROMETHEUS_TARGETS[counter++ % PROMETHEUS_TARGETS.length];
  try {
    // Bypasses fingerprinting; arbitrarily splits series across instances
    // Holds unbounded memory during massive telemetry spikes
    await axios.post(`${target}/api/v1/otlp/v1/metrics`, req.body, {
      headers: { 'Content-Type': req.headers['content-type'] || 'application/x-protobuf' },
      timeout: 30000,
    });
    res.status(200).send({ status: 'success' });
  } catch (err: any) {
    // Masks TSDB out-of-order or WAL lock errors with a generic 500
    res.status(500).send({ error: 'Internal ingestion error' });
  }
}
```

#### Production Standard (Correct)
> **Standard**: Implements deterministic series-affinity shard selection, restricts payload bounds, tracks shard concurrency semaphores, and propagates 429/RESOURCE_EXHAUSTED responses with Retry-After headers to prevent WAL write queue exhaustion.
```typescript
// GOOD: Partitioned series-affinity hashing with deterministic backpressure
// signaling (HTTP 429 / gRPC RESOURCE_EXHAUSTED) and OOO window guardrails.
import { Request, Response } from 'express';
import crypto from 'node:crypto';

interface NodePool {
  endpoint: string;
  activeConnections: number;
  maxConcurrency: number;
}

const TSDB_INSTANCES: readonly NodePool[] = Object.freeze([
  { endpoint: 'http://prom-sharded-0.prom-internal:9090', activeConnections: 0, maxConcurrency: 64 },
  { endpoint: 'http://prom-sharded-1.prom-internal:9090', activeConnections: 0, maxConcurrency: 64 },
]);

const MAX_PAYLOAD_BYTES = 2 * 1024 * 1024; // 2MB limit to prevent TSDB Head-of-Line block
const OOO_WINDOW_MS = 10 * 60 * 1000;     // Corresponds to --storage.tsdb.out-of-order-time-window=10m

function getTargetShard(clusterId: string, metricNamespace: string): NodePool {
  const hash = crypto.createHash('sha256').update(`${clusterId}:${metricNamespace}`).digest();
  const index = hash.readUInt32BE(0) % TSDB_INSTANCES.length;
  return TSDB_INSTANCES[index]!;
}

export async function handleOtlpMetricsSecure(req: Request, res: Response): Promise<void> {
  const contentLength = Number(req.headers['content-length'] ?? 0);
  if (contentLength > MAX_PAYLOAD_BYTES) {
    res.status(413).setHeader('Connection', 'close').json({
      error: 'Payload Too Large: OTLP batch exceeds 2MB TSDB safety threshold',
    });
    return;
  }

  const clusterId = (req.headers['x-cluster-id'] as string) || 'default';
  const namespace = (req.headers['x-metric-namespace'] as string) || 'unknown';
  const target = getTargetShard(clusterId, namespace);

  // Check concurrency limit on target Prometheus shard to prevent WAL thread exhaustion
  if (target.activeConnections >= target.maxConcurrency) {
    res.status(429)
      .setHeader('Retry-After', '2')
      .setHeader('X-Prometheus-Backpressure', 'TSDB_HEAD_SATURATED')
      .json({
        error: 'RESOURCE_EXHAUSTED: Shard WAL saturation. Downstream agent must back off.',
        retryWindowMs: 2000,
      });
    return;
  }

  target.activeConnections++;
  try {
    const forwardResponse = await fetch(`${target.endpoint}/api/v1/otlp/v1/metrics`, {
      method: 'POST',
      headers: {
        'Content-Type': req.headers['content-type'] ?? 'application/x-protobuf',
        'X-Prometheus-OOO-Window-MS': String(OOO_WINDOW_MS),
      },
      body: req.body,
      signal: AbortSignal.timeout(5000),
    });

    if (forwardResponse.status === 429 || forwardResponse.status === 503) {
      res.status(429)
        .setHeader('Retry-After', forwardResponse.headers.get('Retry-After') ?? '5')
        .json({ error: 'Downstream Prometheus TSDB signaled Head backpressure' });
      return;
    }

    res.status(forwardResponse.status).send(await forwardResponse.arrayBuffer());
  } catch (err: unknown) {
    res.status(503).json({
      error: 'TSDB_FORWARDING_FAILED',
      detail: err instanceof Error ? err.message : 'Unknown network failure',
    });
  } finally {
    target.activeConnections--;
  }
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Prometheus 3.0 Native OTLP Sharded Backpressure and TSDB Ingestion Boundary

Prometheus 3.0 Native OTLP Sharded Backpressure and TSDB Ingestion Boundary defines an industrial-grade behavioral standard for devops engineering. Establishes a resilient boundary for Prometheus 3.0 native OTLP ingestion under high-cardinality multi-cluster surges. Mandates consistent metric series-affinity sharding, explicit upstream backpressure propagation (gRPC ResourceExhausted/HTTP 429), and strict TSDB out-of-order ingestion alignment to eliminate Head-of-Line WAL blocking and out-of-order sample eviction. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Unpartitioned direct OTLP stream dumping into Prometheus 3.0 endpoints, triggering Head chunk lock contention, out-of-order drops, and WAL write stalls. Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftUnpartitioned direct OTLP stream dumping into Prometheus 3.0 endpoints, triggering Head chunk lock contention, out-of-order drops, and WAL write stalls.Critical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS route OTLP metrics through an affinity-sharding gateway using consistent hashing on series fingerprints (metric name + sorted normalized label pairs) to prevent split-brain chunk allocation across Prometheus replicas.

Engineers MUST ALWAYS route OTLP metrics through an affinity-sharding gateway using consistent hashing on series fingerprints (metric name + sorted normalized label pairs) to prevent split-brain chunk allocation across Prometheus replicas.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST propagate downstream TSDB backpressure immediately to callers using standard gRPC Status 8 (RESOURCE_EXHAUSTED) or HTTP 429 (Too Many Requests) with explicit 'Retry-After' jitter intervals, NEVER silently dropping or unbounded queuing in memory.

Engineers MUST propagate downstream TSDB backpressure immediately to callers using standard gRPC Status 8 (RESOURCE_EXHAUSTED) or HTTP 429 (Too Many Requests) with explicit 'Retry-After' jitter intervals, NEVER silently dropping or unbounded queuing in memory.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Services MUST explicitly configure Prometheus 3.0 with '--storage.tsdb.out-of-order-time-window' tuned strictly to the ingestion edge buffer's maximum clock skew and transit latency

Services MUST explicitly configure Prometheus 3.0 with '--storage.tsdb.out-of-order-time-window' tuned strictly to the ingestion edge buffer's maximum clock skew and transit latency; samples arriving outside this window MUST trigger alertable gateway rejections.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Engineers MUST enforce strict maximum batch size and message size limits (e.g., maximum 2MB per uncompressed OTLP payload) and mandate zstd or gzip decompression validation prior to TSDB parsing.

Engineers MUST enforce strict maximum batch size and message size limits (e.g., maximum 2MB per uncompressed OTLP payload) and mandate zstd or gzip decompression validation prior to TSDB parsing.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Components NEVER bypass the sharding boundary with direct multi-cluster ingress routing straight to Prometheus stateful pods without concurrency and semaphore controls.

Components NEVER bypass the sharding boundary with direct multi-cluster ingress routing straight to Prometheus stateful pods without concurrency and semaphore controls.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Prometheus 3.0 Native OTLP Sharded Backpressure and TSDB Ingestion Boundary critical for AI coding assistants?

Establishes a resilient boundary for Prometheus 3.0 native OTLP ingestion under high-cardinality multi-cluster surges. Mandates consistent metric series-affinity sharding, explicit upstream backpressure propagation (gRPC ResourceExhausted/HTTP 429), and strict TSDB out-of-order ingestion alignment to eliminate Head-of-Line WAL blocking and out-of-order sample eviction. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Unpartitioned direct OTLP stream dumping into Prometheus 3.0 endpoints, triggering Head chunk lock contention, out-of-order drops, and WAL write stalls.) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

Prometheus