Skip to content

post(blog): 서버리스 환경에서 Prisma 커넥션이 고갈되는 이유와 해결법 (#49) - #139

Merged
Malloc72P merged 2 commits into
mainfrom
claude/issue-49-serverless-prisma
Aug 4, 2026
Merged

post(blog): 서버리스 환경에서 Prisma 커넥션이 고갈되는 이유와 해결법 (#49)#139
Malloc72P merged 2 commits into
mainfrom
claude/issue-49-serverless-prisma

Conversation

@Malloc72P

Copy link
Copy Markdown
Owner

개요

이슈 #49를 다루는 포스트를 추가하고, 이 글이 속할 backend 시리즈 랜딩을 새로 만들었습니다.

서버리스(Lambda)에 Prisma를 올리면 트래픽이 몰릴 때 too many connections로 터지는 문제를, "인스턴스 수 × 인스턴스당 풀 크기"라는 곱셈이 폭발하는 메커니즘으로 먼저 설명하고, 그 두 항을 순서대로 줄여 나가는 해결 순서를 코드와 함께 정리했습니다.

신설: backend 시리즈 랜딩

  • apps/blog/src/app/(main)/posts/backend/page.tsx — 기존 fullstack 랜딩과 동일하게 isSeriesLanding 기반으로 정의했습니다.
  • date2026-07-20로 두어 fullstack(2026-03-24) 뒤, 즉 시리즈 nav 목록 끝에 오도록 했습니다(의도된 순서).
  • 랜딩 frontmatter에는 다른 랜딩들처럼 postId/tags를 넣지 않았습니다.

포스트 내용

  • apps/blog/src/app/(main)/posts/backend/serverless-prisma-connections/page.mdx
  • 왜 서버리스에서 커넥션이 터지는가 (수치 예시로 메커니즘 설명)
  • 1단계 connection_limit 낮추기 → 2단계 핸들러 바깥 클라이언트 재사용(cold start/warm invocation, globalThis 싱글턴) → 3단계 외부 풀러(PgBouncer transaction 모드, Prisma Accelerate)
  • 매 요청 $disconnect()를 부르면 안 되는 이유(재수립 비용 + freeze/thaw 재사용)와 좀비 커넥션 대응

정확도가 중요한 부분(connection_limit 기본값/서버리스 권장, warm invocation 재사용 범위, $disconnect 금지 근거, Data Proxy 종료 후 Accelerate 권장, PgBouncer pgbouncer=true의 버전별 주의)은 Prisma 공식 문서를 웹으로 확인해 반영했습니다.

검증

  • pnpm run build 성공 — /posts/backend, /posts/backend/serverless-prisma-connections 라우트 생성 확인
  • pnpm run lint 통과(--max-warnings 0), pnpm test 115개 전부 통과
  • 로컬 dev 서버에서 시리즈 랜딩과 포스트 렌더링을 브라우저로 확인(코드블록 6개·요약 표 정상)

Closes #49

- backend 시리즈 랜딩(page.tsx) 신설 — isSeriesLanding 기반, date 2026-07-20로 nav 끝에 배치
- 인스턴스 수 × 풀 크기 폭발 메커니즘부터 connection_limit·클라이언트 재사용·외부 풀러까지 정리
- 매 요청 $disconnect 금지 근거(freeze/thaw·재수립 비용)와 좀비 커넥션 대응 포함
@vercel

vercel Bot commented Aug 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
blog Ignored Ignored Preview Aug 4, 2026 12:07am

- 1단계에 Prisma 7 driver adapter(@prisma/adapter-pg, max) 대응 예시 추가, CPU 기반 풀 공식에 클래식 클라이언트 전제 명시
- 좀비 커넥션 정리를 idle_in_transaction_session_timeout → idle_session_timeout(PG14+)으로 정정
- Next.js↔raw Lambda handler 브리지 추가, 도입부 3단계 프레이밍 보정, 문체 다듬기(기하급수→선형·중복 어휘 등)
@Malloc72P
Malloc72P merged commit 8afca54 into main Aug 4, 2026
3 checks passed
@Malloc72P
Malloc72P deleted the claude/issue-49-serverless-prisma branch August 4, 2026 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

서버리스 환경에서 Prisma 커넥션이 고갈되는 이유와 해결법

1 participant