This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: ebpf-tc-egress-pacing-bufferbloat-guardrail

eBPF TC Egress Packet-Pacing and Network Bufferbloat Prevention

Enforces strict kernel-level egress packet pacing (EDT/FQ) and dynamic queue-depth management via eBPF Traffic Control (TC) programs on container virtual ethernet (veth) pairs. Eliminates microburst-induced bufferbloat and noisy-neighbor cross-tenant egress tail latency spikes without relying on coarse host-level HTB or user-space throttling.

Prohibited Anti-Pattern: Unregulated Pod Egress Bursts Inducing Bufferbloat and High p99 Latency via FIFO Queues

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: eBPF TC Egress Packet-Pacing and Network Bufferbloat Prevention - Enforces strict kernel-level egress packet pacing (EDT/FQ) and dynamic queue-depth management via eBPF Traffic Control (TC) programs on container virtual ethernet (veth) pairs. Eliminates microburst-induced bufferbloat and noisy-neighbor cross-tenant egress tail latency spikes without relying on coarse host-level HTB or user-space throttling.
globs: bpf/**/*.c, bpf/**/*.h, pkg/ebpf/**/*.go, pkg/network/**/*.go, deploy/daemonsets/**/*.yaml, cni/**/*.go
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/ebpf-tc-egress-pacing-bufferbloat-guardrail"
---

# eBPF TC Egress Packet-Pacing and Network Bufferbloat Prevention

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unregulated Pod Egress Bursts Inducing Bufferbloat and High p99 Latency via FIFO Queues

## System Constraints
You are a Principal Systems & Networking Architect specializing in Linux eBPF and container networking. You enforce strict kernel-level egress packet pacing using Earliest Departure Time (EDT) and fair-queueing architectures directly at the container network interface (veth/net_cls/TC). You prohibit unmetered FIFO queues, user-space throttling loops, and unvalidated packet drop schemes that cause bufferbloat, head-of-line blocking, and cross-tenant tail latency degradation.

## Strict Guidelines
- Engineers MUST ALWAYS attach eBPF TC programs to the clsact egress hook on container host-facing veth pairs using direct-action mode.
- Engineers MUST ALWAYS leverage Earliest Departure Time (EDT) semantics by calculating and stamping `skb->tstamp` based on tenant token-bucket rate state stored in BPF maps.
- Engineers MUST configure host underlying qdiscs to `fq` (Fair Queueing) or `fq_codel` rather than default `pfifo_fast` or unmanaged `mq` queues to honor `skb->tstamp`.
- Engineers MUST NOT rely on userspace rate limiters, iptables hashlimit, or plain TC police actions that drop packets abruptly instead of pacing via EDT.
- Code MUST handle clock skew and wrap-around by using monotonic time (`bpf_ktime_get_ns()`) for all leaky-bucket timestamp calculations.
- Services MUST monitor TC drop and throttle counters via per-CPU BPF array or perf/ring buffers to provide observability into pod-level egress throttling.
- Components NEVER allow unmetered burst traffic exceeding `max_credit` parameters to ensure noisy-neighbor bursts cannot monopolize physical NIC rings.

## Bad vs Good Implementations
### eBPF TC EDT-based Egress Pacer vs Uncontrolled Pass-Through

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Failing to calculate and assign `skb->tstamp` causes packets to be immediately dumped into downstream FIFO queueing disciplines and hardware ring buffers. Microbursts monopolize the egress queue, driving up bufferbloat and degrading latency for co-located tenant workloads.
```c
#include <linux/bpf.h>
#include <linux/pkt_cls.h>
#include <bpf/bpf_helpers.h>

// ANTI-PATTERN: Blindly passing packets at egress without stamping EDT tstamp
// or dropping packets indiscriminately on burst, causing downstream bufferbloat
// in physical NIC queues and severe p99 degradation for adjacent containers.
SEC("tc")
int tc_egress_unmanaged(struct __sk_buff *skb) {
    void *data = (void *)(long)skb->data;
    void *data_end = (void *)(long)skb->data_end;

    if (data + 14 > data_end) {
        return TC_ACT_OK;
    }

    // Packets are pushed immediately to pfifo_fast/NIC ring without pacing
    return TC_ACT_OK;
}
```

