post(blog): 서버리스 환경에서 Prisma 커넥션이 고갈되는 이유와 해결법 (#49) - #139
Merged
Conversation
- backend 시리즈 랜딩(page.tsx) 신설 — isSeriesLanding 기반, date 2026-07-20로 nav 끝에 배치 - 인스턴스 수 × 풀 크기 폭발 메커니즘부터 connection_limit·클라이언트 재사용·외부 풀러까지 정리 - 매 요청 $disconnect 금지 근거(freeze/thaw·재수립 비용)와 좀비 커넥션 대응 포함
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
- 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단계 프레이밍 보정, 문체 다듬기(기하급수→선형·중복 어휘 등)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
개요
이슈 #49를 다루는 포스트를 추가하고, 이 글이 속할 backend 시리즈 랜딩을 새로 만들었습니다.
서버리스(Lambda)에 Prisma를 올리면 트래픽이 몰릴 때
too many connections로 터지는 문제를, "인스턴스 수 × 인스턴스당 풀 크기"라는 곱셈이 폭발하는 메커니즘으로 먼저 설명하고, 그 두 항을 순서대로 줄여 나가는 해결 순서를 코드와 함께 정리했습니다.신설: backend 시리즈 랜딩
apps/blog/src/app/(main)/posts/backend/page.tsx— 기존 fullstack 랜딩과 동일하게isSeriesLanding기반으로 정의했습니다.date를2026-07-20로 두어 fullstack(2026-03-24) 뒤, 즉 시리즈 nav 목록 끝에 오도록 했습니다(의도된 순서).postId/tags를 넣지 않았습니다.포스트 내용
apps/blog/src/app/(main)/posts/backend/serverless-prisma-connections/page.mdxconnection_limit낮추기 → 2단계 핸들러 바깥 클라이언트 재사용(cold start/warm invocation,globalThis싱글턴) → 3단계 외부 풀러(PgBouncer transaction 모드, Prisma Accelerate)$disconnect()를 부르면 안 되는 이유(재수립 비용 + freeze/thaw 재사용)와 좀비 커넥션 대응정확도가 중요한 부분(connection_limit 기본값/서버리스 권장, warm invocation 재사용 범위,
$disconnect금지 근거, Data Proxy 종료 후 Accelerate 권장, PgBouncerpgbouncer=true의 버전별 주의)은 Prisma 공식 문서를 웹으로 확인해 반영했습니다.검증
pnpm run build성공 —/posts/backend,/posts/backend/serverless-prisma-connections라우트 생성 확인pnpm run lint통과(--max-warnings 0),pnpm test115개 전부 통과Closes #49