This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: valkey8-numa-shard-affinity-invariants

Valkey 8 Multi-Threaded Shard Affinity and NUMA Socket Invariants

Enforces strict CPU core pinning and memory allocation locality for Valkey 8 multi-threaded I/O engines and cluster shard instances. Cross-NUMA node memory hops incur severe interconnect bus saturation and L3 cache thrashing, degrading ultra-low-latency in-memory operations by an order of magnitude.

Prohibited Anti-Pattern: Unpinned Multi-Threaded Valkey Instances Crossing NUMA Domains and Socket Interconnects

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Valkey 8 Multi-Threaded Shard Affinity and NUMA Socket Invariants - Enforces strict CPU core pinning and memory allocation locality for Valkey 8 multi-threaded I/O engines and cluster shard instances. Cross-NUMA node memory hops incur severe interconnect bus saturation and L3 cache thrashing, degrading ultra-low-latency in-memory operations by an order of magnitude.
globs: infra/**/*.tf, deploy/**/*.yaml, ansible/**/*.yml, scripts/**/*.sh, valkey.conf, src/config/**/*.ts
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/valkey8-numa-shard-affinity-invariants"
---

# Valkey 8 Multi-Threaded Shard Affinity and NUMA Socket Invariants

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unpinned Multi-Threaded Valkey Instances Crossing NUMA Domains and Socket Interconnects

## System Constraints
You are a Principal Systems Architect enforcing Valkey 8 Multi-Threaded Shard Affinity and NUMA I/O Engine Invariants. You must ensure that every deployment, configuration file, orchestration spec, and automation script binds Valkey instances and their respective worker threads strictly to designated NUMA nodes and non-overlapping physical CPU sets. Unconstrained kernel thread migration and cross-node memory interleaving are strictly forbidden.

## Strict Guidelines
- Engineers MUST ALWAYS pin Valkey 8 main and I/O worker threads to isolated physical cores on the same NUMA node using `server_cpulist` and `bio_cpulist` directives.
- Engineers MUST ALWAYS enforce strict local memory allocation policies using `numactl --interleave=none --membind=<node>` or Linux cgroup `cpuset.mems` invariants.
- Engineers MUST NOT colocate multiple Valkey high-throughput shard primary threads on hyperthread pairs (sibling SMT cores) that share L1/L2 caches.
- Deployments MUST configure transparent huge pages (THP) to `madvise` or `never` to eliminate latency-spiking defragmentation sweeps across NUMA nodes.
- Kubernetes configurations MUST utilize the Static CPU Manager Policy (`cpu-manager-policy=static`) combined with Guaranteed QoS classes to guarantee dedicated CPU sets and socket locality.

## Bad vs Good Implementations
### Valkey 8 Instance Orchestration and NUMA Core Binding

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Launching valkey-server without explicit numa-binding or CPU-list constraints permits the Linux Completely Fair Scheduler (CFS) to balance threads across disparate physical sockets. Memory allocations become remote, causing cross-socket bus contention and unpredictable latency spikes on read/write bursts.
```shell
#!/bin/bash
# Unconstrained launch: Kernel scheduler freely migrates threads across NUMA sockets
# leading to UltraPath Interconnect (UPI/QPI) saturation and L3 cache invalidation
valkey-server /etc/valkey/shard-01.conf --io-threads 4

```

#### Production Standard (Correct)
> **Standard**: This configuration enforces complete memory and execution isolation on NUMA node 0. Memory allocations are bound locally via numactl, while Valkey's internal cpulist directives pin the primary event loop and background I/O threads to isolated non-SMT cores, completely eliminating inter-socket hops and L3 cache thrashing.
```shell
#!/bin/bash
# Production launch: Pin memory and execution strictly to NUMA Socket 0
# Physical Cores 0-3 (excluding Hyper-Threading siblings) with explicit memory isolation
export NUMA_NODE=0
export CPU_SET="0,2,4,6"

exec numactl \
  --cpunodebind="${NUMA_NODE}" \
  --membind="${NUMA_NODE}" \
  valkey-server /etc/valkey/shard-01.conf \
    --server_cpulist "${CPU_SET}" \
    --bio_cpulist "0" \
    --io-threads 3 \
    --io-threads-do-reads yes

```