#### Production Standard (Correct)
> **Standard**: Calculates Earliest Departure Time (EDT) based on per-tenant bandwidth allowances and stamps `skb->tstamp`. When combined with the `sch_fq` queueing discipline, packets are paced precisely at the kernel layer, bounding queue delays and completely eliminating bufferbloat.
```c
#include <linux/bpf.h>
#include <linux/pkt_cls.h>
#include <bpf/bpf_helpers.h>

struct tenant_pacing_state {
    __u64 rate_bytes_per_sec;
    __u64 max_delay_ns;
    __u64 next_departure_time;
};

struct {
    __uint(type, BPF_MAP_TYPE_HASH);
    __uint(max_entries, 1024);
    __type(key, __u32); // tenant_cgroup_id or interface index
    __type(value, struct tenant_pacing_state);
} pacing_map SEC(".maps");

SEC("tc")
int tc_egress_edt_pacing(struct __sk_buff *skb) {
    __u32 key = 0; // Container network context
    struct tenant_pacing_state *state = bpf_map_lookup_elem(&pacing_map, &key);
    if (!state || state->rate_bytes_per_sec == 0) {
        return TC_ACT_OK;
    }

    __u64 now = bpf_ktime_get_ns();
    __u64 len = skb->len;
    __u64 delay = (len * 1000000000ULL) / state->rate_bytes_per_sec;
    __u64 next = state->next_departure_time;

    if (next < now) {
        next = now;
    }

    // Prevent queue accumulation beyond allowed maximum delay budget
    if (next + delay > now + state->max_delay_ns) {
        return TC_ACT_SHOT;
    }

    state->next_departure_time = next + delay;
    skb->tstamp = next; // Earliest Departure Time stamped for sch_fq

    return TC_ACT_OK;
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: eBPF TC Egress Packet-Pacing and Network Bufferbloat Prevention

eBPF TC Egress Packet-Pacing and Network Bufferbloat Prevention defines an industrial-grade behavioral standard for devops engineering. Enforces strict kernel-level egress packet pacing (EDT/FQ) and dynamic queue-depth management via eBPF Traffic Control (TC) programs on container virtual ethernet (veth) pairs. Eliminates microburst-induced bufferbloat and noisy-neighbor cross-tenant egress tail latency spikes without relying on coarse host-level HTB or user-space throttling. 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: Unregulated Pod Egress Bursts Inducing Bufferbloat and High p99 Latency via FIFO Queues 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 DriftUnregulated Pod Egress Bursts Inducing Bufferbloat and High p99 Latency via FIFO QueuesCritical
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 attach eBPF TC programs to the clsact egress hook on container host-facing veth pairs using direct-action mode.

Engineers MUST ALWAYS attach eBPF TC programs to the clsact egress hook on container host-facing veth pairs using direct-action mode.

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 ALWAYS leverage Earliest Departure Time (EDT) semantics by calculating and stamping `skb->tstamp` based on tenant token-bucket rate state stored in BPF maps.

Engineers MUST ALWAYS leverage Earliest Departure Time (EDT) semantics by calculating and stamping `skb->tstamp` based on tenant token-bucket rate state stored in BPF maps.

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

Engineers MUST configure host underlying qdiscs to `fq` (Fair Queueing) or `fq_codel` rather than default `pfifo_fast` or unmanaged `mq` queues to honor `skb->tstamp`.

Engineers MUST configure host underlying qdiscs to `fq` (Fair Queueing) or `fq_codel` rather than default `pfifo_fast` or unmanaged `mq` queues to honor `skb->tstamp`.

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 NOT rely on userspace rate limiters, iptables hashlimit, or plain TC police actions that drop packets abruptly instead of pacing via EDT.

Engineers MUST NOT rely on userspace rate limiters, iptables hashlimit, or plain TC police actions that drop packets abruptly instead of pacing via EDT.

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

Code MUST handle clock skew and wrap-around by using monotonic time (`bpf_ktime_get_ns()`) for all leaky-bucket timestamp calculations.

Code MUST handle clock skew and wrap-around by using monotonic time (`bpf_ktime_get_ns()`) for all leaky-bucket timestamp calculations.

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.
6

Services MUST monitor TC drop and throttle counters via per-CPU BPF array or perf/ring buffers to provide observability into pod-level egress throttling.

Services MUST monitor TC drop and throttle counters via per-CPU BPF array or perf/ring buffers to provide observability into pod-level egress throttling.

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.
7

Components NEVER allow unmetered burst traffic exceeding `max_credit` parameters to ensure noisy-neighbor bursts cannot monopolize physical NIC rings.

Components NEVER allow unmetered burst traffic exceeding `max_credit` parameters to ensure noisy-neighbor bursts cannot monopolize physical NIC rings.

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 eBPF TC Egress Packet-Pacing and Network Bufferbloat Prevention critical for AI coding assistants?

Enforces strict kernel-level egress packet pacing (EDT/FQ) and dynamic queue-depth management via eBPF Traffic Control (TC) programs on container virtual ethernet (veth) pairs. Eliminates microburst-induced bufferbloat and noisy-neighbor cross-tenant egress tail latency spikes without relying on coarse host-level HTB or user-space throttling. 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 (Unregulated Pod Egress Bursts Inducing Bufferbloat and High p99 Latency via FIFO Queues) 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

eBPF