This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
backendcritical PriorityID: grpc-protobuf-v3-microservices

gRPC Protobuf v3 Interceptors & Deadline Propagation Standard

Enterprise microservice communications standard using gRPC and Protocol Buffers v3. Mandates strict deadline and context propagation, bidirectional client/server interceptors, google.rpc.Status rich error details, and keepalive ping tuning.

Prohibited Anti-Pattern: AI creates bare gRPC clients without timeouts, causing cascading thread pool exhaustion during service brownouts.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: gRPC Protobuf v3 Interceptors & Deadline Propagation Standard - Enterprise microservice communications standard using gRPC and Protocol Buffers v3. Mandates strict deadline and context propagation, bidirectional client/server interceptors, google.rpc.Status rich error details, and keepalive ping tuning.
globs: **/*.proto, **/*grpc*.go, **/*grpc*.ts, **/*grpc*.py
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/grpc-protobuf-v3-microservices"
---

# gRPC Protobuf v3 Interceptors & Deadline Propagation Standard

> **Severity**: CRITICAL | **Category**: backend
> **Anti-Pattern Warning**: AI creates bare gRPC clients without timeouts, causing cascading thread pool exhaustion during service brownouts.

## System Constraints
You are a distributed systems and RPC architect. When implementing gRPC clients and servers, NEVER make RPC calls without context deadlines (e.g. context.WithTimeout). Always register client/server interceptors for distributed tracing, use google.rpc.Status for rich error metadata, and configure keepalive pings.

## Strict Guidelines
- Always enforce request deadlines on client invocations using context.WithTimeout; never issue unbounded RPC requests.
- Implement server interceptors to catch panics/unhandled exceptions and map them to standard gRPC codes (e.g. codes.Internal).
- Use google.rpc.Status with error details (ErrorInfo, BadRequest, PreconditionFailure) instead of unstructured string messages.
- Configure gRPC keepalive parameters (keepalive.ClientParameters) to detect dead TCP connections behind cloud load balancers.

## Bad vs Good Implementations
### Strict Deadline Propagation & Rich Error Mapping in Go gRPC

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Omits context timeout, risks cascading system-wide lockups, and drops structured machine-readable error codes.
```go
// ANTI-PATTERN: Unbounded context and raw string errors in gRPC call
func (s *OrderService) GetCustomerInfo(ctx context.Context, req *pb.CustomerRequest) (*pb.CustomerResponse, error) {
  client := pb.NewBillingClient(s.conn)
  resp, err := client.CheckCredit(context.Background(), &pb.CreditRequest{CustomerId: req.CustomerId})
  if err != nil {
    return nil, fmt.Errorf("billing failed: %v", err)
  }
  return &pb.CustomerResponse{Status: resp.Status}, nil
}
```

#### Production Standard (Correct)
> **Standard**: Guarantees fail-fast behavior under load and returns machine-parsable error details conforming to Google RPC standards.
```go
// PRODUCTION STANDARD: Propagated Timeout & Rich gRPC Status Details
func (s *OrderService) GetCustomerInfo(ctx context.Context, req *pb.CustomerRequest) (*pb.CustomerResponse, error) {
  callCtx, cancel := context.WithTimeout(ctx, 800*time.Millisecond)
  defer cancel()
  client := pb.NewBillingClient(s.conn)
  resp, err := client.CheckCredit(callCtx, &pb.CreditRequest{CustomerId: req.CustomerId})
  if err != nil {
    if errors.Is(callCtx.Err(), context.DeadlineExceeded) {
      return nil, status.Error(codes.DeadlineExceeded, "billing service timed out")
    }
    st := status.New(codes.FailedPrecondition, "insufficient account balance")
    detailedSt, _ := st.WithDetails(&errdetails.ErrorInfo{Reason: "CREDIT_LIMIT_EXCEEDED", Domain: "billing.acme.corp"})
    return nil, detailedSt.Err()
  }
  return &pb.CustomerResponse{Status: resp.Status}, nil
}
```

### Client KeepAlive Connection Health Options

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Silent connection drops by firewalls leave sockets hanging until TCP timeouts expire hours later.
```go
// ANTI-PATTERN: Dialing without keepalive settings
conn, _ := grpc.Dial(addr, grpc.WithInsecure())
```

#### Production Standard (Correct)
> **Standard**: Actively probes idle connections every 10 seconds and automatically reconnects severed TCP channels.
```go
// PRODUCTION STANDARD: Keepalive Ping Configuration
kp := keepalive.ClientParameters{Time: 10 * time.Second, Timeout: 3 * time.Second, PermitWithoutStream: true}
conn, err := grpc.DialContext(ctx, addr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithKeepaliveParams(kp))
```

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: gRPC Protobuf v3 Interceptors & Deadline Propagation Standard

gRPC Protobuf v3 Interceptors & Deadline Propagation Standard defines an industrial-grade behavioral standard for backend engineering. Enterprise microservice communications standard using gRPC and Protocol Buffers v3. Mandates strict deadline and context propagation, bidirectional client/server interceptors, google.rpc.Status rich error details, and keepalive ping tuning. 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: AI creates bare gRPC clients without timeouts, causing cascading thread pool exhaustion during service brownouts. 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 DriftAI creates bare gRPC clients without timeouts, causing cascading thread pool exhaustion during service brownouts.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

Always enforce request deadlines on client invocations using context.WithTimeout

Always enforce request deadlines on client invocations using context.WithTimeout; never issue unbounded RPC requests.

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

Implement server interceptors to catch panics/unhandled exceptions and map them to standard gRPC codes (e.g. codes.Internal).

Implement server interceptors to catch panics/unhandled exceptions and map them to standard gRPC codes (e.g. codes.Internal).

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

Use google.rpc.Status with error details (ErrorInfo, BadRequest, PreconditionFailure) instead of unstructured string messages.

Use google.rpc.Status with error details (ErrorInfo, BadRequest, PreconditionFailure) instead of unstructured string messages.

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

Configure gRPC keepalive parameters (keepalive.ClientParameters) to detect dead TCP connections behind cloud load balancers.

Configure gRPC keepalive parameters (keepalive.ClientParameters) to detect dead TCP connections behind cloud load balancers.

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 gRPC Protobuf v3 Interceptors & Deadline Propagation Standard critical for AI coding assistants?

Enterprise microservice communications standard using gRPC and Protocol Buffers v3. Mandates strict deadline and context propagation, bidirectional client/server interceptors, google.rpc.Status rich error details, and keepalive ping tuning. 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 (AI creates bare gRPC clients without timeouts, causing cascading thread pool exhaustion during service brownouts.) 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

gRPC