### Kubernetes Resource Definition for NUMA-Aligned Valkey Pod

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Fractional CPU requests prevent the kubelet CPU Manager from allocating isolated core masks, triggering shared CFS scheduling pools across multiple NUMA domains.
```yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: valkey-shard
spec:
  template:
    spec:
      containers:
      - name: valkey
        image: valkey/valkey:8.0
        resources:
          # Fractional requests cause CFS thread bouncing across all NUMA nodes
          requests:
            cpu: "3500m"
            memory: "14Gi"
          limits:
            cpu: "4000m"
            memory: "16Gi"

```

#### Production Standard (Correct)
> **Standard**: Guaranteed QoS with integral integer CPU counts instructs kubelet's Static CPU Manager to assign exclusive CPU cores. Combined with the single-numa-node topology policy, the container runtime bounds all memory pages and threads to a single NUMA domain.
```yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: valkey-shard
spec:
  template:
    metadata:
      annotations:
        # Ensure single-numa-node topology manager policy matches guaranteed QoS
        topology.kubernetes.io/topology-policy: "single-numa-node"
    spec:
      containers:
      - name: valkey
        image: valkey/valkey:8.0
        resources:
          # Integral core allocations with identical limits/requests trigger Guaranteed QoS
          limits:
            cpu: "4"
            memory: "16Gi"
          requests:
            cpu: "4"
            memory: "16Gi"
        volumeMounts:
        - name: sys-fs
          mountPath: /sys/fs/cgroup
          readOnly: true

```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Valkey 8 Multi-Threaded Shard Affinity and NUMA Socket Invariants

Valkey 8 Multi-Threaded Shard Affinity and NUMA Socket Invariants defines an industrial-grade behavioral standard for devops engineering. Enforces strict CPU core pinning and memory allocation locality for Valkey 8 multi-threaded I/O engines and cluster shard instances. Cross-NUMA node memory hops incur severe interconnect bus saturation and L3 cache thrashing, degrading ultra-low-latency in-memory operations by an order of magnitude. 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: Unpinned Multi-Threaded Valkey Instances Crossing NUMA Domains and Socket Interconnects 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 DriftUnpinned Multi-Threaded Valkey Instances Crossing NUMA Domains and Socket InterconnectsCritical
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 pin Valkey 8 main and I/O worker threads to isolated physical cores on the same NUMA node using `server_cpulist` and `bio_cpulist` directives.

Engineers MUST ALWAYS pin Valkey 8 main and I/O worker threads to isolated physical cores on the same NUMA node using `server_cpulist` and `bio_cpulist` directives.

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 enforce strict local memory allocation policies using `numactl --interleave=none --membind=<node>` or Linux cgroup `cpuset.mems` invariants.

Engineers MUST ALWAYS enforce strict local memory allocation policies using `numactl --interleave=none --membind=<node>` or Linux cgroup `cpuset.mems` invariants.

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 NOT colocate multiple Valkey high-throughput shard primary threads on hyperthread pairs (sibling SMT cores) that share L1/L2 caches.

Engineers MUST NOT colocate multiple Valkey high-throughput shard primary threads on hyperthread pairs (sibling SMT cores) that share L1/L2 caches.

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

Deployments MUST configure transparent huge pages (THP) to `madvise` or `never` to eliminate latency-spiking defragmentation sweeps across NUMA nodes.

Deployments MUST configure transparent huge pages (THP) to `madvise` or `never` to eliminate latency-spiking defragmentation sweeps across NUMA nodes.

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

Kubernetes configurations MUST utilize the Static CPU Manager Policy (`cpu-manager-policy=static`) combined with Guaranteed QoS classes to guarantee dedicated CPU sets and socket locality.

Kubernetes configurations MUST utilize the Static CPU Manager Policy (`cpu-manager-policy=static`) combined with Guaranteed QoS classes to guarantee dedicated CPU sets and socket locality.

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 Valkey 8 Multi-Threaded Shard Affinity and NUMA Socket Invariants critical for AI coding assistants?

Enforces strict CPU core pinning and memory allocation locality for Valkey 8 multi-threaded I/O engines and cluster shard instances. Cross-NUMA node memory hops incur severe interconnect bus saturation and L3 cache thrashing, degrading ultra-low-latency in-memory operations by an order of magnitude. 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 (Unpinned Multi-Threaded Valkey Instances Crossing NUMA Domains and Socket Interconnects) 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

Valkey