Tobias Keller·
Real proto3 contracts for three RTB services with streaming and proper google.rpc.Status errors
Creates production-grade protobuf definitions, service contracts, streaming patterns, and gRPC-gateway configuration for high-performance inter-service communication.
gRPC Service Contract Design
Act as a distributed systems engineer specializing in high-performance RPC frameworks. Design a complete gRPC-based service architecture.
**System Domain**: {{system_domain}} (e.g., real-time bidding, video streaming backend, logistics platform)
**Services Inventory**: {{services_inventory}} (list of services that need gRPC contracts)
**Inter-service Patterns**: {{inter_service_patterns}} (unary, server-streaming, client-streaming, bidirectional)
**Gateway Requirements**: {{gateway_requirements}} (REST-to-gRPC translation needs, public API exposure)
Deliverables:
1. **Complete .proto Definitions** - All services, messages, enums with proto3 syntax, proper field numbering, and nested types
2. **Service Contract per Service** - RPC methods with request/response types, streaming semantics, and deadlines/timeouts
3. **Protobuf Best Practices** - Field naming, reserved fields strategy, backward compatibility rules, custom options
4. **Streaming Patterns** - Which operations use unary vs streaming with backpressure and flow control configuration
5. **Error Handling** - Google RPC Status details (google.rpc.Status), error codes mapping, rich error details
6. **Interceptors Stack** - Authentication, logging, metrics, retry, circuit breaker interceptor design
7. **Health Checking** - gRPC health checking protocol implementation with custom health indicators
8. **gRPC-Gateway Config** - HTTP annotations for REST translation, OpenAPI generation, swagger UI setup
9. **Load Balancing** - Client-side LB strategy (round-robin, weighted, consistent hashing) with service mesh integration
10. **Code Generation Setup** - protoc plugins, buf configuration, generate scripts for Go/Java/TypeScript/Python
11. **Breaking Change Detection** - buf breaking change rules and CI/CD integration
12. **Performance Tuning** - HTTP/2 settings, connection pooling, message size limits, keepalive configuration
Include actual .proto file contents for at least 3 services.
Ergebnisse
gRPC contracts for a **real-time-bidding** platform — three services, sub-10ms deadlines. Bidding is unary, the win-notice stream is server-streaming.
```protobuf
syntax = "proto3";
package rtb.v1;
import "google/protobuf/timestamp.proto";
service BidService {
// Unary, hard deadline enforced client-side at 8ms.
rpc Bid(BidRequest) returns (BidResponse);
}
message BidRequest {
string auction_id = 1;
string user_segment = 2;
int64 floor_price_micros = 3;
google.protobuf.Timestamp deadline = 4;
reserved 5, 6; // retired fields — never reuse the numbers
}
message BidResponse {
string creative_id = 1;
int64 bid_micros = 2;
bool no_bid = 3;
}
service NoticeService {
// Server-streaming win/loss notices for a bidder session.
rpc StreamNotices(NoticeFilter) returns (stream Notice);
}
```
**Error model:** failures return `google.rpc.Status` with a `BidErrorDetail` in `details` (e.g. `BUDGET_EXHAUSTED`), mapped to `RESOURCE_EXHAUSTED` not a generic `INTERNAL`. **Interceptor stack** (order matters): auth → metrics → logging → retry (only on `UNAVAILABLE`). **Backward compat** is enforced in CI by `buf breaking --against '.git#branch=main'`. Tuning: HTTP/2 `max_concurrent_streams=1000`, 30s keepalive, 4MB message cap. A gRPC-Gateway exposes `Bid` as `POST /v1/bid` for partners that can't speak gRPC.
Modell: Claude Opus 4
17 Likes4 SavesScore: 14
1 Kommentar
Ryan Mitchell·
Stealing this for the next code review.