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:
Antigravity Agent
2026-07-05 00:33:48 +09:00
parent 1cfd3bbb56
commit 9148c358d0
6455 changed files with 1 additions and 86875 deletions
@@ -0,0 +1,389 @@
---
id: backend-edge-runtime-deep
title: Edge Runtime — Workers / Deno Deploy / Vercel Edge
category: Coding
status: draft
source_trust_level: B
verification_status: conceptual
created_at: 2026-05-09
updated_at: 2026-05-09
tags: [backend, edge, vibe-coding]
tech_stack: { language: "TS", applicable_to: ["Backend"] }
applied_in: []
aliases: [Cloudflare Workers, Deno Deploy, Vercel Edge, edge function, V8 isolates, low latency global]
---
# Edge Runtime Deep
> Lambda 보다 빠른, region 가 가까운. **Cloudflare Workers (V8), Deno Deploy, Vercel Edge, AWS Lambda@Edge**.
## 📖 핵심 개념
- V8 isolate: Lambda 보다 작은 (5ms cold start).
- 200+ city deploy.
- Web standard API (Fetch, Crypto).
- Stateless (state 가 KV / D1).
## 💻 코드 패턴
### Cloudflare Workers
```ts
export default {
async fetch(req: Request, env: Env, ctx: ExecutionContext) {
return new Response('Hello from edge');
},
};
```
```bash
npx wrangler deploy
```
### Hono on Workers
```ts
import { Hono } from 'hono';
const app = new Hono();
app.get('/', (c) => c.text('Hello'));
app.get('/users/:id', (c) => c.json({ id: c.req.param('id') }));
export default app;
```
→ Express 비슷. 작은 (10 KB).
### KV (Workers)
```ts
const value = await env.MY_KV.get('key');
await env.MY_KV.put('key', JSON.stringify(data), { expirationTtl: 3600 });
```
→ Eventually consistent. Edge 친화 (1 sec global propagation).
### D1 (SQLite at edge)
```ts
const r = await env.DB.prepare('SELECT * FROM users WHERE id = ?').bind(id).first();
```
→ SQLite. 최신 read 만 region (write 가 1 region).
### R2 (S3-compatible)
```ts
await env.MY_BUCKET.put('file.jpg', buffer);
const obj = await env.MY_BUCKET.get('file.jpg');
```
→ Egress 무료.
### Durable Objects (stateful)
```ts
export class Counter {
state: DurableObjectState;
constructor(state: DurableObjectState) {
this.state = state;
}
async fetch(req: Request) {
let count = await this.state.storage.get<number>('count') ?? 0;
count++;
await this.state.storage.put('count', count);
return new Response(String(count));
}
}
// Worker
const id = env.COUNTER.idFromName('global');
const obj = env.COUNTER.get(id);
const r = await obj.fetch(req);
```
→ Stateful + globally addressable. Chat / game.
### Hyperdrive (DB pool)
```toml
[[hyperdrive]]
binding = 'HYPERDRIVE'
id = '...'
```
```ts
import postgres from 'postgres';
const sql = postgres(env.HYPERDRIVE.connectionString);
const users = await sql`SELECT * FROM users`;
```
→ Edge 가 Postgres 직접. Pool / cache 자동.
### Deno Deploy
```ts
Deno.serve((req) => new Response('Hello'));
```
```bash
deno deploy --project=my-app main.ts
```
### Vercel Edge
```ts
// app/api/hello/route.ts
export const runtime = 'edge';
export async function GET(req: Request) {
return new Response('Hello');
}
```
### Bun
```ts
Bun.serve({
port: 3000,
fetch(req) {
return new Response('Hello');
},
});
```
→ Self-host. Edge 가 아님 (single region).
### Limits
```
Cloudflare Workers:
- 1 MB code (50 MB free plan).
- 10 ms CPU (free), 30 sec (paid).
- 128 MB memory.
- No Node API (npm 일부).
Lambda@Edge:
- 1 MB code.
- 5 sec timeout.
- 128 MB.
Deno Deploy:
- 다른 limits.
```
→ Lambda 보다 strict.
### Web standards
```ts
// fetch, crypto, URL, Headers, Response
const r = await fetch(url);
const hash = await crypto.subtle.digest('SHA-256', data);
const u = new URL('https://example.com/path?x=1');
```
→ Browser-compatible. Node 만 안 됨.
### Node compat (CF)
```toml
compatibility_flags = ['nodejs_compat']
```
```ts
import { readFile } from 'node:fs/promises';
// → 일부 Node API.
```
→ 점진적 추가.
### Cold start
```
Workers: 5 ms (V8 isolate).
Lambda: 200-1000 ms (container).
Deno Deploy: ~10 ms.
→ Edge 가 훨씬 빠름.
```
### Deploy
```bash
# Workers
wrangler deploy
# Vercel
vercel --prod
# Deno
deno deploy
```
→ Atomic, global, secs.
### Routing
```
Cloudflare:
my-app.example.com/* → worker.
Vercel:
/api/* → edge function.
```
### Observability
```ts
console.log('processed');
// → Wrangler tail / Workers Analytics.
```
→ Production 의 Datadog / Sentry 통합.
### Rate limit
```ts
// Cloudflare Rate Limiting Rule (Dashboard).
// 또는 Worker:
const ip = req.headers.get('cf-connecting-ip');
const key = `rl:${ip}`;
const count = await env.KV.get(key);
if (Number(count) > 100) return new Response('Rate limit', { status: 429 });
await env.KV.put(key, String(Number(count ?? 0) + 1), { expirationTtl: 60 });
```
### Cron (Workers)
```toml
[triggers]
crons = ['0 9 * * *']
```
```ts
export default {
async scheduled(event, env, ctx) {
await dailyJob();
},
};
```
### Queue (Workers)
```ts
// Producer
await env.MY_QUEUE.send({ taskId: '...' });
// Consumer
export default {
async queue(batch, env) {
for (const msg of batch.messages) {
await process(msg.body);
}
},
};
```
→ Edge 의 message queue.
### WebSocket (Workers + DO)
```ts
class ChatRoom extends DurableObject {
async fetch(req: Request) {
if (req.headers.get('upgrade') === 'websocket') {
const pair = new WebSocketPair();
this.handleSession(pair[1]);
return new Response(null, { status: 101, webSocket: pair[0] });
}
}
handleSession(ws: WebSocket) {
ws.accept();
ws.addEventListener('message', (e) => {
// ...
});
}
}
```
→ Real-time chat at edge.
### Cost
```
Cloudflare Workers Free:
- 100k req / day.
- $5 / month for 10M.
Vercel Edge:
- 1M / month free.
- $20 / month after.
Deno Deploy:
- 1M / month free.
→ Edge 가 traditional Lambda 보다 cheap (volume).
```
### Use case
```
- API gateway / proxy.
- Auth (verify JWT, OIDC).
- Rate limit / WAF.
- Image transform (CF Image, Vercel Image).
- A/B test routing.
- Static site (Pages).
- Realtime (DO + WS).
- AI inference (Cloudflare Workers AI).
```
### Cloudflare Workers AI
```ts
const r = await env.AI.run('@cf/meta/llama-3-8b-instruct', {
prompt: 'Hello',
});
```
→ Edge 의 LLM. 작은 model.
### vs Lambda
```
Lambda: 더 mature, 큰 ecosystem, 모든 language.
Edge: 빠름, 작은, 가벼운.
→ Heavy compute = Lambda.
HTTP / 작은 = Edge.
```
### Limits 의 함정
```
- Long task (>30 sec) = timeout.
- Big bundle = limit.
- Native module = 안 됨.
- 큰 file (100 MB+) = R2.
- Persistent connection = DO.
```
### When?
```
✓ Global low-latency.
✓ 작은 / simple logic.
✓ Auth proxy.
✓ A/B routing.
✗ Heavy compute (ML training).
✗ Long-running (>5 min).
✗ Complex Node app.
```
## 🤔 의사결정 기준
| 작업 | 추천 |
|---|---|
| Auth gateway | Cloudflare Workers |
| Vercel + Next | Edge function |
| Deno-native | Deno Deploy |
| Stateful | DO |
| DB pool at edge | Hyperdrive / Neon HTTP |
| Local dev | wrangler dev / bun |
| Heavy compute | Lambda / VM |
## ❌ 안티패턴
- **Big bundle**: limit.
- **Long task**: timeout.
- **Persistent connection (no DO)**: 깨짐.
- **State in worker memory**: lost.
- **Heavy compute**: timeout.
- **Node-only API**: 안 됨.
- **Per-request DB connection**: pool 폭발.
## 🤖 LLM 활용 힌트
- Cloudflare Workers + Hono = 가장 modern.
- DO 가 stateful.
- Hyperdrive 가 DB pool.
- Web standards (fetch, crypto) only.
## 🔗 관련 문서
- [[Backend_Edge_Functions]]
- [[Backend_Hono_Modern]]
- [[DB_Serverless_Edge]]