docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를 Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류. - 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로 자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거, 동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거. - 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming, Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business, Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로, 나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는 title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백). 원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지. - 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서. - 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는 지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지. - Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경. - 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
This commit is contained in:
@@ -0,0 +1,215 @@
|
||||
---
|
||||
id: wiki-2026-0508-grpc-and-protocol-buffers
|
||||
title: gRPC and Protocol Buffers
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [gRPC, Protobuf, protocol-buffers]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
verification_status: applied
|
||||
tags: [rpc, networking, protobuf, microservices, http2]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: Multi (Go, Rust, TS, Python)
|
||||
framework: gRPC + Protobuf 3 / Edition 2024
|
||||
---
|
||||
|
||||
# gRPC and Protocol Buffers
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 schema-first IDL + HTTP/2 RPC + binary serialization 의 stack."**. Protocol Buffers 는 2008 Google 공개, gRPC 는 2015 OSS — 매 internal Stubby 의 successor. 매 2026 microservice / cross-language API 의 매 default — 매 REST+JSON 보다 5-10× compact, 매 streaming 매 native, 매 contract 강제.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Protocol Buffers
|
||||
- **Schema**: `.proto` file — 매 message + service 정의.
|
||||
- **Wire format**: tag-length-value, varint encoding — 매 forward/backward compat (unknown field 보존).
|
||||
- **Edition 2024**: `proto2` / `proto3` 의 통합 — 매 explicit feature flag.
|
||||
- **Compiler**: `protoc` + plugin (go, ts-proto, prost, python-betterproto).
|
||||
|
||||
### 매 gRPC
|
||||
- **Transport**: HTTP/2 — 매 multiplexing, header compression (HPACK).
|
||||
- **4 RPC types**: unary, server-stream, client-stream, bidi-stream.
|
||||
- **Status codes**: 매 `OK`, `INVALID_ARGUMENT`, `UNAUTHENTICATED`, `DEADLINE_EXCEEDED` (16개 표준).
|
||||
- **Deadline**: 매 client → server propagate. 매 RPC chain 매 cumulative.
|
||||
- **Metadata**: 매 trailer/header — auth token, trace.
|
||||
- **gRPC-Web**: 매 browser support (HTTP/1.1 fallback proxy).
|
||||
- **Connect / gRPC-Gateway**: 매 REST+gRPC dual.
|
||||
|
||||
### 매 응용
|
||||
1. Microservice internal RPC.
|
||||
2. Mobile ↔ backend (Square, Netflix).
|
||||
3. Service mesh (Envoy, Istio).
|
||||
4. Streaming (live ML inference, IoT).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### .proto schema
|
||||
```protobuf
|
||||
edition = "2024";
|
||||
|
||||
package shop.v1;
|
||||
|
||||
option go_package = "github.com/example/shop/v1;shopv1";
|
||||
|
||||
service Catalog {
|
||||
rpc GetProduct(GetProductRequest) returns (Product);
|
||||
rpc StreamUpdates(StreamUpdatesRequest) returns (stream ProductUpdate);
|
||||
rpc UploadImages(stream Image) returns (UploadAck);
|
||||
rpc Chat(stream ChatMsg) returns (stream ChatMsg);
|
||||
}
|
||||
|
||||
message GetProductRequest {
|
||||
string id = 1;
|
||||
}
|
||||
|
||||
message Product {
|
||||
string id = 1;
|
||||
string name = 2;
|
||||
int64 price_cents = 3;
|
||||
repeated string tags = 4;
|
||||
google.protobuf.Timestamp updated_at = 5;
|
||||
}
|
||||
```
|
||||
|
||||
### Go server (unary + stream)
|
||||
```go
|
||||
type catalogServer struct{ shopv1.UnimplementedCatalogServer }
|
||||
|
||||
func (s *catalogServer) GetProduct(ctx context.Context, req *shopv1.GetProductRequest) (*shopv1.Product, error) {
|
||||
if req.Id == "" {
|
||||
return nil, status.Error(codes.InvalidArgument, "id required")
|
||||
}
|
||||
p, err := s.db.Find(ctx, req.Id)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, status.Error(codes.NotFound, "product missing")
|
||||
}
|
||||
return p, err
|
||||
}
|
||||
|
||||
func (s *catalogServer) StreamUpdates(req *shopv1.StreamUpdatesRequest, srv shopv1.Catalog_StreamUpdatesServer) error {
|
||||
for ev := range s.bus.Subscribe(srv.Context()) {
|
||||
if err := srv.Send(ev); err != nil { return err }
|
||||
}
|
||||
return nil
|
||||
}
|
||||
```
|
||||
|
||||
### TS client (ts-proto + grpc-js)
|
||||
```typescript
|
||||
import { credentials } from '@grpc/grpc-js';
|
||||
import { CatalogClient } from './gen/shop/v1/catalog';
|
||||
|
||||
const client = new CatalogClient('catalog:50051', credentials.createSsl());
|
||||
|
||||
const p = await client.getProduct({ id: 'sku-42' }, { deadline: Date.now() + 1000 });
|
||||
console.log(p.name);
|
||||
|
||||
// streaming
|
||||
const stream = client.streamUpdates({});
|
||||
stream.on('data', (u) => console.log('update', u));
|
||||
stream.on('error', (e) => console.error(e));
|
||||
```
|
||||
|
||||
### Deadline propagation
|
||||
```go
|
||||
ctx, cancel := context.WithTimeout(ctx, 500*time.Millisecond)
|
||||
defer cancel()
|
||||
// 매 outgoing RPC 매 자동 deadline 전달.
|
||||
resp, err := downstream.Sub(ctx, req)
|
||||
```
|
||||
|
||||
### Interceptor (auth + tracing)
|
||||
```go
|
||||
func authUnary(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
tok := md.Get("authorization")
|
||||
if len(tok) == 0 { return nil, status.Error(codes.Unauthenticated, "no token") }
|
||||
user, err := verify(tok[0])
|
||||
if err != nil { return nil, status.Error(codes.Unauthenticated, "bad token") }
|
||||
return handler(context.WithValue(ctx, userKey{}, user), req)
|
||||
}
|
||||
|
||||
s := grpc.NewServer(grpc.UnaryInterceptor(authUnary))
|
||||
```
|
||||
|
||||
### gRPC-Web (browser)
|
||||
```typescript
|
||||
import { createPromiseClient } from '@connectrpc/connect';
|
||||
import { createGrpcWebTransport } from '@connectrpc/connect-web';
|
||||
import { Catalog } from './gen/shop/v1/catalog_connect';
|
||||
|
||||
const transport = createGrpcWebTransport({ baseUrl: 'https://api.example.com' });
|
||||
const client = createPromiseClient(Catalog, transport);
|
||||
const p = await client.getProduct({ id: 'sku-42' });
|
||||
```
|
||||
|
||||
### Buf for build + lint
|
||||
```yaml
|
||||
# buf.yaml
|
||||
version: v2
|
||||
modules:
|
||||
- path: proto
|
||||
lint:
|
||||
use: [DEFAULT]
|
||||
breaking:
|
||||
use: [FILE]
|
||||
```
|
||||
```bash
|
||||
buf lint
|
||||
buf breaking --against '.git#branch=main'
|
||||
buf generate
|
||||
```
|
||||
|
||||
### Backward-compat 규칙
|
||||
```protobuf
|
||||
message Product {
|
||||
string id = 1;
|
||||
string name = 2;
|
||||
// 매 deprecated 후에도 number 재사용 X
|
||||
reserved 3;
|
||||
reserved "old_price";
|
||||
int64 price_cents = 4;
|
||||
}
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| 매 internal microservice | gRPC unary + interceptor |
|
||||
| 매 browser client | Connect / gRPC-Web |
|
||||
| 매 public open API | REST/JSON or gRPC-Gateway dual |
|
||||
| 매 streaming (logs, ML) | server-stream / bidi |
|
||||
| 매 mobile (cellular flaky) | gRPC + retry interceptor + deadline |
|
||||
|
||||
**기본값**: 매 internal = gRPC, 매 external = Connect (dual REST + gRPC).
|
||||
|
||||
## 🔗 Graph
|
||||
- 변형: [[Connect_RPC]]
|
||||
- 응용: [[Service Mesh]] · [[Microservices]] · [[Envoy]]
|
||||
- Adjacent: [[Buf]] · [[OpenAPI]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 cross-language API, 매 streaming, 매 strict contract.
|
||||
**언제 X**: 매 simple browser CRUD (REST 충분), 매 ad-hoc tooling (JSON 직관적).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Field number 재사용**: 매 wire-incompatible — 매 reserved 의 사용.
|
||||
- **매 required 다용**: 매 schema evolution 차단 — proto3 default optional 유지.
|
||||
- **매 deadline 미설정**: 매 server cascade hang.
|
||||
- **매 large message (>4MB)**: 매 default limit hit — 매 stream 으로 분할.
|
||||
- **매 .proto 의 versioning X**: 매 `v1`, `v2` package 분리 mandatory.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (grpc.io docs, protobuf.dev Edition 2024 spec, Buf docs).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — gRPC patterns, Edition 2024, Connect-RPC |
|
||||
Reference in New Issue
Block a user