--- id: wiki-2026-0508-serverless-architecture title: Serverless Architecture category: 10_Wiki/Topics status: verified canonical_id: self aliases: [Serverless, FaaS, Functions-as-a-Service, 서버리스] duplicate_of: none source_trust_level: A confidence_score: 0.9 verification_status: applied tags: [architecture, cloud, serverless, faas] raw_sources: [] last_reinforced: 2026-05-10 github_commit: pending tech_stack: language: typescript framework: aws-lambda --- # Serverless Architecture ## 매 한 줄 > **"매 서버 관리 없이 매 코드 실행 — 매 event-driven, 매 auto-scale, 매 pay-per-use"**. AWS Lambda (2014)로 매 popularize. 2026년에는 매 Lambda + EventBridge + Step Functions, Cloudflare Workers, Vercel Functions, Deno Deploy가 매 생태계 정점. 매 cold-start 문제는 매 SnapStart, Workers V8 isolate로 매 거의 해소. ## 매 핵심 ### 매 특성 - **매 No server mgmt**: 매 OS/patching 없음. - **매 Event-driven**: HTTP, queue, stream, schedule. - **매 Auto-scale**: 매 0 → 1000s, 매 즉시. - **매 Pay-per-use**: 매 idle cost 거의 0. - **매 Stateless**: 매 ephemeral execution. ### 매 trade-off - **매 Cold start**: 매 ms ~ 수 sec (매 Workers isolate ~ 5ms). - **매 Vendor lock-in**: 매 AWS-specific event shape. - **매 Long-running 부적합**: 매 limit (Lambda 15min, Workers 30s CPU). - **매 Stateful 부적합**: 매 외부 state 필수. ### 매 응용 1. API backend (Lambda + API Gateway). 2. Webhook handler (Workers). 3. Stream processing (Lambda + Kinesis). 4. Cron jobs (EventBridge schedule). 5. AI inference edge (Workers AI, Vercel AI SDK). ## 💻 패턴 ### 매 AWS Lambda (TS, SAM) ```typescript // handler.ts import type { APIGatewayProxyHandlerV2 } from "aws-lambda"; export const handler: APIGatewayProxyHandlerV2 = async (event) => { const body = JSON.parse(event.body ?? "{}"); return { statusCode: 200, body: JSON.stringify({ ok: true, echo: body }), }; }; ``` ```yaml # template.yaml (SAM) Resources: Api: Type: AWS::Serverless::Function Properties: Handler: dist/handler.handler Runtime: nodejs22.x SnapStart: { ApplyOn: PublishedVersions } # 매 cold-start ↓ Events: Http: { Type: HttpApi, Properties: { Path: /echo, Method: POST } } ``` ### 매 Cloudflare Workers ```typescript export default { async fetch(req: Request, env: Env): Promise { const { pathname } = new URL(req.url); if (pathname === "/ai") { const r = await env.AI.run("@cf/meta/llama-3.3-70b-instruct", { prompt: "Hello", }); return Response.json(r); } return new Response("ok"); }, }; ``` ### 매 Step Functions (orchestration) ```json { "StartAt": "Validate", "States": { "Validate": { "Type": "Task", "Resource": "arn:aws:lambda:...:Validate", "Next": "Charge" }, "Charge": { "Type": "Task", "Resource": "arn:aws:lambda:...:Charge", "Next": "Notify" }, "Notify": { "Type": "Task", "Resource": "arn:aws:lambda:...:Notify", "End": true } } } ``` ### 매 EventBridge schedule ```yaml Cron: Type: AWS::Events::Rule Properties: ScheduleExpression: "cron(0 * * * ? *)" # 매 hourly Targets: [{ Arn: !GetAtt MyFn.Arn, Id: hourly }] ``` ### 매 Vercel Edge Function (RSC) ```typescript // app/api/hello/route.ts export const runtime = "edge"; export async function GET() { return Response.json({ region: process.env.VERCEL_REGION }); } ``` ### 매 Cold-start mitigation ```typescript // 매 outside handler — 매 init reused across invocations import postgres from "postgres"; const sql = postgres(process.env.DB_URL!, { max: 1 }); export const handler = async () => { const rows = await sql`SELECT NOW()`; return rows; }; ``` ### 매 Bun + Lambda (2026 trend) ```dockerfile FROM public.ecr.aws/lambda/provided:al2023 COPY --from=oven/bun:1.2 /usr/local/bin/bun /usr/local/bin/bun COPY . ${LAMBDA_TASK_ROOT} CMD ["bun", "run", "handler.ts"] ``` ## 매 결정 기준 | 상황 | Approach | |---|---| | 매 spiky / unpredictable load | Serverless (auto-scale-to-zero). | | 매 steady high QPS | EC2/Fargate cheaper. | | 매 long-running batch | Step Functions / Fargate. | | 매 ultra-low latency global | Workers / Vercel Edge. | | 매 stateful | 매 외부 state (DynamoDB/Redis). | **기본값**: 매 API + webhook → Lambda or Workers. 매 latency 중요 → Workers. ## 🔗 Graph - 부모: [[Distributed Systems]] - 변형: [[FaaS]] - 응용: [[API Gateway]] · [[Cloudflare Workers]] - Adjacent: [[Microservices]] · [[Event-Driven Architecture]] · [[Cold Start]] · [[Scalability]] ## 🤖 LLM 활용 **언제**: 매 event-driven workload, 매 auto-scaling 필요, 매 ops cost ↓. **언제 X**: 매 long-running compute, 매 strict latency p99, 매 vendor-neutral 강제. ## ❌ 안티패턴 - **매 huge Lambda monolith**: 매 cold-start ↑, 매 cost ↑. - **매 sync chained Lambdas**: 매 cost double-billing — Step Functions 사용. - **매 connection pool 매 handler 안**: 매 연결 폭발. - **매 secret 매 env에 매 plaintext**: 매 Secrets Manager / KMS. - **매 cold-start 무시**: 매 user-facing path는 매 SnapStart/provisioned. ## 🧪 검증 / 중복 - Verified (AWS Lambda docs, Cloudflare Workers docs, Vercel docs). - 신뢰도 A. ## 🕓 Changelog | 날짜 | 변경 | |---|---| | 2026-05-08 | Phase 1 | | 2026-05-10 | Manual cleanup — Lambda+SnapStart, Workers, Step Functions patterns |