<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>쥐뿔도 모르는 개발자의 개발 블로그 – Tech Blog</title><link>https://jeongil.dev/ko/blog/</link><description>Recent content in Tech Blog on 쥐뿔도 모르는 개발자의 개발 블로그</description><generator>Hugo -- gohugo.io</generator><language>ko</language><atom:link href="https://jeongil.dev/ko/blog/feed.xml" rel="self" type="application/rss+xml"/><item><title>[부동산 통합 AI 에이전트 1/2편] AI의 답을 서비스로 이어지게 만들기까지</title><link>https://jeongil.dev/ko/blog/architecture/real-estate-integrated-agent/</link><pubDate>Fri, 13 Nov 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/architecture/real-estate-integrated-agent/</guid><description>
&lt;p>안녕하세요. 프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 정정일입니다.&lt;/p>
&lt;p>이번엔 부동산과 관련된 문제를 대화 하나로 해결하는 통합 AI 에이전트를 목표로 서비스를 만들고, 그 첫 단계를 운영에 반영한 이야기를 해볼까 합니다.&lt;/p>
&lt;p>사용자가 &amp;ldquo;서울 근교 20억 이하 30평대 매매 아파트 찾아줘&amp;quot;라고 물으면 조건에 맞는 아파트와 오피스텔 단지를 찾아 지도와 카드로 보여주고, 이어서 시세나 학군을 물어보고, 마음에 드는 단지가 생기면 담당 중개사에게 신청하는 것까지 하나의 대화 안에서 이어지는 기능입니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/0c4fvueq1t0qdnmdyy6ls/agentic-search-suburbs.png?rlkey=jyracmrj42kwmfacq48tz0973&amp;amp;raw=1" alt="서울 근교를 묻자 서울과 맞닿은 시들을 지도에 경계로 표시하고 그 안에서 단지를 찾은 화면" loading="lazy" />&lt;/p>
&lt;p>&lt;em>운영 화면. &amp;ldquo;서울 근교&amp;quot;라고만 말해도 서울과 맞닿은 시들을 찾아 지도에 경계로 표시하고, 그 안에서 조건에 맞는 단지를 카드와 지도 핀으로 함께 보여줍니다.&lt;/em>&lt;/p>
&lt;p>사실 저는 지난번 &lt;a href="https://jeongil.dev/ko/blog/architecture/ai-property-recommendation-system/">AI 부동산 매물 추천 시스템 구축기&lt;/a>에서 Agent Loop 대신 Planned Tool Use를 선택했고, 그 이유를 이렇게 적었었습니다.&lt;/p>
&lt;blockquote>
&lt;p>저는 Agent Loop가 강력한 건 &lt;strong>도구 실행 결과를 보고 판단을 바꿔야 하는 경우&lt;/strong>라고 생각합니다. (&amp;hellip;) 하지만 부동산 검색은 그렇지 않았습니다.&lt;/p>
&lt;/blockquote>
&lt;p>그런데 이번에는 기획이 바뀌면서 서비스가 AI로 하려는 일이 달라졌고, 그에 맞춰 구조도 Agent Loop로 다시 만들게 됐습니다.&lt;/p>
&lt;p>이번 작업에서 가장 많이 고민한 건 &lt;strong>AI가 답만 하고 끝나지 않고, 중개 신청 같은 서비스의 실제 기능으로 자연스럽게 이어지게 하는 일&lt;/strong>이었습니다. 그러다 보니 LLM에게 어디까지 맡길지도 정해야 했습니다.&lt;/p>
&lt;p>이 글은 두 편으로 나눠봤습니다. 1편에서는 목표를 어떻게 잡았고 AI의 답을 서비스로 어떻게 이어지게 했는지를 먼저 다루고, LLM에게 어디까지 맡기고 무엇을 코드에 둘지 정한 이야기는 2편에서 이어가보도록 하겠습니다.&lt;/p>
&lt;p>다만 시작하기에 앞서, 이 글은 저희 서비스 상황에서 문제를 만나고 판단했던 과정을 정리한 글이라 다른 상황에는 맞지 않을 수도 있습니다. 그 점을 감안하고 봐주시면 감사하겠습니다.&lt;/p>
&lt;h2>Plan 방식으로 만들었던 AI 추천&lt;span class="hx:absolute hx:-mt-20" id="plan-방식으로-만들었던-ai-추천">&lt;/span>
&lt;a href="#plan-%eb%b0%a9%ec%8b%9d%ec%9c%bc%eb%a1%9c-%eb%a7%8c%eb%93%a4%ec%97%88%eb%8d%98-ai-%ec%b6%94%ec%b2%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>기존 AI 추천은 LLM이 사용자의 질문을 보고 실행 계획을 JSON으로 한 번 세우면, 코드가 그 계획대로 도구를 실행하는 구조였습니다. 장소를 찾고, 그 근처 단지를 검색하고, 점수를 매겨 추천하는 식이었죠.&lt;/p>
&lt;p>추천이 목표였을 때는 이 구조가 잘 맞았다고 생각합니다. 도구를 부르는 순서가 거의 정해져 있었고, 흐름이 고정돼 있으니 응답 시간과 비용도 예측할 수 있었거든요. 계획을 세운 뒤에는 LLM이 실행 흐름을 바꿀 수 없다는 점도 안전장치 역할을 해줬고요.&lt;/p>
&lt;h2>기획 변경과 기존 구조의 한계&lt;span class="hx:absolute hx:-mt-20" id="기획-변경과-기존-구조의-한계">&lt;/span>
&lt;a href="#%ea%b8%b0%ed%9a%8d-%eb%b3%80%ea%b2%bd%ea%b3%bc-%ea%b8%b0%ec%a1%b4-%ea%b5%ac%ec%a1%b0%ec%9d%98-%ed%95%9c%ea%b3%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이번 작업은 기획팀과 새 AI 서비스를 함께 설계하면서 시작됐습니다. 기획팀이 정리해 온 고객 질문이 128개였고, 이 질문들을 아파트 찾기, 계약, 집 관리, 서비스 이용 방법이라는 4개의 여정으로 묶었습니다.&lt;/p>
&lt;p>질문들을 보니 사용자분들이 원하는 건 &amp;ldquo;조건에 맞는 단지 찾기&amp;quot;에서 끝나지 않았습니다. 찾은 단지의 실거래가나 지금 나와 있는 매물을 궁금해하시고, 근처 학교나 지하철, 복비가 얼마나 나오는지, 등기는 괜찮은지도 물어보셨습니다.&lt;/p>
&lt;p>그리고 질문을 따라가다 보면 마지막에는 &amp;ldquo;이 단지 담당 중개사와 이야기해 보고 싶다&amp;quot;로 이어지는 경우가 많았습니다. 사용자분들 입장에서는 이게 다 이어지는 과정인데, 저희 서비스는 이걸 기능마다 따로 나눠서 제공하고 있었죠. 기존 AI 추천도 추천이 끝나면 역할이 끝났고, 그다음은 사용자가 직접 단지 상세로, 다시 중개 신청 화면으로 넘어가야 했습니다.&lt;/p>
&lt;p>기획팀과는 목표를 **&amp;ldquo;사용자의 문제를 AI가 이해하고, 답을 드리고, 서비스 안의 알맞은 기능으로 이어드리는 것&amp;rdquo;**으로 잡았습니다. 늘어난 사용자 요구를 대화 하나에서 받고 중개사 매칭까지 가는 단계를 줄여보자는 거였죠. 자연어로 서비스 기능을 바로 써볼 수 있게 하는 것도 목표에 넣었습니다. 저희는 이걸 묶어서 &amp;ldquo;부동산 통합 AI 에이전트&amp;quot;라고 부르기로 했습니다.&lt;/p>
&lt;p>방향은 기획팀과 협의해서 정했고, 저는 바뀐 서비스를 어떤 구조로 만들지를 맡았습니다. 목표가 큰 만큼 기존 서비스에서 가장 중요한 흐름인 아파트 추천, 상세 정보 확인, 중개 신청까지를 먼저 만들고 나머지를 그 위에 하나씩 붙이기로 했습니다.&lt;/p>
&lt;p>그렇다면 기존 구조를 늘리는 것으로 충분했을까요? 처음에는 계획 단계에 의도를 몇 개 더 추가하고 도구를 더 붙이면 되지 않을까 생각했습니다. 그런데 기존 코드를 다시 분석해보니 늘리는 것만으로는 해결되지 않는 문제들이 있었습니다.&lt;/p>
&lt;ul>
&lt;li>LLM에 보내는 메시지가 시스템 프롬프트와 이번 질문 두 개뿐이라, &amp;ldquo;거기서 좀 더 싼 곳은?&amp;rdquo; 같은 이어지는 질문을 이해하지 못했습니다.&lt;/li>
&lt;li>결과가 0건이어도 조건을 풀어 다시 찾을 방법이 없었습니다.&lt;/li>
&lt;li>장소를 1순위 후보 하나로 고정해서, &amp;ldquo;세종고등학교&amp;quot;가 다른 지역의 같은 이름 학교로 잡히기도 했습니다. 후보가 여럿이면 되물어야 하는데, 계획을 한 번에 세우는 구조라 중간에 멈추고 되물을 수 없었습니다.&lt;/li>
&lt;/ul>
&lt;p>첫 번째는 대화 이력을 함께 보내면 기존 구조에서도 어느 정도 풀 수 있었을 겁니다. 하지만 0건일 때 조건을 푸는 일이나 후보가 여럿일 때 되묻는 일은, 도구를 실행한 결과를 보고 나서야 무엇을 할지 정할 수 있었습니다. 지난 글에서 Agent Loop가 필요하다고 적었던 경우에 해당했죠.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Plan[&amp;#34;기존: 계획을 한 번 세우고 그대로 실행&amp;#34;]
direction LR
Q1[&amp;#34;질문&amp;#34;] --&amp;gt; P1[&amp;#34;LLM이 계획 작성&amp;#34;] --&amp;gt; E1[&amp;#34;코드가 계획대로&amp;lt;br/&amp;gt;도구 실행&amp;#34;] --&amp;gt; A1[&amp;#34;답변&amp;#34;]
end
subgraph Loop[&amp;#34;이번: 결과를 보고 다음 행동을 고름&amp;#34;]
direction LR
Q2[&amp;#34;질문&amp;#34;] --&amp;gt; L2[&amp;#34;LLM이 도구 선택&amp;#34;] --&amp;gt; T2[&amp;#34;도구 실행&amp;#34;] --&amp;gt; R2{&amp;#34;결과 확인&amp;#34;}
R2 --&amp;gt;|더 필요하면| L2
R2 --&amp;gt;|되묻기, 완화안 제시, 답변| A2[&amp;#34;응답&amp;#34;]
end
&lt;/pre>&lt;p>지난 글에서 부동산 검색에는 이런 상황이 잘 생기지 않는다고 판단한 건, 그때 만든 게 질문 한 번을 처리하는 기능이었기 때문이지 않나 싶습니다. 대화가 되면 흐름이 사용자마다 다르고, 앞의 결과에 따라 다음 질문이 달라집니다. 128개 질문의 흐름을 계획 프롬프트에 다 적어두려면 결국 지난 글에서 버렸던 고정 파이프라인과 비슷해질 것 같았습니다.&lt;/p>
&lt;p>그래서 LLM이 도구를 고르고, 결과를 보고, 다음 도구를 고르는 Agent Loop로 가기로 결정했습니다. 다만 LLM이 할 수 있는 일은 저희가 직접 만든 도구로 한정했고, 이 부분은 2편에서 자세히 다루겠습니다.&lt;/p>
&lt;h3>경로를 하나로 둔 이유&lt;span class="hx:absolute hx:-mt-20" id="경로를-하나로-둔-이유">&lt;/span>
&lt;a href="#%ea%b2%bd%eb%a1%9c%eb%a5%bc-%ed%95%98%eb%82%98%eb%a1%9c-%eb%91%94-%ec%9d%b4%ec%9c%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>처음 설계안은 Agent Loop만 쓰는 구조가 아니었습니다. 작은 모델로 질문을 먼저 분류해서, &amp;ldquo;강남역 근처 10억 이하 30평대&amp;quot;처럼 정형화된 질문은 기존 계획 경로로 보내고 모호하거나 이어지는 질문만 Agent Loop로 보내는 하이브리드 구조였습니다.&lt;/p>
&lt;p>정형 질문은 도구 순서가 정해져 있으니 기존 경로가 빠르고 싸거든요. 지난 글에서 인용했던 LLMCompiler 논문도 ReAct 방식(생각하고, 도구를 부르고, 결과를 보고 다시 생각하는 방식) 대비 지연은 최대 3.7배, 비용은 최대 6.7배까지 줄일 수 있다고 보고하고 있었습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
Q[&amp;#34;질문&amp;#34;] --&amp;gt; R{&amp;#34;라우터&amp;lt;br/&amp;gt;(작은 모델로 분류)&amp;#34;}
R --&amp;gt;|정형 질문| P[&amp;#34;기존 계획 경로&amp;#34;]
R --&amp;gt;|모호하거나 이어지는 질문| L[&amp;#34;Agent Loop&amp;#34;]
P --&amp;gt; A[&amp;#34;응답&amp;#34;]
L --&amp;gt; A
P -.-&amp;gt;|가격 규칙 · 0건 처리 · 권유 규칙| X[&amp;#34;같은 규칙을&amp;lt;br/&amp;gt;두 곳에서 유지&amp;#34;]
L -.-&amp;gt; X
&lt;/pre>&lt;p>하지만 라우터는 만들지 않기로 했습니다. 경로가 두 개면 가격 범위를 어떻게 넓힐지, 0건이면 어떻게 할지, 무엇을 권할지 같은 규칙을 두 곳에 똑같이 맞춰둬야 합니다. 사용자가 대화 중에 정형 질문과 이어지는 질문을 섞으면 한 대화 안에서 경로가 계속 바뀌고, 라우터가 잘못 분류했을 때 어느 쪽 문제인지 찾는 것도 일입니다.&lt;/p>
&lt;p>저희는 팀 규모가 작아서 한 번 만든 뒤에도 계속 고쳐 나가야 했고, &lt;strong>두 경로의 규칙을 계속 같게 유지하는 건 저희 상황에서는 어렵다고 생각했습니다.&lt;/strong> 물론 그만큼 응답이 느려지는 건 감수해야 했습니다.&lt;/p>
&lt;p>프레임워크도 비슷한 기준으로 골랐습니다. OpenAI의 Responses API(도구 호출과 추론 모델을 함께 쓰는 새 API)를 지원하는 Spring AI 버전을 쓰려면 Spring Boot 메이저 버전을 올려야 했는데, 서비스 전체에 영향이 가는 업그레이드를 AI 작업과 묶기는 어려웠습니다. LangChain4j는 추상화 계층이 하나 더 생겨서, 문제가 생기면 제 코드와 프레임워크 코드를 같이 봐야 할 것 같았고요.&lt;/p>
&lt;p>결국 공식 SDK의 Responses API 위에 루프를 직접 만들었습니다. 루프 자체는 수백 줄 정도라 생각보다 단순했습니다.&lt;/p>
&lt;h2>AI의 답을 서비스 기능으로&lt;span class="hx:absolute hx:-mt-20" id="ai의-답을-서비스-기능으로">&lt;/span>
&lt;a href="#ai%ec%9d%98-%eb%8b%b5%ec%9d%84-%ec%84%9c%eb%b9%84%ec%8a%a4-%ea%b8%b0%eb%8a%a5%ec%9c%bc%eb%a1%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>초기 버전을 써보니 LLM이 답은 꽤 잘하는데, 그 답에서 서비스 기능으로 넘어가지는 않더라고요. 예를 들어 &amp;ldquo;헬리오시티 33평 29억이면 복비 얼마야?&amp;ldquo;라고 물었을 때 AI는 복비를 정확하게 계산해주고 거기서 끝났습니다. 그 단지를 사려고 복비까지 계산해보는 사용자라면 담당 중개사와 이야기해볼 만한 시점인데도요.&lt;/p>
&lt;p>기획에서도 이 부분을 가장 중요하게 봤습니다. 기획에서는 답변을 답, 근거, 행동 3단으로 나누는데, 그중에서도 서비스의 알맞은 기능으로 이어주는 &amp;ldquo;행동&amp;quot;이 핵심이었거든요. 지표 역시 AI 답변에서 중개 신청이나 등기분석 같은 서비스 기능으로 넘어간 비율로 잡았습니다.&lt;/p>
&lt;p>그렇다면 AI의 답을 어떻게 하면 서비스의 실제 기능으로 자연스럽게 이어줄 수 있을까요? 그리고 사용자 입장에서 그게 억지스러운 권유로 느껴지지 않으려면 무엇이 필요할까요?&lt;/p>
&lt;h2>중개 신청까지 이어지게&lt;span class="hx:absolute hx:-mt-20" id="중개-신청까지-이어지게">&lt;/span>
&lt;a href="#%ec%a4%91%ea%b0%9c-%ec%8b%a0%ec%b2%ad%ea%b9%8c%ec%a7%80-%ec%9d%b4%ec%96%b4%ec%a7%80%ea%b2%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>서비스로 이어지는 가장 직접적인 결과는 중개 신청이었고, 대화 안에서 신청까지 이어지게 하고 싶었습니다.&lt;/p>
&lt;p>먼저 정한 건 &lt;strong>신청을 LLM이 직접 실행하지 않는다&lt;/strong>는 것이었습니다. LLM은 같은 도구를 두 번 부르기도 하고 의도를 잘못 해석하기도 하는데, 신청은 한 번 들어가면 중개사에게 그대로 전달돼서 되돌리기 어렵거든요. 그래서 LLM에게는 신청을 &amp;ldquo;제안&amp;quot;하는 도구까지만 주고, 신청을 실행하는 도구는 주지 않았습니다. 사용자가 확인한 뒤의 신청을 누가 실행할지는 따로 정해야 했습니다.&lt;/p>
&lt;p>처음 설계는 사용자가 확인 버튼을 누르면 LLM을 거치지 않고 서버로 요청이 들어오고, 서버가 제안 ID를 멱등키로 써서 신청을 넣는 방식이었습니다. 네트워크가 끊겨 요청이 다시 들어와도 신청은 한 번만 되게 하려는 설계였죠. 다만 기존 중개 신청 흐름을 따라가보니 단계마다 화면에서 값을 받아 다음 요청을 만드는 구조라, 서버가 대화에서 한 번에 실행하기에는 맞지 않았습니다.&lt;/p>
&lt;p>그래서 신청은 원래 하던 곳에서 하기로 했습니다. 지금은 서버가 신청 제안까지만 만듭니다. 사용자가 확인 카드에서 &amp;ldquo;신청하기&amp;quot;를 누르면 단지 화면에서 쓰던 기존 신청 흐름이 카드 안에서 그대로 실행됩니다. 신청 규칙을 한 곳에만 두고 이미 검증된 흐름을 그대로 쓰자는 생각이었습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant U as 사용자
participant A as LLM
participant S as 서버
participant C as 앱과 웹의 신청 흐름
U-&amp;gt;&amp;gt;A: &amp;#34;잠실엘스 33평 30억에 매매로 사고 싶어&amp;#34;
A-&amp;gt;&amp;gt;S: 신청 제안 도구 호출 (제안 등급)
S-&amp;gt;&amp;gt;S: 담당 중개사 확인, 제안 저장
S--&amp;gt;&amp;gt;U: 신청 확인 카드 (평형과 희망가를 대화에서 채움)
U-&amp;gt;&amp;gt;C: &amp;#34;신청하기&amp;#34; (LLM을 거치지 않음)
C-&amp;gt;&amp;gt;C: 기존 중개 신청 흐름으로 신청
&lt;/pre>&lt;p>서버가 한 응답에 제안을 하나만 남기기 때문에, LLM이 제안 도구를 여러 번 부르더라도 확인 카드는 하나만 뜨고 신청도 사용자가 확인한 한 건만 들어갑니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/7au4wols8uxmn6l7saa3c/agentic-service-link.png?rlkey=xc5qv81lprgwo4bbvolulljzk&amp;amp;raw=1" alt="서비스 연결. 진행 중인 신청이 있으면 새로 권하지 않고 진행 상황을, 거래 의사가 분명하면 대화에서 채운 신청 확인 카드를 보여줍니다" loading="lazy" />&lt;/p>
&lt;p>&lt;em>제 테스트 계정으로 찍은 운영 화면입니다. 왼쪽은 헬리오시티 18억 매매의 복비를 물었을 때입니다. 이 단지에는 이미 진행 중인 신청이 있어서, 새 신청 카드 대신 진행 중인 신청과 담당 중개사 대화 버튼을 붙였습니다. 오른쪽은 &amp;ldquo;사고 싶어&amp;quot;라고 했을 때의 확인 카드로, 평형과 희망가가 대화에서 채워져 있고 신청은 사용자가 &amp;ldquo;신청하기&amp;quot;를 눌러야 진행됩니다.&lt;/em>&lt;/p>
&lt;p>등기분석도 같은 원칙으로 붙였습니다. 대화에서는 결과를 설명하고 신청 준비까지만 하고, 결제와 신청은 기존 등기분석 화면에서 합니다.&lt;/p>
&lt;h2>권유 시점&lt;span class="hx:absolute hx:-mt-20" id="권유-시점">&lt;/span>
&lt;a href="#%ea%b6%8c%ec%9c%a0-%ec%8b%9c%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>신청 말고도 AI가 권할 수 있는 서비스는 여럿 있었습니다. 다만 저는 이게 억지스러우면 안 된다고 생각했습니다.&lt;/p>
&lt;p>단지를 둘러보는 중인데 답변마다 &amp;ldquo;중개사와 연결해 드릴까요?&amp;ldquo;가 붙으면 광고처럼 느껴지고, 저라도 대화를 그만둘 것 같았거든요. 권유를 자주 붙이면 지표는 올라가겠지만, 그게 서비스에 좋은 건지는 잘 모르겠더라고요.&lt;/p>
&lt;p>처음에는 지시문에 &amp;ldquo;단지 추천, 시세, 비교 중에는 중개 연결을 권하지 않는다&amp;quot;고 적었습니다. 그랬더니 사용자가 &amp;ldquo;여기 사고 싶어&amp;quot;라고 해도 AI가 한 번 더 묻거나 아예 연결해주지 않았습니다. 지시문을 대화 주제만 기준으로 적어두다 보니, 사용자가 직접 원할 때도 연결하지 않았던 거죠.&lt;/p>
&lt;p>그래서 &lt;strong>권유 여부를 사용자가 거래 의사를 얼마나 분명하게 보였는지에 따라 나눴습니다.&lt;/strong> 아래 표의 맞춤 중개는 담당 중개사에게 원하는 조건을 전달해 매물을 문의하는, 저희 서비스의 중개 신청입니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>사용자가 보인 의사&lt;/th>
&lt;th>예시&lt;/th>
&lt;th>AI가 하는 일&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>분명함&lt;/td>
&lt;td>&amp;ldquo;여기 사고 싶어&amp;rdquo;, &amp;ldquo;방문해서 볼 수 있어?&amp;rdquo;&lt;/td>
&lt;td>다시 묻지 않고 신청 확인 카드를 띄움 (대화에서 평형과 희망가를 채움)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>가벼운 관심&lt;/td>
&lt;td>&amp;ldquo;맘에 들어&amp;rdquo;, 특정 단지의 시세나 실거래가를 물어봄&lt;/td>
&lt;td>부담이 작은 단지 소식 알림부터 권하고, 맞춤 중개는 그다음&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>일반 정보만 물음&lt;/td>
&lt;td>&amp;ldquo;학군 어때?&amp;rdquo;, &amp;ldquo;전세 계약 주의사항이 뭐야?&amp;rdquo;&lt;/td>
&lt;td>중개는 권하지 않음 (필요하면 계산기 같은 관련 화면만 안내)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/kxgjoxxhkk2a15qox8h6k/agentic-cards-alarm.png?rlkey=onf0sy9q848reybtuxl1n2u3l&amp;amp;raw=1" alt="특정 단지의 실거래가를 물으면 단지 소식 알림부터 권합니다" loading="lazy" />&lt;/p>
&lt;p>&lt;em>&amp;ldquo;헬리오시티 33평 실거래가 알려줘&amp;quot;에 대한 답변입니다. 실거래가 카드(왼쪽)를 보여준 뒤, 답변 끝에 새 실거래와 신저가를 알려주는 알림 카드(오른쪽)를 붙였습니다.&lt;/em>&lt;/p>
&lt;p>의사가 분명할 때 바로 신청 확인 카드를 띄울 수 있었던 건 앞에서 이야기한 것처럼 최종 확인을 사용자에게 맡겼기 때문입니다. 카드를 띄운 뒤에도 사용자가 한 번 더 눌러야 신청이 들어가니, 바로 띄워도 부담이 적다고 생각했습니다.&lt;/p>
&lt;p>다른 서비스는 대화 주제에 맞춰 이어줍니다.&lt;/p>
&lt;ul>
&lt;li>전세 계약이나 근저당 같은 권리 문제: AI 등기분석&lt;/li>
&lt;li>예산, 대출: 대출 계산기&lt;/li>
&lt;li>집을 팔려는 이야기: 집 내놓기&lt;/li>
&lt;li>사무실이나 상가를 구하거나 내놓으려는 이야기: 사무실 전용 맞춤 중개와 내놓기&lt;/li>
&lt;/ul>
&lt;p>표현도 바꿨습니다. 저희끼리는 &amp;ldquo;매칭&amp;quot;이라고 부르지만 사용자에게 &amp;ldquo;매칭해 드릴까요?&amp;ldquo;는 잘 와닿지 않습니다. 대신 &amp;ldquo;헬리오시티 담당 중개사에게 이 가격대 매물을 문의해 보시겠어요?&amp;ldquo;처럼 사용자가 얻는 걸 중심으로 말하도록 바꿨습니다.&lt;/p>
&lt;h2>권유 규칙&lt;span class="hx:absolute hx:-mt-20" id="권유-규칙">&lt;/span>
&lt;a href="#%ea%b6%8c%ec%9c%a0-%ea%b7%9c%ec%b9%99" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>권할 시점 말고도 지켜야 할 규칙이 몇 가지 더 있었습니다. 같은 대화에서 같은 권유가 반복되면 앞에서 걱정한 광고처럼 느껴지고, 담당 중개사가 없는 단지에 중개를 권하면 눌러도 연결할 곳이 없으니까요.&lt;/p>
&lt;p>사용자가 어떤 관심을 보였는지는 대화를 봐야 알 수 있어서 LLM이 판단해 권유 도구에 넘기고, 권해도 되는지는 그 도구 안에서 서버가 확인합니다.&lt;/p>
&lt;p>예를 들어 맞춤 중개를 권하는 도구는 같은 대화에서 이 단지에 이미 권했는지, 담당 중개사가 있는지, 진행 중인 신청이 있는지를 서버에서 확인하고, 조건에 맞지 않으면 &amp;ldquo;권하지 않음&amp;quot;을 돌려줍니다. 알림을 먼저 권할지 맞춤 중개를 바로 권할지도 LLM이 넘긴 관심의 종류와 권유 이력을 보고 서버가 정하고, 한 응답에는 둘 중 하나만 남깁니다. 지시문에 적어두는 것만으로는 이런 규칙이 잘 지켜지지 않았는데, 이 이야기는 2편에서 이어가겠습니다.&lt;/p>
&lt;p>반대로 사용자가 직접 담당 중개사를 물으면, 앞에서 이미 권했더라도 사용자가 먼저 원한 경우라 버튼을 다시 붙입니다.&lt;/p>
&lt;h2>기존 화면으로 연결&lt;span class="hx:absolute hx:-mt-20" id="기존-화면으로-연결">&lt;/span>
&lt;a href="#%ea%b8%b0%ec%a1%b4-%ed%99%94%eb%a9%b4%ec%9c%bc%eb%a1%9c-%ec%97%b0%ea%b2%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>연결되는 곳은 이미 있는 서비스 화면이어야 한다고 생각했습니다. AI 안에 계산기나 등기분석을 새로 만들 수도 있었지만, 그러면 AI에서 본 숫자와 기존 화면에서 본 숫자가 달라질 수 있거든요.&lt;/p>
&lt;p>AI는 대화 안에서 결과까지만 보여주고, 더 해보고 싶으면 기존 화면으로 보냅니다. 이때 &lt;strong>대화에서 나온 값을 채운 상태로&lt;/strong> 보냅니다. 복비 계산 결과에서 계산기로 넘어가면 금액과 거래 유형이 채워진 채 결과가 바로 보이고, 등기분석 신청 확인에서 넘어가면 동, 호수, 보증금이 채워진 채 등기분석 화면이 열립니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/wm6kphpitxdhmv84liylz/agentic-handoff-calculator.png?rlkey=mmvxsb8mvp6db3zasrk6gwa8s&amp;amp;raw=1" alt="대화에서 계산한 복비와 같은 조건으로 열린 기존 계산기" loading="lazy" />&lt;/p>
&lt;p>&lt;em>&amp;ldquo;잠실엘스 25억에 매매하면 복비 얼마야?&amp;ldquo;에 대한 복비 카드(왼쪽)에서 &amp;ldquo;금액 바꿔서 계산하기&amp;quot;를 누르면, 아파트, 매매, 25억이 채워진 채 기존 계산기가 열리고 같은 절약 금액이 보입니다(오른쪽).&lt;/em>&lt;/p>
&lt;p>대화 안에서 보여주는 계산 결과도 기존 화면과 같아야 했습니다. 복비 계산 로직은 웹 계산기 코드를 연산 순서까지 그대로 옮기고, 웹 계산기를 실제로 실행해서 얻은 값을 정답으로 고정한 테스트를 두었습니다. 계산 로직이 한 벌 더 생긴 건 맞지만, 반올림 하나만 달라도 AI와 계산기의 복비가 달라지니 AI 쪽 계산이 웹과 달라지면 테스트가 바로 깨지게 묶어둔 거죠.&lt;/p>
&lt;h2>결과를 먼저 보여주는 화면 구성&lt;span class="hx:absolute hx:-mt-20" id="결과를-먼저-보여주는-화면-구성">&lt;/span>
&lt;a href="#%ea%b2%b0%ea%b3%bc%eb%a5%bc-%eb%a8%bc%ec%a0%80-%eb%b3%b4%ec%97%ac%ec%a3%bc%eb%8a%94-%ed%99%94%eb%a9%b4-%ea%b5%ac%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>서비스로 이어지게 하려면 화면도 달라야 했습니다. 저는 처음부터 이 기능이 긴 텍스트를 보여주는 챗봇처럼 보이지 않았으면 했습니다. 단지 열 곳의 가격과 평형을 문장으로 나열하면 읽기도, 비교하기도 어렵고, 다음에 뭘 할지도 잘 보이지 않으니까요.&lt;/p>
&lt;h3>조건을 다 묻기 전에 결과부터&lt;span class="hx:absolute hx:-mt-20" id="조건을-다-묻기-전에-결과부터">&lt;/span>
&lt;a href="#%ec%a1%b0%ea%b1%b4%ec%9d%84-%eb%8b%a4-%eb%ac%bb%ea%b8%b0-%ec%a0%84%ec%97%90-%ea%b2%b0%ea%b3%bc%eb%b6%80%ed%84%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>처음 만든 버전은 조건이 부족하면 먼저 물었습니다. 거래 유형, 예산, 평형을 하나씩 확인한 뒤에 검색하는 식이었습니다. 정확하긴 했지만 사용자는 결과보다 되묻는 질문을 먼저 받는 경우가 많았습니다.&lt;/p>
&lt;p>그래서 기획팀과 이야기해서 &lt;strong>일단 가정하고 결과부터 보여주는 쪽&lt;/strong>으로 바꿨습니다. 거래 유형을 말하지 않으면 매매로 가정해서 바로 검색하고, 답변에서 매매로 가정했다는 걸 짚어줍니다. 결과가 많을 때는 상위 몇 곳을 먼저 보여주고, 빠진 조건은 결과 아래 버튼으로 묻습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/fw6nlbhfnylacqc0syk5c/agentic-results-first.png?rlkey=ptf6tbxzfaca5rrn6b244jv0x&amp;amp;raw=1" alt="조건이 덜 정해져도 결과부터 보여주고, 빠진 조건은 결과 아래 버튼으로 묻습니다" loading="lazy" />&lt;/p>
&lt;p>&lt;em>&amp;ldquo;마포구 15억 이하 30평대 아파트&amp;quot;에는 거래 유형이 없습니다. 매매로 가정해 33곳을 찾고 그 사실을 답변에 밝힌 뒤(왼쪽), 아래쪽에는 결과를 좁혀볼 수 있는 버튼을 단지 수와 함께 보여줍니다(오른쪽).&lt;/em>&lt;/p>
&lt;p>이후에 거래 유형만큼은 먼저 묻는 방식도 다시 적용해봤습니다. 그런데 대화 기록을 비교해보니 첫 질문부터 되묻는 경우가 크게 늘었고, 매매를 기본으로 두면서 자연스럽게 이어지던 흐름도 같이 사라졌습니다. 결과가 나오면 실거래가 차트와 알림 권유가 이어지는데, 거래 유형이 정해지지 않은 동안에는 해당 도구들이 아예 불리지 않았던 거죠. 그래서 다시 결과부터 보여주는 방식으로 되돌렸습니다. 거래 유형을 잘못 가정했더라도 다음 질문에서 바로 바꾸면 되니까요.&lt;/p>
&lt;h3>카드 고르기&lt;span class="hx:absolute hx:-mt-20" id="카드-고르기">&lt;/span>
&lt;a href="#%ec%b9%b4%eb%93%9c-%ea%b3%a0%eb%a5%b4%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>가격이나 면적 같은 숫자는 코드가 만든 카드로 보여주고, LLM은 답변에서 카드에 없는 설명만 덧붙입니다. 실거래가는 차트로, 매물은 최근 실거래 대비 몇 % 차이인지 보이는 목록으로, 중개 신청 진행 상황은 지금 어느 단계인지 보이는 막대로 보여줍니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/2bor058hkugk8pcprzgjg/agentic-listings-map.png?rlkey=dvmk8pmt1bm7l0a22vpw20rtj&amp;amp;raw=1" alt="매물 카드와 지도. 카드의 매물과 지도의 동별 최저 호가가 같은 데이터를 보여줍니다" loading="lazy" />&lt;/p>
&lt;p>&lt;em>&amp;ldquo;지금 나와있는 매매 매물도 보여줘&amp;quot;에 대한 화면입니다. 오른쪽 카드는 최근 거래 평균보다 싼 매물 수와 각 매물의 최근 거래 대비 %를, 지도는 동별 최저 호가를 보여줍니다.&lt;/em>&lt;/p>
&lt;p>초기 버전은 답변이 다 끝난 뒤에 카드를 붙였습니다. 결과를 먼저 보여주려고 도구가 조회할 때마다 카드를 바로 그리게 바꿨는데, 이번에는 LLM이 답을 만들려고 단지 세 곳을 조회하면 카드도 세 장이 쌓였습니다. 사용자는 하나를 물었는데 화면에는 LLM이 확인해본 것들이 전부 나오는 거죠. 예외 규칙을 하나씩 추가해서 막아봤습니다. 하지만 이번에는 다른 곳에서 카드가 빠지는 문제가 생겨서, 조회와 표시를 나누기로 했습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Before[&amp;#34;이전: 조회할 때마다 카드가 나감&amp;#34;]
direction LR
Q1[&amp;#34;조회 1&amp;#34;] --&amp;gt; K1[&amp;#34;카드 1&amp;#34;]
Q2[&amp;#34;조회 2&amp;#34;] --&amp;gt; K2[&amp;#34;카드 2&amp;#34;]
Q3[&amp;#34;조회 3&amp;#34;] --&amp;gt; K3[&amp;#34;카드 3&amp;#34;]
end
subgraph After[&amp;#34;이후: 조회는 대기, 보여줄 카드는 고름&amp;#34;]
direction LR
P1[&amp;#34;조회 1&amp;#34;] --&amp;gt; W[&amp;#34;대기 중인 카드&amp;#34;]
P2[&amp;#34;조회 2&amp;#34;] --&amp;gt; W
P3[&amp;#34;조회 3&amp;#34;] --&amp;gt; W
W --&amp;gt;|대상이 하나면 서버가 바로| OUT[&amp;#34;보여줄 카드&amp;#34;]
W --&amp;gt;|대상이 여럿이면 LLM이 고름| OUT
end
&lt;/pre>&lt;p>도구가 조회한 결과는 바로 그리지 않고 모아뒀다가, &lt;strong>답변이 시작되기 직전에 어떤 카드를 보여줄지 정합니다.&lt;/strong> 보여줄 대상이 하나뿐이면 서버가 바로 내보내고, 서로 다른 대상이 둘 이상일 때만 LLM에게 고르게 합니다.&lt;/p>
&lt;p>바꾸기 전후로 같은 질문과 화면 조합 56개를 비교해봤습니다. 36개는 그대로였고, 3개는 의도한 대로 나아졌습니다. 나머지 17개도 하나씩 열어봤는데, 아무것도 바꾸지 않고 같은 질문을 두 번 돌렸을 때도 생기는 정도의 흔들림이었고 바뀐 방식 때문에 나빠진 경우는 없었습니다.&lt;/p>
&lt;p>물론 그만큼 감수해야 하는 부분도 있었습니다. LLM이 카드를 고르는 단계가 하나 늘면서 한 턴에 쓰는 호출과 토큰도 늘었습니다. 그래서 카드를 고르는 단계가 필요한 조건을 좁히고 토큰 상한도 다시 잡았습니다. 늘어난 비용이 감당할 만한 수준인지는 운영 데이터가 좀 쌓이면 다시 봐야 할 것 같습니다.&lt;/p>
&lt;h3>화면의 모든 요소가 같은 데이터를 보도록&lt;span class="hx:absolute hx:-mt-20" id="화면의-모든-요소가-같은-데이터를-보도록">&lt;/span>
&lt;a href="#%ed%99%94%eb%a9%b4%ec%9d%98-%eb%aa%a8%eb%93%a0-%ec%9a%94%ec%86%8c%ea%b0%80-%ea%b0%99%ec%9d%80-%eb%8d%b0%ec%9d%b4%ed%84%b0%eb%a5%bc-%eb%b3%b4%eb%8f%84%eb%a1%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>카드를 넣고 나니 화면에서 정보를 보여주는 곳이 여러 개가 됐습니다. LLM이 쓰는 답변과 코드가 그리는 카드, 지도 위의 핀, 선택지 버튼까지요. 써보면서 나온 문제들은 대부분 이것들이 서로 다른 내용을 보여주는 문제였습니다.&lt;/p>
&lt;ul>
&lt;li>답변은 단지를 거리순으로 나열하는데 화면 목록은 추천 순위순이라, &amp;ldquo;첫 번째 단지&amp;quot;라고 하면 답변의 첫 번째와 화면의 첫 번째가 달랐습니다.&lt;/li>
&lt;li>한 응답에서 LLM이 검색을 여러 번 하면 조건을 고르는 버튼 묶음도 여러 번 쌓였는데, 서버는 마지막 묶음의 조건만 기억하고 있어서 앞쪽 버튼과 서버가 기억하는 조건이 어긋날 수 있었습니다.&lt;/li>
&lt;/ul>
&lt;p>두 문제 모두 답변, 카드, 버튼이 서로 다른 데이터를 보고 있었기 때문이라고 생각합니다. 그래서 &lt;strong>화면의 모든 요소가 같은 데이터를 보도록&lt;/strong> 맞췄습니다.&lt;/p>
&lt;p>도구가 LLM에게 넘기는 결과도 화면과 같은 순서로 넘깁니다. 정렬이 필요하면 거리순이나 가격순 같은 정렬을 검색 도구에 넣었는데, 그러면 LLM이 순서를 따로 만들지 않아도 되니까요. 버튼은 실행이 끝날 때 서버가 기억하는 마지막 묶음 하나를 보냅니다. 버튼을 누르면 질문이 전송되고, 다른 화면으로 넘어가는 건 카드에서 합니다.&lt;/p>
&lt;p>데이터 자체도 마찬가지였습니다. 에이전트는 검색 결과와 상세 정보, 실거래가를 한 답변에 같이 쓰기 때문에, 도구도 단지 상세 화면과 같은 데이터를 씁니다.&lt;/p>
&lt;p>진행 단계 이름도 같은 문제였습니다. 중개 신청 진행 현황을 보여줄 때 AI가 &amp;ldquo;중개사 배정 중&amp;quot;이라고 말한 적이 있는데, 저희 서비스에는 배정 중이라는 단계가 없습니다. 단계 이름을 정해주지 않았기 때문에 LLM이 상태값을 보고 그럴듯한 이름을 지어낸 거였죠. 지금은 실제 업무 단계에 맞춘 이름을 코드에서 넘겨주고 있어서, LLM이 이름을 새로 지어내지 않습니다.&lt;/p>
&lt;h2>1편을 마치며&lt;span class="hx:absolute hx:-mt-20" id="1편을-마치며">&lt;/span>
&lt;a href="#1%ed%8e%b8%ec%9d%84-%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>1편에서 다룬 내용을 정리하면 다음과 같습니다.&lt;/p>
&lt;ol>
&lt;li>신청은 LLM이 제안까지만 하고, 사용자가 확인하면 기존 신청 흐름에서 진행됩니다.&lt;/li>
&lt;li>권유는 사용자가 보인 거래 의사의 정도에 맞췄습니다.&lt;/li>
&lt;li>긴 문장 대신 결과와 카드를 먼저 보여주고, 빠진 조건은 결과 아래에서 물었습니다.&lt;/li>
&lt;li>대화 안의 결과는 기존 화면과 같은 데이터, 같은 숫자로 보여줬습니다.&lt;/li>
&lt;/ol>
&lt;p>운영에 반영한 지 얼마 되지 않아서, 기획에서 지표로 잡은 서비스 기능으로 넘어간 비율은 데이터가 쌓이면 이 글에 덧붙이겠습니다.&lt;/p>
&lt;p>그런데 이렇게 AI가 서비스의 기능으로 이어지면, AI가 틀렸을 때 사용자에게 실제로 손해가 생길 수 있습니다. 버튼에 적힌 숫자를 믿고 눌렀는데 다른 결과가 나오거나, 다른 사람의 정보가 보이는 식으로요. AI를 서비스 기능과 이어 붙이다 보니, LLM과 코드의 역할을 어떻게 나눌지도 함께 정해야 했습니다.&lt;/p>
&lt;p>&lt;strong>LLM에게 어디까지 맡길 것인가?&lt;/strong>&lt;/p>
&lt;p>2편에서는 그 기준을 어떻게 정하고 지켰는지, 그리고 느려진 응답은 어떻게 다뤘는지 이야기해보려 합니다.&lt;/p>
&lt;p>후편: &lt;a href="https://jeongil.dev/ko/blog/architecture/real-estate-integrated-agent-llm-boundary/">[부동산 통합 AI 에이전트 2/2편] LLM과 코드의 역할을 나누기까지&lt;/a>&lt;/p>
&lt;p>이 글에서 다룬 기능은 &lt;a href="https://bootalk.co.kr/apt"target="_blank" rel="noopener">부톡 아파트&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> 웹과 앱에서 사용해보실 수 있습니다. 긴 글 읽어주셔서 감사합니다.&lt;/p>
&lt;hr>
&lt;h2>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>관련 글&lt;span class="hx:absolute hx:-mt-20" id="관련-글">&lt;/span>
&lt;a href="#%ea%b4%80%eb%a0%a8-%ea%b8%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/architecture/ai-property-recommendation-system/">AI 부동산 매물 추천 시스템 구축기&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>참고 문헌&lt;span class="hx:absolute hx:-mt-20" id="참고-문헌">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%eb%ac%b8%ed%97%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>Anthropic - &lt;a href="https://www.anthropic.com/engineering/building-effective-agents"target="_blank" rel="noopener">Building Effective Agents&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>OpenAI - &lt;a href="https://cdn.openai.com/business-guides-and-resources/a-practical-guide-to-building-agents.pdf"target="_blank" rel="noopener">A practical guide to building agents&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>OpenAI - &lt;a href="https://platform.openai.com/docs/api-reference/responses"target="_blank" rel="noopener">Responses API&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>Kim et al. - &lt;a href="https://arxiv.org/abs/2312.04511"target="_blank" rel="noopener">An LLM Compiler for Parallel Function Calling&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> (arXiv, 2023)&lt;/li>
&lt;/ul></description></item><item><title>[부동산 통합 AI 에이전트 2/2편] LLM과 코드의 역할을 나누기까지</title><link>https://jeongil.dev/ko/blog/architecture/real-estate-integrated-agent-llm-boundary/</link><pubDate>Fri, 13 Nov 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/architecture/real-estate-integrated-agent-llm-boundary/</guid><description>
&lt;p>전편: &lt;a href="https://jeongil.dev/ko/blog/architecture/real-estate-integrated-agent/">[부동산 통합 AI 에이전트 1/2편] AI의 답을 서비스로 이어지게 만들기까지&lt;/a>&lt;/p>
&lt;p>저번 편에서는 부동산 통합 AI 에이전트를 만들면서 AI의 답을 서비스 기능으로 이어지게 한 과정을 살펴보았습니다.&lt;/p>
&lt;p>1편을 읽지 않으신 분들을 위해 짧게 정리하면 이렇습니다. 저희는 기획 변경에 맞춰 부동산 통합 AI 에이전트를 만들어 운영에 반영했습니다. 대화 하나에서 단지를 찾고, 시세를 묻고, 담당 중개사에게 신청하는 것까지 이어지는 기능입니다.&lt;/p>
&lt;p>기존 AI 추천은 LLM이 계획을 한 번 세우면 코드가 그대로 실행하는 구조였는데, 이번에는 LLM이 도구를 고르고 결과를 보고 다음 도구를 고르는 Agent Loop로 바꿨습니다. 라우터는 두지 않고 모든 질문을 이 루프 하나로 처리합니다. 화면에서는 숫자를 코드가 만든 카드로 보여주고, 거래 유형이 빠지면 매매로 가정해 결과부터 보여준 뒤 버튼으로 묻습니다. 중개 신청은 사용자가 확인 카드를 누르면 앱과 웹의 기존 신청 흐름으로 진행됩니다.&lt;/p>
&lt;p>그런데 AI의 답이 신청이나 기존 화면까지 연결되다 보니, AI가 틀렸을 때의 영향도 화면의 숫자나 실제 신청까지 미칠 수 있었습니다. 이번 글은 그 문제에서 출발해볼까 합니다. LLM에게 맡길 일과 서비스가 책임질 일을 어떤 기준으로 나눴는지, 그 기준을 코드로 어떻게 지켰는지, 그리고 이 구조 때문에 느려진 응답은 어떻게 했는지까지 이야기해보도록 하겠습니다.&lt;/p>
&lt;h2>어디까지 맡길지 정한 기준&lt;span class="hx:absolute hx:-mt-20" id="어디까지-맡길지-정한-기준">&lt;/span>
&lt;a href="#%ec%96%b4%eb%94%94%ea%b9%8c%ec%a7%80-%eb%a7%a1%ea%b8%b8%ec%a7%80-%ec%a0%95%ed%95%9c-%ea%b8%b0%ec%a4%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>Agent Loop에서는 어떤 도구를 몇 번, 어떤 순서로, 어떤 인자로 부를지 LLM이 정합니다. 그만큼 LLM이 틀릴 수 있는 곳도 많아지죠.&lt;/p>
&lt;p>조건에 맞지 않는 단지를 맞다고 하거나, 버튼에 3곳이라고 적어놓고 5곳을 보여주거나, 사용자가 원하지 않았는데 중개 신청을 넣어버리면 사용자에게 실제로 손해가 생기고, 그건 결국 저희 서비스의 문제가 됩니다.&lt;/p>
&lt;p>서비스로 이어지게 하려면 사용자가 AI가 보여주는 것을 믿고 다음 행동으로 넘어갈 수 있어야 했습니다. 그래서 저는 &lt;strong>LLM이 판단할 여지가 큰 일은 가능한 한 도구 안으로 옮기고, LLM은 저희가 만든 도구를 고르고 인자를 채우는 데까지만 하게 하는 게 맞다고 생각했습니다.&lt;/strong> 조건에 맞는지, 몇 곳인지, 실행해도 되는지는 도구와 서버에서 정하는 거죠.&lt;/p>
&lt;p>이 고민과 관련해서 참고한 자료도 있었습니다. 프롬프트 인젝션 방어 패턴을 정리한 &lt;a href="https://arxiv.org/abs/2506.08837"target="_blank" rel="noopener">Design Patterns for Securing LLM Agents against Prompt Injections&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> 논문을 보면, 계획을 먼저 세우고 실행하는 구조는 제어 흐름이 고정돼 있어서 인젝션이 일어나도 영향이 도구 인자에 그치지만, Agent Loop에서는 도구 결과로 들어온 텍스트가 다음 행동 선택에 영향을 줄 수 있다고 설명합니다.&lt;/p>
&lt;p>지난 AI 추천 구조에서는 흐름이 고정돼 있다는 것 자체가 안전장치였는데, Agent Loop로 가면 그게 없어지게 되니 다른 방법으로 대신해야 했습니다.&lt;/p>
&lt;p>그렇다면 무엇을 LLM에게 맡기고 무엇을 코드에 둘까요? 저는 판단 하나하나를 놓고, 틀렸을 때 사용자에게 손해가 생기는지, 되돌릴 수 있는지, 같은 입력에 항상 같은 결과가 나와야 하는지를 봤습니다. 앱과 웹에 이미 있는 화면이나 업무 규칙과 같아야 하는지도 함께 봤습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>판단&lt;/th>
&lt;th>누가&lt;/th>
&lt;th>이유&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>사용자가 무엇을 원하는지 해석&lt;/td>
&lt;td>LLM&lt;/td>
&lt;td>틀려도 되물으면 되고, 손해가 바로 생기지 않는다&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>어떤 도구를, 어떤 조건으로 부를지&lt;/td>
&lt;td>LLM&lt;/td>
&lt;td>잘못 고르면 결과를 보고 다시 고를 수 있다&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>언제 멈출지&lt;/td>
&lt;td>코드&lt;/td>
&lt;td>응답 시간과 비용은 매번 같은 기준이어야 한다&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>무엇이 조건에 맞는지, 몇 곳인지&lt;/td>
&lt;td>코드 (검색 엔진)&lt;/td>
&lt;td>화면의 숫자는 같은 입력에 같은 결과여야 한다&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>어떤 단지, 장소, 사용자를 가리키는지&lt;/td>
&lt;td>서버&lt;/td>
&lt;td>틀리면 엉뚱한 단지나 다른 사람의 정보로 이어진다&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>신청 같은 행동을 할지&lt;/td>
&lt;td>사용자&lt;/td>
&lt;td>되돌릴 수 없으니 사용자가 확인하고, 실행은 LLM을 거치지 않고 기존 신청 흐름에서 한다&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>복비 계산, 진행 단계 이름&lt;/td>
&lt;td>코드&lt;/td>
&lt;td>복비는 기존 계산기와, 단계 이름은 실제 업무 단계와 같아야 한다&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>부동산과 관련 있는 질문인지&lt;/td>
&lt;td>판단은 별도 LLM 호출, 막고 안내하는 건 코드&lt;/td>
&lt;td>판단은 문맥을 봐야 하지만, 그 결과로 무엇을 할지는 매번 같아야 한다&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>화면에 보여줄 카드&lt;/td>
&lt;td>대상이 여럿일 때만 LLM&lt;/td>
&lt;td>카드 안의 숫자는 코드가 만들고, LLM은 무엇을 보여줄지만 고른다&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>어떻게 말할지&lt;/td>
&lt;td>LLM&lt;/td>
&lt;td>다만 LLM이 볼 수 있는 정보는 코드가 정한다&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>원칙은 처음에 정했고, 표의 각 줄은 만들면서 하나씩 채워 나갔습니다. 한 턴의 흐름으로 그려보면 이렇습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
U[&amp;#34;사용자&amp;#34;] --&amp;gt; LLM[&amp;#34;LLM&amp;lt;br/&amp;gt;해석 · 도구 선택 · 답변&amp;#34;]
LLM --&amp;gt;|도구 호출| D[&amp;#34;디스패처&amp;lt;br/&amp;gt;도구 등급 검사&amp;#34;]
D --&amp;gt; T[&amp;#34;도구&amp;#34;]
SS[&amp;#34;로그인 세션&amp;#34;] -.-&amp;gt;|사용자 ID| T
T --&amp;gt; SE[&amp;#34;검색 엔진&amp;lt;br/&amp;gt;조건 확인 · 개수&amp;#34;]
T --&amp;gt; ST[&amp;#34;서버 상태&amp;lt;br/&amp;gt;참조 발급 · 선택지 조건 저장&amp;#34;]
T --&amp;gt;|결과| LLM
T --&amp;gt;|제안만| C[&amp;#34;확인 카드&amp;#34;]
C --&amp;gt;|사용자가 확인| EX[&amp;#34;기존 신청 흐름&amp;lt;br/&amp;gt;(LLM을 거치지 않음)&amp;#34;]
&lt;/pre>&lt;p>디스패처는 LLM이 고른 도구를 실제로 실행하는 서버 쪽 코드입니다. 모든 도구는 조회, 제안, 확인이 필요한 쓰기 중 하나의 등급을 가지는데, 디스패처는 조회와 제안만 실행하고 쓰기 등급은 실행을 거부합니다.&lt;/p>
&lt;p>신청 같은 행동은 &amp;ldquo;제안&amp;rdquo; 등급의 도구가 확인 카드에 띄울 제안으로만 저장하고, 실제 신청은 사용자가 확인 카드를 누른 뒤 앱과 웹의 기존 신청 흐름에서 일어납니다. 그래서 지금은 쓰기 등급 도구가 하나도 없습니다. 그런데도 쓰기 등급을 거부하도록 둔 건, 나중에 쓰기 도구가 실수로 추가되더라도 LLM이 바로 실행하지 못하게 하려는 거였습니다. 이 검사를 디스패처 코드에 둔 건 지시문에 적은 금지 규칙이 생각보다 자주 지켜지지 않았기 때문입니다.&lt;/p>
&lt;p>&amp;ldquo;언제 멈출지&amp;quot;도 코드로 정했습니다. 한 턴에서 LLM을 부르는 횟수와 누적 토큰, 경과 시간에 각각 상한을 두고, 같은 도구를 같은 인자로 다시 부르는 경우에도 멈춥니다. 하나라도 걸리면 도구를 쓸 수 없게 한 상태로 한 번 더 불러서 지금까지의 결과로 답하게 합니다. 사용자 입장에서는 지금까지 찾은 결과로라도 답을 받는 게 낫다고 생각했거든요.&lt;/p>
&lt;h2>버튼에 적힌 숫자와 결과&lt;span class="hx:absolute hx:-mt-20" id="버튼에-적힌-숫자와-결과">&lt;/span>
&lt;a href="#%eb%b2%84%ed%8a%bc%ec%97%90-%ec%a0%81%ed%9e%8c-%ec%88%ab%ec%9e%90%ec%99%80-%ea%b2%b0%ea%b3%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>저는 버튼에 3곳이라고 적었으면 눌렀을 때 3곳이 나와야 하고, &amp;ldquo;두 번째 단지&amp;quot;라고 하면 화면의 두 번째 단지여야 한다고 생각합니다. 그런데 개수를 세는 시점과 결과를 보여주는 시점 사이에 LLM의 해석이 들어가면 둘이 어긋날 수 있었습니다.&lt;/p>
&lt;p>이 문제가 처음 드러난 건 조건 좁히기였습니다. 기획에는 결과가 많으면 조건을 좁히는 객관식 질문을 하고, 선택지마다 남는 단지 수를 보여주자는 요구가 있었습니다.&lt;/p>
&lt;p>처음 떠올린 건 지시문에 &amp;ldquo;결과가 많으면 좁히는 질문을 하라&amp;quot;고 적는 방법이었는데, 문제는 &amp;ldquo;선택지마다 남는 단지 수&amp;quot;였습니다. LLM은 검색 결과 중 상위 몇 곳만 받기 때문에, 선택지마다 전체에서 몇 곳이 남는지 셀 정보가 애초에 없었습니다.&lt;/p>
&lt;p>애플리케이션에서 세는 방법도 검토했지만, 검색 결과에 상한이 있어서 그 이상은 셀 수 없었습니다. 개수와 분포를 세는 건 검색 엔진이 잘하는 일이기도 했고요.&lt;/p>
&lt;p>그렇다면 Elasticsearch에서 세면 되지 않을까요? 그런데 세려고 보니 지난 AI 추천 글에서 이야기했던 포스트 필터링이 걸렸습니다.&lt;/p>
&lt;p>검색 인덱스는 단지 단위라서 ES는 &amp;ldquo;이 단지의 평형 범위가 조건과 겹치는지&amp;quot;까지만 보고, &amp;ldquo;같은 평형에서 가격과 방 개수가 동시에 맞는지&amp;quot;는 검색 후에 애플리케이션에서 다시 걸렀습니다. 조건을 확인하는 곳이 두 곳으로 나뉘어 있었던 거죠. 이 상태로 ES에서 집계를 하면 개수가 실제보다 크게 나옵니다.&lt;/p>
&lt;p>결국 &lt;strong>조건 확인을 ES 한 곳으로 모았습니다.&lt;/strong> 평형별 시세를 nested 필드(배열 안의 객체 하나하나를 따로 검색할 수 있게 하는 필드)로 다시 색인하고, 개수와 분포도 ES에서 셉니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Before[&amp;#34;이전: 조건 확인이 두 곳에 나뉨&amp;#34;]
direction LR
A1[&amp;#34;ES&amp;lt;br/&amp;gt;단지의 평형 범위가 겹치는지&amp;#34;] --&amp;gt; B1[&amp;#34;애플리케이션&amp;lt;br/&amp;gt;같은 평형에서 가격 · 방까지 맞는지&amp;#34;]
B1 --&amp;gt; C1[&amp;#34;결과&amp;lt;br/&amp;gt;(개수를 셀 수 없음)&amp;#34;]
end
subgraph After[&amp;#34;이후: ES 한 곳에서 확인&amp;#34;]
direction LR
A2[&amp;#34;ES (nested)&amp;lt;br/&amp;gt;같은 평형 안에서 모든 조건을 확인&amp;#34;] --&amp;gt; C2[&amp;#34;결과 + 개수 · 분포&amp;#34;]
end
&lt;/pre>&lt;p>확인하는 위치를 옮기면 기존 추천 결과가 바뀔 수 있어서, 옮기기 전에 결과가 같은지부터 봤습니다. 기존 방식과 216개 조건으로 비교했을 때 불일치는 0건이었습니다.&lt;/p>
&lt;p>좁히기 질문 하나 때문에 검색 인덱스를 다시 만드는 게 과한가 싶기도 했는데, 그래도 화면에 보이는 숫자가 틀리는 걸 그대로 둘 수는 없다고 생각했습니다.&lt;/p>
&lt;p>어떤 조건으로 좁힐지도 코드가 정합니다. 후보 조건마다 선택지별 개수를 병렬로 센 뒤, 가장 큰 선택지가 전체에서 차지하는 비율이 가장 작은 조건, 즉 결과를 가장 고르게 나누는 조건을 고릅니다. LLM에게는 질문을 문장으로 다듬는 일만 맡겼습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 결과를 줄이는 선택지(0 &amp;lt; n &amp;lt; 전체)가 둘 이상 남는 조건 중, 가장 큰 선택지가 작을수록 잘 나누는 조건이다. (단순화한 코드)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">val&lt;/span> &lt;span class="py">best&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">counted&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">.&lt;/span>&lt;span class="n">map&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">dimension&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">options&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="n">dimension&lt;/span> &lt;span class="n">to&lt;/span> &lt;span class="n">options&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">mapNotNull&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">k&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">n&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="n">n&lt;/span>&lt;span class="o">?.&lt;/span>&lt;span class="n">takeIf&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="k">it&lt;/span> &lt;span class="k">in&lt;/span> &lt;span class="m">1&lt;/span> &lt;span class="n">until&lt;/span> &lt;span class="n">total&lt;/span> &lt;span class="p">}&lt;/span>&lt;span class="o">?.&lt;/span>&lt;span class="n">let&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="n">k&lt;/span> &lt;span class="n">to&lt;/span> &lt;span class="k">it&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">.&lt;/span>&lt;span class="n">filter&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">_&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">options&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="n">options&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">size&lt;/span> &lt;span class="o">&amp;gt;=&lt;/span> &lt;span class="m">2&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">.&lt;/span>&lt;span class="n">minByOrNull&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">_&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">options&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="n">options&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">maxOf&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="k">it&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">second&lt;/span> &lt;span class="p">}.&lt;/span>&lt;span class="n">toDouble&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">/&lt;/span> &lt;span class="n">total&lt;/span> &lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>개수를 정확히 센 다음에도 남은 문제가 하나 있었습니다. 사용자가 &amp;ldquo;10년 이내 준공 · 2곳&amp;rdquo; 버튼을 누르면 LLM은 그 선택을 해석해서 검색 조건을 다시 만듭니다. 이때 조건을 조금이라도 다르게 만들면 버튼에는 2곳인데 결과는 3곳이 나올 수 있습니다.&lt;/p>
&lt;p>그래서 &lt;strong>선택지마다 검색 조건을 서버에 저장해두고, LLM에게는 선택지의 참조만 넘기기로&lt;/strong> 했습니다. 사용자가 버튼을 누르면 LLM은 &lt;code>N2&lt;/code> 같은 참조만 도구에 넣고, 서버는 저장해둔 조건으로 그대로 검색합니다. 이때 LLM이 다른 조건을 같이 보내도 서버는 쓰지 않습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 고른 선택지가 있으면 서버가 저장해둔 검색 조건을 그대로 쓴다. 모델이 함께 보낸 다른 조건은 무시한다. (단순화한 코드)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">val&lt;/span> &lt;span class="py">chosen&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">input&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">choiceRef&lt;/span>&lt;span class="o">?.&lt;/span>&lt;span class="n">let&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="n">ref&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="n">session&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">pendingChoices&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">firstOrNull&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="k">it&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">ref&lt;/span> &lt;span class="o">==&lt;/span> &lt;span class="n">ref&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">input&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">choiceRef&lt;/span> &lt;span class="o">!=&lt;/span> &lt;span class="k">null&lt;/span> &lt;span class="o">&amp;amp;&amp;amp;&lt;/span> &lt;span class="n">chosen&lt;/span> &lt;span class="o">==&lt;/span> &lt;span class="k">null&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="nc">ToolResult&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">error&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;답을 기다리는 선택지에 없는 참조입니다.&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">val&lt;/span> &lt;span class="py">condition&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">chosen&lt;/span>&lt;span class="o">?.&lt;/span>&lt;span class="n">savedCondition&lt;/span> &lt;span class="o">?:&lt;/span> &lt;span class="n">input&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">toCondition&lt;/span>&lt;span class="p">()&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/y05vs2fkg6n13exhc7648/agentic-narrow.png?rlkey=d3rb2oq4ufox6ifxuuj6ezrbq&amp;amp;raw=1" alt="조건 좁히기. 어떤 조건으로 좁힐지와 남는 단지 수는 코드가 정하고, 버튼을 누르면 적힌 수만큼의 단지가 나옵니다" loading="lazy" />&lt;/p>
&lt;p>&lt;em>잠실동 주변을 찾자(반경 검색이라 광진구 단지도 포함됩니다) 준공 시기로 좁히는 질문이 붙었고(왼쪽), &amp;ldquo;10년 이내 준공 · 2곳&amp;quot;을 고르면 2곳으로 좁혀집니다(오른쪽).&lt;/em>&lt;/p>
&lt;p>물론 사용자가 &amp;ldquo;10년 이내인데 그중에 500세대 이상만&amp;quot;처럼 선택지를 조금 바꿔서 말하는 경우에는 이 방식을 쓸 수 없습니다. 버튼 아래에는 &amp;ldquo;원하는 조건을 직접 입력할 수도 있어요&amp;quot;를 두었습니다. 이렇게 직접 입력한 조건은 저장해둔 조건이 없으니 LLM이 해석해서 검색합니다.&lt;/p>
&lt;p>결과가 0건일 때 보여주는 완화안에도 같은 방식을 적용했습니다. 처음에는 완화 버튼이 &amp;ldquo;가격 상한을 올려서 다시 찾아줘&amp;rdquo; 같은 문장을 다음 질문으로 보냈는데, 이 문장을 LLM이 해석하면서 버튼을 만들 때와 다른 가격 범위로 검색되는 경우가 있었습니다.&lt;/p>
&lt;p>지금은 완화안도 서버가 조건을 하나씩 넓혀 미리 검색해보고, 결과가 있는 완화안만 조건과 함께 저장해둡니다. 버튼을 누르면 저장해둔 조건으로 그대로 검색합니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/0t8lo88f0v9gboms3zb2f/agentic-relax.png?rlkey=bc1myxb393hprnmt9rjitodal&amp;amp;raw=1" alt="0건일 때의 완화안. 서버가 미리 검색해본 완화안만 개수와 함께 보여주고, 누르면 적힌 수만큼 나옵니다" loading="lazy" />&lt;/p>
&lt;p>&lt;em>&amp;ldquo;그 중에 더 싼 곳은 없어? 15억 이하로&amp;quot;라고 이어서 물으면 앞의 조건(잠실동 주변, 30평대, 10년 이내 준공)을 유지한 채로 찾고, 0곳이면 결과가 있는 완화안만 보여줍니다. &amp;ldquo;예산을 높여서 찾기 · 1곳&amp;quot;을 누르면 1곳이 나옵니다.&lt;/em>&lt;/p>
&lt;p>이 방식은 다른 곳에도 적용했습니다. 단지를 가리킬 때 LLM은 실제 ID 대신 서버가 붙인 &lt;code>C1&lt;/code>, &lt;code>C2&lt;/code> 같은 참조를 쓰고, 장소도 좌표 대신 서버가 발급한 참조로 넘깁니다. 대화에 없는 참조는 거부합니다. 다른 화면으로 보내는 링크도 마찬가지로, LLM이 &amp;ldquo;복비 계산기로 보내기&amp;rdquo; 같은 행동을 고르면 주소는 서버가 붙입니다.&lt;/p>
&lt;p>이렇게 &lt;strong>LLM에게 실제 값 대신 서버가 발급한 참조를 넘기게&lt;/strong> 한 건, LLM이 값을 직접 만들면 그 값이 실행할 때마다 달라질 수 있기 때문이었습니다. 참조만 다루게 하면 LLM이 틀리더라도 &amp;ldquo;다른 참조를 고르는 것&amp;rdquo; 정도로 범위가 좁아지고, 그런 실수는 화면에 바로 드러나서 확인하기도 쉬웠습니다.&lt;/p>
&lt;p>앞에서 이야기한 인젝션 문제도 여기서 일부 줄어듭니다. 버튼으로 고른 조건에서는 LLM이 넘길 수 있는 게 대화 안에서 발급된 참조뿐이기 때문이죠. 물론 이것만으로 다 막을 수 있는 건 아니라서, 되돌릴 수 없는 일에 사용자 확인을 거치게 한 것과 함께 보고 있습니다.&lt;/p>
&lt;h2>다른 사용자의 정보&lt;span class="hx:absolute hx:-mt-20" id="다른-사용자의-정보">&lt;/span>
&lt;a href="#%eb%8b%a4%eb%a5%b8-%ec%82%ac%ec%9a%a9%ec%9e%90%ec%9d%98-%ec%a0%95%eb%b3%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>다른 사용자의 정보를 어떻게 막을지도 처음부터 고민했던 부분입니다.&lt;/p>
&lt;p>기존 서비스에서 &amp;ldquo;내 관심 단지&amp;rdquo;, &amp;ldquo;내 신청 내역&amp;rdquo; 같은 조회는 로그인한 사용자가 자기 화면에서 호출하는 구조였습니다. 그런데 에이전트에서는 LLM이 도구의 인자를 만듭니다. 사용자가 대화로 &amp;ldquo;다른 사람 신청 내역도 보여줘&amp;quot;라고 하거나 다른 사용자의 식별자처럼 보이는 값을 입력하면, LLM이 그 값을 도구 인자에 넣을 수 있죠.&lt;/p>
&lt;p>그래서 저는 &lt;strong>LLM이 만든 인자도 사용자 입력처럼 그대로 믿지 않기로 했습니다.&lt;/strong> 사용자 ID처럼 LLM이 바꿀 수 없어야 하는 값은 대화에서 받지 않고, 도구를 실행할 때 서버가 로그인 정보로 채워 넣습니다. 대화 세션이나 현재 상태도 같은 방식으로 채웁니다.&lt;/p>
&lt;p>도구 스키마에는 사용자 식별자 필드를 아예 두지 않았고, 그런 필드가 생기지 않았는지 검사하는 테스트도 두었습니다. 개인 데이터를 다루는 도구는 로그인한 사용자 범위 안에서만 조회합니다.&lt;/p>
&lt;p>대화 세션도 같은 기준으로 처리했습니다. 다른 사용자의 대화 세션으로 요청이 들어오면 세션이 있는지조차 알려주지 않고 없는 세션처럼 응답합니다. 앞에서 이야기한 &lt;code>C1&lt;/code> 같은 참조도 세션 안에서만 의미가 있어서, 다른 세션의 참조를 가져와도 아무것도 가리키지 않습니다.&lt;/p>
&lt;p>LLM이 볼 필요가 없는 개인정보는 처음부터 넘기지 않았습니다. 예를 들어 중개사 연락처나 실명, 내부 식별자 같은 것들이죠. 화면에서도 중개사는 &amp;ldquo;가락동 담당중개사&amp;quot;처럼 동네 이름으로만 안내합니다.&lt;/p>
&lt;p>이것도 생각보다 꼼꼼하게 봐야 했습니다. 등기분석 결과를 설명하는 기능을 붙일 때 소유자 이름 필드는 빼고 넘겼는데, 개발 중에 결과를 확인해보니 설명 문장 안에도 이름이 들어 있을 수 있었습니다. 지금은 필드를 빼는 것과 별도로 문장 안의 이름까지 가린 뒤 넘깁니다.&lt;/p>
&lt;h2>부동산과 관련 없는 질문&lt;span class="hx:absolute hx:-mt-20" id="부동산과-관련-없는-질문">&lt;/span>
&lt;a href="#%eb%b6%80%eb%8f%99%ec%82%b0%ea%b3%bc-%ea%b4%80%eb%a0%a8-%ec%97%86%eb%8a%94-%ec%a7%88%eb%ac%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>범용 LLM을 붙였으니 부동산과 상관없는 질문에도 답할 수 있습니다. 처음에는 지시문에 &amp;ldquo;부동산 외 질문에는 정중히 거절해&amp;quot;라고 적어두면 될 거라고 생각했는데, 그렇게 적어둔 상태에서도 게임이나 요리 질문에 답하고 있었습니다.&lt;/p>
&lt;p>이걸 가볍게 넘길 수 없었던 건, 그 답도 결국 저희 서비스가 한 답이 되기 때문입니다. 틀리거나 부적절해도 책임은 서비스에 있고, 한 턴에 LLM을 여러 번 부르는 구조라 다른 용도로 쓰이면 그 비용도 저희가 냅니다.&lt;/p>
&lt;p>결국 본 루프와 별개로 부동산 관련 여부만 판별하는 짧은 LLM 호출을 두고, 관련 없는 질문이면 본 루프를 멈추고 정해진 안내 문구로 답합니다.&lt;/p>
&lt;p>고민했던 건 &amp;ldquo;이사 가는 날 짐 싸는 팁&amp;quot;처럼 부동산과 걸쳐 있는 질문이었습니다. 저는 부동산 질문을 잘못 막는 쪽이 더 문제라고 생각했습니다. 멀쩡한 부동산 질문에 답할 수 없다고 하면 사용자 입장에서는 오류와 구분하기 어렵거든요. 애매한 질문은 막지 않는 쪽으로 정했고, 본인의 서비스 이용 정보를 묻는 질문도 허용 범위에 넣었습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/amt1d4da23j1i6t4fh275/agentic-offtopic.png?rlkey=er830cr0xeuq3eb2dftowiscy&amp;amp;raw=1" alt="부동산과 관련 없는 질문에는 정해진 안내로 답합니다" loading="lazy" />&lt;/p>
&lt;p>&lt;em>&amp;ldquo;오늘 저녁 메뉴 추천해줘&amp;quot;에는 답하지 않고, 할 수 있는 일을 안내합니다.&lt;/em>&lt;/p>
&lt;p>그런데 이걸 붙이고 나니 판별이 끝난 뒤에 본 루프가 시작돼서, 판별에 걸리는 시간(평균 1.1초)만큼 모든 질문의 첫 반응이 늦어졌습니다. 관련 없는 질문을 거르려고 모든 사용자가 1초를 더 기다리는 건 맞지 않다고 생각했습니다.&lt;/p>
&lt;p>그렇다면 판별과 본 루프를 동시에 시작하면 어떨까요? 이때 판별 결과가 나오기 전에 일어나면 안 되는 건 사용자에게 답변이 보이는 것과 도구가 실행되는 것이었습니다.&lt;/p>
&lt;p>그래서 &lt;strong>본 루프는 판별과 함께 시작하되, 판별이 끝날 때까지 답변은 화면에 보내지 않고 모아두고 도구 실행은 판별 결과를 기다리도록&lt;/strong> 바꿨습니다. 부동산 질문이면 모아둔 답변부터 보내고 이어서 진행하고, 관련 없는 질문이면 본 루프를 취소하고 본 루프가 만든 내용은 이력에 남기지 않습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant U as 사용자
participant G as 주제 판별
participant L as 본 루프
U-&amp;gt;&amp;gt;G: 질문
U-&amp;gt;&amp;gt;L: 질문 (동시에 시작)
L-&amp;gt;&amp;gt;L: LLM 호출, 답변은 모아두기
Note over L: 화면 출력과 도구 실행은&amp;lt;br/&amp;gt;판별 결과를 기다림
alt 부동산 관련
G--&amp;gt;&amp;gt;L: 통과
L--&amp;gt;&amp;gt;U: 모아둔 답변부터 보내고 이어서 진행
else 관련 없는 질문
G--&amp;gt;&amp;gt;L: 취소 (본 루프 결과는 남기지 않음)
G--&amp;gt;&amp;gt;U: 정해진 안내 문구
end
&lt;/pre>&lt;p>관련 없는 질문이면 판별이 끝나기 전에 본 루프가 부른 LLM 호출만큼 비용이 더 듭니다. 하지만 도구는 판별을 기다리니 낭비되는 건 호출 한 번 정도였고, 그 대신 모든 질문의 첫 반응을 앞당길 수 있어서 이쪽을 택했습니다.&lt;/p>
&lt;h2>대화 이력과 상태&lt;span class="hx:absolute hx:-mt-20" id="대화-이력과-상태">&lt;/span>
&lt;a href="#%eb%8c%80%ed%99%94-%ec%9d%b4%eb%a0%a5%ea%b3%bc-%ec%83%81%ed%83%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>대화 상태는 처음부터 저희가 관리해야 한다고 생각했습니다.&lt;/p>
&lt;p>OpenAI의 Responses API는 대화를 공급자 서버에 저장해두고 이어 쓰는 기능을 제공합니다. 물론 이걸 쓰면 구현은 꽤 간단해집니다. 하지만 그러면 대화의 원본이 저희 밖에 있게 됩니다. 저장 기간도, 개인정보를 언제 지울지도 공급자 정책을 따라야 하고, 이어 쓸 때마다 앞의 대화가 다시 과금되니 비용이 줄어드는 것도 아니었습니다. 무엇보다 &amp;ldquo;왜 이런 결과가 나왔어요?&amp;ldquo;라는 질문을 받았을 때 볼 원본 이력을 저희 쪽에 두고 싶었습니다.&lt;/p>
&lt;p>결국 공급자 저장은 끄고 대화 이력과 세션 상태를 저희 DB에 두었습니다. 대신 공급자가 해주던 일을 직접 해야 했습니다. 공급자 저장을 끄면 추론 모델이 이전 턴의 추론을 이어받지 못하기 때문에, 도구 호출과 함께 받은 추론 항목을 암호화된 형태로 저장했다가 다음 요청에 다시 보냅니다.&lt;/p>
&lt;p>매 턴 LLM에게 무엇을 보낼지도 저희가 정해야 했습니다. &amp;ldquo;두 번째 단지 실거래가 어때?&amp;rdquo;, &amp;ldquo;거기 주변에 지하철역 있어?&amp;rdquo; 같은 질문에 맞는 도구를 고르려면 LLM이 앞의 대화를 알아야 합니다. 그렇다고 대화 전체를 매번 그대로 보내면 토큰이 계속 늘어나고, 오래된 도구 결과 때문에 LLM이 잘못 판단하는 경우도 생깁니다. 매 턴 보내는 문맥은 아래처럼 나눠서 조립했습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
subgraph Fixed[&amp;#34;매 턴 같음 (캐시됨)&amp;#34;]
I[&amp;#34;지시문&amp;#34;] --&amp;gt; TD[&amp;#34;도구 정의&amp;#34;]
end
subgraph History[&amp;#34;대화 이력&amp;#34;]
OLD[&amp;#34;오래된 턴&amp;lt;br/&amp;gt;질문과 답변만&amp;#34;] --&amp;gt; RECENT[&amp;#34;최근 턴&amp;lt;br/&amp;gt;도구 호출 · 결과까지 원문&amp;#34;]
end
subgraph State[&amp;#34;매 턴 새로 만듦&amp;#34;]
SS[&amp;#34;세션 상태&amp;lt;br/&amp;gt;확정된 위치 · 결과 목록 · 답을 기다리는 선택지&amp;lt;br/&amp;gt;(모두 참조로)&amp;#34;]
end
Fixed --&amp;gt; History --&amp;gt; State
&lt;/pre>&lt;p>세션 상태에는 지금까지 대화에서 확정된 위치와 검색 결과, 답을 기다리는 선택지를 앞에서 이야기한 참조로 정리해서 붙입니다. 덕분에 &amp;ldquo;두 번째 단지&amp;quot;나 &amp;ldquo;거기&amp;rdquo; 같은 말을 LLM이 해석할 때 근거가 분명해졌습니다. &amp;ldquo;두 번째 단지 담당 중개사와 이야기하고 싶어&amp;quot;처럼 앞의 결과를 가리키며 서비스로 넘어가는 요청도 마찬가지로 정확한 단지로 이어집니다.&lt;/p>
&lt;p>LLM이 도구를 잘못 부르는 경우도 있었습니다. 없는 참조를 넣거나, 필요한 인자를 빼먹거나, 대화에 없는 단지를 가리키는 경우들이었죠. Agent Loop에서는 LLM이 도구 결과를 보고 다시 고를 수 있기 때문에, 잘못된 호출도 예외로 끊지 않고 이유를 도구 결과로 돌려주는 게 맞다고 생각했습니다. 지금은 LLM이 이 결과를 보고 인자를 고치거나 다른 도구를 골라 다시 부릅니다.&lt;/p>
&lt;p>판단 근거도 남겼습니다. Agent Loop에서는 판단이 여러 번의 LLM 호출과 도구 호출에 흩어지기 때문에, 요청 단위가 아니라 실행 한 번의 전체 과정을 기록 단위로 잡았습니다. 도구 호출에는 LLM에게 보내지 않는 검색 후보와 순위도 같이 남겼습니다.&lt;/p>
&lt;p>예를 들어 &amp;ldquo;강남역 근처 30평대 매매&amp;quot;를 물었을 때 AI가 &amp;ldquo;강남역 후보가 두 곳 있는데 어느 쪽인가요?&amp;ldquo;라고 되물은 적이 있습니다. 기록을 열어보니 같은 이름, 같은 좌표의 강남역이 노선별로 두 번 색인되어 있었고, LLM은 그 둘을 다른 장소로 보고 되물은 거였습니다. 기록 덕분에 프롬프트가 아니라 색인 데이터 문제라는 걸 바로 찾을 수 있었습니다.&lt;/p>
&lt;h2>지시문과 도구 설명&lt;span class="hx:absolute hx:-mt-20" id="지시문과-도구-설명">&lt;/span>
&lt;a href="#%ec%a7%80%ec%8b%9c%eb%ac%b8%ea%b3%bc-%eb%8f%84%ea%b5%ac-%ec%84%a4%eb%aa%85" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>권한은 코드로 정했어도, LLM이 어떻게 말하고 어떤 도구를 고를지는 결국 지시문과 도구 설명으로 알려줘야 했습니다. 그런데 지시문이 생각대로 동작하지 않는 경우가 여러 번 있었고, 그러다 보니 몇 가지 경향이 보이더라고요.&lt;/p>
&lt;p>예를 들어 담당 중개사와 이야기할 수 있냐고 물었더니 AI가 &amp;ldquo;앱에서 매칭을 신청해 주세요&amp;quot;라고 답한 적이 있습니다. 지시문에는 대화에서 바로 이어주라고 적어뒀는데도요. 원인을 찾아보니 담당 중개사를 찾는 도구의 결과 문구가 &amp;ldquo;앱의 단지 화면에서 매칭을 신청할 수 있습니다&amp;quot;였습니다. LLM은 이 도구 결과 문구를 따라 답한 거였습니다.&lt;/p>
&lt;p>복비 할인 기준도 비슷했습니다. 할인에는 거래금액 기준이 있는데, LLM이 이 기준을 빼먹거나 다르게 말하는 경우가 있었습니다. 지시문에 기준을 적어봤지만 달라지지 않았고, 복비 계산 도구의 결과에 기준 금액을 항상 담아 보낸 뒤에야 해결됐습니다.&lt;/p>
&lt;p>왜 이런 일이 생겼을까요? 실험으로 잰 건 아니지만, 두 사례 모두 지시문을 고쳤을 때는 그대로였고 도구 설명이나 도구 결과 문구를 고쳤을 때 해결됐습니다. 저는 &lt;strong>LLM이 판단하는 시점 바로 앞에 있는 텍스트가 도구 설명과 도구 결과이기 때문이지 않나 싶습니다.&lt;/strong>&lt;/p>
&lt;p>이걸 알고 나서 몇 가지를 바꿨습니다. 먼저 도구 결과 문구를 사용자에게 보여줄 문장이라고 생각하고 쓰기 시작했습니다. 저는 백엔드 입장에서 도구 결과를 그냥 데이터로 생각했는데, 도구 결과 문구가 답변의 말투와 내용에 그대로 반영되고 있었거든요.&lt;/p>
&lt;p>도구 설명에는 무엇을 하는지뿐 아니라 언제 쓰지 말아야 하는지도 적었습니다. 처음에는 장소 검색, 단지 검색, 단지 상세, 실거래가, 주변 시설 정도의 도구 5개로 시작했는데, 통합 AI 에이전트를 목표로 하다 보니 지금은 30개까지 늘었거든요.&lt;/p>
&lt;p>도구가 늘면서 비슷한 도구 사이에서 잘못 고르는 경우가 생겼는데, OpenAI의 에이전트 가이드에도 도구가 많을 때의 문제는 개수보다 도구 사이의 유사성에서 생긴다는 내용이 있었습니다. 중개 신청 제안은 &amp;ldquo;여기 사고 싶어&amp;quot;처럼 거래 의사를 밝혔을 때 쓰고 &amp;ldquo;맘에 들어&amp;quot;처럼 관심만 보였을 때는 쓰지 않는다는 식으로, 비슷한 도구 사이의 기준을 설명에 적어뒀습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="cl">중개 신청 제안 도구 설명 (단순화한 예시)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- 이럴 때 씁니다: &amp;#34;여기 사고 싶어&amp;#34;, &amp;#34;방문해서 볼 수 있어?&amp;#34;처럼 거래 의사를 분명히 밝혔을 때
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- 이럴 때는 쓰지 않습니다: &amp;#34;맘에 들어&amp;#34;처럼 관심만 보였을 때 (이때는 권유 도구를 쓰고, 알림을 먼저 권할지는 서버가 정함)&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>지난 AI 추천 글에서 도구 경계를 나누는 기준으로 &amp;ldquo;LLM이 이 도구의 역할을 한 문장으로 설명할 수 있는가&amp;quot;를 적었는데, 이번에는 &amp;ldquo;이 도구를 쓰지 말아야 할 때를 한 문장으로 설명할 수 있는가&amp;quot;도 같이 보게 됐습니다.&lt;/p>
&lt;p>사용자에게 보이면 안 되는 정보는 &amp;ldquo;말하지 마&amp;quot;라고 적지 않고, LLM이 볼 수 있는 곳에서 아예 뺐습니다. 금지 문장은 지켜지지 않았을 때 원인을 찾기도 어려웠거든요.&lt;/p>
&lt;p>그리고 지시문으로 지켜지지 않는 규칙은 코드로 옮겼습니다. 예를 들어 좁히기 질문을 낸 응답에서는 다른 선택지 버튼을 또 내지 말라고 지시문에 적어뒀는데, 테스트해보니 버튼을 또 만드는 경우가 꽤 많았습니다. 같은 응답에 버튼 묶음이 두 개 생기면 사용자는 어느 쪽을 눌러야 할지 알 수 없죠. 좁히기 질문이 이미 나간 응답에서 LLM이 선택지 버튼을 또 만들면, 서버가 그 버튼을 버리고 좁히기 질문을 남깁니다.&lt;/p>
&lt;p>1편에서 이야기한 권유 규칙도 마찬가지였습니다. 같은 단지에 중개를 두 번 권하지 않거나, 담당 중개사가 없는 단지에는 권하지 않는 규칙도 지시문에 적어둔 것만으로는 잘 지켜지지 않아서 권유 도구 안에서 서버가 확인합니다.&lt;/p>
&lt;h2>나빠지지는 않았는지&lt;span class="hx:absolute hx:-mt-20" id="나빠지지는-않았는지">&lt;/span>
&lt;a href="#%eb%82%98%eb%b9%a0%ec%a7%80%ec%a7%80%eb%8a%94-%ec%95%8a%ec%95%98%eb%8a%94%ec%a7%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>구조를 바꾸면서 기존 기능보다 나빠지지 않았는지 확인하고 싶었습니다.&lt;/p>
&lt;p>먼저 기존 AI 추천에서 쓰던 예시 질문 16개를 양쪽에 똑같이 넣고, 검색 조건이 의도대로 잡혔는지 비교했습니다. 처음에는 16개 중 7개만 의도한 조건이 잡혔는데, 하나씩 보니 대부분은 조건을 잡기 전에 되물어서 생긴 차이였습니다. 처음 지시문에 되물어야 하는 경우를 너무 넓게 적어둬서, 조건이 충분한데도 묻고 있었던 거죠. 지시문을 고친 뒤에는 16개 중 15개가 맞았습니다.&lt;/p>
&lt;p>다만 지시문을 고칠 때 이 16개를 보면서 고쳤으니, 이 숫자만으로 나아졌다고 말하기는 어려웠습니다. 고칠 때 보지 않은 질문으로도 따로 확인했습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>확인 방법&lt;/th>
&lt;th>결과&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>기존 추천 예시 질문 16개 (지시문 수정 전 → 후)&lt;/td>
&lt;td>7개 → 15개 의도대로&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>기획 시나리오 48개로 직접 대화&lt;/td>
&lt;td>적절 27 / 개선 필요 14 / 당시 기능 없음 7&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>기능을 바꿀 때마다 기존 기능 86개를 두 번씩&lt;/td>
&lt;td>이전과 같은지 회귀 확인&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>아무것도 바꾸지 않고 같은 질문 27개를 두 번&lt;/td>
&lt;td>19개 자동으로 같음 / 8개 사람이 확인&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>기능이 없던 7개는 통근 시간, 초품아, 갭 투자 금액, 급매처럼 당시 데이터나 도구가 없던 조건들이었습니다.&lt;/p>
&lt;p>16개 질문을 비교하면서 기존 경로의 한계가 보이기도 했습니다. &amp;ldquo;서울아산병원 근처 전세&amp;quot;를 물었더니 기존 추천은 이름이 비슷한 다른 지역의 병원을 잡아 김포의 단지를 추천했고, 새 구조는 장소 후보를 보고 문맥에 맞는 서울아산병원을 골라 송파의 단지를 추천했습니다.&lt;/p>
&lt;p>평가에서 가장 어려웠던 건 같은 질문도 실행할 때마다 답이 조금씩 달라진다는 점이었습니다. 한 번 돌려서 맞았다고 끝낼 수가 없었죠.&lt;/p>
&lt;p>그래서 &lt;strong>이후 지시문을 바꿀 때마다 비교할 수 있도록, 아무것도 바꾸지 않고 같은 질문을 두 번 돌렸을 때 결과가 얼마나 달라지는지부터 쟀습니다.&lt;/strong> 표의 마지막 줄이 그 결과로, 기획 시나리오와 기존 추천 예시에서 27개 질문을 골라 돌렸습니다. 원래 이 정도는 흔들린다는 기준선이 있어야, 지시문을 바꾼 뒤의 차이가 개선인지 그냥 흔들림인지 구분할 수 있다고 생각했습니다.&lt;/p>
&lt;p>비교도 점수를 매기는 대신, 기존 답변과 바꾼 답변을 어느 쪽인지 모르게 나란히 놓고 사람이 더 나은 쪽을 고르는 방식으로 하고 있습니다. LLM에게 점수를 매기게 하는 방법도 검토했지만, 판정하는 쪽도 같은 방식으로 흔들리는 상태에서는 그 점수를 기준으로 삼기 어렵다고 생각했습니다.&lt;/p>
&lt;h2>느려진 응답 시간&lt;span class="hx:absolute hx:-mt-20" id="느려진-응답-시간">&lt;/span>
&lt;a href="#%eb%8a%90%eb%a0%a4%ec%a7%84-%ec%9d%91%eb%8b%b5-%ec%8b%9c%ea%b0%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>앞의 16개 질문 비교에서 응답 시간 중앙값은 기존 4.9초, 새 구조 7.4초로 응답이 느려졌습니다.&lt;/p>
&lt;p>어느 정도는 예상했던 부분입니다. 다음 도구를 고르는 일을 LLM에게 맡긴 만큼 LLM 호출이 여러 번 일어날 수밖에 없고, 지난 AI 추천 글에서 Agent Loop를 선택하지 않았던 이유 중 하나도 이것이었습니다. 라우터 없이 정형 질문까지 루프 하나로 처리하게 된 것도 영향이 있었고요.&lt;/p>
&lt;p>그래도 이번에는 느려지는 걸 감수하기로 했습니다. 기존 구조는 이어지는 질문을 이해하지 못했고, 결과를 보고 되묻거나 조건을 바꿀 수도 없었으니까요.&lt;/p>
&lt;p>느려진 만큼을 줄이려고 먼저 어디서 시간이 쓰이는지부터 쟀습니다. 개발 서버에서 2주 동안 쌓인 1,458턴을 LLM 호출 횟수별로 나눠보니 이랬습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
xychart-beta
title &amp;#34;LLM 호출 횟수별 한 턴 응답 시간 (개발 서버 2주)&amp;#34;
x-axis [&amp;#34;1회&amp;#34;, &amp;#34;2회&amp;#34;, &amp;#34;3회&amp;#34;, &amp;#34;4회&amp;#34;]
y-axis &amp;#34;초&amp;#34; 0 --&amp;gt; 12
bar [3.0, 4.7, 7.5, 10.1]
&lt;/pre>&lt;p>호출이 한 번 늘 때마다 응답 시간이 1.7~2.8초씩 늘었고, LLM을 세 번 부른 턴에서는 응답 시간의 91%가 LLM을 기다리는 시간이었습니다. 그래서 LLM을 기다리는 시간을 줄이거나, 기다리는 동안 먼저 보여줄 수 있는 걸 앞당기는 쪽에 집중했습니다.&lt;/p>
&lt;p>먼저 결과가 보이기까지의 시간을 줄였습니다. 초기 버전은 답변이 다 끝난 뒤에 카드를 붙였는데, 답변이 끝나기 전에 카드를 그리게 바꾸면서 결과가 보이기까지 3초 정도 빨라졌습니다. 주제 판별을 본 루프와 동시에 돌린 것도 같은 목적이었습니다. 사용자가 체감하기에는 처음 뭔가 보이기까지의 시간이 중요하다고 생각해서, 기록에도 첫 글자가 나오기까지의 시간을 따로 남기고 있습니다.&lt;/p>
&lt;p>또 프롬프트 캐시가 깨지지 않도록 문맥 조립 순서를 고정했습니다. Agent Loop는 한 턴에 LLM을 여러 번 부르고 그때마다 지시문과 도구 정의를 다시 보냅니다. 앞의 그림처럼 바뀌지 않는 부분을 앞에 두고 매 턴 바뀌는 세션 상태를 뒤에 붙이니, 같은 2주 동안 입력 토큰의 95%가 캐시에 적중했습니다. 도구 정의 순서 하나만 바뀌어도 캐시가 깨지기 때문에, 도구 정의 순서도 코드에서 정해두었습니다.&lt;/p>
&lt;p>제한 시간이 적용되지 않던 도구를 고쳤습니다. 도구마다 실행 시간 제한을 걸어뒀는데, 검색 하나가 그 몇 배가 걸려도 끊기지 않았습니다. 코루틴의 &lt;code>withTimeout&lt;/code>은 코루틴이 중단되는 지점에서만 취소를 확인하는데, 도구 대부분이 ES나 HTTP를 호출하는 블로킹 코드라 중단 지점이 없었던 거죠. 그래서 도구는 별도 스코프에서 실행하고, 루프는 결과를 기다리는 쪽에만 제한 시간을 걸도록 나눴습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="cm">/**
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="cm"> * 도구를 별도 스코프에서 실행하고 기다리는 쪽에만 제한 시간을 건다.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="cm"> * 기다림을 끊으면 루프는 시간 초과 결과를 받고 바로 다음 판단으로 넘어가고, 늦게 끝난 결과는 버린다.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="cm"> */&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">private&lt;/span> &lt;span class="k">suspend&lt;/span> &lt;span class="k">fun&lt;/span> &lt;span class="nf">withWallClockTimeout&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">block&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="k">suspend&lt;/span> &lt;span class="p">()&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="n">ToolResult&lt;/span>&lt;span class="p">):&lt;/span> &lt;span class="n">ToolResult&lt;/span> &lt;span class="p">=&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">withContext&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nc">Dispatchers&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">IO&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">running&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">toolScope&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">async&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="n">block&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">try&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">withTimeout&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">toolTimeout&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="n">running&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">await&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span> &lt;span class="k">finally&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">running&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">cancel&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>덕분에 도구 하나가 느려도 제한 시간이 지나면 루프는 다음 판단으로 넘어갑니다.&lt;/p>
&lt;p>응답 한 번의 시간과 함께, 원하는 결과를 얻기까지 걸리는 전체 시간도 보려고 했습니다. 되묻기가 한 번 생기면 사용자는 대화 한 턴, 수 초를 더 쓰게 되니까요. 그래서 불필요한 되묻기를 줄이는 것도 응답 시간 작업에 넣었습니다. 결과를 먼저 보여주게 바꾼 것이나 0건일 때 서버가 완화안을 미리 검색해 결과가 있는 것만 버튼으로 보여주게 한 것도 같은 이유였습니다.&lt;/p>
&lt;p>개발 서버 2주 기준 응답 시간 중앙값은 5.3초, 상위 10%는 9.5초였습니다. 앞의 16개 질문 비교와는 표본이 달라 바로 비교할 수는 없어서, 같은 질문으로 다시 재보려고 합니다.&lt;/p>
&lt;h2>마치며&lt;span class="hx:absolute hx:-mt-20" id="마치며">&lt;/span>
&lt;a href="#%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>지난 AI 추천 글 마지막에 &amp;ldquo;다음에 비슷한 기능을 만들 때는 처음부터 &amp;lsquo;LLM이 할 일&amp;rsquo;과 &amp;lsquo;코드가 할 일&amp;rsquo;의 경계를 먼저 정의하고 시작할 것 같다&amp;quot;고 적었는데, 이번에는 실제로 그 경계를 먼저 정하고 시작해봤습니다. 판단이 애매할 때마다 처음에 정한 기준으로 돌아가서 정했던 것 같습니다.&lt;/p>
&lt;p>1편의 목표를 지키려다 보니 판단 하나하나를 LLM, 코드, 사용자 중 누구에게 맡길지 정하는 데 시간이 꽤 들었고, LLM에게 맡기지 않은 만큼 저희가 직접 해야 하는 일도 늘었습니다. 확인 버튼을 한 번 더 눌러야 하는 것이나 다시 만든 검색 인덱스, 직접 관리하는 대화 이력 같은 것들이었죠. 그래도 이 비용들은 대부분 미리 예상할 수 있었고, 저희 팀 규모에서도 감당할 수 있는 정도였다고 생각합니다.&lt;/p>
&lt;p>아직 남은 것도 많습니다. 평가는 여전히 사람이 직접 보는 부분이 많아서 판정을 어디까지 자동으로 맡길 수 있을지 계속 고민하고 있고, 응답 속도도 여러 작업을 했지만 같은 질문으로 비교했을 때 기존보다 느렸던 만큼 더 줄여야 합니다. 사용자 확인을 거쳐 실행하는 기능이 늘어나면 이번에 정한 기준들도 그때마다 다시 점검해야 할 것 같습니다.&lt;/p>
&lt;p>참고로 이번 작업 중에 AI 모듈은 별도 서비스로 분리했습니다. AI는 한 요청이 수 초에서 수십 초씩 걸려서 다른 기능과 부하 특성이 많이 다릅니다. AI 쪽 문제가 다른 기능까지 번지지 않게 하려는 결정이었습니다. 이 과정은 &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-to-modular-monolith/">모듈러 모놀리식 전환기&lt;/a>에 이어서 따로 정리해볼 생각입니다.&lt;/p>
&lt;p>부동산 통합 AI 에이전트라는 목표에 비하면 이번 작업은 첫 단계라고 생각합니다. 서비스에 LLM을 붙이면서 비슷한 고민을 하고 계신 분들께 조금이나마 도움이 되었으면 좋겠습니다.&lt;/p>
&lt;p>긴 글 읽어주셔서 감사합니다.&lt;/p>
&lt;hr>
&lt;h2>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>관련 글&lt;span class="hx:absolute hx:-mt-20" id="관련-글">&lt;/span>
&lt;a href="#%ea%b4%80%eb%a0%a8-%ea%b8%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/architecture/real-estate-integrated-agent/">[부동산 통합 AI 에이전트 1/2편] AI의 답을 서비스로 이어지게 만들기까지&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/architecture/ai-property-recommendation-system/">AI 부동산 매물 추천 시스템 구축기&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/architecture/msa-to-modular-monolith/">MSA, 우리에겐 과했다 - 모듈러 모놀리식 전환기&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>참고 문헌&lt;span class="hx:absolute hx:-mt-20" id="참고-문헌">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%eb%ac%b8%ed%97%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>Anthropic - &lt;a href="https://www.anthropic.com/engineering/building-effective-agents"target="_blank" rel="noopener">Building Effective Agents&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>Anthropic - &lt;a href="https://www.anthropic.com/engineering/writing-tools-for-agents"target="_blank" rel="noopener">Writing effective tools for agents&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>OpenAI - &lt;a href="https://cdn.openai.com/business-guides-and-resources/a-practical-guide-to-building-agents.pdf"target="_blank" rel="noopener">A practical guide to building agents&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>OpenAI - &lt;a href="https://platform.openai.com/docs/api-reference/responses"target="_blank" rel="noopener">Responses API&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>OWASP - &lt;a href="https://genai.owasp.org/llmrisk/llm01-prompt-injection/"target="_blank" rel="noopener">LLM01: Prompt Injection&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>Beurer-Kellner et al. - &lt;a href="https://arxiv.org/abs/2506.08837"target="_blank" rel="noopener">Design Patterns for Securing LLM Agents against Prompt Injections&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> (arXiv, 2025)&lt;/li>
&lt;/ul></description></item><item><title>[EKS 업그레이드 2/2편] 노드 롤링부터 1.37까지, ingress-nginx에서 Gateway API로</title><link>https://jeongil.dev/ko/blog/infrastructure/eks-node-upgrade-to-1-37-gateway-api/</link><pubDate>Thu, 05 Nov 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/infrastructure/eks-node-upgrade-to-1-37-gateway-api/</guid><description>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/ga1wn614tl7sn7zm9m9nb/eks-upgrade-cover-part2.png?rlkey=8fht2r1sg9qsc8qu25jxl75or&amp;amp;raw=1" alt="EKS 업그레이드 2/2편 표지" loading="lazy" />&lt;/p>
&lt;p>전편: &lt;a href="https://jeongil.dev/ko/blog/infrastructure/eks-mysql-end-of-standard-support-upgrade/">[EKS 업그레이드 1/2편] 표준 지원이 끝난 EKS와 MySQL, 연장 지원 요금을 멈추기까지&lt;/a>&lt;/p>
&lt;p>안녕하세요. 프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 정정일입니다.&lt;/p>
&lt;p>이번엔 지난 글에 이어서, 그때 미뤄뒀던 EKS 노드를 버전업하고 클러스터를 1.37 버전까지 올린 이야기를 해볼까 합니다.&lt;/p>
&lt;p>지난 9월에는 AWS 표준 지원 기간이 끝난 EKS와 MySQL에 연장 지원 요금이 부과되고 있었고, 우선 요금을 멈추는 게 급했기 때문에 EKS는 컨트롤 플레인만 1.35 버전으로 올리고 노드는 1.33 버전에 남겨뒀었습니다. 이번 작업은 그때 남겨둔 노드를 맞추는 데서 시작했는데, 진행하다 보니 인그레스 컨트롤러를 Gateway API로 옮기는 일까지 하게 됐습니다.&lt;/p>
&lt;p>이 글에서는 노드를 올려야 했던 이유부터 서비스가 끊기지 않게 노드를 롤링한 과정, 그리고 인그레스 컨트롤러를 바꾸게 된 배경과 옮기면서 겪은 일들까지 다뤄보도록 하겠습니다.&lt;/p>
&lt;hr>
&lt;h2>노드를 올려야 했던 이유&lt;span class="hx:absolute hx:-mt-20" id="노드를-올려야-했던-이유">&lt;/span>
&lt;a href="#%eb%85%b8%eb%93%9c%eb%a5%bc-%ec%98%ac%eb%a0%a4%ec%95%bc-%ed%96%88%eb%8d%98-%ec%9d%b4%ec%9c%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>전편 작업 이후 클러스터는 컨트롤 플레인은 1.35 버전, 노드는 1.33 버전인 상태였습니다. 일시적으로 연장 지원 요금이 과금되지 않도록 한 조치였기에 요금은 다시 기존 요금으로 돌아왔지만, 이대로 유지할 수 없는 이유가 두 가지 있었습니다.&lt;/p>
&lt;p>하나는 노드 AMI가 3월에 만들어진 그대로였다는 점입니다. 관리형 노드그룹은 같은 쿠버네티스 버전 안에서도 AMI를 자동으로 새 것으로 바꿔주지 않죠. 그래서 노드를 교체하지 않는 동안에는 그사이 나온 OS, 커널, containerd 보안 패치가 하나도 들어가지 않습니다.&lt;/p>
&lt;p>다른 하나는 버전 차이입니다. 컨트롤 플레인과 노드 사이에는 이미 2 버전의 차이가 있었고, 컨트롤 플레인을 1.36으로 올리면 3 버전의 차이가 발생하게 됩니다. 쿠버네티스는 버전 차이를 3까지만 허용하기 때문에, 그다음부터는 노드를 먼저 올리지 않으면 컨트롤 플레인의 버전도 더 올릴 수가 없습니다. 1.35의 표준 지원이 끝나는 2027년 3월 27일 전에 다음 버전업을 하려면, 결국 노드도 버전업이 필요한 상황이라는 거죠.&lt;/p>
&lt;h2>노드 롤링을 막던 설정&lt;span class="hx:absolute hx:-mt-20" id="노드-롤링을-막던-설정">&lt;/span>
&lt;a href="#%eb%85%b8%eb%93%9c-%eb%a1%a4%eb%a7%81%ec%9d%84-%eb%a7%89%eb%8d%98-%ec%84%a4%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>관리형 노드그룹의 버전업은 새 버전 노드를 먼저 띄운 뒤, 기존 노드를 하나씩 cordon(새 파드 배치 금지)하고 drain(파드 내보내기)한 다음 종료하는 식으로 진행됩니다. 결국 노드 수만큼 그 위에 있던 파드들이 내려갔다가 다른 노드에서 다시 뜨게 되죠. 그래서 노드를 올리기 전에 봐야 했던 건, 이 과정에서 파드가 내려가는 동안에도 서비스가 끊기지 않는 구성인지였습니다.&lt;/p>
&lt;p>그런데 저희 클러스터는 그런 구성이 아니어서, 바로 노드를 롤링할 수 없는 상태였습니다. 살펴보니 롤링 중에 문제가 생길 수 있는 곳이 총 세 군데 있었습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>파드 하나뿐인 인그레스 컨트롤러&lt;/strong>: 외부 트래픽을 받는 인그레스 컨트롤러가 파드 하나로 운영되고 있었고 PDB도 없었습니다. 이 파드가 있는 노드가 비워지면, 새 파드가 다른 노드에서 뜰 때까지 외부 요청이 전부 끊기게 되는 상황이었던 거죠.&lt;/li>
&lt;li>&lt;strong>같은 노드에 함께 뜰 수 있는 서비스&lt;/strong>: 파드가 2개로 구성돼 있으나 두 파드를 서로 다른 노드에 두는 설정(anti-affinity)도, PDB도 없는 구성이 있었습니다. 버전업을 할 때 우연히 다른 노드에 떠 있을 수 있지만, 두 파드가 같은 노드에 올라가면 그 노드가 비워질 때 요청이 처리되지 않는 순간이 발생할 수 있는 구성이었죠.&lt;/li>
&lt;li>&lt;strong>파드 하나에 &lt;code>minAvailable: 1&lt;/code>이 걸린 서비스&lt;/strong>: 파드 하나로 운영되면서 PDB가 &lt;code>minAvailable: 1&lt;/code>로 걸려 있는 서비스가 존재했습니다. 하나뿐인 파드를 최소 하나는 남겨야 하니 사실상 &amp;ldquo;절대 내리지 마라&amp;quot;와 같은 설정이었고, 이대로 노드그룹을 업데이트하면 drain 명령어를 내려도 해당 파드들을 내보내지 못해 업데이트 자체가 실패하게 되는 상태였죠.&lt;/li>
&lt;/ul>
&lt;p>셋 다 노드를 교체할 일이 없던 동안에는 문제가 발생하지 않았던 설정들이었습니다. 물론 인그레스 파드가 하나뿐인 것처럼, 버전업이 아니더라도 파드나 노드에 문제가 생기면 바로 서비스가 멈출 수 있는 구성이긴 했죠. 그래서 노드를 올리기 전에 서비스마다 맞는 방법으로 먼저 해결해야 했습니다.&lt;/p>
&lt;h2>서비스별 대응&lt;span class="hx:absolute hx:-mt-20" id="서비스별-대응">&lt;/span>
&lt;a href="#%ec%84%9c%eb%b9%84%ec%8a%a4%eb%b3%84-%eb%8c%80%ec%9d%91" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>정리하기 전에 기준부터 정했습니다. 사용자 요청을 받는 서비스는 다운타임이 발생하면 안 된다고 봤습니다. 반면 캐시처럼 잠깐 멈춰도 DB 조회로 대신할 수 있는 서비스나, 모니터링 도구처럼 내부에서만 쓰는 리소스는 짧은 중단을 허용하기로 했습니다. 이 기준으로 세 가지에 대해 대응 방법을 하나씩 정리했습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>파드 하나뿐인 인그레스 컨트롤러&lt;/strong>: 파드를 2개로 늘리고, 두 파드가 같은 노드에 뜨지 않도록 노드 단위 anti-affinity와 PDB를 걸었습니다.&lt;/li>
&lt;li>&lt;strong>같은 노드에 함께 뜰 수 있는 서비스&lt;/strong>: 인그레스 컨트롤러와 같은 방식으로 노드 단위 anti-affinity와 PDB를 걸었습니다.&lt;/li>
&lt;li>&lt;strong>파드 하나에 &lt;code>minAvailable: 1&lt;/code>이 걸린 서비스&lt;/strong>: 가장 쉬운 방법은 파드를 2개로 늘리는 것이었지만, 이 중에는 동시성 이슈가 아직 해결되지 않아 한 번에 하나만 떠 있어야 하는 배치성 서비스가 있었습니다. 파드를 늘리는 순간 같은 작업이 두 번 처리될 수 있어서 다른 방법이 필요했습니다.&lt;/li>
&lt;/ul>
&lt;p>그래서 배치성 서비스는 파드를 1개로 그대로 두고, PDB만 &lt;code>maxUnavailable: 1&lt;/code>로 바꿨습니다. drain 할 때 일어나는 eviction은 기존 파드를 먼저 지우고 나서 ReplicaSet이 새 파드를 만드는 순서라, 두 파드가 동시에 떠 있는 순간이 생기지 않죠. 대신 새 파드가 뜰 때까지 1분 정도 멈추게 되는데, 배치성 서비스라 이 정도는 감수하기로 했습니다.&lt;/p>
&lt;p>그런데 이걸 확인하다가 한 가지를 더 알게 됐습니다. 해당 서비스들의 배포 전략이 기본값인 &lt;code>RollingUpdate&lt;/code>(maxSurge 25%, maxUnavailable 25%)였는데, 파드가 1개면 maxSurge는 올림해서 1, maxUnavailable은 내림해서 0이 됩니다. 새 파드가 Ready가 될 때까지 기존 파드가 함께 떠 있다는 뜻이라, 배포할 때마다 두 파드가 잠깐씩 겹칠 수 있었던 거죠. 그래서 배포 전략을 &lt;code>Recreate&lt;/code>로 바꿨습니다. &amp;ldquo;한 번에 하나만 떠 있어야 한다&amp;quot;는 조건은 PDB가 아니라 배포 전략을 통해 구성해야 하는 부분이었습니다.&lt;/p>
&lt;h2>노드 1.35 버전업과 측정&lt;span class="hx:absolute hx:-mt-20" id="노드-135-버전업과-측정">&lt;/span>
&lt;a href="#%eb%85%b8%eb%93%9c-135-%eb%b2%84%ec%a0%84%ec%97%85%ea%b3%bc-%ec%b8%a1%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>설정을 바꿨다고 해서 실제로 다운타임이 발생하지 않는지는 알 수 없었습니다. 그래서 이후로는 개발 노드그룹의 버전업을 먼저 진행했고, 롤링할 때마다 외부에서 요청을 계속 보내며 실패 건수를 쟀습니다. 롤링하는 동안 외부 요청이 실패하면 원인을 찾아 고친 뒤 다시 측정하는 식으로 진행했습니다.&lt;/p>
&lt;h3>인그레스 종료 처리&lt;span class="hx:absolute hx:-mt-20" id="인그레스-종료-처리">&lt;/span>
&lt;a href="#%ec%9d%b8%ea%b7%b8%eb%a0%88%ec%8a%a4-%ec%a2%85%eb%a3%8c-%ec%b2%98%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>인그레스 파드를 2개로 늘렸으니 이제 무중단으로 버전업할 수 있을 거라 생각했습니다. 그런데 인그레스를 롤링하면서 재보니, 89건 중 1건이 3초 타임아웃으로 실패하더라고요. 실패한 시각을 쿠버네티스 이벤트와 맞춰보니, 기존 인그레스 파드가 종료 신호를 받은 시각과 같았습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant K as Kubernetes
participant P as 종료되는 인그레스 파드
participant N as 각 노드의 kube-proxy
participant C as 외부 요청
K-&amp;gt;&amp;gt;P: 종료 신호(SIGTERM)
K-&amp;gt;&amp;gt;N: 엔드포인트에서 파드 제거
Note over P: nginx 바로 종료
C-&amp;gt;&amp;gt;N: 요청
N-&amp;gt;&amp;gt;P: 아직 반영 전이라 종료된 파드로 전달
P--xC: 연결 실패
Note over N: 잠시 뒤 엔드포인트 변경 반영
&lt;/pre>&lt;p>원인은 파드가 종료되는 순서에 있었습니다. 쿠버네티스는 파드를 지울 때 컨테이너에 종료 신호를 보내는 일과 엔드포인트에서 그 파드를 빼는 일을 동시에 시작합니다. 그런데 엔드포인트 변경이 각 노드에 반영되기까지는 시간이 조금 걸립니다. 그 사이에 nginx가 먼저 멈춰버리면, 아직 그 파드로 향하던 연결이 실패하게 되는 거죠.&lt;/p>
&lt;p>ingress-nginx에는 종료 신호를 받은 뒤에도 정해진 시간 동안 요청을 계속 받게 하는 &lt;code>--shutdown-grace-period&lt;/code> 옵션이 있습니다. 그래서 15초로 설정하고 다시 측정해봤습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>측정&lt;/th>
&lt;th>종료된 파드&lt;/th>
&lt;th>실패&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>옵션을 반영하는 롤링&lt;/td>
&lt;td>옵션 적용 전 파드 2개&lt;/td>
&lt;td>78건 중 2건&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>옵션 반영 후 &lt;code>rollout restart&lt;/code>&lt;/td>
&lt;td>옵션 적용 후 파드 2개&lt;/td>
&lt;td>102건 중 0건&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>측정을 두 번으로 나눈 이유가 있습니다. 파드의 종료 동작은 &amp;ldquo;종료되는 파드&amp;quot;의 설정을 따릅니다. 옵션을 반영하는 롤링에서 내려가는 파드는 아직 옵션이 없는 예전 파드라서, 그 롤링만 쟀다면 옵션이 효과가 없나 싶었을 겁니다. 이때의 경험이 뒤에서 Gateway를 고칠 때 한 번 더 도움이 됐습니다.&lt;/p>
&lt;h3>개발 노드그룹 먼저 버전업&lt;span class="hx:absolute hx:-mt-20" id="개발-노드그룹-먼저-버전업">&lt;/span>
&lt;a href="#%ea%b0%9c%eb%b0%9c-%eb%85%b8%eb%93%9c%ea%b7%b8%eb%a3%b9-%eb%a8%bc%ec%a0%80-%eb%b2%84%ec%a0%84%ec%97%85" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>운영 노드를 바로 올리기 전에 개발 노드그룹부터 먼저 올려서 확인했습니다. 개발 노드그룹은 운영과 같은 클러스터 안에 taint로 분리되어 있어서, 같은 컨트롤 플레인과 애드온 위에서 미리 확인해볼 수 있었습니다. 노드그룹을 1.33에서 1.35로 한 번에 올려도 되는지는 확인하지 못해서, 일반적으로 권장되는 대로 한 마이너 버전씩 올리기로 했습니다. 그래서 노드그룹 기본값은 그대로 두고 개발 노드그룹에만 1.34를 먼저 지정했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;span class="lnt">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-hcl" data-lang="hcl">&lt;span class="line">&lt;span class="cl">&lt;span class="n">eks_managed_node_group_defaults&lt;/span> &lt;span class="o">=&lt;/span> {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> cluster_version&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s2">&amp;#34;1.33&amp;#34;&lt;/span>&lt;span class="c1"> # 운영 노드그룹은 그대로
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">eks_managed_node_groups&lt;/span> &lt;span class="o">=&lt;/span> {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> dev&lt;/span> &lt;span class="o">=&lt;/span> {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> cluster_version&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s2">&amp;#34;1.34&amp;#34;&lt;/span>&lt;span class="c1"> # 개발 노드그룹만 먼저
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> }
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">}&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>개발 노드그룹으로 테스트하면서 발생한 문제가 하나 있었습니다. 개발 환경에는 다른 서비스들에 설정을 내려주는 설정 서버가 있는데, 이 서버가 파드 하나였습니다. 이 서버와 이 서버의 응답을 기다리는 서비스들이 같은 시점에 다른 노드로 옮겨지면서, 몇몇 서비스가 설정을 받지 못하고 재시작을 반복하게 됐죠. 노드그룹 업데이트는 PDB를 지키면서 파드를 내보내긴 하지만, 서비스 사이의 기동 순서까지 챙겨주지는 않으니까요. 운영에서는 설정 서버가 파드 2개에 PDB가 있어서 drain 중에도 하나는 남는다는 걸 확인하고 넘어갔습니다.&lt;/p>
&lt;p>개발 노드그룹을 올리면서 1.35에서 바뀌는 노드 쪽 변경도 함께 확인했습니다. 1.35에서는 cgroup v1 노드에서 kubelet이 기본 설정으로 뜨지 않고, kube-proxy IPVS 모드가 deprecated되고, containerd 1.x 지원이 마지막입니다. 확인해보니 저희 노드는 &lt;code>/sys/fs/cgroup&lt;/code>이 &lt;code>cgroup2&lt;/code>로 마운트돼 있었고, kube-proxy는 &lt;code>iptables&lt;/code> 모드, containerd는 2.x를 쓰고 있어서 세 가지 모두 해당이 없었습니다.&lt;/p>
&lt;h3>운영 노드그룹&lt;span class="hx:absolute hx:-mt-20" id="운영-노드그룹">&lt;/span>
&lt;a href="#%ec%9a%b4%ec%98%81-%eb%85%b8%eb%93%9c%ea%b7%b8%eb%a3%b9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>운영은 무상태 서비스가 올라가는 spot 노드그룹과, 볼륨을 쓰는 서비스가 올라가는 on-demand 노드그룹으로 나뉘어 있습니다. 롤링하는 동안 인그레스가 직접 응답하는 경로 하나와, 인그레스를 거쳐 앱까지 가는 경로 두 곳에 각각 요청을 계속 보냈습니다. 인그레스 응답만 재면 앱 파드가 옮겨지는 동안 생기는 실패를 놓칠 수 있기 때문입니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>단계&lt;/th>
&lt;th>소요&lt;/th>
&lt;th>인그레스 경로 실패&lt;/th>
&lt;th>앱 경로 실패&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>spot 1.33 → 1.34&lt;/td>
&lt;td>17분 27초&lt;/td>
&lt;td>999건 중 0건&lt;/td>
&lt;td>1,998건 중 1건&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>on-demand 1.33 → 1.34&lt;/td>
&lt;td>7분 49초&lt;/td>
&lt;td>455건 중 0건&lt;/td>
&lt;td>910건 중 0건&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>운영 일괄 1.34 → 1.35&lt;/td>
&lt;td>약 12분&lt;/td>
&lt;td>676건 중 0건&lt;/td>
&lt;td>1,352건 중 4건&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>앱 경로에서 나온 실패는 접근 로그를 보니 인그레스가 아니라 앱이 직접 돌려준 503이었습니다. Spring Boot는 종료를 시작하면 readiness를 &lt;code>REFUSING_TRAFFIC&lt;/code>으로 바꾸고 503을 돌려주는데, 종료 중인 파드가 엔드포인트에서 빠지기 전에 요청이 그 파드로 들어간 것으로 보고 있습니다. 인그레스에서 봤던 엔드포인트 반영 지연이 앱 파드에도 똑같이 있었던 거죠.&lt;/p>
&lt;p>이렇게 노드가 모두 1.35로 올라갔고, 컨트롤 플레인과의 버전 차이도 0이 됐습니다.&lt;/p>
&lt;p>이로써 전편에서 미뤄뒀던 노드 버전업까지 모두 마무리됐습니다.&lt;/p>
&lt;h2>1.37을 막던 컴포넌트&lt;span class="hx:absolute hx:-mt-20" id="137을-막던-컴포넌트">&lt;/span>
&lt;a href="#137%ec%9d%84-%eb%a7%89%eb%8d%98-%ec%bb%b4%ed%8f%ac%eb%84%8c%ed%8a%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>다만 버전을 1.35로 맞추고 나니 이번엔 버전을 1.37까지 올릴 수 있는지 검토해보기로 했습니다. 1.37은 표준 지원이 2027년 12월까지라 1.35보다 8개월이나 여유가 있었고 보안과 관련된 패치도 진행됐기 때문이죠.&lt;/p>
&lt;p>그렇다면 1.35에서 1.37로 올라가면서 무엇이 바뀌는지부터 확인해야 했습니다. 1.35 때처럼 1.36과 1.37 릴리스 노트에서 저희 클러스터에 해당할 만한 항목을 추려봤습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>버전&lt;/th>
&lt;th>변경&lt;/th>
&lt;th>저희 클러스터&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>1.36&lt;/td>
&lt;td>GA·beta API 제거 없음&lt;/td>
&lt;td>해당 없음&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>1.36&lt;/td>
&lt;td>Service의 &lt;code>externalIPs&lt;/code> 필드 deprecated (1.43 제거 예정)&lt;/td>
&lt;td>&lt;code>externalIPs&lt;/code>를 쓰는 Service 없음&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>1.37&lt;/td>
&lt;td>GA·beta API 제거 없음&lt;/td>
&lt;td>해당 없음&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>1.37&lt;/td>
&lt;td>일부 cAdvisor 지표 제거 (&lt;code>container_cpu_load_average_10s&lt;/code> 등)&lt;/td>
&lt;td>대시보드와 매니페스트에서 쓰는 곳 없음&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>1.37&lt;/td>
&lt;td>kube-proxy IPVS 모드 사용 시 deprecation 경고 (1.40부터 기본 비활성, 1.43 제거 예정)&lt;/td>
&lt;td>&lt;code>iptables&lt;/code> 모드라 해당 없음&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>1.35 때와 달리 노드가 아예 뜨지 않을 수 있는 큰 변경은 없었고, 걸리는 항목도 없었습니다. EKS upgrade insights에서도 1.37에서 제거되는 API를 쓰는 곳은 없었고, EKS 애드온 5개도 버전마다 kube-proxy만 올려주면 지금 버전 그대로 1.37과 호환됐습니다. 쿠버네티스 쪽은 버전업에 제약이 발생하는 부분이 없었던 거죠.&lt;/p>
&lt;p>그러나 저희가 직접 설치한 컴포넌트들은 조금 이야기가 달랐습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>컴포넌트&lt;/th>
&lt;th>상태&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>ingress-nginx&lt;/td>
&lt;td>쓰던 버전의 공식 지원 범위가 1.35보다 한참 아래. 프로젝트는 2026년 3월에 지원 종료&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Argo CD&lt;/td>
&lt;td>1.37이 테스트 범위에 들어가려면 2.x에서 3.6으로 메이저 버전업 필요&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Node Termination Handler&lt;/td>
&lt;td>최신 버전도 1.32까지만 테스트&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>EKS 애드온은 AWS가 버전별 호환 목록을 API로 알려주지만, Helm으로 직접 설치한 컨트롤러는 프로젝트마다 지원 범위를 따로 찾아봐야 합니다. 전편에서 컨트롤 플레인을 1.35로 올릴 때는 EKS 버전별 변경점과 EKS 애드온 호환성까지만 확인했고, 이렇게 직접 설치한 컴포넌트의 지원 범위는 확인하지 못했습니다. ingress-nginx도 프로젝트 지원 종료는 알고 있었지만, 쓰던 버전이 이미 공식 지원 범위를 한참 벗어나 있었다는 건 이때 알게 됐습니다.&lt;/p>
&lt;h3>ingress-nginx 지원 종료 배경&lt;span class="hx:absolute hx:-mt-20" id="ingress-nginx-지원-종료-배경">&lt;/span>
&lt;a href="#ingress-nginx-%ec%a7%80%ec%9b%90-%ec%a2%85%eb%a3%8c-%eb%b0%b0%ea%b2%bd" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>셋 중 가장 큰 문제는 ingress-nginx였습니다. 쿠버네티스 공식 블로그의 지원 종료 공지를 보면 그 이유가 적혀 있습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/d3u3zn7r2tjaeuuk9gwbf/eks-upgrade-k8s-ingress-nginx-retirement.png?rlkey=l2l4a64jt81d3lbyw7ajntxz3&amp;amp;raw=1" alt="쿠버네티스 공식 블로그의 ingress-nginx 지원 종료 공지. 2026년 3월까지만 유지보수하고 이후 보안 패치도 없다는 내용" loading="lazy" />&lt;/p>
&lt;p>&lt;em>쿠버네티스 공식 블로그의 &lt;a href="https://kubernetes.io/blog/2025/11/11/ingress-nginx-retirement/"target="_blank" rel="noopener">지원 종료 공지&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> (2025년 11월 11일)&lt;/em>&lt;/p>
&lt;blockquote>
&lt;p>For years, the project has had only one or two people doing development work, on their own time, after work hours and on weekends.&lt;/p>
&lt;p>What were once considered helpful options have sometimes come to be considered serious security flaws, such as the ability to add arbitrary NGINX configuration directives via the &amp;ldquo;snippets&amp;rdquo; annotations.&lt;/p>
&lt;/blockquote>
&lt;p>많은 클러스터에서 쓰던 인그레스 컨트롤러는 사실 한두 명의 개인 시간으로 유지되고 있었고, 편하게 쓰던 snippets 같은 기능이 오히려 보안 문제가 됐다는 설명입니다. 후속으로 준비하던 프로젝트도 참여하는 사람이 모이지 않아 함께 중단됐다고 하네요.&lt;/p>
&lt;p>공지에는 이런 문장도 있습니다.&lt;/p>
&lt;blockquote>
&lt;p>Existing deployments will continue to work, so unless you proactively check, you may not know you are affected until you are compromised.&lt;/p>
&lt;/blockquote>
&lt;p>이 문장을 읽고 전편에서 겪은 일이 떠올랐습니다. 그때도 클러스터가 아무 문제 없이 돌고 있어서 EKS 표준 지원이 끝난 걸 몰랐고, AWS 비용이 늘어난 걸 보고서야 알게 됐었죠.&lt;/p>
&lt;p>ingress-nginx는 그마저도 없었습니다. 지원이 끝나도 비용이 달라지지 않고, 서비스도 계속 잘 돌아가니까요. 사실 지원 종료 소식은 알고 있었지만, 당장 문제가 없다 보니 계속 미뤄왔습니다. 그러다 1.37 버전업을 검토하면서 결국 더 미룰 수 없게 된 거죠.&lt;/p>
&lt;h2>대체 방식 선택&lt;span class="hx:absolute hx:-mt-20" id="대체-방식-선택">&lt;/span>
&lt;a href="#%eb%8c%80%ec%b2%b4-%eb%b0%a9%ec%8b%9d-%ec%84%a0%ed%83%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>그렇다면 ingress-nginx를 무엇으로 바꿀지 정해야 했습니다. 공지에서도 그대로 바꿔 끼울 수 있는 대체재는 없다고 하고, Gateway API로 옮기거나 다른 인그레스 컨트롤러를 쓰는 걸 권하고 있었습니다. 그래서 크게 두 갈래를 놓고 비교해봤습니다. 하나는 Ingress 리소스는 그대로 두고 컨트롤러만 바꾸는 방법이고, 다른 하나는 Ingress 대신 Gateway API로 옮기는 방법이었습니다.&lt;/p>
&lt;blockquote>
&lt;p>Gateway API란?
쿠버네티스에서 외부 트래픽을 클러스터 안의 서비스로 연결하는 방식을 정의한 표준 API입니다. 기존 Ingress가 하나의 리소스에 모든 설정을 담고 세부 기능은 컨트롤러별 어노테이션에 맡겼다면, Gateway API는 트래픽을 받는 입구(Gateway)와 경로 규칙(HTTPRoute)을 나누고 경로 재작성 같은 기능도 표준 필드로 정의합니다. 실제로 트래픽을 처리하는 구현체는 Istio, Envoy Gateway, NGINX Gateway Fabric 등 여러 프로젝트가 따로 제공합니다.&lt;/p>
&lt;/blockquote>
&lt;p>비교 기준은 지금 쓰고 있는 설정을 얼마나 그대로 옮길 수 있는지였습니다. 저희 Ingress에는 정규식 경로와 rewrite, 여러 origin을 허용하는 CORS, 경로별 본문 크기와 타임아웃, IP당 요청 수 제한 같은 설정이 들어가 있었습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>후보&lt;/th>
&lt;th>방식&lt;/th>
&lt;th>장점&lt;/th>
&lt;th>걸리는 점&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Traefik&lt;/td>
&lt;td>컨트롤러만 교체&lt;/td>
&lt;td>ingress-nginx 어노테이션을 대부분 그대로 읽음&lt;/td>
&lt;td>나중에 Gateway API로 가려면 한 번 더 옮겨야 함&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>F5 NGINX Ingress Controller&lt;/td>
&lt;td>컨트롤러만 교체&lt;/td>
&lt;td>엔진이 nginx라 지금과 동작이 가장 비슷함&lt;/td>
&lt;td>어노테이션 이름이 달라 매니페스트를 새로 써야 하고, 역시 한 번 더 옮겨야 함&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>AWS ALB&lt;/td>
&lt;td>컨트롤러만 교체&lt;/td>
&lt;td>AWS가 관리해서 운영 부담이 적음&lt;/td>
&lt;td>CORS를 앱 코드로 옮겨야 하고, 요청 수 제한에는 WAF(추가 비용)가 필요하며, 타임아웃은 ALB 단위로만 설정 가능&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Gateway API&lt;/td>
&lt;td>API 자체를 교체&lt;/td>
&lt;td>쿠버네티스가 권장하는 방향. 기능을 표준 필드로 정의&lt;/td>
&lt;td>모든 Ingress를 HTTPRoute로 새로 써야 함&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>처음에는 Traefik 쪽으로 마음이 기울었습니다. 지금 매니페스트를 거의 그대로 옮길 수 있으니 이관 부담이 가장 적어 보였거든요. 그런데 걸리는 부분이 두 가지 있었습니다.&lt;/p>
&lt;p>첫 번째, 매니페스트를 새로 쓰는 건 별다른 문제가 아니었습니다. Ingress가 십여 개 정도라 다시 쓰는 것 자체는 몇 시간이면 되는 일이었고, 정말 시간이 드는 건 컨트롤러마다 다른 동작을 하나씩 맞추는 일이었습니다. 그 비용은 어느 후보를 고르든 똑같이 들었습니다.&lt;/p>
&lt;p>두 번째, Gateway API로는 저희 rewrite를 옮기기 어려울 거라고 생각했는데, 실제로 쓰고 있는 rewrite를 전부 뽑아보니 모두 &amp;ldquo;경로 앞의 접두어를 떼는&amp;rdquo; 용도였습니다. 이건 Gateway API 표준 기능으로 그대로 표현할 수 있었습니다(자세한 내용은 아래 이관 과정에서 다루겠습니다). Gateway API로 바로 가지 못할 이유가 사라진 셈이죠.&lt;/p>
&lt;p>그렇다고 Traefik으로 가는 게 끝은 아니었습니다. Ingress API 자체가 없어지는 건 아니지만, Ingress는 표준이 다루는 범위가 좁아서 rewrite나 CORS 같은 기능은 컨트롤러마다 다른 어노테이션으로 설정해야 합니다. 이번에 컨트롤러를 바꾸기 어려웠던 것도 결국 그 설정들이 ingress-nginx 어노테이션에 묶여 있었기 때문이었죠. Traefik은 그 ingress-nginx 어노테이션을 그대로 읽어주는 방식이라, 옮기더라도 이 구조는 그대로 남고 다음에 컨트롤러를 바꿀 일이 생기면 같은 일을 또 겪게 됩니다.&lt;/p>
&lt;p>반면 Gateway API는 이런 기능을 표준 필드로 정의하고 있어서, 표준 범위 안의 설정은 구현체를 바꾸더라도 그대로 가져갈 수 있습니다. 쿠버네티스가 Ingress 다음으로 Gateway API를 권하고, 새 기능도 그쪽에만 넣고 있는 것도 같은 이유입니다. 그렇다면 Traefik으로 옮겼다가 언젠가 다시 Gateway API로 옮기느니, 처음부터 Gateway API로 가는 게 같은 일을 두 번 하지 않는 길이라고 판단했습니다.&lt;/p>
&lt;p>ALB는 운영 부담이 적다는 점이 끌렸지만, CORS를 앱 코드로 옮기고 WAF 비용까지 감수할 만큼의 이점은 아니라고 봤습니다. 그래서 처음부터 Gateway API로 옮기기로 결정했습니다.&lt;/p>
&lt;h3>Gateway API 구현체 선택&lt;span class="hx:absolute hx:-mt-20" id="gateway-api-구현체-선택">&lt;/span>
&lt;a href="#gateway-api-%ea%b5%ac%ed%98%84%ec%b2%b4-%ec%84%a0%ed%83%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Gateway API는 스펙이기 때문에, 실제로 트래픽을 처리할 구현체는 따로 골라야 했습니다. 쿠버네티스 쪽에서 특정 구현체를 권하지는 않고, 공식 구현체 목록도 conformance 테스트 통과 여부만 보여줍니다. 그래서 저희 기준으로 직접 비교해봤습니다.&lt;/p>
&lt;p>기준은 세 가지였습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>쿠버네티스 신버전 추적&lt;/strong>: 이번 ingress-nginx처럼 구현체가 클러스터 버전업을 막지 않아야 했습니다. 새 쿠버네티스 버전이 나온 뒤 지원하기까지 얼마나 걸렸는지, 지원 기간이 정책으로 정해져 있는지를 봤습니다.&lt;/li>
&lt;li>&lt;strong>관리 주체&lt;/strong>: 한두 명이 유지하는 구조는 피하고 싶었습니다.&lt;/li>
&lt;li>&lt;strong>지금 쓰는 기능&lt;/strong>: rewrite, CORS, 타임아웃, 본문 크기 제한, IP당 요청 수 제한을 표준 기능이나 정식 설정으로 지원하는지 봤습니다.&lt;/li>
&lt;/ul>
&lt;p>CNI를 바꿔야 하는 Cilium, Gateway API 지원이 부분적인 AWS Load Balancer Controller와 Traefik, 기본 이미지가 유료 버전인 Kong은 먼저 제외했고, 나머지 네 개를 비교했습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>구현체&lt;/th>
&lt;th>신버전 지원까지 걸린 기간 (1.34~1.37)&lt;/th>
&lt;th>지원 기간 정책&lt;/th>
&lt;th>관리 주체&lt;/th>
&lt;th>걸리는 점&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Envoy Gateway&lt;/td>
&lt;td>50~162일, 조사 시점에 1.37 정식 지원 없음&lt;/td>
&lt;td>마이너별 6개월&lt;/td>
&lt;td>Envoy 조직(CNCF), 여러 회사&lt;/td>
&lt;td>골랐다면 지금 1.37 버전업이 막혀 있었음&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>NGINX Gateway Fabric&lt;/td>
&lt;td>7~56일 (1.36은 테스트 기록 없음)&lt;/td>
&lt;td>명시 없음&lt;/td>
&lt;td>F5 단독&lt;/td>
&lt;td>지원 기간이 정해져 있지 않음&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>kgateway&lt;/td>
&lt;td>44~92일&lt;/td>
&lt;td>약 3개월마다 마이너&lt;/td>
&lt;td>CNCF Sandbox, 관리자 대부분이 한 회사&lt;/td>
&lt;td>IP당 요청 수 제한에 별도 서비스 필요&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Istio&lt;/td>
&lt;td>26~70일&lt;/td>
&lt;td>N+2 마이너 출시 후 6주까지&lt;/td>
&lt;td>CNCF 졸업, 여러 회사&lt;/td>
&lt;td>본문 크기 제한과 IP당 요청 수 제한이 표준 기능 밖(EnvoyFilter 필요)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>처음에는 NGINX Gateway Fabric이 가장 유력해 보였습니다. 엔진이 nginx라 본문 크기 제한, 타임아웃, 요청 수 제한이 지금과 같은 방식으로 동작하고, 1.37도 일주일 만에 지원했으니까요. 이관할 때 바뀌는 게 가장 적어서, 인프라를 혼자 맡고 있는 입장에서는 디버깅 부담도 가장 작아 보였습니다.&lt;/p>
&lt;p>그런데 생각해야 할 부분이 두 가지 있었습니다.&lt;/p>
&lt;p>첫 번째, 어떤 구현체를 고르든 그 구현체 자체를 계속 버전업해야 하는 건 마찬가지였습니다. 그렇다면 중요한 건 &amp;ldquo;각 버전을 언제까지 지원하는지가 정해져 있느냐&amp;quot;였는데, NGINX Gateway Fabric은 이게 정해져 있지 않았습니다. 이번에 제가 EKS와 ingress-nginx 모두 지원 종료를 제때 챙기지 못한 걸 생각하면, 지원 기간이 정책으로 명시된 쪽이 낫다고 봤습니다.&lt;/p>
&lt;p>두 번째, 1년 안쪽으로 서비스 메시 도입을 검토하고 있었습니다. NGINX Gateway Fabric으로 갔다가 메시를 도입하면 인그레스와 메시를 따로 운영하거나, 인그레스를 다시 한번 옮겨야 합니다. 앞에서 Traefik을 거치지 않기로 한 것과 같은 이유로, 이번에도 같은 일을 두 번 하고 싶지는 않았습니다.&lt;/p>
&lt;p>그래서 Istio를 골랐습니다. 신버전 지원이 꾸준히 빠르고, 지원 기간이 정책으로 정해져 있고, 여러 회사가 함께 관리하며, 나중에 메시까지 같은 컴포넌트로 이어갈 수 있었기 때문입니다. 다만 아직 메시로 쓰지 않는 지금은 Gateway 기능만 쓰기에는 다소 무거운 선택일 수 있다는 점도 알고 선택했습니다.&lt;/p>
&lt;p>남은 문제는 본문 크기 제한과 IP당 요청 수 제한이었습니다. Istio에서 이 둘을 게이트웨이에 걸려면 Envoy 내부 설정을 직접 고치는 EnvoyFilter를 써야 하는데, Istio 문서 스스로 &amp;ldquo;내부 구현을 노출하므로 업그레이드할 때 극도로 주의하라&amp;quot;고 경고하는 기능입니다. 그래서 한 가지 원칙을 정했습니다. EnvoyFilter는 쓰지 않고, Gateway API 표준 리소스로만 구성하기로 했습니다. ingress-nginx를 떠나게 된 이유 중 하나가 snippets처럼 표준 밖의 설정이 쌓인 것이었는데, 옮겨 가서 같은 일을 반복하고 싶지는 않았기 때문입니다. 표준으로 구성할 수 없는 두 기능은 게이트웨이가 아니라 앱 쪽에서 처리하는 방향으로 정리했습니다.&lt;/p>
&lt;h3>개발·운영 Gateway 분리&lt;span class="hx:absolute hx:-mt-20" id="개발운영-gateway-분리">&lt;/span>
&lt;a href="#%ea%b0%9c%eb%b0%9c%ec%9a%b4%ec%98%81-gateway-%eb%b6%84%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>기존에는 인그레스 컨트롤러 하나가 개발과 운영 트래픽을 함께 받고 있었습니다. 이번에는 Istio의 컨트롤 플레인인 istiod는 하나로 두고, 실제로 트래픽을 받는 Gateway(Envoy와 NLB)는 개발과 운영을 나눴습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/4xz4d07azfimmzq5t4dc6/eks-upgrade-p2-ingress-before.ko.png?rlkey=d3zxus2qhzlbhoy8ju4zfi1vc&amp;amp;raw=1" alt="이전 구조. 사용자, CDN, NLB 하나, 개발·운영 공용 ingress-nginx를 거쳐 운영 앱과 개발 앱으로" loading="lazy" />&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/0ggkxn172pcq9hroit2e3/eks-upgrade-p2-ingress-after.ko.png?rlkey=k6npon97xxdf7q9ootrvfgacn&amp;amp;raw=1" alt="이후 구조. CDN에서 운영 NLB와 개발 NLB로 나뉘고 각각 운영 Gateway와 개발 Gateway를 거쳐 앱으로. istiod가 두 Gateway에 설정을 배포" loading="lazy" />&lt;/p>
&lt;p>개발 쪽 설정을 바꾸다 실수하더라도 그 영향이 운영 트래픽까지 번지지 않게 하고 싶었고, 나중에 Istio를 버전업할 때도 개발 Gateway부터 먼저 바꿔볼 수 있기 때문입니다. 또 NLB 어노테이션이나 노드 배치 같은 AWS 전용 설정은 Gateway마다 ConfigMap 한 곳에만 모아두고, 경로를 정의하는 HTTPRoute에는 넣지 않았습니다. 나중에 다른 클러스터로 옮기게 되더라도 고칠 곳을 줄이기 위해서였습니다.&lt;/p>
&lt;h2>이관하면서 확인한 동작 차이&lt;span class="hx:absolute hx:-mt-20" id="이관하면서-확인한-동작-차이">&lt;/span>
&lt;a href="#%ec%9d%b4%ea%b4%80%ed%95%98%eb%a9%b4%ec%84%9c-%ed%99%95%ec%9d%b8%ed%95%9c-%eb%8f%99%ec%9e%91-%ec%b0%a8%ec%9d%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이관은 Ingress 파일 하나당 HTTPRoute 파일 하나로 1:1 변환하는 방식으로 진행했습니다. 변환 자체는 스크립트로 했는데, 오히려 시간이 더 걸린 건 두 컨트롤러가 같은 설정을 서로 다르게 해석하는 부분을 찾아내는 일이었습니다.&lt;/p>
&lt;h3>rewrite 옮기기&lt;span class="hx:absolute hx:-mt-20" id="rewrite-옮기기">&lt;/span>
&lt;a href="#rewrite-%ec%98%ae%ea%b8%b0%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>nginx에서는 &lt;code>/service(/|$)(.*)&lt;/code> 같은 정규식 경로에 &lt;code>rewrite-target: /$2&lt;/code>를 걸어 경로 앞의 접두어를 떼고 있었습니다. 앞에서 말씀드린 것처럼 저희 rewrite는 전부 이런 용도였고, 이건 &lt;code>PathPrefix&lt;/code> 매치에 &lt;code>ReplacePrefixMatch: /&lt;/code>를 쓰면 같은 결과를 얻을 수 있었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">- &lt;span class="nt">matches&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">path&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">type&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">PathPrefix&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">value&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">/service&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">filters&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">type&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">URLRewrite&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">urlRewrite&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">path&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">type&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">ReplacePrefixMatch&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">replacePrefixMatch&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">/&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>다만 이 필터를 쓰는 규칙에는 &lt;code>PathPrefix&lt;/code> 매치가 하나만 있어야 해서, 접두어마다 규칙을 따로 만들어야 했습니다. 그러다 보니 HTTPRoute 하나에 넣을 수 있는 규칙 16개를 넘기게 돼서 라우트를 나눠야 했죠. 이 문제는 서버 쪽 dry-run 단계에서 미리 확인할 수 있었습니다.&lt;/p>
&lt;h3>응답 비교 테스트&lt;span class="hx:absolute hx:-mt-20" id="응답-비교-테스트">&lt;/span>
&lt;a href="#%ec%9d%91%eb%8b%b5-%eb%b9%84%ea%b5%90-%ed%85%8c%ec%8a%a4%ed%8a%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>설정을 구성한 뒤에는 실제로 같은 응답이 나오는지 확인해야 했습니다. 그래서 nginx와 새 Gateway에 같은 요청을 보내 응답을 비교했습니다. 다만 그 전에 비교 방법 자체를 믿을 수 있는지부터 보려고, 같은 nginx에 두 번 보내서 차이가 0건인지 먼저 확인했습니다. 확인해보니 실제 동작 차이는 두 종류였습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>차이&lt;/th>
&lt;th>nginx&lt;/th>
&lt;th>Gateway&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>정규식 경로가 하나라도 있는 호스트&lt;/td>
&lt;td>그 호스트의 모든 경로를 정규식 접두어로 처리해서 &lt;code>/api&lt;/code>가 &lt;code>/apix&lt;/code>도 잡음&lt;/td>
&lt;td>적힌 대로 매치&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>정규식 경로의 대소문자&lt;/td>
&lt;td>무시&lt;/td>
&lt;td>구분&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>둘 다 Gateway 쪽이 더 엄격했고, 원래 의도에 더 가까운 동작이었습니다. nginx의 &lt;code>use-regex&lt;/code>가 경로 하나가 아니라 호스트 전체에 적용된다는 건 이번에 처음 알게 됐습니다.&lt;/p>
&lt;p>반대로 정규식 경로 자체는 Gateway 쪽이 더 엄격해서 손을 봐야 했습니다. Envoy의 정규식은 경로 전체와 일치해야 하는데, nginx는 앞부분만 맞으면 됐기 때문입니다. 그래서 &lt;code>$&lt;/code>로 끝나지 않는 정규식에는 끝에 &lt;code>.*&lt;/code>를 붙여서 같은 범위를 잡도록 했습니다.&lt;/p>
&lt;p>CORS 쪽에서도 하나가 있었습니다. 기존 설정은 허용 origin &lt;code>*&lt;/code>와 credentials 허용을 함께 보내고 있었는데, 이 조합은 브라우저가 거부하는 응답입니다. 그래서 Gateway로 옮기면서 origin이 &lt;code>*&lt;/code>인 곳은 credentials를 끄도록 바꿨습니다.&lt;/p>
&lt;p>마지막으로 운영 접근 로그 1시간 가까운 분량을 새 Gateway의 라우트에 대입해봤는데, 매치되지 않는 요청은 0건이었습니다.&lt;/p>
&lt;h3>istiod 차트 기본값&lt;span class="hx:absolute hx:-mt-20" id="istiod-차트-기본값">&lt;/span>
&lt;a href="#istiod-%ec%b0%a8%ed%8a%b8-%ea%b8%b0%eb%b3%b8%ea%b0%92" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>istiod를 설치하다 보니 Helm 차트 기본값이 파드 1개에 PDB &lt;code>minAvailable: 1&lt;/code>이었습니다. 앞에서 노드 롤링을 막는다고 정리했던 조합과 똑같았죠. 그래서 파드 2개에 노드 단위 anti-affinity를 걸어서 설치했습니다. 이 일 이후로는 새 차트를 설치할 때 PDB 기본값부터 확인하고 있습니다.&lt;/p>
&lt;h3>트래픽 전환 순서&lt;span class="hx:absolute hx:-mt-20" id="트래픽-전환-순서">&lt;/span>
&lt;a href="#%ed%8a%b8%eb%9e%98%ed%94%bd-%ec%a0%84%ed%99%98-%ec%88%9c%ec%84%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>트래픽 전환은 호스트마다 CDN 레코드의 원본을 새 NLB로 바꾸는 방식으로 진행했습니다. 개발 호스트를 먼저 옮겨서 로그인과 주요 API 흐름을 직접 확인해본 뒤, 운영은 모니터링처럼 내부에서 쓰는 호스트부터 옮겼습니다.&lt;/p>
&lt;p>한 번은 개발서버에서 순서를 지키지 못했습니다. HTTPRoute가 반영되기 전에 DNS를 먼저 바꾼 호스트가 있었는데, 그 사이 1초 동안 들어온 요청 2건이 라우트를 찾지 못해 404가 났습니다. 그 뒤로는 라우트 반영을 확인한 다음에 DNS를 바꾸도록 순서를 지켰습니다. 또 CDN이 기존 원본에 맺어둔 연결은 레코드를 바꾸고도 1~2분 정도 이어지더라고요. 그래서 그동안은 양쪽 접근 로그를 같이 보면서 확인했습니다.&lt;/p>
&lt;p>모든 호스트를 옮긴 뒤에는 기존 nginx로 들어오는 실제 요청이 0건인 걸 확인하고, 컨트롤러와 기존 NLB를 지웠습니다.&lt;/p>
&lt;h2>Argo CD와 Node Termination Handler&lt;span class="hx:absolute hx:-mt-20" id="argo-cd와-node-termination-handler">&lt;/span>
&lt;a href="#argo-cd%ec%99%80-node-termination-handler" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>인그레스를 옮긴 뒤에는 앞에서 정리한 나머지 두 컴포넌트를 처리했습니다. Argo CD는 2.x에서 3.6으로 한 번에 올렸습니다. 같은 Argo CD가 개발과 운영 앱을 함께 관리하고 있어서, 버전업하면 개발과 운영에 동시에 적용되는 구조였습니다. 그래서 3.0에서 바뀐 기본값 중 리소스 추적 방식, reconcile 주기, NetworkPolicy 생성은 일부러 이전 동작으로 고정해서, 한 번에 바뀌는 범위를 최대한 줄였습니다. 버전업 전에 모든 앱의 sync와 health 상태를 파일로 저장해두고, 버전업 후 다시 뽑아서 비교해봤는데 차이는 0건이었습니다. 적용은 56초 걸렸고, Argo CD는 배포 경로일 뿐 사용자 요청이 지나가는 경로가 아니라서 그동안 서비스 요청 실패도 없었습니다.&lt;/p>
&lt;p>Node Termination Handler는 버전업하지 않고 아예 지웠습니다. spot 인스턴스가 회수된다는 알림을 받아 노드를 비워주는 컴포넌트인데, &lt;a href="https://github.com/aws/aws-node-termination-handler"target="_blank" rel="noopener">NTH 공식 저장소의 README&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에도 &amp;ldquo;EKS 관리형 노드그룹을 쓰면 NTH가 필요 없다&amp;quot;고 적혀 있었습니다. 관리형 노드그룹에서는 EKS가 같은 일을 &lt;a href="https://docs.aws.amazon.com/eks/latest/userguide/managed-node-groups.html"target="_blank" rel="noopener">직접 해주기&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> 때문입니다. 저희 노드그룹은 모두 관리형이었고, spot 리밸런싱 설정이 켜져 있는 것도 확인했습니다. 버전업을 검토하다 보니 올려야 할 것뿐 아니라 지워도 되는 것도 함께 보이더라고요.&lt;/p>
&lt;h2>1.36과 1.37을 이어서 진행한 이유&lt;span class="hx:absolute hx:-mt-20" id="136과-137을-이어서-진행한-이유">&lt;/span>
&lt;a href="#136%ea%b3%bc-137%ec%9d%84-%ec%9d%b4%ec%96%b4%ec%84%9c-%ec%a7%84%ed%96%89%ed%95%9c-%ec%9d%b4%ec%9c%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>1.36과 1.37은 같은 절차로, 같은 날 이어서 진행했습니다.&lt;/p>
&lt;p>보통은 버전 사이에 며칠씩 두고 지켜보는 게 더 안전하다는 건 알고 있었습니다. 그래도 한 번에 끝내기로 한 건 제 상황 때문이었습니다. 인프라를 혼자 맡으면서 다른 개발도 같이 하고 있다 보니, 여기서 멈추면 다음에 다시 시작할 때 클러스터 상태와 그날 바꾼 것들을 다시 파악하는 데만 꽤 시간이 들 것 같았습니다. 그래서 노드, 인그레스, Argo CD를 정리하면서 맥락을 가장 잘 잡고 있을 때 끝내는 쪽을 택했습니다.&lt;/p>
&lt;p>대신 쉬어가지 않는 만큼 단계마다 잘 확인하고 넘어가기로 했습니다. 버전마다 컨트롤 플레인을 먼저 올리고, 개발 노드그룹을 롤링한 뒤, 노드그룹 기본값을 올려 운영 노드그룹을 한 번에 롤링했습니다. 각 단계 동안 외부에서 요청을 계속 보내 실패 건수를 봤고, 개발에서 문제가 없을 때만 운영으로 넘어갔습니다. 실패가 나오면 원인을 찾아 고친 뒤에만 다음 단계로 넘어갔고요. 다만 버전업 직후에는 보이지 않고 며칠 지나서야 드러나는 문제는 이 방식으로 잡을 수 없기 때문에, 그 부분은 작업이 끝난 뒤 계속 지켜보는 것으로 남겨뒀습니다.&lt;/p>
&lt;h2>1.36 버전업과 Gateway 종료 처리&lt;span class="hx:absolute hx:-mt-20" id="136-버전업과-gateway-종료-처리">&lt;/span>
&lt;a href="#136-%eb%b2%84%ec%a0%84%ec%97%85%ea%b3%bc-gateway-%ec%a2%85%eb%a3%8c-%ec%b2%98%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>1.36 컨트롤 플레인 버전업은 약 8분이 걸렸고, 그동안 요청 실패는 0건이었습니다. 문제는 노드에서 나왔습니다. 이제 노드를 롤링하면 nginx 대신 Gateway 파드가 옮겨지게 되는데, Gateway의 종료 처리는 아직 한 번도 재본 적이 없었습니다. 그래서 운영으로 넘어가기 전에 개발 Gateway를 재시작하면서 먼저 측정해봤습니다. 짧은 실패도 놓치지 않으려고 이때부터는 요청을 더 촘촘하게 보냈습니다.&lt;/p>
&lt;h3>개발 Gateway 롤아웃 전략&lt;span class="hx:absolute hx:-mt-20" id="개발-gateway-롤아웃-전략">&lt;/span>
&lt;a href="#%ea%b0%9c%eb%b0%9c-gateway-%eb%a1%a4%ec%95%84%ec%9b%83-%ec%a0%84%eb%9e%b5" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>첫 재시작은 아예 롤아웃이 끝나지 않았습니다. 개발 노드는 2대인데, Gateway 파드 2개를 서로 다른 노드에 두도록 필수 anti-affinity를 걸어둔 상태였습니다. 그런데 기본 롤링 전략은 새 파드를 먼저 하나 띄우고 기존 파드를 내리는 방식이라, 새 파드가 들어갈 노드가 없어서 Pending 상태로 남아 있었던 거죠. 기존 파드 2개가 계속 요청을 받고 있어서 실패는 없었지만, 개발 Gateway는 기존 파드를 먼저 하나 내리고 새 파드를 띄우도록(&lt;code>maxSurge: 0&lt;/code>) 바꿨습니다.&lt;/p>
&lt;h3>NLB 헬스체크와 파드 Ready 시점&lt;span class="hx:absolute hx:-mt-20" id="nlb-헬스체크와-파드-ready-시점">&lt;/span>
&lt;a href="#nlb-%ed%97%ac%ec%8a%a4%ec%b2%b4%ed%81%ac%ec%99%80-%ed%8c%8c%eb%93%9c-ready-%ec%8b%9c%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>전략을 고친 뒤 다시 롤아웃을 해보니, 이번에는 459건 중 12건이 실패했습니다. 원인을 찾아보니 두 가지였습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant D as Deployment
participant N as 새 Gateway 파드
participant L as NLB
participant O as 기존 Gateway 파드
D-&amp;gt;&amp;gt;N: 생성
N-&amp;gt;&amp;gt;D: 컨테이너 준비 완료(Ready)
D-&amp;gt;&amp;gt;O: 종료
Note over L: 헬스체크 10초 x 3회 통과 전&amp;lt;br/&amp;gt;새 파드는 아직 대상이 아님
L--xO: 종료되는 파드로 계속 전달
&lt;/pre>&lt;p>첫 번째, 쿠버네티스가 보는 Ready와 NLB가 보는 healthy가 서로 달랐습니다. NLB는 새 대상을 10초 간격 헬스체크를 3번 통과해야 정상으로 보는데, 쿠버네티스는 그보다 먼저 새 파드를 Ready로 보고 기존 파드를 내려버렸습니다. 두 번째, 기존 파드가 NLB 대상에서 빠진 뒤에도 NLB는 한동안 그 파드로 새 연결을 계속 보냈습니다. nginx 때 봤던 엔드포인트 반영 지연과 같은 종류의 문제가 NLB에서도 있었던 겁니다.&lt;/p>
&lt;p>첫 번째 문제는 AWS Load Balancer Controller의 pod readiness gate로 해결했습니다.&lt;/p>
&lt;blockquote>
&lt;p>pod readiness gate란?
파드가 Ready가 되기 위한 조건을 하나 더 추가하는 기능입니다. AWS Load Balancer Controller의 readiness gate를 켜면, 파드는 컨테이너가 준비된 것만으로는 Ready가 되지 않고 NLB 대상으로 등록돼 헬스체크를 통과해야 Ready가 됩니다. 네임스페이스에 레이블만 붙이면 그 안의 파드에 자동으로 적용됩니다.&lt;/p>
&lt;/blockquote>
&lt;p>이렇게 하면 롤아웃과 PDB가 쿠버네티스 기준이 아니라 NLB 기준으로 기다리게 됩니다. 두 번째 문제는 Envoy가 종료 신호를 받은 뒤에도 연결을 계속 받도록 &lt;code>terminationDrainDuration&lt;/code>을 30초로 늘려서 대응했습니다. 그리고 다시 재시작해보니 519건 중 0건이었습니다.&lt;/p>
&lt;h3>운영 노드 롤링 결과&lt;span class="hx:absolute hx:-mt-20" id="운영-노드-롤링-결과">&lt;/span>
&lt;a href="#%ec%9a%b4%ec%98%81-%eb%85%b8%eb%93%9c-%eb%a1%a4%eb%a7%81-%ea%b2%b0%ea%b3%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>운영 Gateway에도 같은 설정을 넣고 운영 노드를 1.36으로 롤링했습니다. 그런데 이번엔 1,841건 중 13건 실패가 발생하게 됐습니다. 그래서 실패 시각을 쿠버네티스 이벤트와 하나씩 맞춰봤습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>실패&lt;/th>
&lt;th>건수&lt;/th>
&lt;th>원인&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Gateway 파드 종료 35~43초 뒤&lt;/td>
&lt;td>6&lt;/td>
&lt;td>NLB가 30초가 지난 뒤에도 종료된 파드로 연결을 보냄. 30초 drain으로는 부족&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>LBC 리더 파드가 옮겨지는 동안&lt;/td>
&lt;td>6&lt;/td>
&lt;td>같은 노드에 있던 컨트롤러 리더가 옮겨지면서, 새 리더가 정해질 때까지 20초 동안 NLB 대상 해제가 멈춤&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>앱 파드 종료&lt;/td>
&lt;td>1&lt;/td>
&lt;td>1.35 때 봤던 앱 쪽 엔드포인트 반영 지연&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>개발에서 0건이었으니 운영에서도 0건일 거라고 생각했는데, 운영 노드 drain에는 개발에서는 없던 조건이 있었습니다. NLB 대상을 관리하는 컨트롤러 자신도 노드와 함께 옮겨진다는 점이었죠.&lt;/p>
&lt;p>그래서 Envoy drain을 90초로 늘려 NLB 대상 해제 지연과 리더 교체 시간을 함께 덮도록 했고, 앱 파드에는 종료 전에 15초를 기다리는 &lt;code>preStop&lt;/code>을 넣었습니다. 1.35 때 앱 경로에서 봤던 503도 같은 엔드포인트 반영 지연 때문이었는데, 그때 미뤄뒀던 설정을 이번에 함께 넣은 겁니다. 이 설정들을 운영에 반영하는 동안에는 573건 중 실패가 0건이었습니다.&lt;/p>
&lt;h2>1.37 버전업 결과&lt;span class="hx:absolute hx:-mt-20" id="137-버전업-결과">&lt;/span>
&lt;a href="#137-%eb%b2%84%ec%a0%84%ec%97%85-%ea%b2%b0%ea%b3%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>단계&lt;/th>
&lt;th>소요&lt;/th>
&lt;th>외부 요청 실패&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>컨트롤 플레인 1.36 → 1.37&lt;/td>
&lt;td>약 8분&lt;/td>
&lt;td>756건 중 0건&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>개발 노드그룹&lt;/td>
&lt;td>10분 31초&lt;/td>
&lt;td>개발 API 약 4분 중단(개발 앱이 파드 1개, 사용자가 없는 환경이라 허용)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>운영 노드그룹&lt;/td>
&lt;td>약 16분&lt;/td>
&lt;td>2,405건 중 6건&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Gateway 경로에서의 실패는 0건이 됐습니다. 남은 6건은 7초 안에 몰려 있었는데, Gateway 접근 로그에 남은 요청은 응답을 기다리던 클라이언트가 먼저 연결을 끊은 것으로 찍혀 있었고, 같은 시각 앱 로그에는 캐시 서버 재연결 실패가 찍혀 있었습니다. spot 노드가 비워지면서 캐시 서버 파드가 옮겨졌고, 그동안 앱이 재연결을 기다리느라 응답이 3초를 넘긴 거였습니다.&lt;/p>
&lt;p>캐시는 멈춰도 DB에서 읽으면 되니까 짧은 중단은 괜찮다고 봤는데, 실제로는 재연결을 기다리는 몇 초 동안 응답 자체가 늦어졌습니다. 캐시가 멈춰도 되는지는 캐시를 쓸 수 없을 때 앱이 얼마나 빨리 포기하는지까지 봐야 판단할 수 있는 것 같습니다. 캐시 서버 쪽 설정과 앱의 타임아웃은 다음 작업으로 남겨뒀습니다.&lt;/p>
&lt;p>1.36과 1.37 운영 노드 롤링을 분 단위로 나란히 놓고 보면 이렇습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/icvfxguff5wzexrb5vgrm/eks-upgrade-node-rollout-failures.ko.png?rlkey=aqe4wx8den0gae8saq13f233b&amp;amp;raw=1" alt="1.36과 1.37 운영 노드 롤링 중 분당 실패 요청 수. 1.36은 5~9분 사이 앱 파드 종료, Gateway 파드 종료, LBC 리더 이동으로 13건, 1.37은 8분에 캐시 서버 파드 이동으로 6건" loading="lazy" />&lt;/p>
&lt;p>참고로 롤링이 다 끝나고 아무 작업도 하지 않던 시간에도 같은 방식으로 재보니 2,082건 중 3건이 3초 타임아웃으로 찍혔습니다. 측정하는 경로 자체에도 이 정도의 잡음이 있다는 뜻이라, 위 표의 숫자도 이 정도 오차는 감안해서 봐주시면 감사할 것 같습니다.&lt;/p>
&lt;p>이렇게 컨트롤 플레인과 노드가 모두 1.37 버전이 됐습니다. 1.37 버전의 표준 지원은 2027년 12월 1일까지입니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/oz9ey2r2a1o9zzf35ttts/eks-upgrade-eks-console-cluster-1.37.png?rlkey=nif6isskkqsmkyjb5joscqlkz&amp;amp;raw=1" alt="EKS 콘솔의 클러스터 목록. 쿠버네티스 버전 1.37, 2027년 12월 1일까지 표준 지원" loading="lazy" />&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/cs9yjqxdlwx3dirikn6k0/eks-upgrade-eks-console-nodegroups-1.37.png?rlkey=hzdgzbvl5zsl9y7qxtcotoy0z&amp;amp;raw=1" alt="EKS 콘솔의 노드그룹 목록. dev, on-demand, spot 세 노드그룹 모두 AMI 1.37.1" loading="lazy" />&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/ix3chg975hbagalgiink4/eks-upgrade-kubectl-nodes-1.37.png?rlkey=qjkmz2xnfn86ix1t00h1kmava&amp;amp;raw=1" alt="kubectl로 확인한 서버 버전 v1.37.1과 노드 6대의 kubelet 버전 v1.37.1" loading="lazy" />&lt;/p>
&lt;p>&lt;em>EKS 콘솔과 kubectl로 확인한 최종 상태. 컨트롤 플레인과 노드그룹 3개, 노드 6대가 모두 1.37입니다.&lt;/em>&lt;/p>
&lt;h2>마치며&lt;span class="hx:absolute hx:-mt-20" id="마치며">&lt;/span>
&lt;a href="#%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이번 작업에서 가장 오래 그리고 중요하게 확인한 부분은 파드가 준비되고 죽는 시점의 차이였습니다. 컨테이너가 준비된 시점, 엔드포인트에서 빠진 시점, NLB가 정상으로 본 시점이 모두 달랐고, 그 차이마다 요청이 몇 건씩 실패하게 됐죠. 문서로 읽었을 때는 이해했다고 생각했는데, 직접 요청을 보내 측정하기 전까지는 어느 지점에서 어떤 순간에 요청이 실패하게 되는지 알 수 없었습니다.&lt;/p>
&lt;p>그리고 이번에 처음으로 직접 설치한 컴포넌트들의 지원 범위를 정리해본 것 같습니다. 실제로 다음 버전업을 막은 건 이 부분이였기 때문에, 다음 버전업 전에는 이 목록부터 다시 확인할 생각입니다.&lt;/p>
&lt;p>개발 환경은 노드를 옮길 때마다 몇 분씩 다운타임이 발생했습니다. 파드가 하나뿐이라 생긴 일이고 이번에는 감수 하고 진행했지만, 계속 이대로 두는 게 맞는지는 아직 고민 중입니다.&lt;/p>
&lt;p>비슷한 버전업이나 인그레스 이관을 앞두고 계신 분들께 조금이나마 도움이 되셨기를 바라며 이만 글을 마치겠습니다. 긴글 읽어주셔서 감사합니다.&lt;/p>
&lt;hr>
&lt;h3>Reference&lt;span class="hx:absolute hx:-mt-20" id="reference">&lt;/span>
&lt;a href="#reference" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://docs.aws.amazon.com/eks/latest/userguide/update-managed-node-group.html"target="_blank" rel="noopener">Amazon EKS: Update a managed node group&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://docs.aws.amazon.com/eks/latest/userguide/managed-node-groups.html"target="_blank" rel="noopener">Amazon EKS managed node groups (Spot capacity rebalancing)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://kubernetes.io/releases/version-skew-policy/"target="_blank" rel="noopener">Kubernetes Version Skew Policy&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://kubernetes.io/docs/concepts/workloads/pods/disruptions/"target="_blank" rel="noopener">Kubernetes: Pod Disruption Budgets&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination"target="_blank" rel="noopener">Kubernetes: Termination of Pods&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://kubernetes.github.io/ingress-nginx/user-guide/cli-arguments/"target="_blank" rel="noopener">ingress-nginx command line arguments&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://kubernetes.io/blog/2025/11/11/ingress-Nginx-retirement/"target="_blank" rel="noopener">Ingress NGINX Retirement: What You Need to Know&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://gateway-api.sigs.k8s.io/api-types/httproute/"target="_blank" rel="noopener">Gateway API: HTTPRoute&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://istio.io/latest/docs/tasks/traffic-management/ingress/gateway-api/"target="_blank" rel="noopener">Istio: Kubernetes Gateway API&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://istio.io/latest/docs/reference/config/istio.mesh.v1alpha1/#ProxyConfig"target="_blank" rel="noopener">Istio ProxyConfig: terminationDrainDuration&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/deploy/pod_readiness_gate/"target="_blank" rel="noopener">AWS Load Balancer Controller: Pod readiness gate&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://argo-cd.readthedocs.io/en/stable/operator-manual/upgrading/2.14-3.0/"target="_blank" rel="noopener">Argo CD upgrading 2.14 to 3.0&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://argo-cd.readthedocs.io/en/stable/operator-manual/tested-kubernetes-versions/"target="_blank" rel="noopener">Argo CD tested Kubernetes versions&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/aws/aws-node-termination-handler"target="_blank" rel="noopener">AWS Node Termination Handler&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>[EKS 업그레이드 1/2편] 표준 지원이 끝난 EKS와 MySQL, 연장 지원 요금을 멈추기까지</title><link>https://jeongil.dev/ko/blog/infrastructure/eks-mysql-end-of-standard-support-upgrade/</link><pubDate>Wed, 14 Oct 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/infrastructure/eks-mysql-end-of-standard-support-upgrade/</guid><description>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/gqf0ppjb39xbnxkxl0ri0/eks-upgrade-cover-part1.png?rlkey=sq0q0xrm8w37nnqlwptylv5fk&amp;amp;raw=1" alt="EKS 업그레이드 1/2편 표지" loading="lazy" />&lt;/p>
&lt;p>안녕하세요. 프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 정정일입니다.&lt;/p>
&lt;p>이번엔 지난 9월, AWS 표준 지원 기간이 끝난 EKS 1.33 클러스터와 RDS MySQL 8.0을 버전업한 이야기를 해볼까 합니다. 미리 계획해서 하게 된 작업은 아니고 지원 종료 일정을 미리 챙기지 못해 8월 서버 비용 금액이 예상보다 많이 나오게 됐고 그로 인해 부랴부랴 준비해서 작업하게 된 내용을 담고 있습니다.&lt;/p>
&lt;p>그래서 이 글도 제가 이 작업을 시작하게 된 계기인 AWS Billing에서부터 출발해볼까 합니다. 서버 비용 상승의 원인을 어떻게 찾았는지, 버전이 올라가면 무엇이 바뀌는지, 그리고 저는 어떤 식으로 작업했는지 다뤄보도록 하겠습니다.&lt;/p>
&lt;p>다만 시작하기에 앞서 저는 인프라를 전문으로 하는 사람은 아니고, 지금 회사에서 백엔드와 인프라를 함께 맡고 있습니다. 이게 정답이라고 공유하는 글이라기보단 문제를 만나서 탐색하고 저희 상황에 맞게 판단한 과정을 기록으로 남겼다는 점에 중점을 두고 봐주시면 감사하겠습니다.&lt;/p>
&lt;h2>8월 AWS 비용 증가&lt;span class="hx:absolute hx:-mt-20" id="8월-aws-비용-증가">&lt;/span>
&lt;a href="#8%ec%9b%94-aws-%eb%b9%84%ec%9a%a9-%ec%a6%9d%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>9월 초에 회사 재무 담당자분께서 8월 AWS 비용과 관련해 저희 팀에 문의를 주셨습니다. 평소보다 요금이 많이 부과됐는데 원인을 공유해줄 수 있냐는 문의였죠. 바로 비용을 확인해보니 서버 비용이 이전 몇 달간의 평균 금액보다 두 배 가까이 부과되어 있었습니다.&lt;/p>
&lt;p>처음 보자마자 어라? 싶었습니다. 8월에 서버 리소스를 증량하거나 서비스를 추가하거나 하지 않은 상태였거든요. 트래픽이 엄청나게 늘어났다거나 하지도 않았기 때문에 다른 부분을 살펴봐야겠다 싶었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>서비스 7월 대비 8월
Amazon RDS &amp;#43;$534.89
Amazon EKS &amp;#43;$334.80
Tax (위 두 항목만큼 증가)
EC2 - Compute 소폭 감소
그 외(CloudWatch, S3, ELB, VPC ...) 변동 없음&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>세부적으로 살펴보니 EC2는 오히려 비용이 소폭 줄었고 늘어난 건 RDS와 EKS뿐이었습니다. 인스턴스를 추가한 적도 없고 노드 수도 그대로였기 때문에, 사용량 때문에 생긴 비용은 아니라고 봤습니다.&lt;/p>
&lt;h2>연장 지원 요금&lt;span class="hx:absolute hx:-mt-20" id="연장-지원-요금">&lt;/span>
&lt;a href="#%ec%97%b0%ec%9e%a5-%ec%a7%80%ec%9b%90-%ec%9a%94%ea%b8%88" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>사용량 유형(Usage Type)까지 내려가 보니 이전에 보지 못한 항목들이 바로 보이더라고요.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>APN2-ExtendedSupport:Yr1-Yr2:MySQL8.0 $534.24
APN2-AmazonEKS-Hours:extendedSupport $371.00&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>항목 이름에 ExtendedSupport가 붙어 있었고, 일별로 다시 조회해보니 각 버전의 표준 지원 종료일 다음 날부터 매일 같은 금액이 찍히고 있었습니다. 저희가 사용하는 서비스의 특정 버전의 표준 지원 기간이 종료돼 발생한 금액이었던 거죠.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/6zfavxrdlsn1uf59419dc/eks-upgrade-cost-explorer-extended-support.png?rlkey=2wcxkmubw9lpznuteqeuxowfb&amp;amp;raw=1" alt="Cost Explorer에서 사용량 유형별로 본 일별 연장 지원 요금. 7월 29일부터 EKS, 8월 1일부터 MySQL 요금이 매일 같은 금액으로 붙다가 9월 2일 이후 사라짐" loading="lazy" />&lt;/p>
&lt;p>&lt;em>Cost Explorer에서 사용량 유형별로 나눠 본 일별 요금. 매일 같은 높이의 막대가 특정 날짜부터 시작됩니다.&lt;/em>&lt;/p>
&lt;p>저희 서비스 구성이 바뀐 건 없는데, 쓰던 버전의 표준 지원이 끝나면서 AWS가 자동으로 연장 지원으로 넘긴 것이었습니다.&lt;/p>
&lt;blockquote>
&lt;p>AWS 표준 지원이란?
EKS나 RDS처럼 오픈소스(쿠버네티스, MySQL 등)를 AWS가 관리형으로 제공하는 서비스에는 버전마다 지원 기간이 정해져 있습니다. 표준 지원(Standard Support) 기간에는 AWS가 해당 버전에 보안 패치와 버그 수정을 제공하고, 추가 요금 없이 평소 요금으로 쓸 수 있습니다. 이 기간이 끝나면 연장 지원(Extended Support)으로 넘어가는데, 연장 지원 기간에도 보안 패치는 계속 제공되지만 업그레이드할 시간을 더 주는 대가로 추가 요금이 붙습니다. 연장 지원까지 끝나면 AWS가 지원되는 버전으로 자동 업그레이드합니다.&lt;/p>
&lt;/blockquote>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/f0rxdp8elfy99g44z4zm8/eks-upgrade-eks-release-calendar.png?rlkey=98bav2nysz3o1548w1t3bu0ro&amp;amp;raw=1" alt="AWS 문서의 EKS 쿠버네티스 버전 릴리스 캘린더. 1.33의 표준 지원 종료일은 2026년 7월 29일, 1.35는 2027년 3월 27일" loading="lazy" />&lt;/p>
&lt;p>&lt;em>AWS 문서의 &lt;a href="https://docs.aws.amazon.com/eks/latest/userguide/kubernetes-versions.html#kubernetes-release-calendar"target="_blank" rel="noopener">EKS 버전 릴리스 캘린더&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>. 저희가 쓰던 1.33의 표준 지원은 2026년 7월 29일에 끝났습니다.&lt;/em>&lt;/p>
&lt;p>AWS는 표준 지원 종료 전에 안내를 발송해 주는데, 저희 계정에도 안내 메일은 와 있었습니다. 다만 AWS 계정 연락처로 등록된 메일 계정을 당시에는 제가 확인할 수 없었습니다. 이 메일 계정이 담당자가 바뀌는 과정에서 매끄럽게 인수인계가 되지 않았고, 인프라를 혼자 맡다 보니 그 계정을 누가 보고 있는지 확인하는 일이 뒤로 밀려 있었습니다. 돌아보면 제가 챙기지 못한 부분이 있다는 걸 깨달아 마음이 무거웠습니다. 지금은 해당 계정을 넘겨받아 제가 직접 관리하고 있습니다.&lt;/p>
&lt;h3>EKS 요금의 기준&lt;span class="hx:absolute hx:-mt-20" id="eks-요금의-기준">&lt;/span>
&lt;a href="#eks-%ec%9a%94%ea%b8%88%ec%9d%98-%ea%b8%b0%ec%a4%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>EKS는 클러스터당 시간 단위로 과금됩니다. 표준 지원 버전이면 시간당 $0.10, 연장 지원 버전이면 $0.60입니다. 하루로 치면 $0.50 × 24시간 = $12가 추가되고, 저희 비용 관리에서 확인했을 때 APN2-AmazonEKS-Hours:extendedSupport가 일별로 찍힌 금액이 해당 금액이었죠.&lt;/p>
&lt;p>그렇다면 결국 이 요금을 다시금 기존에 내던 요금으로 줄이기 위해선 AWS에서 표준 지원해주는 버전으로 EKS를 버전업할 필요가 있었고, 최대한 빨리 진행하기로 했습니다.&lt;/p>
&lt;p>그 후 업그레이드 절차와 리스크를 조사하고 어떤 작업들을 해야 할지 정리하는 과정을 거치게 됐습니다. 클러스터에는 컨트롤 플레인과 노드그룹이 존재하는데, EKS 내부의 모든 노드그룹과 컨트롤 플레인이 제가 EKS를 구성하던 당시의 표준 지원 버전인 1.33으로 구성돼 있었습니다. 노드그룹까지 올리려면 노드를 전부 새 버전으로 교체해야 하고, 그 과정에서 노드 위의 모든 파드가 다른 노드로 옮겨지게 됩니다. 그래서 서비스 영향도가 클 수 있겠다 싶었습니다.&lt;/p>
&lt;p>그러나 EKS 요금 문서와 버전 지원 정책 문서를 읽으면서 한 가지 중요한 점을 알게 됐습니다. EKS의 연장 지원 요금은 클러스터, 즉 컨트롤 플레인의 버전을 기준으로 산정된다는 점이었습니다. 노드가 어느 버전인지는 요금에 영향이 없었습니다. 이 부분이 작업 규모와 순서를 정하는 큰 기준이 됐습니다.&lt;/p>
&lt;p>RDS는 인스턴스 vCPU 수만큼 과금되고 최소 2 vCPU로 계산됩니다. 8.0 인스턴스 3대 × 2 vCPU × 24시간 × $0.12 = 하루 $17.28이었습니다. 계산하다 보니 가장 작은 개발용 DB는 인스턴스 요금보다 연장 지원 요금을 4.7배 더 내고 있었습니다. 꽤 큰 금액이었죠.&lt;/p>
&lt;p>둘을 합치면 월 약 $905(세전)였고, RDS는 3년 차부터 단가가 두 배로 오릅니다. 미룰수록 비싸지고 요금은 더 나가니 최대한 빠르게 바로 정리하기로 했습니다.&lt;/p>
&lt;h2>업그레이드 범위와 순서&lt;span class="hx:absolute hx:-mt-20" id="업그레이드-범위와-순서">&lt;/span>
&lt;a href="#%ec%97%85%ea%b7%b8%eb%a0%88%ec%9d%b4%eb%93%9c-%eb%b2%94%ec%9c%84%ec%99%80-%ec%88%9c%ec%84%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>목표 버전&lt;span class="hx:absolute hx:-mt-20" id="목표-버전">&lt;/span>
&lt;a href="#%eb%aa%a9%ed%91%9c-%eb%b2%84%ec%a0%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그럼 이제 어디까지 버전을 올려야 하는가가 그다음 고민이었는데 EKS 1.34의 표준 지원도 2026년 12월에 끝나기 때문에, 1.34까지만 버전업을 하면 몇 달 뒤 같은 일을 다시 겪게 될 걸로 판단됐습니다. 그래서 1.35(표준 지원 2027년 3월 27일까지)까지 올리기로 결정했습니다.&lt;/p>
&lt;p>다만 EKS는 마이너 버전을 한 번에 하나씩만 올릴 수 있습니다. 1.33에서 바로 1.35로 가지 못하고 1.33 → 1.34 → 1.35 이런 식으로 단계적인 버전업이 필요하죠.&lt;/p>
&lt;p>그렇다면 버전에 따른 어떤 변경점들이 있는지 검토해야 했습니다. 쿠버네티스는 버전이 올라가면서 오래된 API를 제거하기도 하고, 기본값이나 동작 방식이 바뀌기도 하고, 노드에서 쓰는 cgroup이나 컨테이너 런타임 같은 구성 요소의 지원을 끝내기도 합니다. 1.33에서 문제없이 쓰던 리소스나 설정이 바뀐 버전에서는 거부되거나 다르게 동작할 수 있다는 뜻입니다. 그렇기에 1.34 버전과 1.35 버전의 변경점을 컨트롤 플레인 쪽과 노드 쪽으로 나눠서 검토했습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>버전&lt;/th>
&lt;th>컨트롤 플레인 / API 쪽&lt;/th>
&lt;th>노드 쪽&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>1.34&lt;/td>
&lt;td>DRA GA, 캐시 기반 일관된 읽기 GA&lt;/td>
&lt;td>cgroup 드라이버 자동 감지 GA&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>1.35&lt;/td>
&lt;td>Job &lt;code>managedBy&lt;/code> GA, SPDY → WebSocket 전환 GA&lt;/td>
&lt;td>cgroup v1 지원 제거, kube-proxy IPVS 모드 deprecated, containerd 1.x를 지원하는 마지막 버전&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>컨트롤 플레인 쪽에서 제일 걱정한 건 저희가 쓰고 있는 API가 새 버전에서 제거되는 경우였습니다. 위에서 언급했듯 쿠버네티스는 버전이 올라가면서 오래된 API를 하나씩 없애는데, 그런 API를 쓰고 있으면 업그레이드 뒤에 배포가 깨지게 될 가능성이 있었습니다. API 서버는 deprecated API가 호출될 때마다 &lt;code>apiserver_requested_deprecated_apis&lt;/code>라는 메트릭에 기록을 남기는데 이걸로 확인해보니 잡힌 건 &lt;code>core/v1 endpoints&lt;/code> 하나였고, 제거 예정이 없는 API라 컨트롤 플레인 쪽은 제거되는 API 측면에서는 문제가 없었습니다.&lt;/p>
&lt;p>노드 쪽은 조금 달랐습니다. 1.35에서는 cgroup v1을 쓰는 노드에서 kubelet이 기본 설정으로 뜨지 않고, kube-proxy의 IPVS 모드가 deprecated되며, containerd 1.x를 지원하는 마지막 버전이 됩니다. 노드의 OS 설정이나 런타임에 따라 노드 자체가 뜨지 않거나 네트워크 동작이 달라질 수 있는 변경들이라, 노드를 올릴 때는 저희 노드가 각각 어떤 상태인지 먼저 확인해야 했습니다.&lt;/p>
&lt;h3>in-place 방식을 고른 이유&lt;span class="hx:absolute hx:-mt-20" id="in-place-방식을-고른-이유">&lt;/span>
&lt;a href="#in-place-%eb%b0%a9%ec%8b%9d%ec%9d%84-%ea%b3%a0%eb%a5%b8-%ec%9d%b4%ec%9c%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>변경점을 검토한 다음에는 어떤 방식으로 올릴지 정해야 했습니다. EKS 업그레이드 사례를 찾아보면 새 버전으로 클러스터를 하나 더 만들고 트래픽을 옮기는 Blue-Green 방식이 많았습니다. 해당 방식은 문제가 생기면 기존 클러스터로 트래픽을 되돌리면 되고, 1.33에서 1.35로 바로 건너뛸 수도 있다는 장점이 있습니다.&lt;/p>
&lt;p>하지만 저희 상황에서는 비용이 컸습니다. 저희는 개발과 운영 환경이 한 클러스터 안에 네임스페이스와 노드그룹으로 나뉘어 있어서, 새 클러스터로 가려면 둘을 함께 옮겨야 했습니다. 애플리케이션뿐 아니라 캐시, 검색 엔진, 모니터링처럼 EBS 볼륨에 데이터를 두는 서비스도 데이터를 옮겨야 하고, 외부 트래픽을 받는 로드밸런서와 DNS도 모두 새 클러스터로 바꿔야 했습니다. 그동안에는 컨트롤 플레인과 노드 비용이 두 벌로 나가고, 연장 지원 요금도 계속 붙게 되죠. 이 작업을 혼자 진행하면서 두 클러스터의 설정을 맞춰 가는 기간이 길어질수록 실수할 여지도 커진다고 생각했습니다. 그래서 기존 클러스터를 그대로 올리는 in-place 방식을 택하게 되었습니다.&lt;/p>
&lt;h3>노드 롤링을 막던 설정&lt;span class="hx:absolute hx:-mt-20" id="노드-롤링을-막던-설정">&lt;/span>
&lt;a href="#%eb%85%b8%eb%93%9c-%eb%a1%a4%eb%a7%81%ec%9d%84-%eb%a7%89%eb%8d%98-%ec%84%a4%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>in-place로 정한 뒤에는 앞에서 걱정했던 서비스 영향도를 확인해야 했습니다. EKS 문서가 권장하는 순서는 먼저 컨트롤 플레인 버전을 올리고, 노드도 같은 버전으로 맞춘 뒤 다음 버전으로 넘어가는 방식이죠. 노드를 새 버전으로 맞추려면 새 노드를 띄우고 기존 노드에 있던 파드를 하나씩 옮기는 롤링이 필요한데, 이 과정에서 서비스가 무중단 상태를 유지하고 정상적으로 요청을 처리할 수 있는 상태인지 클러스터를 먼저 점검해봤습니다.&lt;/p>
&lt;p>여기서 검토해야 하는 게 PDB(PodDisruptionBudget)였습니다. PDB는 노드를 비울 때 &amp;ldquo;이 서비스의 파드는 최소 몇 개는 살아 있어야 한다&amp;quot;는 조건을 거는 설정입니다. 노드를 비우는 쪽은 이 조건을 어기지 않는 선에서만 파드를 내보낼 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>NAME MIN AVAILABLE ALLOWED DISRUPTIONS
service-a-pdb 1 0
service-b-pdb 1 0
service-c-pdb 1 0&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>세 서비스 모두 파드가 1개인데 &lt;code>minAvailable: 1&lt;/code>, 즉 &amp;ldquo;최소 1개는 살아 있어야 한다&amp;quot;로 걸려 있었습니다. 파드가 하나뿐이니 내보낼 수 있는 파드가 0개가 되고, 사실상 &amp;ldquo;절대 내리지 마라&amp;quot;와 같은 설정이었죠. 이대로 노드그룹을 업데이트하면 이 파드들을 옮기지 못해 &lt;code>PodEvictionFailure&lt;/code>로 실패하게 됩니다. 게다가 외부 트래픽을 받는 인그레스 컨트롤러도 파드 하나에 PDB조차 없어서, 그 파드가 있는 노드가 비워지는 순간 외부 트래픽이 전부 끊기는 상태였습니다.&lt;/p>
&lt;p>고칠 수 있는 문제였지만 바로 고칠 수는 없었습니다. 가장 쉬운 방법은 파드를 2개로 늘리는 것인데, 세 서비스 중에는 중복 처리를 막기 위해 한 번에 하나만 떠 있어야 하는 서비스도 있어서 서비스마다 다른 방법을 정해야 했습니다. 인그레스 컨트롤러도 파드를 늘리는 것만으로는 부족하고, 두 파드가 같은 노드에 뜨지 않게 배치를 정하고 실제로 끊김 없이 넘어가는지 확인까지 해야 했습니다. 그동안에도 연장 지원 요금은 하루에 약 $29씩 나가고 있었습니다.&lt;/p>
&lt;p>그래서 앞에서 읽은 요금 기준을 다시 떠올리게 됐습니다. 요금이 컨트롤 플레인 버전 기준이라면, 노드는 잠시 그대로 두고 컨트롤 플레인만 버전을 올려도 되는지를 확인했습니다. 쿠버네티스에는 버전 차이(skew) 정책이 있는데, 노드에서 도는 kubelet은 컨트롤 플레인의 kube-apiserver보다 마이너 버전이 3개까지 낮아도 허용해줍니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>컨트롤 플레인&lt;/th>
&lt;th>노드(kubelet)&lt;/th>
&lt;th>버전 차이&lt;/th>
&lt;th>&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>1.34&lt;/td>
&lt;td>1.33&lt;/td>
&lt;td>1&lt;/td>
&lt;td>허용&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>1.35&lt;/td>
&lt;td>1.33&lt;/td>
&lt;td>2&lt;/td>
&lt;td>허용&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>1.36&lt;/td>
&lt;td>1.33&lt;/td>
&lt;td>3&lt;/td>
&lt;td>허용되지만 여기서 더는 못 올림&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3>컨트롤 플레인만 먼저 올린 이유&lt;span class="hx:absolute hx:-mt-20" id="컨트롤-플레인만-먼저-올린-이유">&lt;/span>
&lt;a href="#%ec%bb%a8%ed%8a%b8%eb%a1%a4-%ed%94%8c%eb%a0%88%ec%9d%b8%eb%a7%8c-%eb%a8%bc%ec%a0%80-%ec%98%ac%eb%a6%b0-%ec%9d%b4%ec%9c%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/aqlicikbfhrgwgz1wyhhf/eks-upgrade-p1-cluster-structure.ko.png?rlkey=xb6ctzzoozp1hopy0q18zjjby&amp;amp;raw=1" alt="EKS 클러스터 구조. AWS가 관리하는 컨트롤 플레인만 1.35로 올리고, 노드그룹 dev·spot·on-demand는 kubelet 1.33을 유지. spot에는 PDB 없는 인그레스와 minAvailable 1인 서비스가 있음" loading="lazy" />&lt;/p>
&lt;p>&lt;em>컨트롤 플레인(요금 기준)만 먼저 올리고, 노드 롤링을 막던 인그레스와 PDB가 있는 노드그룹은 1.33에 남겨둔 구조&lt;/em>&lt;/p>
&lt;p>1.35까지 올려도 노드와의 차이는 2라 허용 범위 안이었습니다. 그래서 컨트롤 플레인만 1.35까지 올리고 노드는 1.33에 두기로 했습니다. 컨트롤 플레인 업그레이드는 노드를 건드리지 않아 파드가 재시작되지 않고, 요금은 기존과 동일하게 표준 지원 요금만 부과되죠. 노드는 인그레스를 이중화하고 PDB를 정리한 뒤 별도 일정으로 버전업을 진행하기로 결정했습니다.&lt;/p>
&lt;p>물론 권장 순서에서 벗어나는 만큼 리스크를 감수해야 하는 점도 있었습니다. 노드는 1.33 AMI 그대로라 그동안 나오는 OS와 커널 패치가 들어가지 않고, 버전 차이가 이미 2라서, 컨트롤 플레인을 1.36 이상으로 계속 올리려면 그 전에 노드를 먼저 올려야 했습니다. 그래도 요금을 멈추는 일과 노드 롤링처럼 서비스가 끊길 수 있는 일을 한 번에 묶는 것보다는, 둘을 나눠서 노드 롤링은 준비를 마친 뒤에 하는 쪽이 맞다고 판단했습니다.&lt;/p>
&lt;h2>컨트롤 플레인 업그레이드&lt;span class="hx:absolute hx:-mt-20" id="컨트롤-플레인-업그레이드">&lt;/span>
&lt;a href="#%ec%bb%a8%ed%8a%b8%eb%a1%a4-%ed%94%8c%eb%a0%88%ec%9d%b8-%ec%97%85%ea%b7%b8%eb%a0%88%ec%9d%b4%eb%93%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>Terraform 모듈의 노드그룹 버전 상속&lt;span class="hx:absolute hx:-mt-20" id="terraform-모듈의-노드그룹-버전-상속">&lt;/span>
&lt;a href="#terraform-%eb%aa%a8%eb%93%88%ec%9d%98-%eb%85%b8%eb%93%9c%ea%b7%b8%eb%a3%b9-%eb%b2%84%ec%a0%84-%ec%83%81%ec%86%8d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>방향이 정해졌으니 이제 작업을 할 차례였습니다. 저희는 EKS를 Terraform으로 관리하고 있어서, 클러스터 버전을 바꾸는 것도 Terraform 코드의 &lt;code>cluster_version&lt;/code> 값을 1.34로 바꾸는 것부터 시작했습니다. 그리고 plan을 보니, 컨트롤 플레인만 바뀔 줄 알았던 변경 목록에 노드그룹 3개까지 함께 1.33 → 1.34로 버전업되는 항목으로 들어가 있었습니다.&lt;/p>
&lt;p>원인은 저희가 쓰는 &lt;code>terraform-aws-modules/eks&lt;/code> 모듈(v20.37.2)의 동작이었습니다. 이 모듈은 노드그룹에 버전을 따로 지정하지 않으면 클러스터 버전을 그대로 따라가게 됩니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-hcl" data-lang="hcl">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># node_groups.tf:304
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="n">cluster_version&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">try&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">each&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">value&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">cluster_version&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">var&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">eks_managed_node_group_defaults&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">cluster_version&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">time_sleep&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">this&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="m">0&lt;/span>&lt;span class="p">].&lt;/span>&lt;span class="k">triggers&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;cluster_version&amp;#34;&lt;/span>&lt;span class="p">])&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>컨트롤 플레인만 올리겠다고 정해 놓고 plan을 대충 보고 넘겼다면, 작업하지 않으려 했던 노드 롤링이 그대로 같이 일어나 예상치 못한 일이 벌어져 당황했을 수 있을 겁니다. 그래서 노드그룹 기본값에 버전을 명시해서 고정해 줬습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-hcl" data-lang="hcl">&lt;span class="line">&lt;span class="cl">&lt;span class="n">eks_managed_node_group_defaults&lt;/span> &lt;span class="o">=&lt;/span> {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> cluster_version&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s2">&amp;#34;1.33&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">}&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>그 후 다시 plan을 보니 변경이 10개에서 7개로 줄었고, 빠진 3가지의 항목이 노드그룹이었습니다.&lt;/p>
&lt;p>plan을 보다가 하나 더 걸린 게 있었습니다. EKS와 상관없는 변경까지 같이 잡혀 있었던 겁니다. 예전에 제가 혹은 다른 개발자분이 콘솔이나 CLI로 직접 바꾼 설정들이 코드에 반영되지 않은 것들이 일부 남아 있어서, Terraform은 그걸 코드 상태로 되돌리려 했습니다. 그대로 apply했다면 운영 DB 엔진 버전을 예전 버전으로 되돌리고, 사용하고 있는 보안 그룹 규칙을 지워버렸을 겁니다. 그래서 이번 작업은 &lt;code>-target=module.eks&lt;/code> 옵션으로 EKS 모듈만 대상으로 plan 파일을 만들고, 그 파일만 apply했습니다. 코드와 실제 상태가 어긋난 부분은 따로 정리해줬습니다.&lt;/p>
&lt;p>클러스터 버전을 올릴 때는 coredns, kube-proxy, vpc-cni 같은 EKS 애드온도 새 버전에 맞게 같이 올려야 합니다. 처음에는 AWS가 버전별로 정해둔 기본 버전을 쓰면 되겠다고 생각했는데, coredns의 1.34 기본 버전이 오히려 저희가 운영 중인 버전보다 낮았습니다. 기본값을 그대로 쓰면 업그레이드가 아니라 다운그레이드가 되는 상황이었죠. 1.35에서도 마찬가지였습니다. 그 뒤로는 애드온 버전을 기본값에 맡기지 않고, 호환 목록에서 직접 골라 지정하고 있습니다.&lt;/p>
&lt;h3>업그레이드 결과&lt;span class="hx:absolute hx:-mt-20" id="업그레이드-결과">&lt;/span>
&lt;a href="#%ec%97%85%ea%b7%b8%eb%a0%88%ec%9d%b4%eb%93%9c-%ea%b2%b0%ea%b3%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>단계&lt;/th>
&lt;th>소요&lt;/th>
&lt;th>결과&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>1.33 → 1.34&lt;/td>
&lt;td>약 8분&lt;/td>
&lt;td>재시작된 파드 0개, 비정상 파드 0건, 인그레스 재시작 0회, 노드 1.33 유지&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>1.34 → 1.35&lt;/td>
&lt;td>비슷&lt;/td>
&lt;td>같은 결과&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>컨트롤 플레인이 교체되는 동안에는 API 서버로 가는 요청이 잠깐씩 실패할 수 있긴 합니다. 배포 도구인 Argo CD도 API 서버와 계속 통신하기 때문에, 그동안은 Argo CD Sync를 멈춰두고 진행했습니다.&lt;/p>
&lt;h3>&lt;code>supportType&lt;/code>의 의미&lt;span class="hx:absolute hx:-mt-20" id="supporttype의-의미">&lt;/span>
&lt;a href="#supporttype%ec%9d%98-%ec%9d%98%eb%af%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>컨트롤 플레인의 버전업이 끝난 뒤 요금이 표준 요금으로 산정됐는지 확인하는 과정에서 예상과 다른 값이 하나 있었습니다. 업그레이드 후 &lt;code>upgradePolicy.supportType&lt;/code>이 &lt;code>EXTENDED&lt;/code>에서 &lt;code>STANDARD&lt;/code>로 바뀌는지 확인했는데, 1.34로 올린 뒤에도 값이 &lt;code>EXTENDED&lt;/code> 그대로였습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/916qaas8wh6mvv6ao7xg9/eks-upgrade-term-eks-upgrade-policy.png?rlkey=khxnf95axxo4pb3saob7y57us&amp;amp;raw=1" alt="aws eks describe-cluster로 조회한 upgradePolicy. supportType이 EXTENDED" loading="lazy" />&lt;/p>
&lt;p>찾아보니 이 필드는 지금 연장 지원 중인지를 나타내는 상태값이 아니라, 표준 지원이 끝났을 때 어떻게 할지를 정하는 정책값이었습니다. &lt;code>EXTENDED&lt;/code>면 연장 지원으로 넘어가 요금을 내고, &lt;code>STANDARD&lt;/code>면 AWS가 자동으로 업그레이드하는 옵션을 표기해둔 거였죠. 그래서 요금이 멈췄는지는 이 값이 아니라 AWS Cost Explorer의 일별 금액으로 확인했습니다.&lt;/p>
&lt;p>이 설정을 그대로 두면 1.35 표준 지원이 끝나는 2027년 3월 27일에 같은 방식으로 요금이 다시 붙게 됩니다. 그렇다고 &lt;code>STANDARD&lt;/code>로 바꾸면 저희가 원하지 않는 시점에 자동으로 버전업이 일어날 수 있죠. 그래서 저는 시점을 직접 고르는 쪽이 낫다고 보고 &lt;code>EXTENDED&lt;/code>를 유지했습니다. 대신 표준 지원 기간이 종료되기 전에 작업해야 한다는 사실을 문서로 정리해두고 말이죠.&lt;/p>
&lt;h3>요금&lt;span class="hx:absolute hx:-mt-20" id="요금">&lt;/span>
&lt;a href="#%ec%9a%94%ea%b8%88" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;/th>
&lt;th>8월&lt;/th>
&lt;th>9월&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>EKS 연장 지원&lt;/td>
&lt;td>$372.00&lt;/td>
&lt;td>$13.27&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>MySQL 8.0 연장 지원&lt;/td>
&lt;td>$535.68&lt;/td>
&lt;td>$25.92&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>9월에 남은 금액은 업그레이드 전까지 며칠 동안 나간 요금이고, 10월 들어서는 일별 금액이 0원으로 유지됐습니다.&lt;/p>
&lt;h2>MySQL 8.0 → 8.4&lt;span class="hx:absolute hx:-mt-20" id="mysql-80--84">&lt;/span>
&lt;a href="#mysql-80--84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>EKS를 정리하고 나니 남은 건 RDS였습니다. 앞에서 본 것처럼 MySQL 8.0도 같은 이유로 연장 지원 요금이 붙고 있었습니다.&lt;/p>
&lt;p>목표 버전은 8.4로 정했습니다. MySQL은 8.0 이후로 출시 방식이 바뀌어서, 오래 지원하는 LTS 버전과 다음 버전이 나오면 지원이 끝나는 Innovation 버전으로 나뉩니다. Innovation 버전은 다음 버전이 나오면 버그와 보안 수정이 끊기기 때문에, 운영 DB에 쓰면 몇 달마다 메이저 업그레이드를 다시 해야 합니다. 그래서 운영 DB에는 LTS인 8.4 버전을 쓰기로 했습니다. RDS에서 8.4의 표준 지원은 2029년 7월까지라 당분간 같은 일을 겪을 걱정도 없었죠. EKS 때처럼 작업에 들어가기 전에 버전에 따른 변경점부터 검토했고, 여기서는 그중 판단을 하게 됐던 부분들만 적도록 하겠습니다.&lt;/p>
&lt;h3>&lt;code>mysql_native_password&lt;/code> 기본값&lt;span class="hx:absolute hx:-mt-20" id="mysql_native_password-기본값">&lt;/span>
&lt;a href="#mysql_native_password-%ea%b8%b0%eb%b3%b8%ea%b0%92" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>가장 걱정한 건 인증 방식이었습니다. MySQL 계정은 접속할 때 쓰는 인증 플러그인이 정해져 있는데, &lt;a href="https://dev.mysql.com/doc/refman/8.4/en/native-pluggable-authentication.html"target="_blank" rel="noopener">MySQL 8.4 공식 문서&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>를 보니 예전 방식인 &lt;code>mysql_native_password&lt;/code>가 8.4부터 기본으로 꺼진다고 되어 있었습니다. 저희 DB 계정은 해당 방식을 주로 쓰고 있어서, 문서대로라면 업그레이드하는 순간 애플리케이션이 DB에 접속하지 못하게 됐죠.&lt;/p>
&lt;p>그런데 RDS는 MySQL을 그대로 쓰는 게 아니라 기본 파라미터를 따로 관리하고 있습니다. 그래서 RDS에서도 정말 같은 기본값인지 &lt;code>mysql8.4&lt;/code> 기본 파라미터를 직접 조회해봤습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/bw7miezjtpv0979l814n1/eks-upgrade-term-rds-mysql84-auth.png?rlkey=jybjwb8l2ylaey9oh6tvrfq3r&amp;amp;raw=1" alt="aws rds describe-engine-default-parameters로 조회한 mysql8.4 기본값. mysql_native_password는 ON이고 수정 불가" loading="lazy" />&lt;/p>
&lt;p>RDS는 이 플러그인을 켜둔 채로 고정하고 있었습니다. MySQL 문서만 보고 판단했다면 필요 없는 계정 전환을 운영 DB에서 먼저 했을 수 있었죠.&lt;/p>
&lt;h3>옵션 그룹과 메이저 버전&lt;span class="hx:absolute hx:-mt-20" id="옵션-그룹과-메이저-버전">&lt;/span>
&lt;a href="#%ec%98%b5%ec%85%98-%ea%b7%b8%eb%a3%b9%ea%b3%bc-%eb%a9%94%ec%9d%b4%ec%a0%80-%eb%b2%84%ec%a0%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>RDS의 메이저 버전 업그레이드는 진행되는 동안 DB가 잠시 내려가는 걸 피할 수 없습니다. 운영 DB를 내리기 전에 절차에 빠진 게 없는지, 실제로 얼마나 내려가는지 알고 싶어서 개발 DB로 먼저 진행을 해봤습니다. 그런데 apply가 13초 만에 실패하게 됐습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>api error InvalidParameterCombination:
Current Option Group (&amp;lt;audit-option-group&amp;gt;-mysql80) is non-default.
You need to explicitly specify a new Option Group in this case (default or custom)&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>RDS에는 파라미터 그룹 말고도 옵션 그룹이라는 설정이 있습니다. 감사 로그 플러그인처럼 DB에 붙는 추가 기능을 설정하는 곳인데, 파라미터 그룹처럼 메이저 버전에 묶여 있습니다. 그래서 기본 옵션 그룹이 아닌 그룹을 쓰는 DB를 메이저 업그레이드할 때는 새 버전용 옵션 그룹을 함께 지정해야 했습니다. 이 검사는 AWS가 실제 변경 요청을 받을 때 이뤄지기 때문에, Terraform plan에서는 보이지 않고 apply에서야 실패하더라고요. 그래서 8.4용 옵션 그룹을 새로 만들고 같은 설정을 옮긴 뒤에 다시 업데이트를 진행했습니다.&lt;/p>
&lt;p>운영 DB들도 같은 옵션 그룹을 쓰고 있었기 때문에, 개발 DB에서 먼저 올려보지 않고 운영에서 처음 만났다면 공지한 작업 시간 동안 원인을 찾느라 작업 시간이 연장되거나 했을 것 같습니다.&lt;/p>
&lt;p>이럴 때마다 느끼는 거지만 작년에 개발 서버를 사전에 구성해 둔 걸 정말 잘한 것 같다는 생각이 많이 듭니다.&lt;/p>
&lt;h3>다운타임 측정&lt;span class="hx:absolute hx:-mt-20" id="다운타임-측정">&lt;/span>
&lt;a href="#%eb%8b%a4%ec%9a%b4%ed%83%80%ec%9e%84-%ec%b8%a1%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>업그레이드하면서 실제 다운타임도 재봤습니다. 개발 DB와, 같은 방식으로 먼저 올린 다른 DB 한 대입니다. RDS 이벤트에서 인스턴스가 shutdown된 시점부터 restarted된 시점까지를 다운타임으로 봤습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>대상&lt;/th>
&lt;th>데이터&lt;/th>
&lt;th>다운타임&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>개발 DB&lt;/td>
&lt;td>큰 쪽&lt;/td>
&lt;td>2분 45초&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>다른 DB&lt;/td>
&lt;td>7분의 1 정도&lt;/td>
&lt;td>2분 01초&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>데이터가 7배 가까이 작은데도 다운타임은 크게 줄지 않았습니다. 찾아보니 메이저 업그레이드는 사용자 데이터를 다시 쓰는 게 아니라 데이터 딕셔너리와 시스템 테이블을 갱신하는 작업이라 그런 것 같습니다. 덕분에 운영 DB도 2~3분 정도로 예상하고 일정을 잡을 수 있었습니다. 애플리케이션은 따로 재시작하지 않아도, 커넥션 풀(HikariCP)이 끊긴 커넥션을 버리고 새로 맺으면서 복구됐습니다.&lt;/p>
&lt;h2>남은 일&lt;span class="hx:absolute hx:-mt-20" id="남은-일">&lt;/span>
&lt;a href="#%eb%82%a8%ec%9d%80-%ec%9d%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이렇게 요금은 다시 기존 요금으로 돌아왔지만 EKS 업그레이드는 아직 절반만 끝난 상태입니다. 노드는 여전히 1.33 버전이고, 노드 AMI도 3월에 만들어진 그대로입니다. 관리형 노드그룹은 같은 쿠버네티스 버전 안에서도 AMI를 알아서 새 것으로 바꿔주지 않아서, 노드를 교체하지 않는 동안에는 OS나 커널 패치도 들어가지 않기 때문에 어찌 됐건 버전업은 꼭 진행해야 하는 상황입니다.&lt;/p>
&lt;p>그래서 다음 작업은 노드 버전업입니다. 그 전에 인그레스 컨트롤러를 이중화하고, 노드 롤링을 막던 PDB 세 개를 서비스별로 어떻게 바꿀지 정해야 하는 과정도 필요하죠. 1.35 표준 지원 종료일은 2027년 3월 27일인데, 이번처럼 종료일이 지나서야 작업하지 않도록 노드부터 먼저 정리하려고 합니다.&lt;/p>
&lt;h2>마치며&lt;span class="hx:absolute hx:-mt-20" id="마치며">&lt;/span>
&lt;a href="#%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이번 일로 버전을 올리지 않고 그대로 두는 것에도 비용이 추가로 든다는 걸 알게 됐습니다. 온프레미스였다면 오래된 버전은 언젠가 생길 보안 문제 정도로 남았을 텐데, 클라우드에서 Managed Service는 추가 과금이 발생하네요.&lt;/p>
&lt;p>작업하면서 적절한 판단을 내릴 수 있었던 근거들은 대부분 문서를 읽을 때보다 저희의 상황이나 실제 값을 조회할 때였던 것 같습니다. RDS의 인증 플러그인도 그랬고, &lt;code>supportType&lt;/code>과 Terraform plan의 노드그룹 변경도 마찬가지고요. 다음 노드 업그레이드도 같은 방식으로 잘 확인하면서 진행하려고 합니다.&lt;/p>
&lt;p>저처럼 표준 지원 기간을 놓쳐 예상치 못한 비용을 내는 일이 없으시길 바라며 읽어주셔서 감사드리고 조금이나마 도움이 되셨으면 좋겠습니다. 감사합니다.&lt;/p>
&lt;h3>Reference&lt;span class="hx:absolute hx:-mt-20" id="reference">&lt;/span>
&lt;a href="#reference" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://docs.aws.amazon.com/eks/latest/userguide/kubernetes-versions.html"target="_blank" rel="noopener">Amazon EKS Kubernetes versions lifecycle&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://docs.aws.amazon.com/eks/latest/userguide/update-cluster.html"target="_blank" rel="noopener">Update existing cluster to new Kubernetes version&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://docs.aws.amazon.com/eks/latest/userguide/view-upgrade-policy.html"target="_blank" rel="noopener">View cluster upgrade policy&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://aws.amazon.com/eks/pricing/"target="_blank" rel="noopener">Amazon EKS pricing&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://kubernetes.io/releases/version-skew-policy/"target="_blank" rel="noopener">Kubernetes Version Skew Policy&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://kubernetes.io/blog/2025/08/27/kubernetes-v1-34-release/"target="_blank" rel="noopener">Kubernetes v1.34 release&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://kubernetes.io/blog/2025/12/17/kubernetes-v1-35-release/"target="_blank" rel="noopener">Kubernetes v1.35 release&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://kubernetes.io/docs/concepts/workloads/pods/disruptions/"target="_blank" rel="noopener">Kubernetes: Pod Disruption Budgets&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/extended-support-charges.html"target="_blank" rel="noopener">Amazon RDS Extended Support charges&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://dev.mysql.com/doc/refman/8.4/en/native-pluggable-authentication.html"target="_blank" rel="noopener">MySQL 8.4: Native Pluggable Authentication&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_UpgradeDBInstance.MySQL.Major.html"target="_blank" rel="noopener">Major version upgrades for RDS for MySQL&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>비전공자 개발자로 살아남기 (만 3년차 회고)</title><link>https://jeongil.dev/ko/blog/reflection/3-years-as-a-non-cs-startup-developer/</link><pubDate>Thu, 18 Jun 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/reflection/3-years-as-a-non-cs-startup-developer/</guid><description>
&lt;p>안녕하세요. 프롭테크 스타트업에서 백엔드 개발자로 일하고 있는 만 3년차 개발자 정정일입니다.&lt;/p>
&lt;p>비전공자로 개발을 시작해볼까 고민하는 분들을 떠올리며, 제가 어떻게 여기까지 왔는지 시간순으로 정리해봤습니다.&lt;/p>
&lt;p>&amp;lsquo;성공적인 케이스라 자랑하겠다!&amp;rsquo; 뭐 이런건 아니구요. 간절함과 운을 반쯤 섞어 그럭저럭 살아남은 기록에 가깝습니다.&lt;/p>
&lt;h2>시작&lt;span class="hx:absolute hx:-mt-20" id="시작">&lt;/span>
&lt;a href="#%ec%8b%9c%ec%9e%91" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>2018 · 영업으로 사회에 나오다&lt;span class="hx:absolute hx:-mt-20" id="2018--영업으로-사회에-나오다">&lt;/span>
&lt;a href="#2018--%ec%98%81%ec%97%85%ec%9c%bc%eb%a1%9c-%ec%82%ac%ed%9a%8c%ec%97%90-%eb%82%98%ec%98%a4%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>제 부모님은 한 가지 확고한 가치관이 있으셨습니다.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;고등학교를 졸업하면 3,000만원을 줄 테니 독립해라. 대학을 가든, 취업을 하든, 창업을 하든 하고 싶은 걸 해라.&amp;rdquo;&lt;/p>
&lt;/blockquote>
&lt;p>뚜렷한 꿈이 없던 저는 지금 대학에 가면 돈과 시간이 아깝겠다고 생각했습니다. 그래서 졸업하자마자 군대에 다녀왔고, 제대 후 바로 영업에 뛰어들었습니다. 그 때가 스물한 살이었습니다.&lt;/p>
&lt;p>영업은 약 5년을 했습니다. 그런데 영업은 실적이 매달 0으로 리셋되는 구조라 조금 회의감이 들더라구요. 한 달을 잘 채워도 다음 달이면 처음부터 다시 시작이었고, 쌓아온 게 사라지는 느낌이 들 때마다 &amp;ldquo;내가 발전하고 있는 게 맞나&amp;rdquo; 싶었습니다.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>느낀 점 —&lt;/strong> 저는 제가 성장할 수 있는 꾸준히 쌓여가는 일을 하고 싶었던 것 같습니다.&lt;/p>
&lt;/blockquote>
&lt;h3>2022.07 · 개발자가 되기로 하다&lt;span class="hx:absolute hx:-mt-20" id="202207--개발자가-되기로-하다">&lt;/span>
&lt;a href="#202207--%ea%b0%9c%eb%b0%9c%ec%9e%90%ea%b0%80-%eb%90%98%ea%b8%b0%eb%a1%9c-%ed%95%98%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>어느날 친동생이 국비지원으로 개발을 준비한다는 이야기를 듣고 처음 개발자라는 직업을 들여다보게 됐습니다. &amp;ldquo;개발자는 평생 공부해야 한다&amp;quot;는 말이, 매달 리셋되던 일을 하던 저에게는 단점이 아니라 매력으로 다가왔습니다. 며칠 고민하다 일을 그만두고 국비 학원에 등록했습니다. 이 때가 스물다섯이었습니다.&lt;/p>
&lt;p>학원은 하루 8시간, 주 5일, 6개월 과정이었습니다. 같은 교육이어도 수강하는 모습은 사람마다 갈렸습니다. 무료라 &amp;ldquo;일단 들어보자&amp;quot;는 분이 많았는데, 저는 생활비를 스스로 책임지던 터라 &amp;ldquo;이게 내가 무언가를 온전히 공부할 수 있는 마지막 기회다&amp;quot;라는 마음이 컸습니다. 제 반 20명 중 개발자가 된 사람은 서너 명이었습니다.&lt;/p>
&lt;p>제 공부법은 &lt;strong>강의로 개념을 익히고 → 작은 개인 프로젝트로 직접 만들어 보고 → 이해하게 되는&lt;/strong> 식이었습니다. 거기에 주 2~3회 스터디를 더했습니다. 강의만 보면 머리로만 아는 느낌이라, 한 번은 손으로 만들어 봐야 비로소 체득된다고 느꼈습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/23tqkp2uqaaxfhbhcfujc/play-data-1.png?rlkey=rx3wbmg7dnsux94riw8w3r5ge&amp;amp;st=2rtyv778&amp;amp;raw=1" alt="도서관리 프로젝트" loading="lazy" />&lt;/p>
&lt;p>학원에 도서관리가 수기로 되고 있어 바코드로 책 대여관리를 할 수 있는 도서 관리 프로그램을 만드는 프로젝트를 진행하거나 하는식으로 흥미롭거나 필요할거같은 프로젝트를 만들며 개념을 체득화 했었죠.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>느낀 점 —&lt;/strong> 사실 개발이 아니더라도 무언가를 할 때 간절히 원하면, 그만큼 더 빨리 배울 수 있는 것 같습니다.&lt;/p>
&lt;/blockquote>
&lt;h2>첫 회사&lt;span class="hx:absolute hx:-mt-20" id="첫-회사">&lt;/span>
&lt;a href="#%ec%b2%ab-%ed%9a%8c%ec%82%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>2023.03 · 첫 취업&lt;span class="hx:absolute hx:-mt-20" id="202303--첫-취업">&lt;/span>
&lt;a href="#202303--%ec%b2%ab-%ec%b7%a8%ec%97%85" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>2022년 12월 ~ 2023년 1월 학원을 수료하며 본격적으로 취업 준비를 시작했습니다.&lt;/p>
&lt;p>회사에는 수료 전부터 지원했지만 현실은 학원 홍보와 달랐습니다. 서류에서 숱하게 떨어졌고, 자신감이 가장 바닥이던 시기였습니다. 그래도 이력서와 포트폴리오를 다듬으며 면접을 보다 보니, 경험과 열정을 봐주는 스타트업들이 있었습니다. 그렇게 지원을 시작한지 약 2~3개월 만에 반에서 가장 먼저 취업을 하게 됐습니다.&lt;/p>
&lt;p>합격한 회사의 면접은 CTO 한 분, 개발팀장 두 분과 1시간가량 진행됐습니다. 처음에는 인적성 위주였는데 중반부터 기술 질문이 이어졌고, 꼬리질문이 깊어지면서 어느 순간 제가 답을 못 하는 지점이 왔습니다. 그때 CTO님이 &amp;ldquo;이렇게 질문과 답이 오가는 건 좋은 신호다. 그만큼 더 듣고 싶은 이야기가 많다는 뜻이다&amp;quot;라고 하셨습니다. 면접이 끝나고 나서도 그 말이 계속 생각났습니다.&lt;/p>
&lt;h3>2023 · 처음으로 크게 데인 날&lt;span class="hx:absolute hx:-mt-20" id="2023--처음으로-크게-데인-날">&lt;/span>
&lt;a href="#2023--%ec%b2%98%ec%9d%8c%ec%9c%bc%eb%a1%9c-%ed%81%ac%ea%b2%8c-%eb%8d%b0%ec%9d%b8-%eb%82%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>첫 회사는 20~30명 규모의 핀테크 스타트업이었습니다. 처음 개발자로 실무를 접하는 거다 보니 배울 게 많아 너무 즐거웠습니다. 인정을 받고 싶어 팀장님께 일을 더 달라고 요청드리기도 했죠.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/i1l836zhffib22xp4m0bq/hello-2.png?rlkey=64dxfeye07b1pipz7pnhi2ua5&amp;amp;st=x9xyrt6t&amp;amp;raw=1" alt="회사에 앉아있는 모습" loading="lazy" />&lt;/p>
&lt;p>솔직히 말씀드려서 일 자체는 제게 크게 어려운 부분이 없었습니다. 흔히 이야기하는 java, spring, json, rest api, db, ci/cd 정도를 다룰 줄 알면 충분히 해낼 수 있는 일들이었습니다. 도메인 지식의 부족함은 있었지만, 그건 시간이 지나면 해결되는 문제라고 생각했습니다. 실제로 그랬구요.&lt;/p>
&lt;p>선배 개발자분들께서 심심치 않게 농담반 진담반으로 &amp;ldquo;에이스가 들어왔네&amp;quot;라고 해주시면 그때마다 인정받는 것 같아 정말 기분이 좋았습니다.&lt;/p>
&lt;p>그러다 수습기간이 끝날때쯤 한번 크게 사고를 치게 됐습니다. 개발서버 테스트 데이터에 실제 고객 데이터가 섞인 걸 확인하지 못하고 약 600분에게 테스트 메일을 보냈고, 운영팀에 CS로 사용자 분들께서 불편을 겪으셨다는 연락이 들어왔습니다.&lt;/p>
&lt;p>CS를 받던 운영팀이 개발팀으로 &amp;ldquo;혹시 이런 메일 보낸 적 있냐&amp;quot;고 확인하러 왔을 때, 등골이 서늘하고 온몸에 식은땀이 났습니다. 그때는 정말 벌벌 떨었습니다. 내가 회사에 큰 피해를 줬구나 싶었고, 한동안은 실행 버튼을 누를 때마다 손이 멈칫했습니다.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>느낀 점 —&lt;/strong> 사고는 거창한 데서 나지 않고 늘 확인 한 번 건너뛴 자리에서 났습니다. 그 전까지 저는 인정을 받고싶은 마음에 빠르게, 많이 처리하는 데만 정신이 팔려 있었습니다.&lt;/p>
&lt;/blockquote>
&lt;p>회사를 나온 지금도 사고를 수습해주신 운영팀의 대리님과 가끔 술 한잔 하며 이때 이야기를 나누곤 하는데, 그땐 정말 제가 미우셨다고&amp;hellip; 그때마다 저는 정말 고생하셨다고 항상 감사한 마음뿐이라고 말씀드리곤 합니다. ㅎㅎ&lt;/p>
&lt;p>이후 맡는 일이 점점 늘었습니다. 입사 1년이 안 됐을 때 부사수가 생겨 후배를 가르치게 되기도 했고, 정산과 백오피스를 맡으며 서버와 DB 권한 전체를 받게 되기도 했습니다. 새 요구사항을 개발하고 사고를 수습하기를 반복하다 보니, 어느 순간 &amp;ldquo;내가 이 일을 할 줄 알게 됐구나&amp;rdquo; 싶었습니다.&lt;/p>
&lt;h3>2023.12 · DevOps를 떠안다&lt;span class="hx:absolute hx:-mt-20" id="202312--devops를-떠안다">&lt;/span>
&lt;a href="#202312--devops%eb%a5%bc-%eb%96%a0%ec%95%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>열심히 일하던 와중에 제 개발 인생에서 중요한 전환점이 된 사건이 발생하게 됩니다.&lt;/p>
&lt;p>2023년 12월 유일한 회사의 DevOps 담당자께서 더 좋은 조건으로 스카우트되어 이직하면서, 회사 서버를 온전히 아는 사람이 사라질 상황이 됐습니다. 후임을 뽑아 한 달간 인수인계를 하려 했지만 회사 사정상 채용이 어려웠고, 결국 &amp;ldquo;그럼 문서라도 남기고 가겠다&amp;quot;로 정리됐습니다.&lt;/p>
&lt;p>그런데 개발자인 제 입장에서는 여간 불안한 게 아니었습니다. 당시 회사 서버 구성을 모두 알고있던건 DevOps분께서 유일하다고 해도 과언이 아니었고, DevOps분께서 이직을 하시게 되면 회사 서버에 문제가 생겼을 때 대응할 수 있는 사람이 아무도 없는 상황이 오게 되는 거였죠.&lt;/p>
&lt;p>다음 DevOps가 언제 채용될지도 모르는 상황에서 서버에 문제라도 생긴다면 저희 서비스에 심각한 장애가 생길 수 있다고 판단했거든요.&lt;/p>
&lt;p>그래서 제가 실례를 무릅쓰고 DevOps분을 따로 찾아뵈어&lt;/p>
&lt;blockquote>
&lt;p>“혹시 실례가 안된다면 제게 회사 인프라에 대해 조금만 알려주실 수 있으실까요..? DevOps가 공백인 기간에 혹시라도 서버에 문제가 생기면 누군가는 해결해야 할 텐데… 번거로우시겠지만 조금만 알려주신다면 제가 부족한 지식으로라도 어떻게든 버텨보겠습니다.”&lt;/p>
&lt;/blockquote>
&lt;p>라고 말씀드렸습니다.&lt;/p>
&lt;p>당시 그런 저를 좋게 봐주셨는지, 그분은 제게 한 달간 멘토링과 인수인계를 해주셨습니다. 덕분에 쿠버네티스, AWS EKS, Jenkins, ArgoCD, ELK에 대한 개념을 접할 수 있었죠. 한 달로 다 흡수할 수 있는 양이 아니어서, 던져주시는 키워드를 노트에 받아적어 하나하나 찾아보며 공부했던 기억이 납니다. 핀테크 회사라 내외부망이 분리된 환경이라 더 까다로웠던 점도 컸죠.&lt;/p>
&lt;p>그렇게 다음 DevOps가 채용되기 전까지 약 7개월을 혼자 인프라를 운영하게 됐습니다. 지금 생각하면 꽤나 호기로운 자세가 아니었나 싶습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/m8ll55wazhh85mmx36wi8/hello-1.png?rlkey=fn0x6m9z6pgvchaw9jzv3g9ee&amp;amp;st=elc7ad8x&amp;amp;raw=1" alt="회사 데스크탑 모습" loading="lazy" />&lt;/p>
&lt;p>그 7개월 사이에 어떻게든 막아낸 장애도 몇 번 있었고, 제가 도저히 해결하지 못해 이직하신 그분께 사적으로 연락드려 SOS를 청한 적도 있었습니다.&lt;/p>
&lt;p>그래도 이 시기가 제 개발 인생에서 가장 많이 배운 때 중 하나인 것 같습니다. 돌아보면 저에게는 정말 큰 행운이었던 것 같습니다. 많은 회사의 개발자분들께서는 그렇든 이 전에는 인프라에 접근할 수 있는 권한 자체가 없었거든요.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>느낀 점 —&lt;/strong> 이 때 부터는 개발자이면서도 인프라를 다룰 수 있는 능력이 제게 큰 무기가 된 것 같습니다. 좀 더 넓은 시야에서 서비스를 바라볼 수 있게 됐고, 개발자와 DevOps의 입장을 모두 이해할 수 있게 됐습니다.&lt;/p>
&lt;/blockquote>
&lt;h3>2024.01 · 인수합병, 그리고 버티기&lt;span class="hx:absolute hx:-mt-20" id="202401--인수합병-그리고-버티기">&lt;/span>
&lt;a href="#202401--%ec%9d%b8%ec%88%98%ed%95%a9%eb%b3%91-%ea%b7%b8%eb%a6%ac%ea%b3%a0-%eb%b2%84%ed%8b%b0%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>회사가 어렵다는 소문이 돌았고, 10명이던 개발팀이 4명으로 줄었습니다. 사수와 팀장님도 떠나 제가 정산팀에서 가장 오래된 사람이 됐습니다. 얼마 뒤 회사는 동종업계 다른 회사에 인수합병됐고, 줄어든 인원만큼 일은 더 늘었습니다. 1년 차에 한 회사의 정산과 서버를 혼자 맡는 상황이, 지금 생각해도 쉽지 않았습니다.&lt;/p>
&lt;h3>2024.03 · 연봉협상&lt;span class="hx:absolute hx:-mt-20" id="202403--연봉협상">&lt;/span>
&lt;a href="#202403--%ec%97%b0%eb%b4%89%ed%98%91%ec%83%81" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>인수한 회사에서 &amp;ldquo;연봉을 많이 올려줄 테니 남아달라&amp;quot;는 말을 믿고 기다렸지만, 인상폭은 기대에 한참 못 미쳤습니다.&lt;/p>
&lt;p>제 개인적으로는 정산, 백오피스, 신규 기능 개발, 인프라 운영까지 맡아서 하고 있었기 때문에 그만큼의 가치를 인정받고 싶었으나 반영되지 않았다는 점이 많이 아쉬웠습니다.&lt;/p>
&lt;p>사측에서는 &amp;lsquo;제 연봉인상&amp;rsquo;과 &amp;lsquo;신규 DevOps 채용&amp;rsquo;중 연봉테이블을 벗어나기는 어려우니 신규 DevOps 채용을 선택할테니 채용될때까지만 기다려 달라고 했습니다.&lt;/p>
&lt;h3>2024.07 · DevOps 인수인계&lt;span class="hx:absolute hx:-mt-20" id="202407--devops-인수인계">&lt;/span>
&lt;a href="#202407--devops-%ec%9d%b8%ec%88%98%ec%9d%b8%ea%b3%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>신입 DevOps분께서 입사하셨고, 제가 7개월간 운영하던 인프라를 인수인계했습니다. 그동안 제가 혼자서 운영하며 겪었던 시행착오와 장애 대응 경험을 공유했습니다. 다행히도 DevOps분께서 빠르게 적응하시고, 이후로는 안정적으로 인프라를 운영할 수 있었습니다.&lt;/p>
&lt;h3>2025.01 · 이직을 결심하다&lt;span class="hx:absolute hx:-mt-20" id="202501--이직을-결심하다">&lt;/span>
&lt;a href="#202501--%ec%9d%b4%ec%a7%81%ec%9d%84-%ea%b2%b0%ec%8b%ac%ed%95%98%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그렇게 다시금 연봉협상 시기가 다가오게 됐습니다.&lt;/p>
&lt;p>사측에서 회사가 어려워져 올해에는 &amp;ldquo;연봉협상할지 안할지. 한다면 언제 할지 확답을 줄 수 없다&amp;quot;는 말을 했습니다. 면담에서 &amp;ldquo;할 수 있으면 할 수 있다, 없으면 없다 확실히 말씀해 달라&amp;quot;고 여러 번 청했지만 끝내 답은 같았습니다.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>느낀 점 —&lt;/strong> 막연한 기대를 붙잡는 것보다, 확답이 없으면 움직이는 게 맞다고 판단했습니다.&lt;/p>
&lt;/blockquote>
&lt;p>2025년 2월 지금의 회사에 합격했고, 한 달 인수인계를 마치고 3월에 이직을 하게 됐습니다.&lt;/p>
&lt;p>퇴사 의사를 밝히고 나서 여러차례 면담이 오가기도 했습니다. 회사 상황이 어려워 금전적인 부분의 협상은 어렵지만 원한다면 재택근무와 같은 방법으로 근무하는 등의 편의를 제공할 수 있다 라는 말씀을 여러차례 해주셨지만,&lt;/p>
&lt;p>이미 마음이 떠난 상태이기도 했고 면접본 회사에서 1000만원 이상 처우가 올라가는 제안을 받았던 상황이기도 했기 때문에, 회사에서 해주시는 편의 제공 제안은 솔직히 크게 와닿지는 않았습니다.&lt;/p>
&lt;p>그 회사는 결국 2025년 8월, 연봉협상 없이 개발팀 전체에 권고사직이 내려지며 모두 떠났다고 합니다.&lt;/p>
&lt;h2>두번째 회사&lt;span class="hx:absolute hx:-mt-20" id="두번째-회사">&lt;/span>
&lt;a href="#%eb%91%90%eb%b2%88%ec%a7%b8-%ed%9a%8c%ec%82%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>2025.03 · 이직&lt;span class="hx:absolute hx:-mt-20" id="202503--이직">&lt;/span>
&lt;a href="#202503--%ec%9d%b4%ec%a7%81" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/jxs9j46urgdr4gc1go0l5/bootalk-1.png?rlkey=kpdx62krhgakd9cwus6svwak6&amp;amp;st=6ftmfyps&amp;amp;raw=1" alt="부톡 회사 책상" loading="lazy" />&lt;/p>
&lt;p>새 회사는 아파트·오피스텔과 같은 집을 사고팔려는 분들과 공인중개사를 연결하는 프롭테크 플랫폼이었습니다. pre-A 단계, 15명 남짓, 백엔드는 CTO와 저 둘뿐이었습니다.&lt;/p>
&lt;p>합류한 팀은 마침 레거시 모놀리식을 MSA로 옮기는 중이었습니다. 그래서 첫인상은 &amp;ldquo;할 게 많겠다&amp;quot;였습니다. 16개로 쪼개진 레포, 규모에 비해 과한 MSA, 아직 IDC에 남아 있는 모놀리식 서비스, 제대로 된 모니터링 시스템의 부재, 그리고 단일 인스턴스에 몰려 있던 서비스들.&lt;/p>
&lt;p>꽤나 많은 기술부채를 보유하고 있었기 때문에 할일이 많겠다 싶어 오히려 흥미로웠습니다.&lt;/p>
&lt;h3>2025.04 · 처음은 문서화부터 MSA까지&lt;span class="hx:absolute hx:-mt-20" id="202504--처음은-문서화부터-msa까지">&lt;/span>
&lt;a href="#202504--%ec%b2%98%ec%9d%8c%ec%9d%80-%eb%ac%b8%ec%84%9c%ed%99%94%eb%b6%80%ed%84%b0-msa%ea%b9%8c%ec%a7%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>처음 입사해서 가장 먼저한 일은 문서화였습니다. 제가 입사한 시점에 회사에는 온보딩 문서가 없어, 제가 궁금한 부분들을 직접 CTO님께 여쭤보며 문서화했습니다. 시스템 아키텍처를 그려보며 서비스 구조와 흐름을 이해할 수 있었습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/660wm4i69kbcogwkl89di/bootalk-3.png?rlkey=zrjbfyb6a3tj300vio6jsy9d6&amp;amp;st=pris1di3&amp;amp;raw=1" alt="시스템 아키텍처 PR" loading="lazy" />
&lt;img src="https://www.dropbox.com/scl/fi/e7a5xf482f4j1qwsxk353/bootalk-2.png?rlkey=q52ypl3xy41ondp4imrd707xs&amp;amp;st=znx7wk4k&amp;amp;raw=1" alt="Git 전략 문서 추가 PR" loading="lazy" />&lt;/p>
&lt;p>회사의 첫 기여가 문서화였다는 점에서 CTO분께서는 감사하기도 하며 미안하기도 하다고 말씀해주셨습니다. 이후 온보딩문서는 회사 내부 Confluence에 정리됐고, 이후 입사하는 개발자분들은 온보딩 문서를 참고할 수 있도록 구성해뒀습니다.&lt;/p>
&lt;p>그 이후 레거시 서비스를 MSA로 전환하는 과정에 참여했고, 핵심 도메인인 &amp;lsquo;아파트&amp;rsquo;를 MSA로 분리하려다 &lt;a href="https://jeongil.dev/ko/blog/architecture/is-gradual-msa-transition-an-illusion/">한 번 크게 고민하게 되는 일이 생기기도 했습니다&lt;/a>. 아파트와 매칭이 같은 테이블을 공유하며 깊게 얽혀 있어서, 하나만 떼어낼 수가 없었습니다.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>느낀 점 —&lt;/strong> 이 때 사이드 프로젝트로만 구성해본 MSA를 실제 서비스 환경에서 운영하고 개발하려하니 MSA의 장단점이 더 선명하게 보였습니다. 개인적인 판단으로 저희 회사 서비스는 MSA는 과하다고 판단해 차후(2026년 1월) MSA 서비스들을 모듈러 모놀리식으로 합쳤습니다.&lt;/p>
&lt;/blockquote>
&lt;h3>2025.06 · 쿠버네티스와 모니터링&lt;span class="hx:absolute hx:-mt-20" id="202506--쿠버네티스와-모니터링">&lt;/span>
&lt;a href="#202506--%ec%bf%a0%eb%b2%84%eb%84%a4%ed%8b%b0%ec%8a%a4%ec%99%80-%eb%aa%a8%eb%8b%88%ed%84%b0%eb%a7%81" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이때 회사 서비스는 단일 인스턴스에 모든 MSA 컨테이너가 떠있는 방식으로 구성돼 있었습니다. 서비스가 늘면서 메모리 부족으로 죽거나, 한 서비스가 CPU를 독점해 옆 서비스까지 느려지는 일이 발생하게도 했죠. 또 개발 서버조차 없어 테스트를 운영 환경에서 해오고 있었습니다. (이때 꽤나 충격을 받았습니다. 개발 환경은 당연하다고 생각했어서) 6월부터 &lt;a href="https://jeongil.dev/ko/blog/infrastructure/docker-compose-to-k8s/">쿠버네티스(GKE)로 옮기면서&lt;/a> Eureka·게이트웨이를 걷어내고, ArgoCD로 GitOps를 구성했습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/b16bd57a-406b-49d1-b582-735b18ea8c88/image.png" alt="bootalk-kubernetes-k9" loading="lazy" />&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/e91c4082-9184-4bf0-ba0e-46d4823308e2/image.png" alt="bootalk-argocd" loading="lazy" />&lt;/p>
&lt;p>그리고 가장 신경 쓴 건 모니터링이었습니다. 그전까지는 &lt;strong>시스템 장애를 개발팀에서 먼저 인지할 수 없는 상태였습니다.&lt;/strong> 모니터링 환경이 CloudWatch만으로는 부족하다 판단해, &lt;a href="https://jeongil.dev/ko/blog/infrastructure/building-a-monitoring-system/">Loki·Grafana·Tempo·Prometheus로 직접 모니터링 스택을 만들었습니다&lt;/a>.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/c8eb91a8-2c88-4524-bf73-065e5ab1d788/image.png" alt="직접 구축한 모니터링 시스템 아키텍처" loading="lazy" />&lt;/p>
&lt;p>덕분에 장애 감지가 수 시간에서 수 분으로 줄었습니다. 실제로 &lt;a href="https://jeongil.dev/ko/blog/culture/naming-convention/">네이밍이 컨벤션이 지켜지지 않아 발생하고 있던 예외&lt;/a> 같은 문제를, 발견하기도 했습니다.&lt;/p>
&lt;h3>2025.06 · 투자가 무산되다&lt;span class="hx:absolute hx:-mt-20" id="202506--투자가-무산되다">&lt;/span>
&lt;a href="#202506--%ed%88%ac%ec%9e%90%ea%b0%80-%eb%ac%b4%ec%82%b0%eb%90%98%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>면접 때 &amp;ldquo;시리즈 A에 투자가 거의 확정났다&amp;quot;는 이야기를 듣고 입사했는데, 입사 3개월이 채 안 돼 그 투자가 어그러졌다는 말을 듣게 됐습니다.&lt;/p>
&lt;p>이때 꽤나 충격이 컸습니다. 저는 &amp;ldquo;거의 확정났다&amp;quot;를 &amp;ldquo;투자가 확정됐다&amp;quot;로 오해했었고, 그 투자금으로 회사가 안정화될 거라 생각했기 때문입니다. 계약서에 사인했더라도 돈 들어오기 전까진 모른다는 걸 이 이후에야 깨닫게 됐습니다. (나중에 알았지만 계약서에 사인한 상태도 아니었습니다. 하하&amp;hellip;)&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>느낀 점 —&lt;/strong> &amp;ldquo;투자가 거의 확정났다&amp;rdquo; != &amp;ldquo;투자를 받았다&amp;rdquo; 이 말을 꼭 기억하시길 바랍니다.&lt;/p>
&lt;/blockquote>
&lt;p>투자 실패로 회사의 현금흐름이 악화됐다는 이야기를 듣긴 했지만 월급이 밀리지 않는한 1년은 버티자라는 마음으로 다니게 됐습니다.&lt;/p>
&lt;p>또 회사가 가진 가능성을 보고 입사한 것도 있기 때문에 이번 투자가 무산됐다 하더라도 회사가 가진 가능성을 믿고, 제가 할 수 있는 한 최선을 다해 회사에 기여하고 싶다는 마음이 컸습니다.&lt;/p>
&lt;h3>2025.08 · 혼자가 되다&lt;span class="hx:absolute hx:-mt-20" id="202508--혼자가-되다">&lt;/span>
&lt;a href="#202508--%ed%98%bc%ec%9e%90%ea%b0%80-%eb%90%98%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그러나 투자 무산의 여파는 사람으로 돌아왔습니다. 8월부터 10월까지 CTO 분을 시작으로 동료들이 연달아 회사를 떠났고, 어쩌다 보니 입사 반년도 안 돼 &lt;strong>MAU 2만 규모 플랫폼의 백엔드와 서버를 혼자&lt;/strong> 책임지게 됐습니다.&lt;/p>
&lt;p>처음에 CTO의 퇴사가 결정났을때 CEO분께서는 어느정도 불안감을 내포한 상태로 &amp;ldquo;신규 채용은 어려운 상황인데 백엔드 혼자서 서비스 운영과 개발을 다 할 수 있겠냐&amp;quot;라는 질문을 하셨습니다.&lt;/p>
&lt;p>새 환경에 대한 설렘이 가시기도 전이라 솔직히 막막했습니다. 그렇지만 5개월의 기간동안 시스템에 대한 파악은 어느정도 되어 있어 &amp;ldquo;가능은 하다&amp;quot;는 게 제 결론이었습니다.&lt;/p>
&lt;p>제가 &amp;ldquo;쉽지 않겠지만 불가능하지는 않다&amp;quot;라고 답하자, CEO는 &amp;ldquo;당분간은 현상 유지만을 해도 좋으니 안정적으로 서비스를 유지시켜만 달라&amp;quot;고 요청하셨습니다.&lt;/p>
&lt;p>그 뒤로는 한동안 살아남기 위한 시간이었습니다. 다만 신기하게도, 혼자가 되니 손볼 곳이 더 또렷하게 보였습니다.&lt;/p>
&lt;p>나 혼자 이 시스템을 다 봐야한다고? 라는 생각에 혼자 관리하려면 이것들부터 해야겠다. 라는 생각이 들었습니다. 그래서 우선순위를 정해, 관리 병목이 되는 부분부터 하나씩 개선하기로 결심했습니다.&lt;/p>
&lt;h3>2025.09 · 모노레포로 전환&lt;span class="hx:absolute hx:-mt-20" id="202509--모노레포로-전환">&lt;/span>
&lt;a href="#202509--%eb%aa%a8%eb%85%b8%eb%a0%88%ed%8f%ac%eb%a1%9c-%ec%a0%84%ed%99%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>가장 먼저 눈에 걸린 건 코드 중복이었습니다. MSA 환경으로 16개 레포를 관리하다 보니, 공통 Exception 하나를 고치려면 16개 레포에 똑같은 수정을 반복해야 했습니다.&lt;/p>
&lt;p>그래서 관리하기 쉽도록 &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-to-multi-module/">16개 레포를 하나의 모노레포(멀티모듈)로 합쳤습니다&lt;/a>. Git Subtree로 커밋 히스토리를 살린 채 통합했고, 그 결과 빌드 시간이 &lt;strong>27분에서 8분으로&lt;/strong> 줄고 중복 코드 약 5,500줄이 사라졌습니다. (대신 23만 줄짜리 PR이 만들어졌습니다.)&lt;/p>
&lt;p>이게 4월부터 작업하던 걸 급하게 8~9월에 몰아서 마무리 짓게 됐습니다.&lt;/p>
&lt;h3>2025.09 · 증명후에 협상&lt;span class="hx:absolute hx:-mt-20" id="202509--증명후에-협상">&lt;/span>
&lt;a href="#202509--%ec%a6%9d%eb%aa%85%ed%9b%84%ec%97%90-%ed%98%91%ec%83%81" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>1달간 혼자서 서비스를 안정적으로 유지하는 모습을 보여드린 뒤, CEO께 면담을 요청해 연봉협상을 진행했습니다. 그 결과 연봉 만족할 만큼 인상된 급여를 11월부터 받기로 협의가 이루어졌습니다.&lt;/p>
&lt;h3>2025.10 · 안정화에 매달리다&lt;span class="hx:absolute hx:-mt-20" id="202510--안정화에-매달리다">&lt;/span>
&lt;a href="#202510--%ec%95%88%ec%a0%95%ed%99%94%ec%97%90-%eb%a7%a4%eb%8b%ac%eb%a6%ac%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>서버를 쿠버네티스로 옮긴 뒤, 배포만 하면 첫 요청이 느려지는 게 눈에 띄었습니다. 평소 100~200ms이던 첫 응답이 배포 직후엔 &lt;strong>1.2초&lt;/strong>까지 치솟아 &lt;a href="https://jeongil.dev/ko/blog/backend/performance/k8s-jvm-warm-up/">JVM Cold Start 문제&lt;/a>를 해결하거나&lt;/p>
&lt;p>MSA 전환 과정에서 한 컬럼을 bigint에서 varchar로 바꿨다가 &lt;a href="https://jeongil.dev/ko/blog/backend/troubleshooting/mysql-collation-performace/">쿼리가 8배 느려진 일&lt;/a>을 해결하거나&lt;/p>
&lt;p>CI로 사용중이던 GitHub Actions 무료 한도(월 2,000분)가 리밋을 넘게 생겨 급한 대로 팀원 맥북에 Self-hosted Runner를 붙이기도 하고, &lt;a href="https://jeongil.dev/ko/blog/infrastructure/github-actions-to-jenkins/">Jenkins를 쿠버네티스 위에 올려&lt;/a> 필요할 때만 파드를 띄우는 구조로 바꾸기도 하며 서비스 안정화에 집중했습니다.&lt;/p>
&lt;h3>2025.12 · 정말 MSA가 필요했을까&lt;span class="hx:absolute hx:-mt-20" id="202512--정말-msa가-필요했을까">&lt;/span>
&lt;a href="#202512--%ec%a0%95%eb%a7%90-msa%ea%b0%80-%ed%95%84%ec%9a%94%ed%96%88%ec%9d%84%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>연말에는 한가지 질문을 스스로에게 던지게 됐습니다. 저 혼자 13개가 넘는 서비스를 분산환경에서 운영하며 기능 개발까지 한다는 건 병목지점이 너무 많았고, MSA는 회사 규모에 비해 비용도 복잡도도 과하다고 판단했습니다. 그리고 GCP 스타트업 크레딧이 2026년 4월에 끝나기 때문에 비용 절감의 필요성도 있는 상황이라 MSA의 필요성에 대해 진지하게 검토해보기로 했습니다.&lt;/p>
&lt;p>이후 MSA를 해보며 느꼈던 내용을 고찰하며 &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-7-conclusion/">&amp;ldquo;우리에게 정말 MSA가 필요했나&amp;rdquo;&lt;/a>와 같은 MSA 시리즈 글을 남기기도 했죠.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>느낀 점 —&lt;/strong> 제가 느꼈던 MSA의 장점을 위 글에 자세히 적어뒀지만 제가 느낀 바를 짧게 정리하자면 MSA는 특정한 문제를 풀기위해 복잡성을 감수하는 선택입니다. 그렇지만 문제가 발생하지도 않았음에도 MSA를 선택하는 건, 복잡성을 감수할 이유가 없는 선택이라고 생각합니다. MSA는 문제를 해결하기 위한 수단이지, 목적이 되어서는 안된다 생각합니다.&lt;/p>
&lt;/blockquote>
&lt;h3>2026.01 · 모듈러 모놀리식으로 되돌리다&lt;span class="hx:absolute hx:-mt-20" id="202601--모듈러-모놀리식으로-되돌리다">&lt;/span>
&lt;a href="#202601--%eb%aa%a8%eb%93%88%eb%9f%ac-%eb%aa%a8%eb%86%80%eb%a6%ac%ec%8b%9d%ec%9c%bc%eb%a1%9c-%eb%90%98%eb%8f%8c%eb%a6%ac%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그래서 &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-to-modular-monolith/">11개 서비스를 하나의 애플리케이션으로 합쳤습니다&lt;/a>. 알림과 배치 서비스만 독립으로 남기고, 모듈 간 호출은 ModuleApi 인터페이스로 추상화했습니다. 그 결과 &lt;strong>파드가 26개 이상에서 두세 개로&lt;/strong>, Compute 비용이 &lt;strong>하루 96,505원에서 58,768원(월 약 113만원 절감)&lt;/strong> 으로 줄어 들게 되고 복잡성도 크게 줄어들게 됐습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/xpsueudcdebbiw6v7csad/after-moduler-credit.png?rlkey=7nsgpgge7crevuitprl1fl78w&amp;amp;st=v9ldtz7k&amp;amp;raw=1" alt="모듈러 모놀리식으로 전환한 뒤의 서비스 구조" loading="lazy" />&lt;/p>
&lt;p>기존에는 문제가 발생하면 여러 SQS를 뒤지고 여러 서비스의 로그를 뒤져야 했지만, 이제는 한 서비스에서 모든 로그를 확인할 수 있게 됐습니다. 혼자 하다보니 여러 서비스를 뒤져서 문제를 찾는게 여간 쉽지 않았는데 이제는 한 서비스의 스택트레이스로 추적되니 문제 해결 속도가 훨씬 빨라졌습니다.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>느낀 점 —&lt;/strong> 팀과 서비스의 상황에 맞게 선택하는게 중요하다는 것을 다시금 느꼈습니다.&lt;/p>
&lt;/blockquote>
&lt;h3>2026.02 · AI 신규기능 론칭&lt;span class="hx:absolute hx:-mt-20" id="202602--ai-신규기능-론칭">&lt;/span>
&lt;a href="#202602--ai-%ec%8b%a0%ea%b7%9c%ea%b8%b0%eb%8a%a5-%eb%a1%a0%ec%b9%ad" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이 때 쯤은 AI를 서비스에 녹이는 일을 시작했습니다.&lt;/p>
&lt;p>회사에는 기존에 고정 RAG 파이프라인으로 된 LLM 기반 서비스가 있었는데,&lt;/p>
&lt;p>회사에서 기획한 신규 기능은 &amp;ldquo;송도역이나 강남역 근처에 30평대 10억 이하 500세대 신축 아파트 추천해줘&amp;rdquo; 같은 자연어 기반의 매물 추천이 됐으면 좋겠다는 요구사항이 있었습니다.&lt;/p>
&lt;p>그래서 &lt;a href="https://jeongil.dev/ko/blog/architecture/ai-property-recommendation-system/">LLM이 계획만 세우고 실행은 코드가 맡는 구조&lt;/a>로 재설계하면서, &amp;lsquo;AI 매물 추천&amp;rsquo; 신규 기능을 론칭하게 됐습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/9x56dxoydvfonon6vr7au/ai-estate-result-5.png?rlkey=jp0ayi58mvtr0t68d928qokrt&amp;amp;st=gpe4xoql&amp;amp;raw=1" alt="“송도역 혹은 상동역 근처에 30평대 10억 이하로 살 수 있는 500세대 이상 신축 아파트 찾아 줘”" loading="lazy" />&lt;/p>
&lt;p>또 전세사기 위험도를 분석해주는 &amp;lsquo;AI 등기 분석&amp;rsquo; 기능도 개발해 론칭하게 됐죠.&lt;/p>
&lt;h3>2026.05 · 신뢰성을 &amp;lsquo;약속&amp;rsquo;으로&lt;span class="hx:absolute hx:-mt-20" id="202605--신뢰성을-약속으로">&lt;/span>
&lt;a href="#202605--%ec%8b%a0%eb%a2%b0%ec%84%b1%ec%9d%84-%ec%95%bd%ec%86%8d%ec%9c%bc%eb%a1%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>가장 최근 손댄 건 SRE이었습니다. 저 혼자 예외 로그도 확인하다보니 &lt;em>&amp;ldquo;ERROR!!! 확인 요망&amp;rdquo;&lt;/em> 알림이 울려도 실제로는 멀쩡한 경우가 잦아지자, 어느새 제가 알림을 확인하지 않는 경우들이 발생하게 됐습니다. 또 &amp;ldquo;지금 배포해도 되나?&amp;ldquo;를 판단할 객관 기준이 없었습니다.&lt;/p>
&lt;p>그래서 5xx 비율을 SLI로 잡고, &lt;a href="https://jeongil.dev/ko/blog/infrastructure/from-observability-to-reliability-slo-error-budget/">99.9%(30일에 약 43분 실패 허용)라는 Error Budget으로 신뢰성을 수치화&lt;/a>했습니다. 한 가지 더 배운 건, &lt;strong>200 OK가 늘 정상은 아니라는 것&lt;/strong>이었습니다. 실거래가 배치가 멈춰 한 달째 옛 데이터를 주는데도 API는 200을 응답하고 있었거든요. 그래서 데이터 신선도까지 검사하는 Synthetic 모니터링도 붙이게 됐습니다.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>느낀 점 —&lt;/strong> 신뢰는 &amp;lsquo;감&amp;rsquo;이 아니라 &amp;lsquo;약속&amp;rsquo;이어야 한다는 것.&lt;/p>
&lt;/blockquote>
&lt;h3>2026.06 · 회사는 지금&lt;span class="hx:absolute hx:-mt-20" id="202606--회사는-지금">&lt;/span>
&lt;a href="#202606--%ed%9a%8c%ec%82%ac%eb%8a%94-%ec%a7%80%ea%b8%88" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>아직 회사는 투자를 받지 못한 상태입니다. 어찌저찌 살아남을지 망할지 모르겠지만, 저는 제 역할을 다하기 위해 노력하고 있습니다.&lt;/p>
&lt;p>물론 의욕이 사그라드려 하는 날도 있지만 &amp;ldquo;이 회사가 망하든 말든 나는 내 역할을 다할거야&amp;quot;라는 생각으로 버티고 있습니다.&lt;/p>
&lt;h2>지금, 3년차&lt;span class="hx:absolute hx:-mt-20" id="지금-3년차">&lt;/span>
&lt;a href="#%ec%a7%80%ea%b8%88-3%eb%85%84%ec%b0%a8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이제 만으로 3년이 넘었습니다. 4년 전만 해도 &lt;code>System.out.println(&amp;quot;Hello World&amp;quot;)&lt;/code>도 제대로 모르던 사람이, 지금은 백엔드와 인프라를 함께 보고 서비스 안정성을 책임지고 있는 나날을 보내고 있습니다.&lt;/p>
&lt;p>돌아보면 비전공자라는 건 시장에서 분명한 약점이라고 생각합니다. 그래서 출발선이 남들보다 뒤에 있다는 걸 인정하고, 부족한 만큼 다른 데서 강점을 만들려 하는게 중요하다고 생각합니다. 강의를 듣고 끝내지 않고 직접 만들어 본 것도, 인프라처럼 비어 있는 자리를 떠안은 것도 부족한걸 알기에 더 열심히 하려는 마음에서 나온 선택이었습니다.&lt;/p>
&lt;p>영업하던 시절 가장 견디기 힘들었던 게 매달 0으로 돌아가는 느낌이었는데, 개발은 어제 막힌 것이 오늘의 바탕이 되는 것 같습니다. 여전히 모르는 것투성이지만, 하루하루 쌓아갈 수 있다는 것만으로도 저에게는 감사한 날들이라 생각이 듭니다.&lt;/p>
&lt;p>비전공자로 개발을 시작해볼까 고민하시는 분이 이 글을 보셨다면, 이런 사람도 이렇게 개발자로 살아가고 있구나 정도로 읽어주시면 좋겠습니다. 긴 글 읽어주셔서 감사합니다.&lt;/p></description></item><item><title>서비스는 어떻게 사용자의 신뢰를 얻는가 — 신뢰성을 '감'이 아니라 '약속'으로</title><link>https://jeongil.dev/ko/blog/infrastructure/from-observability-to-reliability-slo-error-budget/</link><pubDate>Wed, 27 May 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/infrastructure/from-observability-to-reliability-slo-error-budget/</guid><description>
&lt;p>안녕하세요. 프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 정정일입니다.&lt;/p>
&lt;p>이번 글은 코드나 특정 기술에 대한 이야기라기보다는, 한동안 제 머릿속을 떠나지 않았던 질문 하나에서 출발했습니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;서비스는 어떻게 사용자의 신뢰를 얻는가?&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>조금 거창하게 들릴 수 있는데, 사실 생각하지 않을 수 없는 현실적인 질문이죠. 저는 사용자가 서비스를 사용하는 이유 중 큰 부분을 차지하는 게 &lt;strong>신뢰&lt;/strong>라고 생각합니다. &amp;ldquo;이 서비스는 내가 필요할 때, 내가 기대한 대로 동작한다&amp;quot;는 믿음이요. 그리고 이 믿음은 쌓기는 더디지만 잃기는 한순간입니다. 한 번 이상하게 멈추거나, 엉뚱한 데이터를 보여주거나, 느려서 답답했던 경험 한 번이면 사용자는 굳이 항의하지 않고 &lt;strong>조용히 떠나게 됩니다. 사용자 이탈이죠.&lt;/strong>&lt;/p>
&lt;p>&lt;a href="https://jeongil.dev/ko/blog/infrastructure/building-a-monitoring-system/">예전에 모니터링 시스템을 구축한 이야기&lt;/a>에서도 다룬 적이 있지만, 불만족한 사용자의 대다수는 CS로 문의하지 않고 그냥 이탈합니다. 그래서 그때 저는 &amp;ldquo;장애를 사용자가 알려주지 않아도 우리가 먼저 알아야 한다&amp;quot;고 했고, 그렇게 모니터링 체계를 만든 적이 있죠.&lt;/p>
&lt;p>그런데 그 시스템을 1년 가까이 운영하면서, 한 가지를 느끼게 된게 있습니다. &lt;strong>장애를 먼저 아는 것은 신뢰를 지키는 출발점일 뿐, 그 자체로 신뢰를 보장해주지는 않더라&lt;/strong>는 점입니다. 그래서 이번 글에서는 &amp;ldquo;신뢰란 무엇이고, 그것을 어떻게 &lt;em>느낌,감이 아니라 약속의 형태로&lt;/em> 정의하고 지킬 수 있는가&amp;quot;에 대해, 제가 SRE의 개념들(SLI·SLO·Error Budget·Synthetic Monitoring)을 빌려 고민하고 적용해본 과정을 풀어보려 합니다.&lt;/p>
&lt;p>여전히 진행 중인 부분도 있어서, 작은 팀에서 &amp;ldquo;신뢰성&amp;quot;이라는 막연한 단어를 어떻게 손에 잡히는 것으로 바꿔 나갔는지에 대한 기록에 가깝다고 봐주시면 좋을 것 같습니다.&lt;/p>
&lt;p>미리 말씀드리면 저는 SRE를 깊게 공부한 사람은 아닙니다. 아래 내용도 &amp;ldquo;이게 정석이다&amp;quot;라기보다는, 문제를 만나서 이것저것 찾아보고 우리 상황에 맞게 적용해본 과정에 가까우니 그런 눈으로 봐주시면 감사하겠습니다.&lt;/p>
&lt;h2>알림이 와도 믿지 않게되기 시작했습니다.&lt;span class="hx:absolute hx:-mt-20" id="알림이-와도-믿지-않게되기-시작했습니다">&lt;/span>
&lt;a href="#%ec%95%8c%eb%a6%bc%ec%9d%b4-%ec%99%80%eb%8f%84-%eb%af%bf%ec%a7%80-%ec%95%8a%ea%b2%8c%eb%90%98%ea%b8%b0-%ec%8b%9c%ec%9e%91%ed%96%88%ec%8a%b5%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이 고민이 어디서부터 시작됐는지를 말씀드리면 좋을 것 같습니다.&lt;/p>
&lt;p>어느 날 &lt;code>legacy-service - ERROR LOG!!! Pls Check it ASAP&lt;/code> 슬랙 알림이 짧은 간격으로 계속 울렸습니다. 알림 문구만 보면 명백한 운영 장애였습니다. 그런데 막상 로그를 하나씩 까보면, 정작 사용자가 실패를 겪은 흔적은 없었습니다. 대부분 잠깐 떴다가 알아서 복구되는, 말하자면 일시적인 예외들이었습니다.&lt;/p>
&lt;p>예를 들면 알림 발송이 첫 시도에 실패했다가 바로 다음 재시도에서 성공한 경우가 있었습니다. 최종적으로 사용자에게는 알림이 잘 갔는데, 첫 번째 실패가 &lt;code>ERROR&lt;/code> 로그로 남은 거죠. 또 SPOT 인스턴스가 회수되면서 pod가 종료될 때, 그 순간 물려 있던 커넥션이 끊기며 예외가 나기도 했습니다. 트래픽은 다른 pod가 받아줘서 사용자는 아무 영향이 없었는데, 끊긴 커넥션이 &lt;code>ERROR&lt;/code>로 남은 겁니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
graph TB
A1[&amp;#34;알림 발송 첫 시도 실패&amp;lt;br/&amp;gt;(다음 재시도에서 성공)&amp;#34;] --&amp;gt; E[&amp;#34;severity=ERROR 로그&amp;#34;]
A2[&amp;#34;SPOT 회수로 pod 종료&amp;lt;br/&amp;gt;물려 있던 커넥션 끊김&amp;#34;] --&amp;gt; E
E --&amp;gt; F[&amp;#34;Grafana 알림 룰(level=error) 발화&amp;#34;]
F --&amp;gt; G[&amp;#34;Slack: &amp;#39;ERROR LOG!!! Pls Check ASAP&amp;#39;&amp;#34;]
G --&amp;gt; H[&amp;#34;실제 사용자 영향: 없음&amp;#34;]
style H fill:#238636,color:#fff
style G fill:#f85149,color:#fff
&lt;/pre>&lt;p>하나하나 떼어놓고 보면 다 &amp;ldquo;그럴 수 있는&amp;rdquo; 예외였습니다. 재시도로 복구됐거나, pod가 갈리는 와중에 잠깐 났거나 한 거니까요. 문제는 이런 게 쌓이면서 알림이 자주 울리게 됐다는 점입니다. 그러다 보니 팀도 알림이 오더라도 &amp;ldquo;또 그거겠지&amp;rdquo; 하면서 넘기게 되는 겁니다. 진짜 장애가 그 사이에 끼어 있어도 넘어가 버리게 되는 경우가 생기게 되는 거죠. 알림의 피로도가 높아지면서, 알림이 와도 안 믿게 되는 상황이 된 겁니다.&lt;/p>
&lt;p>그럼 그냥 룰에서 걸러내면 되지 않냐고 할 수 있습니다. 눈에 띄는 패턴 몇 개는 실제로 그렇게 줄이기도 했습니다. 그런데 근본적으로 께름칙한 게 남았습니다. 이 예외들은 레벨로 보면 다 똑같은 &lt;code>ERROR&lt;/code>라, &amp;ldquo;무시해도 되는 ERROR&amp;quot;와 &amp;ldquo;꼭 봐야 하는 ERROR&amp;quot;를 레벨만으로는 가를 수가 없었습니다. 결국 우리가 알림을 걸어둔 기준이 &amp;ldquo;사용자가 실제로 실패를 겪었는가&amp;quot;가 아니라 &amp;ldquo;예외 로그가 찍혔는가&amp;quot;였던 겁니다. 따지고 보면 둘은 전혀 다른 얘기였는데 말이죠.&lt;/p>
&lt;p>비슷한 시기에 걸리는 게 하나 더 있었습니다. 배포할 때 &amp;ldquo;지금 배포해도 되나?&amp;ldquo;를 판단하는 기준이 사람 머릿속에만 있었거든요. 오해는 하지 않으셨으면 좋겠습니다 ㅎㅎ.. 아무 생각 없이 막 배포한 건 아닙니다. breaking change가 들어간 배포인지, 사용자 영향이 큰 변경인지에 따라 나름 신중하게 봤습니다만 그게 명확한 기준이 있는 게 아니라 그때그때 사람이 머리로 따지는 거라, 결국 책임자 한 명이 &amp;ldquo;이때쯤이 괜찮겠다&amp;quot;라고 판단하는 형태가 되곤 했습니다. 특히 새벽이나 주말처럼 아무도 대시보드를 안 보고 있을 때는 그 판단을 받쳐줄 게 아무것도 없었습니다.&lt;/p>
&lt;p>두 경우 다 따지고 보면 비슷한 문제였습니다. &amp;ldquo;지금 우리 서비스가 괜찮은 건가, 아닌가&amp;quot;를 판단하는 게 전부 사람 머릿속에만 있었지, 어디에도 데이터 기준으로 판단할 근거가 없었던 겁니다.&lt;/p>
&lt;p>그래서 신뢰성이라는 걸 사람 감각에만 맡기지 말고 좀 더 분명한 기준으로 다룰 방법이 없을까 싶어서, 이것저것 찾아보기 시작했습니다.&lt;/p>
&lt;h2>&amp;ldquo;신뢰성&amp;quot;을 데이터로 바꿔보기로 했습니다&lt;span class="hx:absolute hx:-mt-20" id="신뢰성을-데이터로-바꿔보기로-했습니다">&lt;/span>
&lt;a href="#%ec%8b%a0%eb%a2%b0%ec%84%b1%ec%9d%84-%eb%8d%b0%ec%9d%b4%ed%84%b0%eb%a1%9c-%eb%b0%94%ea%bf%94%eb%b3%b4%ea%b8%b0%eb%a1%9c-%ed%96%88%ec%8a%b5%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>찾다 보니 SRE에서 쓰는 SLI / SLO / Error Budget이라는 개념이 눈에 들어왔습니다. 처음엔 용어가 좀 거창해 보였는데, 제가 이해한 바로는 대충 이런 것이었습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>SLI&lt;/strong> — 뭘 &amp;ldquo;성공&amp;quot;으로 볼 것인가. (예: 5xx 없이 응답한 요청의 비율)&lt;/li>
&lt;li>&lt;strong>SLO&lt;/strong> — 그 성공을 어느 수준까지 약속할 것인가. (예: 30일간 99.9%)&lt;/li>
&lt;li>&lt;strong>Error Budget&lt;/strong> — 약속에서 허용되는 실패의 여유분. (99.9%면 0.1%, 30일에 약 43분)&lt;/li>
&lt;/ul>
&lt;p>뜯어보니 결국 제가 하려던 거랑 같은 얘기였습니다. 뭘 성공으로 볼지 정하고(SLI), 그걸 어느 수준까지 지킬지 약속하고(SLO), 그 약속에 여유를 좀 두자(Error Budget)는 것이죠. 막연하던 &amp;ldquo;신뢰성&amp;quot;을 데이터로 바꿔보자는 겁니다.&lt;/p>
&lt;p>정리해 보면 결국 이건 신뢰성을 사용자에게 하는 &amp;lsquo;약속&amp;rsquo;으로 바꾸는 일이었습니다. SLO가 &amp;ldquo;어느 수준까지는 지키겠다&amp;quot;는 목표잖아요. &amp;ldquo;30일 동안 5xx 없이 99.9%&amp;ldquo;처럼요. 데이터는 그 약속을 재고 지키기 위한 수단이고, 약속을 지켜야 사용자 신뢰도 쌓이는 거죠.&lt;/p>
&lt;p>순서가 중요해 보였습니다. 뭘 성공으로 볼지부터 안 정하면, 앞에서 겪은 false alarm처럼 뭘 알려야 할지도 모르는 채로 알림만 쌓일 테니까요. 그래서 SLI부터 정하고, 그걸 잴 수 있는 토대를 만드는 순서로 가봤습니다.&lt;/p>
&lt;h3>일단 메트릭부터 믿을 만하게&lt;span class="hx:absolute hx:-mt-20" id="일단-메트릭부터-믿을-만하게">&lt;/span>
&lt;a href="#%ec%9d%bc%eb%8b%a8-%eb%a9%94%ed%8a%b8%eb%a6%ad%eb%b6%80%ed%84%b0-%eb%af%bf%ec%9d%84-%eb%a7%8c%ed%95%98%ea%b2%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>막상 데이터로 보려고 하니 토대부터 문제가 있었습니다. 기존 트래픽 대시보드는 각 서비스의 actuator를 Prometheus가 스크랩하는 방식이었는데, ingress를 통하다 보니 여러 파드 중 랜덤하게 하나만 잡혔고, 파드가 갈릴 때마다 카운터가 점프했거든요. 신뢰성을 재겠다면서 정작 그 근거 데이터를 신뢰할 수 없던 겁니다.&lt;/p>
&lt;p>그래서 메트릭을 OTLP push 방식으로 바꿨습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-promql" data-lang="promql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Before: actuator 스크랩 (랜덤 1파드 → 카운터 점프)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nv">http_server_requests_seconds_count&lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="nl">job&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="p">&amp;#34;&lt;/span>&lt;span class="s">...&lt;/span>&lt;span class="p">&amp;#34;}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1"># After: OTLP push (각 파드가 service_instance_id 로 직접 push)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nv">http_server_request_duration_seconds_count&lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nl">deployment_environment_name&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="p">&amp;#34;&lt;/span>&lt;span class="s">$env&lt;/span>&lt;span class="p">&amp;#34;,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nl">service_name&lt;/span>&lt;span class="o">=~&lt;/span>&lt;span class="p">&amp;#34;&lt;/span>&lt;span class="s">$service&lt;/span>&lt;span class="p">&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>각 파드가 직접 메트릭을 보내니 스크랩 편향이 사라졌고, 라벨도 OTel 컨벤션(&lt;code>http_route&lt;/code>, &lt;code>http_response_status_code&lt;/code>)에 맞췄습니다. 앞으로 SLI를 다 이 위에서 계산할 거라, 여기부터 정리하고 가는 게 맞겠다 싶었습니다.&lt;/p>
&lt;h3>RED 대시보드부터 만들어봤습니다&lt;span class="hx:absolute hx:-mt-20" id="red-대시보드부터-만들어봤습니다">&lt;/span>
&lt;a href="#red-%eb%8c%80%ec%8b%9c%eb%b3%b4%eb%93%9c%eb%b6%80%ed%84%b0-%eb%a7%8c%eb%93%a4%ec%96%b4%eb%b4%a4%ec%8a%b5%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그런데 막상 &amp;ldquo;뭘 성공으로 볼지&amp;quot;를 정하려니 어디서부터 봐야 할지 막막했습니다. 그래서 또 찾아봤는데, 요청 기반 서비스는 &lt;strong>RED&lt;/strong>(Rate / Errors / Duration)를 많이 본다길래 그것부터 대시보드로 만들어봤습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Rate&lt;/strong> — 초당 요청 수&lt;/li>
&lt;li>&lt;strong>Errors&lt;/strong> — 실패한 요청의 비율&lt;/li>
&lt;li>&lt;strong>Duration&lt;/strong> — 응답 지연 분포 (p50 / p95 / p99)&lt;/li>
&lt;/ul>
&lt;p>여기서 좀 고민됐던 게 에러율이었습니다. 4xx도 에러에 넣어야 하나 싶었거든요. 그런데 4xx는 대부분 클라이언트 쪽 문제(잘못된 요청, 권한 없음)지 서버가 약속을 어긴 건 아닙니다. 봇이 이상한 URL을 긁고 다니는 것만으로 우리 신뢰성 지표가 깎이면 좀 이상하니까요. 그래서 일단 4xx는 따로 보기만 하고, SLI는 5xx 비율로 잡았습니다.&lt;/p>
&lt;p>이게 맞는 정의인지는 솔직히 아직 확신이 없습니다. 429(rate limit)는 어떻게 볼지, 200으로 내려가지만 사실상 실패인 응답은 어떻게 잡을지 같은 건 아직 숙제로 남겨뒀습니다.&lt;/p>
&lt;h3>Error Budget이라는 개념이 인상 깊었습니다&lt;span class="hx:absolute hx:-mt-20" id="error-budget이라는-개념이-인상-깊었습니다">&lt;/span>
&lt;a href="#error-budget%ec%9d%b4%eb%9d%bc%eb%8a%94-%ea%b0%9c%eb%85%90%ec%9d%b4-%ec%9d%b8%ec%83%81-%ea%b9%8a%ec%97%88%ec%8a%b5%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>RED 위에 Error Budget 패널을 얹었는데, 개인적으로 이 개념이 사고방식을 좀 바꿔줬습니다.&lt;/p>
&lt;p>Error가 0이어야 한다고 생각하면, 0이 아닌 순간마다 &amp;ldquo;비상&amp;quot;이 되는 거죠. 그런데 Error Budget은 그걸 &amp;ldquo;예산 안에서 쓰는 것&amp;quot;으로 보게 해줬습니다. Error는 존재할 수 있고, 예산 안에서만 쓰면 정상이라고 보는 겁니다.&lt;/p>
&lt;p>가용성을 99.9%로 약속한다는 건 뒤집으면 0.1%까지는 실패해도 약속을 어긴 건 아니라는 뜻입니다. 그렇게 보니 마음가짐이 좀 달라지더라구요. 예산이 남아 있으면 배포하고, 바닥나면 잠깐 멈춰서 신뢰 회복에 집중하면 되니까요.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>패널&lt;/th>
&lt;th>의미&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>30일 Availability&lt;/td>
&lt;td>30일 롤링 가용성 (%)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>30일 잔여 버짓 %&lt;/td>
&lt;td>100% = 손해 없음, 0% = 한계, 음수 = 약속 위반&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Burn Rate (1h / 6h)&lt;/td>
&lt;td>예산을 얼마나 빠르게 쓰고 있나&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Burn Trend&lt;/td>
&lt;td>예산 소진 추이&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/pns3umqkq06glaxmc8i8g/error-budget-dashboard.png?rlkey=4l3jjlf8ng7wngpycuw0cfkjv&amp;amp;st=rfk5vacz&amp;amp;raw=1" alt="error-budget-dashboard" loading="lazy" />&lt;/p>
&lt;p>그런데 여기서 고민해야 할 부분이 있었습니다. SLO를 99.9%로 잡을지 99.99%로 잡을지가 고민이었죠. 숫자로는 한 자리 차이인데 그걸 지키는 비용은 엄청나게 차이 나고, 결국 &amp;ldquo;사용자한테 어느 수준을 약속할 거냐&amp;quot;는 비즈니스랑 같이 정할 문제지 제가 혼자 정할 게 아니었습니다. 그래서 일단 99.9%를 placeholder로 두고, 실제 값부터 쌓아가면서 나중에 합의하기로 했습니다.&lt;/p>
&lt;h2>그런데 200 OK가 늘 정상은 아니었습니다&lt;span class="hx:absolute hx:-mt-20" id="그런데-200-ok가-늘-정상은-아니었습니다">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%9f%b0%eb%8d%b0-200-ok%ea%b0%80-%eb%8a%98-%ec%a0%95%ec%83%81%ec%9d%80-%ec%95%84%eb%8b%88%ec%97%88%ec%8a%b5%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>SLI랑 Error Budget으로 &amp;ldquo;요청이 성공했나, 빨랐나&amp;quot;는 볼 수 있게 됐습니다. 그런데 운영하다 보니 이걸로도 안 잡히는 경우가 있었습니다.&lt;/p>
&lt;p>그러면서 한 가지 의문이 들었습니다. &lt;strong>API가 200 OK를 내려주면, 그건 정상일까요?&lt;/strong> 저는 한동안 그렇다고만 생각하고 있었거든요.&lt;/p>
&lt;p>저희는 부동산 플랫폼이라 실거래가 데이터가 핵심인데, 이 데이터는 외부에서 배치로 들어옵니다. 그 배치가 조용히 멈춰서 한 달째 새 거래가 안 들어온다고 해보겠습니다. 그래도 실거래가 조회 API는 200 OK를 잘 내려줍니다. 과거 데이터를 그대로 주니까요. RED 대시보드도 멀쩡합니다. 5xx도 없고 응답도 빠릅니다.&lt;/p>
&lt;p>기술적으로는 멀쩡한데 사용자 입장에선 &amp;ldquo;이 데이터 왜 이렇게 옛날 거야&amp;rdquo; 싶은 상황인 겁니다. 상태 코드나 응답 시간만 봐서는 안 잡히는 종류의 문제였습니다.&lt;/p>
&lt;p>이런 건 어떻게 잡나 찾아봤더니 Synthetic Monitoring이라는 게 있었습니다. 단순히 살아있나 죽었나(uptime)만 보는 게 아니라, 응답 내용이 비즈니스 기준으로 정상인지까지 주기적으로 확인하는 방식이었습니다.&lt;/p>
&lt;h3>검증을 어디서 할지 좀 헤맸습니다&lt;span class="hx:absolute hx:-mt-20" id="검증을-어디서-할지-좀-헤맸습니다">&lt;/span>
&lt;a href="#%ea%b2%80%ec%a6%9d%ec%9d%84-%ec%96%b4%eb%94%94%ec%84%9c-%ed%95%a0%ec%a7%80-%ec%a2%80-%ed%97%a4%eb%a7%b8%ec%8a%b5%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>처음엔 CronJob으로 셸이나 k6 스크립트를 돌려서 API를 호출하고, 응답 body를 &lt;code>jq&lt;/code>로 검증한 다음 결과를 Prometheus Pushgateway로 보내는 걸 생각했습니다.&lt;/p>
&lt;p>그런데 만들다 보니 좀 걸렸습니다. &amp;ldquo;데이터가 신선한가&amp;quot;를 판단하는 기준은 결국 비즈니스 로직인데, 그걸 외부 스크립트에 두면 백엔드 코드랑 따로 놀게 됩니다. 그래서 방향을 바꿨습니다. 백엔드가 직접 자기 데이터 신선도를 판단하는 health 엔드포인트를 하나 열고, Blackbox exporter가 그걸 주기적으로 찔러보게 했습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
graph LR
BB[&amp;#34;Blackbox Exporter&amp;lt;br/&amp;gt;주기적 probe&amp;#34;] --&amp;gt;|GET| EP[&amp;#34;/real-price/synthetic/health&amp;lt;br/&amp;gt;(백엔드가 데이터 신선도 판정)&amp;#34;]
EP --&amp;gt;|&amp;#34;FRESH → 200&amp;lt;br/&amp;gt;STALE → 503&amp;#34;| BB
BB --&amp;gt;|&amp;#34;probe_success&amp;lt;br/&amp;gt;probe_duration_seconds&amp;#34;| Prom[&amp;#34;Prometheus&amp;#34;]
Prom --&amp;gt; Graf[&amp;#34;Grafana&amp;lt;br/&amp;gt;SLO 패널 + Alert&amp;#34;]
style EP fill:#1f6feb,color:#fff
style BB fill:#238636,color:#fff
&lt;/pre>&lt;p>&lt;code>/synthetic/health&lt;/code>는 안에서 &amp;ldquo;이번 달 데이터에 최근 거래가 들어있나&amp;rdquo; 같은 걸 검사해서 FRESH/STALE을 내려줍니다. Blackbox exporter는 그걸 찔러보면서 &lt;code>probe_success&lt;/code>(1=정상, 0=stale 또는 down)랑 &lt;code>probe_duration_seconds&lt;/code>를 Prometheus에 남깁니다. 이렇게 하니 검증 로직은 도메인 코드 안에 있고, 인프라는 그냥 찔러보고 결과만 기록하는 단순한 역할만 하게 됐습니다. 처음 생각했던 것보다 훨씬 깔끔해졌습니다.&lt;/p>
&lt;p>그리고 이 &lt;code>probe_success&lt;/code>로 비즈니스 관점의 SLO 패널도 만들었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-promql" data-lang="promql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 실거래가 데이터 가용성 (30일 롤링)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kr">avg_over_time&lt;/span>&lt;span class="o">(&lt;/span>&lt;span class="nv">probe_success&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s">30d&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="o">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">100&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/ooq0pn5wowvjwb7tzkuiv/Synthetic-Monitoring-dashboard.png?rlkey=h115utowtpaiokyjdxjr1q048&amp;amp;st=9v3zvx79&amp;amp;raw=1" alt="Synthetic-Monitoring-SLO-패널" loading="lazy" />&lt;/p>
&lt;p>이제 &lt;code>probe_success&lt;/code>가 0으로 떨어지면, RED 대시보드는 멀쩡해도 데이터가 묵었다는 걸 알 수 있게 됐습니다. 다만 지금은 &lt;code>probe_success=0&lt;/code>이 &amp;ldquo;다운&amp;quot;이랑 &amp;ldquo;stale&amp;quot;을 같이 묶고 있어서, 대응이 다른 둘을 &lt;code>probe_http_status_code&lt;/code>로 나누는 건 다음 숙제로 남겨뒀습니다.&lt;/p>
&lt;h2>배포 판단을 사람 머릿속에만 두지 않기로 했습니다&lt;span class="hx:absolute hx:-mt-20" id="배포-판단을-사람-머릿속에만-두지-않기로-했습니다">&lt;/span>
&lt;a href="#%eb%b0%b0%ed%8f%ac-%ed%8c%90%eb%8b%a8%ec%9d%84-%ec%82%ac%eb%9e%8c-%eb%a8%b8%eb%a6%bf%ec%86%8d%ec%97%90%eb%a7%8c-%eb%91%90%ec%a7%80-%ec%95%8a%ea%b8%b0%eb%a1%9c-%ed%96%88%ec%8a%b5%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>여기까지 오니 &amp;ldquo;약속을 정하고 재는&amp;rdquo; 건 어느 정도 됐습니다. 그런데 글 앞에서 말한 두 번째 문제, &amp;ldquo;지금 배포해도 되나?&amp;ldquo;는 여전히 사람 판단에만 기대고 있었습니다. 앞에서 말했듯 breaking change 여부나 사용자 영향도는 보고 결정했지만, 그건 어디까지나 사람이 그때그때 챙기는 것이었습니다.&lt;/p>
&lt;p>제 경험상 서비스가 크게 흔들리는 건 대개 새로 뭔가 배포한 직후였습니다. 그래서 약속이 위태로울 땐 배포를 잠깐 멈출 수 있으면 좋겠다 싶었는데, 사람이 챙기는 판단은 새벽에 배포 누르는 사람이 깜빡하거나 상태를 잘못 읽으면 그냥 뚫려버리더라구요.&lt;/p>
&lt;p>그래서 이 부분도 사람 판단에만 맡기지 말고, 데이터로 한 번 더 걸러줄 방법이 없을까 찾아봤는데, 선택지가 몇 개 있었습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>방법&lt;/th>
&lt;th>장점&lt;/th>
&lt;th>단점&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Pre-deployment Check&lt;/strong>&lt;/td>
&lt;td>단순, ArgoCD에 그냥 붙일 수 있음&lt;/td>
&lt;td>Canary처럼 점진 노출은 아님&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Argo Rollouts (Canary)&lt;/td>
&lt;td>자동 롤백, 점진 노출&lt;/td>
&lt;td>도입·운영 부담이 큼&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Lockdown Mode&lt;/td>
&lt;td>가장 강력&lt;/td>
&lt;td>조직적 합의가 필요&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>사람이 그때그때 판단 (지금)&lt;/td>
&lt;td>단순, 맥락 반영 잘됨&lt;/td>
&lt;td>새벽·주말·놓침엔 보호 안 됨&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Argo Rollouts의 Canary가 제일 좋아 보이긴 했습니다. 트래픽을 조금씩 흘려보다가 지표가 나빠지면 알아서 롤백해준다니까요. 그런데 우리 팀 규모에서 그걸 도입하고 계속 관리할 자신이 솔직히 없었습니다. 그래서 제일 가벼운 &lt;strong>Pre-deployment Check&lt;/strong>부터 해보기로 했습니다. 배포 직전에 지표 몇 개를 보고, 너무 안 좋으면 배포를 막는 겁니다.&lt;/p>
&lt;p>뭘 볼지는 이렇게 잡았습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>볼 지표&lt;/th>
&lt;th>기준(초안)&lt;/th>
&lt;th>윈도우&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>5xx 비율&lt;/td>
&lt;td>&amp;lt; 0.5%&lt;/td>
&lt;td>최근 15분&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>P95 지연&lt;/td>
&lt;td>&amp;lt; 800ms&lt;/td>
&lt;td>최근 15분&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Error Budget 잔량&lt;/td>
&lt;td>&amp;gt; 10%&lt;/td>
&lt;td>30일&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>기준을 알림보다 살짝 느슨하게 잡았는데, 이건 &amp;ldquo;경고를 울릴 선&amp;quot;이 아니라 &amp;ldquo;이 정도면 배포해도 되는 선&amp;quot;이기 때문입니다. 너무 빡빡하게 잡으면 멀쩡한 배포까지 막혀서, 결국 다들 우회만 하게 될 것 같았거든요.&lt;/p>
&lt;p>붙이는 건 ArgoCD의 PreSync hook으로 했습니다. hook이 실패하면 sync 자체가 안 되니 배포가 자연스럽게 멈춥니다. 대신 진짜 급한 핫픽스를 위해 &lt;code>[skip-slo-check]&lt;/code> 같은 걸로 우회할 수 있게 하되, 우회하면 알림이 따로 가도록 해뒀습니다. 막을 순 없어도 조용히 넘어가진 않게 한 겁니다.&lt;/p>
&lt;p>솔직히 이 게이팅은 아직 제대로 자리 잡은 건 아닙니다. dev에서 돌려보면서 prod로 넓혀가는 중이고, 기준값도 실제 데이터를 보면서 계속 만져야 합니다. 그래도 &amp;ldquo;신뢰성 상태가 배포를 막을 수 있다&amp;quot;는 장치가 코드로 생겼다는 것 자체가, 사람 판단에만 기대던 때보단 한 걸음 나아간 것 같습니다.&lt;/p>
&lt;h2>그래서 뭐가 달라졌나&lt;span class="hx:absolute hx:-mt-20" id="그래서-뭐가-달라졌나">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%9e%98%ec%84%9c-%eb%ad%90%ea%b0%80-%eb%8b%ac%eb%9d%bc%ec%a1%8c%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이제는 false alarm이 신뢰성 지표를 안 건드리니 자연스럽게 걸러집니다. &amp;ldquo;ERROR 로그가 떴다&amp;quot;가 아니라 &amp;ldquo;5xx가 SLO를 깎고 있다&amp;quot;로 기준이 바뀌었거든요. 덕분에 알림이 다시 좀 믿을 만해졌습니다.&lt;/p>
&lt;p>또 &amp;ldquo;지금 괜찮은 거 맞아?&amp;ldquo;에 30일 잔여 Error Budget이라는 데이터로 답할 수 있게 됐습니다. 그리고 200 OK 뒤에 숨어 있던 데이터 묵음 문제를 잡을 수 있게 됐습니다.&lt;/p>
&lt;p>결국 배포 결정이 조금씩 사람의 판단에서 데이터를 기준으로 점점 넘어오기 시작했습니다.&lt;/p>
&lt;h2>하면서 느낀 것들&lt;span class="hx:absolute hx:-mt-20" id="하면서-느낀-것들">&lt;/span>
&lt;a href="#%ed%95%98%eb%a9%b4%ec%84%9c-%eb%8a%90%eb%82%80-%ea%b2%83%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>&lt;strong>뭘 성공으로 볼지부터 정하는 게 먼저였던 것 같습니다.&lt;/strong> false alarm의 진짜 문제는 알림 룰이 엉성한 게 아니라, 애초에 &amp;ldquo;신뢰가 깨진 상태&amp;quot;를 정의한 적이 없다는 것이었습니다. 정의가 없으니 뭘 알리고 뭘 무시할지 기준도 없었던 겁니다. SLI 한 줄을 정하고 나서야 그걸 가를 수 있었습니다.&lt;/p>
&lt;p>&lt;strong>어느 정도의 신뢰를 보장할 것이냐를 정하는 일도 똑같이 중요했습니다.&lt;/strong> 처음엔 99.9%냐 99.99%냐를 제가 정하지 못하는 게 답답했는데, 지금 생각하면 당연한 것이었습니다. 그건 &amp;ldquo;사용자한테 뭘 약속할 거냐&amp;quot;의 문제고, 그 비용을 누가 감당할지의 문제니까요. 엔지니어가 혼자 99.99%를 외쳐봐야 지킬 여력이 없으면 의미가 없으니까요.&lt;/p>
&lt;p>&lt;strong>작은 팀이라 다 갖추기보다 제일 급한 것부터 했습니다.&lt;/strong> Argo Rollouts 같은 게 자꾸 눈에 밟혔는데, 멋지다고 다 들고 오는 게 능사는 아니었습니다. 우리 규모에서 지금 신뢰를 제일 위협하는 게 뭔지부터 보고, 거기에 제일 가벼운 방법을 붙이는 게 맞았던 것 같습니다.&lt;/p>
&lt;h2>마치며&lt;span class="hx:absolute hx:-mt-20" id="마치며">&lt;/span>
&lt;a href="#%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>쭉 적고 보니 여기서 쓴 것들 — SLI, SLO, Error Budget, Synthetic Monitoring, 배포 게이팅 — 은 다 SRE 하는 분들한텐 익숙한 것들일 겁니다. 저는 &amp;ldquo;신뢰성을 어떻게 지키지&amp;quot;라는 막연한 고민을 들고 이것저것 찾아보다가, 우리 상황에 맞게 하나씩 가져다 붙여본 정도죠.&lt;/p>
&lt;p>아직 못 한 것도 많다고 생각합니다. burn rate 기반 multi-window 알림, 전 서비스를 한눈에 보는 SLO Overview, &lt;code>probe_success&lt;/code>의 stale/down 분리, 매물 검색·채팅 같은 다른 핵심 경로의 synthetic probe, 배포 게이팅 prod 적용, 그리고 언젠가 Argo Rollouts까지. SLO 목표값도 아직 비즈니스적으로 합의가 필요하죠.&lt;/p>
&lt;p>그래서 &amp;ldquo;신뢰성을 다 갖췄다&amp;quot;고는 하지 못할 것 같습니다. 애초에 &lt;a href="https://jeongil.dev/ko/blog/backend/performance/backend-api-performance-optimization/">성능&lt;/a>처럼 신뢰성도 한 번 끝내면 되는 게 아니라 계속 지켜야 유지되는 것 같습니다.&lt;/p>
&lt;p>혹시 모니터링은 어느 정도 해놨는데 &amp;ldquo;그래서 우리 서비스 괜찮은 거 맞아?&amp;ldquo;에 시원하게 답이 안 나오는 분이 계실지도 모르겠습니다. 그렇다면 거창한 도구를 더 들이기 전에, &amp;ldquo;우리가 사용자한테 뭘 약속하는가&amp;quot;를 한 문장으로 — 그러니까 SLI 한 줄로 — 적어보는 것부터 시작해봐도 좋지 않을까 싶습니다. 저한테는 그게 출발점이었거든요.&lt;/p>
&lt;p>긴 글 읽어주셔서 감사합니다.&lt;/p>
&lt;h2>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>관련 글&lt;span class="hx:absolute hx:-mt-20" id="관련-글">&lt;/span>
&lt;a href="#%ea%b4%80%eb%a0%a8-%ea%b8%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/infrastructure/building-a-monitoring-system/">서비스 장애는 사용자가 알려주지 않아도 알아야한다 — 사내 모니터링 시스템 구축기&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/backend/performance/backend-api-performance-optimization/">API 성능 P95 7초 → 0.1초 백엔드 성능 최적화 — 느린 곳을 찾는 게 고치는 것보다 어려웠다&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>SRE / SLO&lt;span class="hx:absolute hx:-mt-20" id="sre--slo">&lt;/span>
&lt;a href="#sre--slo" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://sre.google/sre-book/service-level-objectives/"target="_blank" rel="noopener">Google SRE Book — Service Level Objectives&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> — SLI/SLO/Error Budget의 출발점&lt;/li>
&lt;li>&lt;a href="https://sre.google/workbook/alerting-on-slos/"target="_blank" rel="noopener">Google SRE Workbook — Alerting on SLOs&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> — Burn rate 기반 multi-window 알림&lt;/li>
&lt;li>&lt;a href="https://grafana.com/blog/2018/08/02/the-red-method-how-to-instrument-your-services/"target="_blank" rel="noopener">The RED Method (Tom Wilkie)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> — Rate / Errors / Duration&lt;/li>
&lt;/ul>
&lt;h3>도구&lt;span class="hx:absolute hx:-mt-20" id="도구">&lt;/span>
&lt;a href="#%eb%8f%84%ea%b5%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://github.com/prometheus/blackbox_exporter"target="_blank" rel="noopener">Prometheus Blackbox Exporter&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> — 엔드포인트 probe 기반 합성 모니터링&lt;/li>
&lt;li>&lt;a href="https://argo-cd.readthedocs.io/en/stable/user-guide/resource_hooks/"target="_blank" rel="noopener">Argo CD — Resource Hooks&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> — PreSync hook을 이용한 배포 게이팅&lt;/li>
&lt;li>&lt;a href="https://argo-rollouts.readthedocs.io/en/stable/features/analysis/"target="_blank" rel="noopener">Argo Rollouts — Analysis &amp;amp; Canary&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> — 다음 단계 후보로 검토 중인 점진 배포&lt;/li>
&lt;/ul></description></item><item><title>ISTQB CTFL (Certified Tester Foundation Level) 합격 후기</title><link>https://jeongil.dev/ko/blog/reflection/istqb-ctfl/</link><pubDate>Wed, 29 Apr 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/reflection/istqb-ctfl/</guid><description>
&lt;h2>들어가며&lt;span class="hx:absolute hx:-mt-20" id="들어가며">&lt;/span>
&lt;a href="#%eb%93%a4%ec%96%b4%ea%b0%80%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>안녕하세요. 저는 백엔드 개발자로 일하고 있는 3년차 개발자 정정일입니다.&lt;/p>
&lt;p>이번에 &lt;strong>ISTQB Certified Tester Foundation Level (CTFL)&lt;/strong> 자격증을 취득하게 됐는데, 이에 대한 후기를 공유드리고자 합니다.&lt;/p>
&lt;p>ISTQB는 International Software Testing Qualifications Board의 약자로, 소프트웨어 테스팅 분야에서 국제적으로 가장 널리 인정받는 자격증 중 하나입니다. CTFL은 그 중에서도 Foundation Level, 가장 기초 단계에 해당하는 자격증입니다.&lt;/p>
&lt;h2>왜 CTFL을 응시하게 됐나요?&lt;span class="hx:absolute hx:-mt-20" id="왜-ctfl을-응시하게-됐나요">&lt;/span>
&lt;a href="#%ec%99%9c-ctfl%ec%9d%84-%ec%9d%91%ec%8b%9c%ed%95%98%ea%b2%8c-%eb%90%90%eb%82%98%ec%9a%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>사실 CTFL을 응시하게 된 계기는 거창하지 않습니다.&lt;/p>
&lt;p>백엔드 개발을 하다 보면 자연스럽게 테스트 코드를 작성하게 됩니다. 근데 돌이켜보면 저는 테스트를 오랫동안 그냥 &amp;ldquo;코드가 잘 돌아가는지 확인하는 것, 비즈니스 로직을 정확히 수행하는가 확인하는&amp;rdquo; 정도로만 생각했던 것 같습니다. 어떤 기법이 있는지, 어떤 기준으로 테스트를 설계해야 하는지 같은 체계적인 고민은 별로 해본 적이 없었거든요.&lt;/p>
&lt;p>그러다 보니 테스트 코드를 짤 때도 감에 의존하는 경우가 많았습니다. &amp;ldquo;이 정도면 충분하지 않을까?&amp;ldquo;라는 식으로요. 그게 좀 찜찜하기도 했고, 테스팅이라는 분야 자체를 한번쯤 제대로 공부해보고 싶다는 생각이 들었습니다.&lt;/p>
&lt;p>여기에 더해 나중에 DevOps로 직무 전환을 하고싶다는 생각도 있었습니다. DevOps 업무 중에는 테스트 자동화 파이프라인을 구축하는 일도 있다 보니, 테스팅을 체계적으로 이해해두면 도움이 될 것 같았거든요. 또 ISTQB에는 CTFL 이후로 더 세분화된 전문 자격증들도 있어서, 나중에 Certified Tester Automotive Software Tester (CT-AuT) 같은 자격증에도 도전해볼 생각이 있기도 합니다.&lt;/p>
&lt;p>마침 테스트 관련 자격증을 찾아보다 ISTQB CTFL을 알게 됐고, 입문 단계라 테스팅의 기초 개념들을 정리하기 좋을 것 같다는 생각에 응시하게 됐습니다. 개발 지식이 어느 정도 있었기 때문에 준비 기간이 길지 않아도 될 것 같았고, 고민은 길지 않았습니다.&lt;/p>
&lt;h2>시험 응시 및 준비&lt;span class="hx:absolute hx:-mt-20" id="시험-응시-및-준비">&lt;/span>
&lt;a href="#%ec%8b%9c%ed%97%98-%ec%9d%91%ec%8b%9c-%eb%b0%8f-%ec%a4%80%eb%b9%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>CTFL 시험은 국제자격증이라 국가마다 다르지만 한국에선 한국소프트웨어테스팅자격위원회(KSTQB)에서 주관하며, 정기적으로 지정된 오프라인 시험장에서 응시하는 방식입니다. 저는 스페이스쉐어 삼성역센터(서울 강남구 영동대로96길 20, 대화빌딩 지하 1층)에서 응시했습니다. 종이 시험지에 컴퓨터용 수성 사인펜으로 OMR 답안을 마킹하는 방식이고, 총 40문항이며 한국어로 응시하면 60분, 영어로 응시하면 75분이 주어집니다. 합격 기준은 65% 이상, 즉 26문항 이상 맞춰야 합격입니다.&lt;/p>
&lt;p>저는 약 &lt;strong>4~5일&lt;/strong> 정도 준비했습니다. 개발 경험이 있다 보니 테스팅 개념 자체가 아예 낯설지는 않았고, 그 덕분에 비교적 짧은 기간에 준비할 수 있었던 것 같습니다.&lt;/p>
&lt;p>사실 시험 범위나 준비 방법은 다른 분들이 잘 정리해두신 글이 많기 때문에, 저는 제가 활용한 자료 위주로만 공유드리겠습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>실버너스 PDF 자료&lt;/strong>
&lt;ul>
&lt;li>CTFL 준비하시는 분들이라면 한번쯤 접해보셨을 자료입니다. 시험 범위를 체계적으로 정리해줘서 개념 잡는 데 많은 도움이 됐습니다.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>&lt;strong>KSTQB 공식 샘플 문제 A~D&lt;/strong>
&lt;ul>
&lt;li>KSTQB 공식 홈페이지에서 PDF로 다운로드할 수 있습니다. 각 세트를 못해도 3번씩은 풀어본 것 같습니다. 문제 유형을 파악하는 데 있어 가장 핵심적인 자료였습니다.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h2>시험 결과 및 솔직한 후기&lt;span class="hx:absolute hx:-mt-20" id="시험-결과-및-솔직한-후기">&lt;/span>
&lt;a href="#%ec%8b%9c%ed%97%98-%ea%b2%b0%ea%b3%bc-%eb%b0%8f-%ec%86%94%ec%a7%81%ed%95%9c-%ed%9b%84%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>결과부터 말씀드리면 &lt;strong>75점으로 합격&lt;/strong>했습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/ii5oyp16yxpvvk777m8qw/istqb-ctfl-score.png?rlkey=ohxutdo4non0g2ka22kqtl0m6&amp;amp;st=c9be0nqp&amp;amp;raw=1" alt="istqb-ctfl-score" loading="lazy" />&lt;/p>
&lt;p>시험을 보면서 가장 먼저 든 생각은 &lt;strong>&amp;ldquo;샘플 문제보다 실전이 좀더 어렵다&amp;rdquo;&lt;/strong> 는 것이었습니다. 다른 후기 글들을 보면 샘플 문제 대비 약 1.5배 정도 어렵다고들 하시던데, 저도 그 말에 동의하는 편입니다.&lt;/p>
&lt;p>그렇다고 내용 자체가 어렵냐고 하면, 그건 또 아닌 것 같습니다. 개념 자체는 크게 어렵지 않아요. 문제가 &lt;strong>헷갈리게 나오는 경향&lt;/strong>이 있습니다. 선택지들이 두개 이상은 맞는 말처럼 보이도록 교묘하게 구성되어 있어서, 개념을 정확히 이해하고 있지 않으면 비슷한 보기들 사이에서 헤매게 되더라구요.&lt;/p>
&lt;p>샘플 문제를 여러 번 반복해서 풀다 보면 어느 정도 패턴이 보이긴 합니다만, 실전에서는 그 패턴이 살짝 비틀려서 나오기 때문에 결국 개념을 제대로 이해하고 있어야 정확히 풀 수 있는 구조인 것 같습니다.&lt;/p>
&lt;h2>그래서 CTFL 추천 하나요?&lt;span class="hx:absolute hx:-mt-20" id="그래서-ctfl-추천-하나요">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%9e%98%ec%84%9c-ctfl-%ec%b6%94%ec%b2%9c-%ed%95%98%eb%82%98%ec%9a%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>솔직하게 말씀드리면, &lt;strong>QA 직무를 희망하시는 분이 아니라면 굳이 취득하실 필요는 없을 것 같습니다.&lt;/strong>&lt;/p>
&lt;p>이유는 두 가지입니다.&lt;/p>
&lt;p>첫번째는 &lt;strong>가격&lt;/strong>입니다. 응시료가 198,000원으로 20만원에 육박합니다. 커리어에 명확하게 기여하는 자격증이라면 모를까, 개발 직군에서 CTFL이 채용 시장에서 얼마나 유의미하게 평가받을지는 솔직히 잘 모르겠습니다. 아마 크지 않을 것 같다는 게 개인적인 생각입니다.&lt;/p>
&lt;p>두번째는 &lt;strong>직무 관련성&lt;/strong>입니다. QA 직무를 하시는 분들이라면 이 자격증이 분명 의미 있을 것입니다. 하지만 다른 개발 직군에 계신 분들께는 포지션이 좀 애매하게 느껴지더라구요.&lt;/p>
&lt;p>저처럼 테스팅을 체계적으로 공부하고 싶어서 응시하신다면, 자격증 준비 과정에서 테스팅에 대한 관점을 정리하는 데 도움이 되긴 합니다. 다만 그 목적이라면 굳이 20만원을 쓰지 않아도 실버너스 자료나 공식 실라버스를 읽어보는 것으로도 충분하지 않을까 싶기도 합니다. ㅎㅎ&lt;/p>
&lt;h2>마치며&lt;span class="hx:absolute hx:-mt-20" id="마치며">&lt;/span>
&lt;a href="#%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이상으로 ISTQB CTFL 자격증 취득 후기를 공유드렸습니다.&lt;/p>
&lt;p>75점 합격이라는 결과보다, 테스팅을 하나의 전문적인 영역으로 바라보게 됐다는 관점 변화가 개인적으로는 더 의미있었던 것 같습니다.&lt;/p>
&lt;p>다만 QA 직무가 아니신 분들께는 선뜻 추천하기 어렵다고 생각합니다. 개발자로써는 비용 대비 실용성을 따졌을 때 아쉬움이 남는 자격증이라는 게 솔직한 저의 결론입니다. 나중에 DevOps로 직무를 전환할때 CI/CD 단계에서 테스트 자동화 파이프라인 구축 업무가 생긴다면, Certified Tester Automotive Software Tester (CT-AuT)는 도움이 될 수도 있겠다는 생각이 들긴 합니다만, 그때 가서 고민해봐야 할 것 같습니다.&lt;/p>
&lt;p>긴 글 읽어주셔서 감사합니다!&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/i4mclsa0qlhsfin3cqan5/istqb-ctfl.jpg?rlkey=2rns0bvnkmhge1qzvzot9pecq&amp;amp;st=cn4hs20y&amp;amp;raw=1" alt="istqb-ctfl-certificate" loading="lazy" />&lt;/p></description></item><item><title>AI 부동산 매물 추천 시스템 구축기 - '강남역 근처 30평대 신축 아파트 추천해줘'를 처리하는 서비스를 만들기까지</title><link>https://jeongil.dev/ko/blog/architecture/ai-property-recommendation-system/</link><pubDate>Wed, 25 Mar 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/architecture/ai-property-recommendation-system/</guid><description>
&lt;p>안녕하세요. 프롭테크 플랫폼에서 백엔드 개발을 하고 있는 정정일입니다.&lt;/p>
&lt;p>최근 많은 회사들이 AI를 서비스에 어떻게 녹여내 유의미한 가치를 제공할 수 있을지 고민하고 계시는 것 같습니다.&lt;/p>
&lt;p>저희 회사도 마찬가지입니다. 어떻게 하면 AI를 활용해서 사용자분들께 더 나은 경험을 제공할 수 있을까 고민을 꾸준히 해왔습니다.&lt;/p>
&lt;p>그 과정에서 아무래도 부동산 도메인이다 보니 자연어로 부동산 매물을 추천하는 AI 기능을 만들게 되었습니다.&lt;/p>
&lt;p>사용자가 자연어로 조건을 입력하면 조건에 맞는 아파트를 추천해주는 기능인데 서비스 하는 모습은 아래와 같습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/9x56dxoydvfonon6vr7au/ai-estate-result-5.png?rlkey=jp0ayi58mvtr0t68d928qokrt&amp;amp;st=gpe4xoql&amp;amp;raw=1" alt="“송도역 혹은 상동역 근처에 30평대 10억 이하로 살 수 있는 500세대 이상 신축 아파트 찾아 줘”" loading="lazy" />&lt;/p>
&lt;p>이번 글에서는 어떻게 이 기능을 만들었는 지 그리고 기능을 만들면서 겪었던 기술적 챌린지들과 그 과정에서 했던 고민들을 정리해보려 합니다.&lt;/p>
&lt;h2>처음에는 고정 파이프라인 RAG였다&lt;span class="hx:absolute hx:-mt-20" id="처음에는-고정-파이프라인-rag였다">&lt;/span>
&lt;a href="#%ec%b2%98%ec%9d%8c%ec%97%90%eb%8a%94-%ea%b3%a0%ec%a0%95-%ed%8c%8c%ec%9d%b4%ed%94%84%eb%9d%bc%ec%9d%b8-rag%ec%98%80%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>저희 회사 AI 서비스는 기존 제가 팀에 합류했던 시점의 구조는 전형적인 RAG 파이프라인이었습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
Q[&amp;#34;사용자 질문&amp;#34;] --&amp;gt; QC[&amp;#34;QuestionClassifier\n(LLM 1회)&amp;#34;]
QC --&amp;gt;|Strategy 분기| CE[&amp;#34;ConditionExtractor\n(LLM 1회)&amp;#34;]
CE --&amp;gt; ES[&amp;#34;ES 검색&amp;#34;]
ES --&amp;gt; RG[&amp;#34;ResponseGenerator\n(LLM 1회)&amp;#34;]
RG --&amp;gt; A[&amp;#34;스트리밍 응답&amp;#34;]
&lt;/pre>&lt;p>사용자의 질문이 들어오면 &lt;code>QuestionClassifier&lt;/code>가 의도를 분류하고, Strategy 패턴으로 분기한 뒤, &lt;code>ConditionExtractor&lt;/code>가 검색 조건을 추출하고, Elasticsearch로 검색한 결과를 &lt;code>ResponseGenerator&lt;/code>가 자연어로 응답하는 구조였습니다. LLM을 총 3번 호출하는 구조였죠.&lt;/p>
&lt;p>이 구조로 어느 정도는 동작했습니다. 다만 운영하다 보니 몇가지 한계점을 맞이하게 됐습니다. 우선 기존의 RAG 구조에서 Vector DB에 있는 문서들은 부동산과 관련된 단순 법적 자료들 뿐이였습니다.&lt;/p>
&lt;p>그렇기 때문에 이번에 개발하려는 &amp;ldquo;송도역 근처에 30평대 10억 이하로 살 수 있는 500세대 이상 신축 아파트 찾아 줘&amp;quot;와 같은 질문을 처리하지는 못했습니다. 이런경우 LLM에 전적으로 의존해서 단순 응답을 기대하게 되는데 이럴경우 두가지 문제가 생기게 되죠.&lt;/p>
&lt;p>플랫폼에서 제공하는 LLM (ex.gpt 모델, gemini 모델)들이 송도역 근처라는 지역적 정보, 30평대라는 평형 정보, 10억 이하라는 가격 정보, 500세대 이상이라는 세대수 정보, 신축 아파트라는 조건을 정확히 이해하고 그에 맞는 응답을 생성하는 건 기대하기 어려웠습니다. LLM이 부동산 도메인에 대한 충분한 지식을 가지고 있지 않거나, 지식이 있더라도 그 지식을 정확히 활용해서 응답을 생성하는 건 또 다른 문제였죠.&lt;/p>
&lt;p>또 설령 LLM에 모든걸 의지해서 응답을 생성한다 하더라도 해당하는 아파트 정보와 우리 서비스를 이어 해당 부동산 매물 상세조회로 연결하는 것도 어려운 문제였습니다. LLM이 &amp;ldquo;송도역 근처에 30평대 10억 이하로 살 수 있는 500세대 이상 신축 아파트&amp;quot;라는 조건을 이해해서 응답을 생성하더라도, 그 응답이 실제로 우리 서비스의 매물 상세조회로 연결되는 형태가 되도록 하는 건 또 다른 문제였죠.&lt;/p>
&lt;p>그리고 가장 큰 문제는 &lt;strong>파이프라인이 고정되어 있다는 점&lt;/strong>이었습니다. LLM이 도구를 선택하는 구조가 아닌 시스템에서 LLM을 고정적으로 호출해 추론이 필요한 영역 혹은 응답이 필요한 영역에만 개입하는 구조였기 때문에, &amp;ldquo;강남역이랑 신림역 사이 아파트 찾아줘&amp;quot;와 같은 복합 질문에는 대응이 안 됐습니다.&lt;/p>
&lt;p>이런 질문을 처리하려면 &amp;ldquo;강남역 좌표를 찾고, 신림역 좌표를 찾고, 두 좌표의 중간점을 계산하고, 그 중간점 주변을 검색한다&amp;quot;는 여러 단계의 조합이 필요한데, 고정 파이프라인에서는 이 흐름을 전략 하나하나 따로 구현해주거나 해야하는데 이는 분명한 한계였죠.&lt;/p>
&lt;h2>Agent Loop vs Planned Tool Use — 무엇을 선택할 것인가&lt;span class="hx:absolute hx:-mt-20" id="agent-loop-vs-planned-tool-use--무엇을-선택할-것인가">&lt;/span>
&lt;a href="#agent-loop-vs-planned-tool-use--%eb%ac%b4%ec%97%87%ec%9d%84-%ec%84%a0%ed%83%9d%ed%95%a0-%ea%b2%83%ec%9d%b8%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>그렇기 때문에 파이프라인의 한계를 느끼고 나서 구조를 바꿔야겠다고 생각했습니다. 고정 파이프라인을 없애고 LLM이 도구를 선택하고 실행하는 구조로 바꿔야겠다고 생각했죠. 그런데 이때 두 가지 방식 사이에서 고민이 생겼습니다.&lt;/p>
&lt;h3>Full Agent Loop&lt;span class="hx:absolute hx:-mt-20" id="full-agent-loop">&lt;/span>
&lt;a href="#full-agent-loop" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>첫 번째는 요즘 많이 이야기되는 &lt;strong>Agent Loop&lt;/strong> 방식입니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
Q[&amp;#34;사용자 질문&amp;#34;] --&amp;gt; LLM[&amp;#34;LLM&amp;#34;]
LLM --&amp;gt;|tool 선택| T[&amp;#34;Tool 실행&amp;#34;]
T --&amp;gt;|결과 관찰| LLM
LLM --&amp;gt;|완료 판단| A[&amp;#34;응답&amp;#34;]
&lt;/pre>&lt;p>LLM이 도구를 실행하고, 결과를 관찰하고, 다음 action을 결정하고, 다시 도구를 실행하고&amp;hellip; 이 루프를 LLM이 &amp;ldquo;충분하다&amp;quot;고 판단할 때까지 반복하는 방식이죠.&lt;/p>
&lt;p>구체적으로 &amp;ldquo;강남역 근처 30평대 아파트&amp;quot;를 Agent Loop로 처리한다고 가정하면 이런 흐름이 됩니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>[LLM 1회] &amp;#34;강남역 좌표를 찾아야겠다&amp;#34; → poi_search(&amp;#34;강남역&amp;#34;) 실행
[LLM 2회] 결과 관찰: {lat: 37.49, lon: 127.02} → &amp;#34;이 좌표로 검색하자&amp;#34; → property_search 실행
[LLM 3회] 결과 관찰: 아파트 15개 → &amp;#34;결과가 있으니 응답하자&amp;#34; → 응답 생성&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>LLM이 3번 호출됩니다. 그런데 같은 질문이라도 LLM이 다른 판단을 내릴 수 있습니다. &amp;ldquo;결과가 너무 많으니 조건을 좁혀보자&amp;quot;고 판단해서 한 번 더 검색할 수도 있고, &amp;ldquo;결과가 적으니 반경을 넓혀보자&amp;quot;고 추가 루프를 돌 수도 있습니다. 루프 횟수를 예측할 수 없다는 건 곧 응답 시간과 비용을 통제할 수 없다는 뜻이기도 합니다.&lt;/p>
&lt;p>LLM을 호출할수록 레이턴시가 생기는건 어쩔 수 없으니까요.&lt;/p>
&lt;h3>Planned Tool Use&lt;span class="hx:absolute hx:-mt-20" id="planned-tool-use">&lt;/span>
&lt;a href="#planned-tool-use" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>두 번째는 &lt;strong>Planned Tool Use&lt;/strong> 방식입니다. Anthropic의 &lt;a href="https://www.anthropic.com/engineering/building-effective-agents"target="_blank" rel="noopener">&amp;ldquo;Building Effective Agents&amp;rdquo;&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> 가이드에서 영감을 받았는데, 핵심은 &lt;strong>&amp;ldquo;minimum autonomy&amp;rdquo;&lt;/strong> 라는 원칙이었습니다. 필요한 최소한의 자율성만 부여한다는 거죠.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
Q[&amp;#34;사용자 질문&amp;#34;] --&amp;gt; P[&amp;#34;Plan\n(LLM 1회)&amp;#34;]
P --&amp;gt;|DAG 생성| E[&amp;#34;Execute\n(코드가 실행)&amp;#34;]
E --&amp;gt; G[&amp;#34;Generate\n(LLM 1회)&amp;#34;]
G --&amp;gt; A[&amp;#34;스트리밍 응답&amp;#34;]
&lt;/pre>&lt;p>LLM이 한 번에 전체 실행 계획을 생성하고, 코드가 그 계획을 확정적으로 실행하는 방식입니다. 같은 &amp;ldquo;강남역 근처 30평대 아파트&amp;quot;를 처리하면&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>[LLM 1회] Plan: &amp;#34;poi_search(강남역) → 그 좌표로 property_search&amp;#34; (DAG 한 번에 생성)
[코드] DAG 실행: poi_search → property_search (LLM 개입 없이 코드가 실행)
[LLM 1회] Generate: 결과 기반 응답 생성&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>LLM은 2번만 호출됩니다. 그리고 저희가 제어하기 때문에 항상 2번을 보장하게 됩니다. 같은 질문에 대해 루프 횟수가 달라지는 일이 없죠.&lt;/p>
&lt;h3>왜 Agent Loop를 선택하지 않았나&lt;span class="hx:absolute hx:-mt-20" id="왜-agent-loop를-선택하지-않았나">&lt;/span>
&lt;a href="#%ec%99%9c-agent-loop%eb%a5%bc-%ec%84%a0%ed%83%9d%ed%95%98%ec%a7%80-%ec%95%8a%ec%95%98%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>저는 결국 Planned Tool Use를 선택했습니다.&lt;/p>
&lt;p>사용자가 &amp;ldquo;강남역 근처 30평대 아파트&amp;quot;라고 했을 때, 필요한 도구와 순서는 거의 정해져 있다고 판단했거든요. 강남역 좌표를 찾고, 그 좌표 주변을 조건에 맞게 검색하면 됩니다. LLM이 매 단계마다 &amp;ldquo;다음에 뭘 할까&amp;quot;를 고민할 필요가 적은 도메인이었습니다.&lt;/p>
&lt;p>저는 Agent Loop가 강력한 건 &lt;strong>도구 실행 결과를 보고 판단을 바꿔야 하는 경우&lt;/strong>라고 생각합니다. 예를 들어 코드를 생성하는 AI라면 &amp;ldquo;컴파일 에러가 나니까 코드를 수정하자&amp;quot;처럼 결과에 따라 다음 행동이 달라져야 하죠. 하지만 부동산 검색은 그렇지 않았습니다. &amp;ldquo;강남역 좌표를 찾았는데, 이 좌표가 마음에 안 드니까 다른 좌표를 찾아보자&amp;quot;라는 상황이 생기진 않으니까요.&lt;/p>
&lt;p>부동산 매물 검색이라는 도메인 특성상, &lt;strong>한 번 계획하면 실행은 확정적인 경우가 대부분&lt;/strong>이었습니다. 그래서 Agent의 유연성보다는 Planned Tool Use의 예측 가능성이 더 중요하다고 판단했습니다.&lt;/p>
&lt;p>물론 이건 저희 도메인에 조금 더 알맞는 선택이었을 뿐이라고 생각합니다. &amp;ldquo;minimum autonomy&amp;rdquo; 원칙이 말하는 것도 결국 &lt;strong>도메인에 맞는 최소한의 자율성&lt;/strong>이니까요. 도메인 특성을 무시하고 Agent가 좋다, Planned Tool Use가 좋다고 말하는 건 의미가 없다고 생각합니다.&lt;/p>
&lt;p>또 레이턴스를 줄일 수 있다는 점도 중요했습니다. Agent Loop는 루프가 길어질수록 레이턴스가 늘어나는데, Planned Tool Use는 어느정도 일정한 레이턴스를 보장할 수 있다고 생각했습니다.&lt;/p>
&lt;p>사용자께 되도록 빠르게 응답하는 게 중요하다고 생각했기 때문에 이런 점도 고려해서 Planned Tool Use를 선택하게 됐습니다.&lt;/p>
&lt;h2>자연어를 구조화된 파라미터로 바꾸는 법&lt;span class="hx:absolute hx:-mt-20" id="자연어를-구조화된-파라미터로-바꾸는-법">&lt;/span>
&lt;a href="#%ec%9e%90%ec%97%b0%ec%96%b4%eb%a5%bc-%ea%b5%ac%ec%a1%b0%ed%99%94%eb%90%9c-%ed%8c%8c%eb%9d%bc%eb%af%b8%ed%84%b0%eb%a1%9c-%eb%b0%94%ea%be%b8%eb%8a%94-%eb%b2%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/aekyf0455h29pcw6g75rg/ai-estate-result-4.png?rlkey=gnn22ya2bqb3mt7xl5350ayru&amp;amp;st=osy64mzz&amp;amp;raw=1" alt="자연어 입력 모달 — 사용자는 이 화면에서 자연어로 조건을 입력합니다" loading="lazy" />&lt;/p>
&lt;p>Planned Tool Use 구조에서 가장 도메인 지식이 많이 녹아드는 부분은 &lt;strong>Plan 프롬프트&lt;/strong>라고 생각합니다. LLM이 사용자의 자연어를 이해하고 구조화된 실행 계획으로 변환해야 하는데, 이 변환 규칙을 어떻게 정의하느냐가 추천 품질에 직접적인 영향을 미치게 됩니다.&lt;/p>
&lt;p>예를 들어 사용자가 &amp;ldquo;5억대 아파트&amp;quot;라고 했을 때, 이걸 어떻게 파라미터로 바꿔야 할까요?&lt;/p>
&lt;p>&amp;ldquo;5억대&amp;quot;라는 표현은 한국어에서 5억&lt;del>5.9억을 의미합니다. 만원 단위로 환산하면 &lt;code>priceMin: 50000, priceMax: 59999&lt;/code>가 되죠. 그런데 &amp;ldquo;30억대&amp;quot;는 30억&lt;/del>39.9억입니다. 같은 &amp;ldquo;~대&amp;quot;라는 표현인데 자릿수에 따라 범위가 다릅니다.&lt;/p>
&lt;p>이런 변환 규칙들을 시스템 프롬프트에 명시적으로 정의해야 했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>## 가격 변환 규칙 (만원 단위):
- &amp;#34;5억대&amp;#34; → priceMin: 50000, priceMax: 59999 (5억~5.9억)
- &amp;#34;30억대&amp;#34; → priceMin: 300000, priceMax: 399999 (30억~39.9억)
- &amp;#34;2억~3억&amp;#34; → priceMin: 20000, priceMax: 30000
- &amp;#34;15억 정도&amp;#34; → priceMin: 135000, priceMax: 165000 (±10%)
- &amp;#34;30억 이하&amp;#34; → priceMin: null, priceMax: 300000
## 평형 변환 규칙:
- &amp;#34;30평대&amp;#34; → areaMin: 30, areaMax: 39
- &amp;#34;30평 정도&amp;#34; → areaMin: 27, areaMax: 33
- &amp;#34;30평&amp;#34; (정확히) → areaMin: 30, areaMax: 30&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>처음에는 이런 규칙들을 프롬프트에 넣지 않고 LLM이 알아서 변환하도록 했었습니다. 결과는 어렵지 않게 예상하실 수 있으실 것 같습니다. &amp;ldquo;5억대&amp;quot;를 5억&lt;del>9.9억으로 변환하는 경우도 있었고, &amp;ldquo;30평대&amp;quot;를 30&lt;/del>30으로 변환하기도 했습니다. LLM이 한국어 부동산 용어를 정확히 이해하지 못하는 거죠.&lt;/p>
&lt;p>결국 LLM이 한국어 자체를 못 이해하는 게 아니라, &amp;ldquo;5억대&amp;quot;가 정확히 어떤 범위인지를 사용자가 원하는 바를 정확하게 추론하지 못하는 경우들이 있었던 겁니다. 이런 부분은 프롬프트로 알려줘야 하는 영역이었죠.&lt;/p>
&lt;p>반면에 LLM의 추론 능력이 필요한 도메인 영역들도 있었습니다. 예를 들면 &lt;strong>가족 구성에 따라 평형을 추론하는 규칙&lt;/strong>이었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>## 평형/방갯수를 명시하지 않은 경우:
사용자가 평수나 방 갯수를 직접 말하지 않았지만 가족 구성, 라이프스타일 등의 힌트가 있으면,
너의 부동산 상식으로 적절한 범위를 판단하여 params에 넣어.
예: &amp;#34;신혼부부&amp;#34; → 적절한 평수/방갯수를 네가 판단
판단 근거를 systemContext에 간단히 메모해.&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&amp;ldquo;신혼부부인데 강남역 근처 전세 구해요&amp;quot;라고 하면 LLM이 &lt;code>areaMin: 15, areaMax: 25, roomCountMin: 2, roomCountMax: 3, dealType: LEASE&lt;/code>로 변환하고, &lt;code>systemContext: &amp;quot;신혼부부 기준 소형~중형 평수, 방 2~3개 추천&amp;quot;&lt;/code>이라고 판단 근거까지 남기게 하는거죠.&lt;/p>
&lt;p>물론 처음부터 이 추론이 잘 된 건 아닙니다. 4인 가족이면 30평대 이상이 일반적인데 &amp;ldquo;아이 둘 있는 4인 가족&amp;quot;이라고 했을 때 20평대를 추천하는 경우가 있었죠. 이런 케이스를 프롬프트의 few-shot 예시로 추가하면서 점차 정확도를 올려갔습니다.&lt;/p>
&lt;p>결국 이 부분에서 느낀 건, &amp;ldquo;5억대&amp;rdquo; 같은 명확한 규칙은 프롬프트로 정의하되, 맥락 추론이 필요한 부분은 LLM에게 맡기는 게 맞다는 것이었습니다. 다만 그 경계가 생각보다 모호해서, 프롬프트 설계에서 가장 고민이 많았던 부분이지 않나 싶습니다.&lt;/p>
&lt;h2>어떤 도구들이 필요한가&lt;span class="hx:absolute hx:-mt-20" id="어떤-도구들이-필요한가">&lt;/span>
&lt;a href="#%ec%96%b4%eb%96%a4-%eb%8f%84%ea%b5%ac%eb%93%a4%ec%9d%b4-%ed%95%84%ec%9a%94%ed%95%9c%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>구조와 프롬프트를 정했으니 이제 LLM이 사용할 도구를 설계해야 했습니다. &amp;ldquo;강남역 근처 30평대 아파트&amp;quot;를 처리하려면 어떤 단계가 필요할까요?&lt;/p>
&lt;ol>
&lt;li>&amp;ldquo;강남역&amp;quot;이라는 장소명을 좌표로 변환한다&lt;/li>
&lt;li>그 좌표 주변에서 조건에 맞는 아파트를 검색한다&lt;/li>
&lt;li>특정 아파트의 상세 정보를 조회한다&lt;/li>
&lt;/ol>
&lt;p>이 단계들을 각각 독립된 도구로 만들었습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Tools[&amp;#34;도구 구성&amp;#34;]
direction LR
POI[&amp;#34;poi_search\n장소명 → 좌표&amp;#34;]
PS[&amp;#34;property_search\n좌표 + 조건 → 아파트 목록&amp;#34;]
PI[&amp;#34;property_info\n단지명 → 상세 정보&amp;#34;]
end
&lt;/pre>&lt;ul>
&lt;li>&lt;strong>&lt;code>poi_search&lt;/code>&lt;/strong>: 장소명으로 좌표 및 장소 정보를 검색합니다. &amp;ldquo;강남역&amp;rdquo; → &lt;code>{ lat: 37.49, lon: 127.02 }&lt;/code>&lt;/li>
&lt;li>&lt;strong>&lt;code>property_search&lt;/code>&lt;/strong>: 좌표와 조건으로 아파트를 검색합니다.&lt;/li>
&lt;li>&lt;strong>&lt;code>property_info&lt;/code>&lt;/strong>: 특정 아파트 단지의 상세 정보를 조회합니다.&lt;/li>
&lt;/ul>
&lt;p>이렇게 도구를 나누면 &amp;ldquo;강남역이랑 신림역 사이 아파트&amp;quot;같은 복합 질문도 자연스럽게 처리됩니다. LLM이 &lt;code>poi_search(&amp;quot;강남역&amp;quot;)&lt;/code>, &lt;code>poi_search(&amp;quot;신림역&amp;quot;)&lt;/code>, 그리고 두 좌표를 받는 &lt;code>property_search&lt;/code>를 스스로 조합하면 되니까요. 도구 하나하나가 명확한 역할을 가지고 있으면 LLM이 알아서 조합할 수 있게 되는 거죠.&lt;/p>
&lt;h3>왜 DAG가 필요했나&lt;span class="hx:absolute hx:-mt-20" id="왜-dag가-필요했나">&lt;/span>
&lt;a href="#%ec%99%9c-dag%ea%b0%80-%ed%95%84%ec%9a%94%ed%96%88%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>도구를 나누고 나니 다음 문제는 이 도구들을 어떤 순서로 실행할지였습니다. 처음에는 단순하게 생각했습니다. LLM이 필요한 도구 목록을 뽑아주면 그냥 병렬로 돌리면 되지 않을까?&lt;/p>
&lt;p>실제로 그게 가능한 경우도 있었습니다. &amp;ldquo;혼자 살만한 아파트 추천해줘&amp;quot;같은 질문은 위치 특정이 필요 없으니 &lt;code>property_search&lt;/code> 하나만 실행하면 됩니다. &amp;ldquo;강남역이랑 신림역 근처 아파트&amp;quot;도 &lt;code>poi_search&lt;/code> 두 개를 병렬로 돌린 뒤 &lt;code>property_search&lt;/code>를 돌리면 되죠.&lt;/p>
&lt;p>그런데 문제는 &lt;strong>도구 간 의존성&lt;/strong>이었습니다. &amp;ldquo;강남역 근처 30평대 아파트&amp;quot;를 처리하려면 &lt;code>poi_search(&amp;quot;강남역&amp;quot;)&lt;/code>의 결과(좌표)가 나와야 &lt;code>property_search&lt;/code>를 실행할 수 있습니다. &lt;code>poi_search&lt;/code>가 끝나기 전에 &lt;code>property_search&lt;/code>를 실행할 수가 없는 거죠. 반면 &amp;ldquo;강남역이랑 신림역 사이&amp;quot;에서는 &lt;code>poi_search(&amp;quot;강남역&amp;quot;)&lt;/code>과 &lt;code>poi_search(&amp;quot;신림역&amp;quot;)&lt;/code>은 서로 의존성이 없으니 동시에 실행할 수 있습니다.&lt;/p>
&lt;p>결국 &lt;strong>의존성이 있는 도구는 순서대로, 없는 도구는 병렬로&lt;/strong> 실행해야 했습니다. 이걸 표현하기에 가장 자연스러운 구조가 DAG(Directed Acyclic Graph)였습니다.&lt;/p>
&lt;p>코드로는 모든 Tool이 하나의 인터페이스를 구현하도록 했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="k">interface&lt;/span> &lt;span class="nc">ChatTool&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">name&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">String&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">description&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">String&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">parameterSchema&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">String&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">suspend&lt;/span> &lt;span class="k">fun&lt;/span> &lt;span class="nf">execute&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">params&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">Map&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">Any&lt;/span>&lt;span class="p">?&amp;gt;):&lt;/span> &lt;span class="n">ToolResult&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;code>name&lt;/code>과 &lt;code>description&lt;/code>, &lt;code>parameterSchema&lt;/code>는 Plan 단계에서 LLM의 시스템 프롬프트에 포함됩니다. LLM이 이 정보를 보고 어떤 Tool을 어떤 순서로 실행할지 결정하는 거죠. 새로운 Tool을 추가하려면 이 인터페이스를 구현하고 빈으로 등록하기만 하면 됩니다. Spring의 &lt;code>List&amp;lt;ChatTool&amp;gt;&lt;/code> 주입으로 자동 등록되니까요.&lt;/p>
&lt;p>&lt;code>poi_search&lt;/code>의 경우 Elasticsearch의 가중치 기반 텍스트 검색을 사용하는데, 정확한 매칭에 가장 높은 가중치를 부여합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>1. name.keyword 정확 매칭 (boost 10)
2. name 형태소 매칭 (boost 5)
3. search_text 형태소 매칭 (boost 3) — 주소, 노선명 포함
4. search_text.ngram 부분 매칭 (boost 1)&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&amp;ldquo;강남역&amp;quot;이라고 검색하면 정확히 &amp;ldquo;강남역&amp;quot;이 먼저 매칭되고, 형태소 분석으로 &amp;ldquo;강남&amp;quot;이 포함된 결과, 주소에 &amp;ldquo;강남&amp;quot;이 들어간 결과 순서로 정렬됩니다.&lt;/p>
&lt;p>이 가중치를 잡는 게 생각보다 까다로웠습니다. 처음에는 keyword 매칭에 boost 5, 형태소 매칭에 boost 3을 줬었는데, &amp;ldquo;강남역&amp;quot;을 검색하면 &amp;ldquo;강남구청역&amp;quot;이 1위로 나오는 현상이 있었습니다. 원인을 찾아보니 &amp;ldquo;강남구청역&amp;quot;이 형태소 매칭에서 &amp;ldquo;강남&amp;quot;과 &amp;ldquo;역&amp;rdquo; 두 토큰이 매칭되면서 점수가 올라간 거였습니다. keyword 정확 매칭의 boost를 10으로 크게 벌리고 나서야 &amp;ldquo;강남역&amp;quot;이 확실하게 1위에 올라왔습니다. 결국 boost 값은 상대적 비율이 중요한 거라, 비슷한 값으로 주면 의도치 않은 역전이 일어나더라고요.&lt;/p>
&lt;h2>LLM이 생성한 DAG를 실행하는 법&lt;span class="hx:absolute hx:-mt-20" id="llm이-생성한-dag를-실행하는-법">&lt;/span>
&lt;a href="#llm%ec%9d%b4-%ec%83%9d%ec%84%b1%ed%95%9c-dag%eb%a5%bc-%ec%8b%a4%ed%96%89%ed%95%98%eb%8a%94-%eb%b2%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>Tool을 나눴으면 이제 이 Tool들을 어떻게 실행할지가 문제입니다. 여기서 &lt;strong>LLMCompiler&lt;/strong> (&lt;a href="https://arxiv.org/pdf/2312.04511"target="_blank" rel="noopener">arXiv 논문&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>)의 DAG 패턴을 참고했습니다.&lt;/p>
&lt;h3>LLM이 생성하는 DAG&lt;span class="hx:absolute hx:-mt-20" id="llm이-생성하는-dag">&lt;/span>
&lt;a href="#llm%ec%9d%b4-%ec%83%9d%ec%84%b1%ed%95%98%eb%8a%94-dag" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Plan 단계에서 LLM은 JSON mode로 실행 계획을 한 번에 생성합니다. &amp;ldquo;강남역 근처 30평대 아파트&amp;quot;라는 질문이 들어오면 이런 DAG가 생성하게 되는 겁니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;intent&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;PROPERTY_SEARCH&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;steps&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;1&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;name&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;poi_search&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;params&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nt">&amp;#34;location&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;강남역&amp;#34;&lt;/span> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;deps&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;name&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;property_search&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;params&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;pois&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[{&lt;/span> &lt;span class="nt">&amp;#34;name&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;$1.name&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nt">&amp;#34;lat&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;$1.lat&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nt">&amp;#34;lon&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;$1.lon&amp;#34;&lt;/span> &lt;span class="p">}],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;areaMin&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">30&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;areaMax&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">39&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;dealType&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;DEAL&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;radiusKm&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mf">3.0&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;deps&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;1&amp;#34;&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>여기서 중요한 두 가지 개념이 있습니다.&lt;/p>
&lt;p>&lt;strong>첫 번째는 &lt;code>deps&lt;/code>(의존성)입니다.&lt;/strong> step 2의 &lt;code>deps: [&amp;quot;1&amp;quot;]&lt;/code>은 &amp;ldquo;step 1이 완료된 후에 실행하라&amp;quot;는 뜻입니다. 위에서 설명한 도구 간 의존성을 이 필드로 표현하는 거죠.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
P1[&amp;#34;Step 1: poi_search\n(강남역)&amp;#34;] --&amp;gt; PS[&amp;#34;Step 3: property_search\n(두 좌표의 중간점)&amp;#34;]
P2[&amp;#34;Step 2: poi_search\n(신림역)&amp;#34;] --&amp;gt; PS
&lt;/pre>&lt;p>&lt;strong>두 번째는 변수 참조(&lt;code>$1.lat&lt;/code>)입니다.&lt;/strong> step 2의 파라미터에 &lt;code>&amp;quot;$1.lat&amp;quot;&lt;/code>이라고 적으면, step 1의 실행 결과에서 &lt;code>lat&lt;/code> 값을 꺼내서 치환합니다. 이 덕분에 step 간에 데이터를 전달할 수 있습니다.&lt;/p>
&lt;h3>왜 OpenAI function calling을 쓰지 않았나&lt;span class="hx:absolute hx:-mt-20" id="왜-openai-function-calling을-쓰지-않았나">&lt;/span>
&lt;a href="#%ec%99%9c-openai-function-calling%ec%9d%84-%ec%93%b0%ec%a7%80-%ec%95%8a%ec%95%98%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이 시점에서 &amp;ldquo;OpenAI의 네이티브 function calling을 쓰면 되지 않나?&amp;ldquo;라는 의문이 드실 수 있다고 생각합니다.&lt;/p>
&lt;p>다만 네이티브 function calling은 &amp;ldquo;이 도구들을 실행해라&amp;quot;까지는 표현할 수 있습니다. parallel function calling으로 여러 도구를 동시에 실행하는 것도 가능하죠. 하지만 &lt;strong>&amp;ldquo;step 1이 끝난 후 그 결과의 lat 값을 step 2의 파라미터에 넣어서 실행해라&amp;quot;를 한 번의 호출로 표현하는 건 불가능합니다.&lt;/strong>&lt;/p>
&lt;p>또 function calling은 도구를 호출할 때 모든 파라미터 값을 미리 알아야 합니다. 그런데 &lt;code>property_search&lt;/code>의 좌표는 &lt;code>poi_search&lt;/code>가 실행되어야 알 수 있죠. 결국 Agent Loop처럼 여러 번 LLM을 호출해야 하고, 그러면 Planned Tool Use의 장점(예측 가능한 호출 횟수)이 사라집니다.&lt;/p>
&lt;p>그래서 LLM에게 DAG 스키마를 프롬프트로 제공하고, &lt;code>deps&lt;/code>와 변수 참조(&lt;code>$1.lat&lt;/code>)를 포함한 실행 계획을 JSON mode로 한 번에 생성하게 하는 방식을 선택했습니다. LLMCompiler 논문에서 이 접근 방식의 이론적 근거를 얻었고요.&lt;/p>
&lt;h3>DAG 실행 엔진&lt;span class="hx:absolute hx:-mt-20" id="dag-실행-엔진">&lt;/span>
&lt;a href="#dag-%ec%8b%a4%ed%96%89-%ec%97%94%ec%a7%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>생성된 DAG를 실행하는 &lt;code>ToolExecutor&lt;/code>는 &lt;strong>Kahn&amp;rsquo;s algorithm&lt;/strong>으로 위상 정렬을 수행한 뒤, 같은 레벨의 step들을 coroutine으로 병렬 실행합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="k">suspend&lt;/span> &lt;span class="k">fun&lt;/span> &lt;span class="nf">executeDag&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">steps&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">List&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">DagStep&lt;/span>&lt;span class="p">&amp;gt;,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">timeoutMs&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">Long&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="m">20&lt;/span>&lt;span class="n">_000&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">):&lt;/span> &lt;span class="n">List&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">ToolResult&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">coroutineScope&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">resultMap&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">ConcurrentHashMap&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">ToolResult&lt;/span>&lt;span class="p">&amp;gt;()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">levels&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">topologicalSort&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">steps&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="c1">// Kahn&amp;#39;s algorithm
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">for&lt;/span> &lt;span class="p">((&lt;/span>&lt;span class="n">levelIdx&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">level&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="k">in&lt;/span> &lt;span class="n">levels&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">withIndex&lt;/span>&lt;span class="p">())&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">levelResults&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">level&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">map&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="n">step&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">async&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nc">Dispatchers&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">IO&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">resolvedParams&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">resolveVariables&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">step&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">params&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">resultMap&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">step&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">id&lt;/span> &lt;span class="n">to&lt;/span> &lt;span class="n">executeSingle&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">ToolCallRequest&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">step&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">resolvedParams&lt;/span>&lt;span class="p">),&lt;/span> &lt;span class="n">timeoutMs&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}.&lt;/span>&lt;span class="n">map&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="k">it&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">await&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">levelResults&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">forEach&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">result&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="n">resultMap&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="p">]&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">result&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">steps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">map&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="n">step&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="n">resultMap&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">step&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="o">!!&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>Kahn&amp;rsquo;s algorithm으로 &amp;ldquo;이 step은 어떤 레벨에서 실행 가능한가&amp;quot;를 분류하고, 같은 레벨에 있는 step들은 &lt;code>async&lt;/code>로 병렬 실행합니다. 레벨이 끝나면 결과를 &lt;code>resultMap&lt;/code>에 저장하고, 다음 레벨의 step들은 이 결과에서 변수를 치환해서 실행합니다.&lt;/p>
&lt;p>변수 치환 로직에서 한 가지 신경 쓴 부분이 있습니다. &lt;strong>&lt;code>$1.lat&lt;/code>처럼 값 전체가 변수인 경우에는 원래 타입(Double 등)을 유지하고, &lt;code>&amp;quot;$1.name 근처&amp;quot;&lt;/code>처럼 문자열 안에 변수가 포함된 경우에는 문자열로 치환합니다.&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="k">private&lt;/span> &lt;span class="k">fun&lt;/span> &lt;span class="nf">resolveStringVariable&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">value&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">String&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">resultMap&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">Map&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">ToolResult&lt;/span>&lt;span class="p">&amp;gt;):&lt;/span> &lt;span class="n">Any&lt;/span>&lt;span class="p">?&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 값 전체가 변수 → 원래 타입 유지 (예: &amp;#34;$1.lat&amp;#34; → 37.49 as Double)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">val&lt;/span> &lt;span class="py">fullMatch&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="nc">VARIABLE_PATTERN&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">matchEntire&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">value&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">fullMatch&lt;/span> &lt;span class="o">!=&lt;/span> &lt;span class="k">null&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="err">(&lt;/span>&lt;span class="py">stepId&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="k">field&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">fullMatch&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">destructured&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">extractField&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">resultMap&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">stepId&lt;/span>&lt;span class="p">],&lt;/span> &lt;span class="k">field&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">?:&lt;/span> &lt;span class="k">value&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 문자열 내 변수 → 문자열 치환 (예: &amp;#34;$1.name 근처&amp;#34; → &amp;#34;강남역 근처&amp;#34;)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">return&lt;/span> &lt;span class="nc">VARIABLE_PATTERN&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">replace&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">value&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="n">match&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="err">(&lt;/span>&lt;span class="py">stepId&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="k">field&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">match&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">destructured&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">extractField&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">resultMap&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">stepId&lt;/span>&lt;span class="p">],&lt;/span> &lt;span class="k">field&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="o">?.&lt;/span>&lt;span class="n">toString&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="o">?:&lt;/span> &lt;span class="s2">&amp;#34;null&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 구분이 왜 중요하냐면, &lt;code>$1.lat&lt;/code>을 문자열 &lt;code>&amp;quot;37.49&amp;quot;&lt;/code>로 치환하면 Elasticsearch 검색에서 타입 에러가 납니다. 좌표는 Double이어야 하니까요. 처음에는 이 구분 없이 전부 문자열로 치환했었는데, 검색이 깨지는 걸 보고 나서야 이 로직을 추가했습니다.&lt;/p>
&lt;h3>LLM 출력은 신뢰할 수 없다&lt;span class="hx:absolute hx:-mt-20" id="llm-출력은-신뢰할-수-없다">&lt;/span>
&lt;a href="#llm-%ec%b6%9c%eb%a0%a5%ec%9d%80-%ec%8b%a0%eb%a2%b0%ed%95%a0-%ec%88%98-%ec%97%86%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>DAG를 LLM이 생성하기 때문에, 당연히 잘못된 결과가 나올 수 있습니다. 그렇기 때문에 &lt;code>sanitizePlan&lt;/code>이라는 방어 로직을 추가했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="k">private&lt;/span> &lt;span class="k">fun&lt;/span> &lt;span class="nf">sanitizePlan&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">plan&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">DagPlanResult&lt;/span>&lt;span class="p">):&lt;/span> &lt;span class="n">DagPlanResult&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 1단계: 화이트리스트에 없는 tool name → 제거
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">var&lt;/span> &lt;span class="py">sanitizedSteps&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">plan&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">steps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">filter&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="k">it&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">name&lt;/span> &lt;span class="k">in&lt;/span> &lt;span class="n">validToolNames&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 2단계: 제거된 step을 deps로 참조하는 후속 step도 연쇄 제거
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">do&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">prevSize&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">sanitizedSteps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">size&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">validIds&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">sanitizedSteps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">map&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="k">it&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">id&lt;/span> &lt;span class="p">}.&lt;/span>&lt;span class="n">toSet&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">sanitizedSteps&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">sanitizedSteps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">filter&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="n">step&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="n">step&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">deps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">all&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="k">it&lt;/span> &lt;span class="k">in&lt;/span> &lt;span class="n">validIds&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span> &lt;span class="k">while&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">sanitizedSteps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">size&lt;/span> &lt;span class="o">!=&lt;/span> &lt;span class="n">prevSize&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 3단계: step 수 상한 (N개 POI 독립 검색 시 ES 호출 과다 방지)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">sanitizedSteps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">size&lt;/span> &lt;span class="p">&amp;gt;&lt;/span> &lt;span class="n">maxDagSteps&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">sanitizedSteps&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">sanitizedSteps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">take&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">maxDagSteps&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">plan&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">copy&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">intent&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">sanitizedIntent&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">steps&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">sanitizedSteps&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 자유 텍스트 필드는 길이 제한 + 줄바꿈 제거 (인젝션 방어)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">etcCondition&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">sanitizeString&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">plan&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">etcCondition&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">systemContext&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">sanitizeString&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">plan&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">systemContext&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">maxLen&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="m">200&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>2단계의 &lt;strong>연쇄 제거&lt;/strong>같은 경우에 step 1이 잘못된 tool name으로 제거되면, step 1에 의존하는 step 2도 실행할 수 없습니다. step 2에 의존하는 step 3도 마찬가지고요. 이 연쇄를 고정점 수렴(더 이상 제거할 step이 없을 때까지 반복)으로 처리합니다.&lt;/p>
&lt;p>&lt;code>etcCondition&lt;/code>과 &lt;code>systemContext&lt;/code>도 새니타이즈하는 이유는, 이 필드들이 LLM이 자유롭게 텍스트를 생성하는 영역이라 인젝션 공격에 취약할 수 있기 때문입니다. 길이를 제한하고 줄바꿈을 제거해서 최소한의 방어를 합니다.&lt;/p>
&lt;p>이 방어 로직들은 처음부터 고려한 건 아닙니다. 실제로 운영하면서 LLM이 예상 외의 출력을 내는 경우들을 겪으면서 하나씩 추가하게 된 것들입니다. LLM 기반 시스템을 만들면서 느낀 건, &lt;strong>LLM의 출력을 코드가 실행하는 구조에서는 이런 새니타이즈 로직이 생각보다 많이 필요하다&lt;/strong>는 점이었습니다. LLM을 &amp;ldquo;믿되 검증한다&amp;quot;는 원칙이 필요하지 않나 싶습니다.&lt;/p>
&lt;h2>&amp;ldquo;찾기&amp;quot;와 &amp;ldquo;추천&amp;quot;은 다른 문제였다&lt;span class="hx:absolute hx:-mt-20" id="찾기와-추천은-다른-문제였다">&lt;/span>
&lt;a href="#%ec%b0%be%ea%b8%b0%ec%99%80-%ec%b6%94%ec%b2%9c%ec%9d%80-%eb%8b%a4%eb%a5%b8-%eb%ac%b8%ec%a0%9c%ec%98%80%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>여기서 제가 가장 크게 반성한 부분이 있습니다.&lt;/p>
&lt;p>DAG 실행 엔진까지 만들고 E2E 테스트를 돌렸는데, 결과를 보니 뭔가 이상했습니다. 거리 안에 있는 아파트들이 나오긴 하는데, &lt;strong>순서에 의미가 없었습니다.&lt;/strong> 비싼 아파트, 싼 아파트, 조건에 잘 맞는 아파트, 안 맞는 아파트가 뒤섞여 있었죠.&lt;/p>
&lt;p>돌이켜보면 당연한 결과였습니다. 그때까지 만든 건 &lt;strong>&amp;ldquo;AI 단지 찾기&amp;rdquo;&lt;/strong> 였지 &lt;strong>&amp;ldquo;AI 단지 추천&amp;rdquo;&lt;/strong> 이 아니었으니까요. 조건에 맞는 걸 찾아주긴 하는데, 뭐가 더 좋은지 판단하는 로직이 없었던 겁니다. 반경 3km 안에 조건을 만족하는 아파트가 30개 있으면 30개를 그냥 나열하는 거였으니까요.&lt;/p>
&lt;h3>이건 LLM 문제가 아니었다&lt;span class="hx:absolute hx:-mt-20" id="이건-llm-문제가-아니었다">&lt;/span>
&lt;a href="#%ec%9d%b4%ea%b1%b4-llm-%eb%ac%b8%ec%a0%9c%ea%b0%80-%ec%95%84%eb%8b%88%ec%97%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이 문제를 해결하려면 LLM을 바꾸거나 프롬프트를 고치는 게 아니라, &lt;strong>검색 자체의 스코어링 로직&lt;/strong>을 만들어야 했습니다. 순수한 검색 엔지니어링 문제였죠.&lt;/p>
&lt;p>Elasticsearch의 &lt;code>function_score&lt;/code>를 활용해서 5가지 가중치 스코어링을 설계했습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph FunctionScore[&amp;#34;function_score (scoreMode: Sum, boostMode: Replace)&amp;#34;]
direction TB
D[&amp;#34;거리 감쇠 (35%)\nGaussian decay&amp;#34;]
P[&amp;#34;가격 근접도 (35%)\n호가 우선, 실거래가 fallback&amp;#34;]
A[&amp;#34;평형 매칭 (15%)\n매칭 비율&amp;#34;]
N[&amp;#34;신축 가산 (5%)\n2020년 이후&amp;#34;]
L[&amp;#34;매물수 가산 (10%)\nlog 스케일&amp;#34;]
end
&lt;/pre>&lt;h3>가중치를 어떻게 정했나&lt;span class="hx:absolute hx:-mt-20" id="가중치를-어떻게-정했나">&lt;/span>
&lt;a href="#%ea%b0%80%ec%a4%91%ec%b9%98%eb%a5%bc-%ec%96%b4%eb%96%bb%ea%b2%8c-%ec%a0%95%ed%96%88%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>솔직히 말씀드리면 이론적 근거로 정한 건 아닙니다. 다만 아무 근거 없이 감으로 정한 것도 아닙니다.&lt;/p>
&lt;p>출발점은 &lt;strong>&amp;ldquo;사용자가 매물을 고를 때 가장 중요하게 보는 게 뭔가&amp;rdquo;&lt;/strong> 였습니다. 부동산 서비스를 운영하고 사용자 분들께서 검색하는 로그를 보면서 느낀 건, 사용자분들이 가장 먼저 보는 건 &lt;strong>위치&lt;/strong>와 &lt;strong>가격&lt;/strong>이라는 점이었습니다. 평형이나 신축 여부는 그 다음이었죠. 그래서 거리와 가격에 각각 35%로 가장 큰 가중치를 주고, 평형 매칭에 15%, 나머지를 신축(5%)과 매물 수(10%)에 배분했습니다.&lt;/p>
&lt;p>이 비율을 정하고 나서 실제 검색 결과를 보면서 미세하게 조정했습니다. 예를 들어 처음에는 거리를 50%로 줬었는데, &amp;ldquo;강남역 근처 10억 이하 아파트&amp;quot;를 검색하면 30억짜리 아파트가 1위로 올라오는 경우가 있었습니다. 가격은 전혀 안 맞지만 강남역에서 200m라서 거리 점수만으로 1위가 된 거죠. 거리와 가격의 중요도가 비슷하다고 판단해서 35/35로 맞췄고, 그 이후로는 이런 문제가 많이 줄었습니다.&lt;/p>
&lt;h3>가격 근접도 — 호가와 실거래가 사이에서&lt;span class="hx:absolute hx:-mt-20" id="가격-근접도--호가와-실거래가-사이에서">&lt;/span>
&lt;a href="#%ea%b0%80%ea%b2%a9-%ea%b7%bc%ec%a0%91%eb%8f%84--%ed%98%b8%ea%b0%80%ec%99%80-%ec%8b%a4%ea%b1%b0%eb%9e%98%ea%b0%80-%ec%82%ac%ec%9d%b4%ec%97%90%ec%84%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>가장 고민이 많았던 부분은 &lt;strong>가격 근접도&lt;/strong>였습니다. 단순히 &amp;ldquo;사용자가 원하는 가격에 가까운 아파트에 높은 점수를 준다&amp;quot;는 개념인데, 실제로 구현하려니 어떤 가격을 기준으로 스코어링할지가 문제였습니다.&lt;/p>
&lt;p>부동산에서 가격 데이터는 크게 두 가지입니다. &lt;strong>실거래가&lt;/strong>(실제 거래된 가격)와 &lt;strong>호가&lt;/strong>(매물에 등록된 가격)인데, 모든 아파트에 두 데이터가 다 있는 건 아닙니다. 최근 거래가 없는 아파트나 빌라 등은 실거래가가 없고, 매물이 없는 아파트는 호가가 없죠.&lt;/p>
&lt;p>그러나 보통 실거래가의 경우 거래가 된 이후에 한달정도 지나야 공개가 됩니다. 반면 호가는 매물로 등록되는 즉시 알 수 있죠. 그래서 실거래가는 최신 시장 상황을 반영하지 못하는 경우가 많다고 판단해 &lt;strong>호가를 우선으로 탐색하고, 호가가 없으면 실거래가를 fallback으로 사용하는 전략&lt;/strong>을 택했습니다. 이 로직을 ES의 Painless 스크립트로 구현했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 가격 근접도 Painless 스크립트 (핵심부, 변수명은 예시)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">def&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">minDiff&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Double&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">MAX_VALUE&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">def&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">map&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Object&lt;/span>&lt;span class="o">[]&lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="n">askingPriceMap&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">tradedPriceMap&lt;/span>&lt;span class="p">})&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 호가 먼저, 실거래가 fallback&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">map&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">==&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">||&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">map&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">isEmpty&lt;/span>&lt;span class="p">())&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">continue&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">entry&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">in&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">map&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">entrySet&lt;/span>&lt;span class="p">())&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kt">double&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">priceVal&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">((&lt;/span>&lt;span class="n">Number&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="n">entry&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getValue&lt;/span>&lt;span class="p">()).&lt;/span>&lt;span class="na">doubleValue&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">priceVal&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">==&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">0&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">0&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">continue&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 가격 0 건너뛰기&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">def&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">diff&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Math&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">abs&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">priceVal&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">midpoint&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">diff&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">minDiff&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">minDiff&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">diff&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">minDiff&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Double&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">MAX_VALUE&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">break&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 호가가 있으면 실거래가 탐색 안 함&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">minDiff&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">==&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Double&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">MAX_VALUE&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">0&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">3&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 가격 데이터 없으면 중립 점수&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Math&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">exp&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="n">0&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">5&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Math&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">pow&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">minDiff&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">/&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">scale&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">2&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">//&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Gaussian&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">decay&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>여기서 가격 데이터가 아예 없는 아파트에 &lt;strong>중립 점수 0.3&lt;/strong>을 부여하는 게 중요했습니다. 0점을 주면 가격 데이터가 없다는 이유만으로 무조건 하위로 밀려나고, 1점을 주면 오히려 상위로 올라옵니다. 0.3이라는 값은 &amp;ldquo;가격을 모르지만, 최소한 불이익을 주지는 않겠다&amp;quot;는 의미였습니다. 이 값도 결과를 보면서 조정했고요.&lt;/p>
&lt;p>또 하나 고민했던 건 &lt;strong>&amp;ldquo;5억 이상&amp;rdquo;&lt;/strong> 같은 오픈 범위 검색의 처리였습니다. &amp;ldquo;5억 이상&amp;quot;이면 &lt;code>priceMin: 50000, priceMax: 9999999&lt;/code>(약 999억)가 되는데, 이 범위의 중심점은 약 500억입니다. 당연히 의미 없는 값이죠. 그래서 오픈 범위일 때는 중심점을 &lt;code>min * 1.5&lt;/code>로 보정했습니다. &amp;ldquo;5억 이상&amp;quot;이면 7.5억 근처의 아파트에 가장 높은 점수를 주는 거죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 오픈 범위 보정 (코드는 예시)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">val&lt;/span> &lt;span class="py">effectiveMax&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">isOpenRange&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="n">effectiveMin&lt;/span> &lt;span class="p">*&lt;/span> &lt;span class="m">2&lt;/span> &lt;span class="k">else&lt;/span> &lt;span class="n">priceRange&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">last&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>복수 POI 지원 — &amp;ldquo;강남역이랑 신림역 사이 아파트&amp;rdquo;&lt;span class="hx:absolute hx:-mt-20" id="복수-poi-지원--강남역이랑-신림역-사이-아파트">&lt;/span>
&lt;a href="#%eb%b3%b5%ec%88%98-poi-%ec%a7%80%ec%9b%90--%ea%b0%95%eb%82%a8%ec%97%ad%ec%9d%b4%eb%9e%91-%ec%8b%a0%eb%a6%bc%ec%97%ad-%ec%82%ac%ec%9d%b4-%ec%95%84%ed%8c%8c%ed%8a%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>스코어링까지 해결하고 나니 또 다른 챌린지가 있었습니다. 사용자가 위치를 2개 이상 말하는 경우였습니다.&lt;/p>
&lt;p>&amp;ldquo;강남역이랑 신림역 사이 아파트&amp;rdquo;, &amp;ldquo;신림역 혹은 강남역 근처 아파트&amp;rdquo;, &amp;ldquo;강남역에 더 가깝게&amp;rdquo;, &amp;ldquo;삼성역, 강남역, 고속터미널역이랑 가까운&amp;rdquo; — 이런 질문들을 처리해야 했습니다.&lt;/p>
&lt;p>분석해보니 크게 세 가지 패턴이 있었습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>패턴&lt;/th>
&lt;th>예시&lt;/th>
&lt;th>검색 전략&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&amp;ldquo;A 또는 B&amp;rdquo;&lt;/td>
&lt;td>&amp;ldquo;신림역 혹은 강남역 근처&amp;rdquo;&lt;/td>
&lt;td>독립 검색 N개 (각 POI별 property_search)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&amp;ldquo;A와 B 사이&amp;rdquo;&lt;/td>
&lt;td>&amp;ldquo;잠실역이랑 강남역 사이&amp;rdquo;&lt;/td>
&lt;td>midpoint 계산 → property_search 1개&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&amp;ldquo;A에 더 가깝게&amp;rdquo;&lt;/td>
&lt;td>&amp;ldquo;강남역보다 신림역에 더 가깝게&amp;rdquo;&lt;/td>
&lt;td>weighted center → property_search 1개&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>독립 검색의 경우 LLM이 POI 수만큼 별도의 &lt;code>property_search&lt;/code> step을 생성합니다. midpoint나 weighted center의 경우에는 &lt;code>property_search&lt;/code> 1개에 여러 POI를 전달하고, &lt;code>PropertySearchTool&lt;/code>이 가중 중심점을 계산합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="k">private&lt;/span> &lt;span class="k">fun&lt;/span> &lt;span class="nf">calculateCenter&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">pois&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">List&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">PoiCoord&lt;/span>&lt;span class="p">&amp;gt;,&lt;/span> &lt;span class="n">weights&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">List&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">Double&lt;/span>&lt;span class="p">&amp;gt;):&lt;/span> &lt;span class="n">Pair&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">Double&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">Double&lt;/span>&lt;span class="p">&amp;gt;?&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">pois&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">isEmpty&lt;/span>&lt;span class="p">())&lt;/span> &lt;span class="k">return&lt;/span> &lt;span class="k">null&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">pois&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">size&lt;/span> &lt;span class="o">==&lt;/span> &lt;span class="m">1&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="k">return&lt;/span> &lt;span class="n">pois&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="m">0&lt;/span>&lt;span class="p">].&lt;/span>&lt;span class="n">lat&lt;/span> &lt;span class="n">to&lt;/span> &lt;span class="n">pois&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="m">0&lt;/span>&lt;span class="p">].&lt;/span>&lt;span class="n">lon&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">weightedPoints&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">pois&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">zip&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">weights&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="n">map&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">poi&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">w&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nc">GeoUtils&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">WeightedPoint&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">poi&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">lat&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">poi&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">lon&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">w&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="nc">GeoUtils&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">calculateWeightedCenter&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">weightedPoints&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>여기에도 전략 분기를 LLM이 판단하도록 했습니다. &amp;ldquo;집은 신림역이고 회사는 교대역인데&amp;quot;처럼 명시적 키워드(&amp;ldquo;사이&amp;rdquo;, &amp;ldquo;또는&amp;rdquo;)가 없어도, LLM이 &amp;ldquo;두 곳 모두 오가야 하는 맥락&amp;quot;을 파악해서 midpoint 전략을 선택하게 한거죠. 반대로 &amp;ldquo;강남역도 괜찮고 신림역도 괜찮은데&amp;quot;는 &amp;ldquo;둘 중 하나를 고르려는 맥락&amp;quot;이니 독립 검색으로 판단합니다.&lt;/p>
&lt;p>이런 맥락 기반 판단은 규칙으로 처리하기 어려운 부분이었습니다. 자연어의 뉘앙스와 맥락을 모두 포착하려면 규칙이 엄청 복잡해질 텐데, LLM의 맥락 이해 능력에 맡기는 게 훨씬 효율적이겠다고 판단했습니다. 그래서 이 판단을 LLM이 잘 하도록 프롬프트에 &lt;strong>맥락 기반 규칙&lt;/strong>을 추가했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>- &amp;#34;집은 A이고 회사는 B&amp;#34; → 두 곳 모두 오가야 하는 맥락 → midpoint
- &amp;#34;A도 괜찮고 B도 괜찮은데&amp;#34; → 둘 중 하나를 고르려는 맥락 → 독립 검색&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>명시적 키워드만으로는 처리할 수 없는 자연어의 모호함을 LLM의 맥락 이해 능력에 맡기는 거죠. 이런 부분은 규칙으로 처리하려면 끝이 없었을 것 같습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/433657pr8jefq963mdcas/ai-estate-result-1.png?rlkey=52nvd21u3u6l16zbgv7srgwh1&amp;amp;st=7k1pknsk&amp;amp;raw=1" alt="AI 채팅으로 매물 추천" loading="lazy" />&lt;/p>
&lt;h3>포스트 필터링 — ES 스코어링만으로는 부족하다&lt;span class="hx:absolute hx:-mt-20" id="포스트-필터링--es-스코어링만으로는-부족하다">&lt;/span>
&lt;a href="#%ed%8f%ac%ec%8a%a4%ed%8a%b8-%ed%95%84%ed%84%b0%eb%a7%81--es-%ec%8a%a4%ec%bd%94%ec%96%b4%eb%a7%81%eb%a7%8c%ec%9c%bc%eb%a1%9c%eb%8a%94-%eb%b6%80%ec%a1%b1%ed%95%98%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>한 가지 더 문제가 있었습니다. ES의 &lt;code>function_score&lt;/code>가 스코어링은 해주지만, &lt;strong>평형+가격+방갯수를 동시에 검증하지는 않는다는 점&lt;/strong>이었습니다.&lt;/p>
&lt;p>이게 왜 문제냐면, ES 인덱스는 &lt;strong>단지(아파트) 레벨&lt;/strong>로 구성되어 있기 때문입니다. 하나의 단지에 20평형, 30평형, 40평형이 있을 수 있습니다. 사용자가 &amp;ldquo;30평대, 15억&amp;quot;이라고 검색했는데, 어떤 단지의 20평형이 15억이면 이 단지가 검색 결과에 포함됩니다. 하지만 사용자가 원하는 건 30평대가 15억인 아파트이지, 20평형이 15억인 아파트가 아닙니다.&lt;/p>
&lt;p>그래서 ES 검색 후에 &lt;strong>포스트 필터링&lt;/strong>을 추가했습니다. 후보 평형 중 하나라도 평형+가격+방갯수를 &lt;strong>모두 동시에&lt;/strong> 만족하는지 검증하는 로직입니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 변수명은 예시
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">val&lt;/span> &lt;span class="py">matched&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">candidateTypes&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">any&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="n">type&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">typeKey&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">type&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">toString&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 가격 검증: 호가 우선, 없으면 실거래가 fallback (스코어링과 동일한 정책)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">val&lt;/span> &lt;span class="py">priceMatches&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">priceRange&lt;/span> &lt;span class="o">!=&lt;/span> &lt;span class="k">null&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">price&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">askingPrices&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">typeKey&lt;/span>&lt;span class="p">]&lt;/span> &lt;span class="o">?:&lt;/span> &lt;span class="n">tradedPrices&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">typeKey&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">price&lt;/span> &lt;span class="o">!=&lt;/span> &lt;span class="k">null&lt;/span> &lt;span class="o">&amp;amp;&amp;amp;&lt;/span> &lt;span class="n">price&lt;/span> &lt;span class="k">in&lt;/span> &lt;span class="n">priceRange&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span> &lt;span class="k">else&lt;/span> &lt;span class="k">true&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 방 갯수 검증
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">val&lt;/span> &lt;span class="py">roomCountMatches&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">roomCountRange&lt;/span> &lt;span class="o">!=&lt;/span> &lt;span class="k">null&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">roomCount&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">roomCountsByType&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">typeKey&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">roomCount&lt;/span> &lt;span class="o">!=&lt;/span> &lt;span class="k">null&lt;/span> &lt;span class="o">&amp;amp;&amp;amp;&lt;/span> &lt;span class="n">roomCount&lt;/span> &lt;span class="k">in&lt;/span> &lt;span class="n">roomCountRange&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span> &lt;span class="k">else&lt;/span> &lt;span class="k">true&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">priceMatches&lt;/span> &lt;span class="o">&amp;amp;&amp;amp;&lt;/span> &lt;span class="n">roomCountMatches&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 포스트 필터링도 결국 LLM과는 관계없는 순수 검색 로직이었습니다. 가격 근접도 스코어링과 마찬가지로 &lt;strong>호가 우선, 실거래가 fallback&lt;/strong> 정책을 동일하게 적용했고요.&lt;/p>
&lt;h2>돌이켜보면&lt;span class="hx:absolute hx:-mt-20" id="돌이켜보면">&lt;/span>
&lt;a href="#%eb%8f%8c%ec%9d%b4%ec%bc%9c%eb%b3%b4%eb%a9%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이 기능을 만들면서 아키텍처를 여러 번 바꾸게 되었는데 굉장히 개발하면서 재미있는 경험이었습니다. 만들면서 즐겁더라구요.&lt;/p>
&lt;p>처음 고정 파이프라인에서 Plan + Execute + Generate 구조로 바꾸고 하는 과정들과 실제 서비스에 AI를 녹여가는 과정 그리고 그 결과를 보니 뿌듯하기도 했습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/c26tem3bosa6m4wm94amj/ai-estate-result-3.png?rlkey=y3qk46xc977gvjw0gyapshzam&amp;amp;st=k5p10nze&amp;amp;raw=1" alt="독립 추천 API — 지도 화면에서는 추천 결과가 마커로 표시됩니다" loading="lazy" />&lt;/p>
&lt;h3>Tool 경계를 나누는 건 서비스 경계를 나누는 것과 같았다&lt;span class="hx:absolute hx:-mt-20" id="tool-경계를-나누는-건-서비스-경계를-나누는-것과-같았다">&lt;/span>
&lt;a href="#tool-%ea%b2%bd%ea%b3%84%eb%a5%bc-%eb%82%98%eb%88%84%eb%8a%94-%ea%b1%b4-%ec%84%9c%eb%b9%84%ec%8a%a4-%ea%b2%bd%ea%b3%84%eb%a5%bc-%eb%82%98%eb%88%84%eb%8a%94-%ea%b2%83%ea%b3%bc-%ea%b0%99%ec%95%98%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>위에서 모놀리식 Tool을 원자적으로 분해한 경험을 이야기했는데, 이 과정에서 느낀 건 결국 MSA에서 서비스 경계를 나누는 고민과 본질적으로 같았다는 점입니다. Tool이 너무 크면 LLM이 유연하게 조합할 수 없고, 너무 작으면 Plan 단계에서 step이 불필요하게 많아집니다. 서비스 크기 고민과 똑같죠.&lt;/p>
&lt;p>사실 이건 단일 책임 원칙이 Tool 설계에도 적용된다는 거지 않나 싶습니다. 다만 전통적인 SRP에서는 &amp;ldquo;변경의 이유&amp;quot;가 기준이라면, Tool SRP에서는 &amp;ldquo;LLM이 이 Tool의 역할을 한 문장으로 설명할 수 있는가&amp;quot;가 기준이 된다고 느꼈습니다.&lt;/p>
&lt;h3>&amp;ldquo;추천&amp;quot;이라는 단어를 가볍게 봤다&lt;span class="hx:absolute hx:-mt-20" id="추천이라는-단어를-가볍게-봤다">&lt;/span>
&lt;a href="#%ec%b6%94%ec%b2%9c%ec%9d%b4%eb%9d%bc%eb%8a%94-%eb%8b%a8%ec%96%b4%eb%a5%bc-%ea%b0%80%eb%b3%8d%ea%b2%8c-%eb%b4%a4%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이건 제가 반성을 크게 한 부분입니다&amp;hellip; ㅎ 요구사항에 &amp;ldquo;추천&amp;quot;이라는 단어가 있었는데, &amp;ldquo;추천하려면 기준이 필요하고, 기준이 있으려면 스코어링이 필요하다&amp;quot;는 연결고리를 처음부터 떠올리지 못했습니다. 단순히 LLM을 통한 &amp;ldquo;AI 매물,단지 찾기&amp;rdquo; 정도로만 생각했었죠. E2E 테스트에서 결과를 직접 보고 나서야 깨달았죠.&lt;/p>
&lt;p>요구사항의 단어 하나하나에 어떤 기술적 요구가 숨어있는지를 더 깊이 분석했다면 스코어링 설계를 더 일찍 시작할 수 있었을 것 같습니다. &amp;ldquo;찾기&amp;quot;와 &amp;ldquo;추천&amp;quot;은 사용자 입장에서는 비슷해 보이지만, 만드는 입장에서는 완전히 다른 문제라는 걸 이번에 확실히 배웠습니다.&lt;/p>
&lt;h3>아직 남은 과제들&lt;span class="hx:absolute hx:-mt-20" id="아직-남은-과제들">&lt;/span>
&lt;a href="#%ec%95%84%ec%a7%81-%eb%82%a8%ec%9d%80-%ea%b3%bc%ec%a0%9c%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>아직 한계도 있습니다. 현재 응답 시간이 좀 느려서 사용자 경험 면에서 개선이 필요하다고 생각합니다. Plan LLM 호출에 대부분의 시간이 소요되는데, 프롬프트 캐싱이나 모델 최적화로 줄일 수 있는 여지가 있다고 보고 있습니다.&lt;/p>
&lt;p>그리고 이 글을 쓰면서 다시 느낀 건데, 다음에 비슷한 기능을 만들 때는 처음부터 &amp;ldquo;LLM이 할 일&amp;quot;과 &amp;ldquo;코드가 할 일&amp;quot;의 경계를 먼저 정의하고 시작할 것 같습니다. 이번에는 그 경계를 만들면서 찾아갔는데 다음 기회가 있다면 처음부터 제대로 모듈간 경계를 정하듯 &amp;ldquo;LLM이 할 일은 이거, 코드가 할 일은 이거&amp;quot;를 명확히 정의하고 시작할 것 같습니다.&lt;/p>
&lt;p>이 글에서 다룬 AI 매물 추천 기능을 직접 사용해보고 싶으신 분들은 &lt;a href="https://bootalk.co.kr/apt"target="_blank" rel="noopener">부톡 아파트&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에서 &lt;strong>&amp;ldquo;문자 / 음성으로 찾기&amp;rdquo;&lt;/strong> 버튼을 눌러 사용해보시면 좋을 것 같습니다.&lt;/p>
&lt;p>이 글이 누군가에게 조금이라도 도움이 되길 바라며 이만 가보겠습니다. 긴 글 읽어주셔서 감사합니다.&lt;/p>
&lt;hr>
&lt;h2>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;ul>
&lt;li>Anthropic - &lt;a href="https://www.anthropic.com/engineering/building-effective-agents"target="_blank" rel="noopener">Building Effective Agents&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>Kim et al. - &lt;a href="https://arxiv.org/pdf/2312.04511"target="_blank" rel="noopener">An LLM Compiler for Parallel Function Calling&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> (arXiv, 2023)&lt;/li>
&lt;li>Elasticsearch - &lt;a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html"target="_blank" rel="noopener">Function Score Query&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>API 성능 P95 7초 → 0.1초 백엔드 성능 최적화 — 느린 곳을 찾는 게 고치는 것보다 어려웠다</title><link>https://jeongil.dev/ko/blog/backend/performance/backend-api-performance-optimization/</link><pubDate>Wed, 04 Mar 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/backend/performance/backend-api-performance-optimization/</guid><description>
&lt;p>안녕하세요. 프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 정정일입니다.&lt;/p>
&lt;p>어느 날 평소처럼 모니터링을 위해 Grafana 대시보드를 들여다보고 있었습니다. 평균 응답시간은 대부분 수백ms 이내라 &amp;ldquo;괜찮네&amp;rdquo; 하고 넘어가려다 습관적으로 &lt;strong>P95&lt;/strong>(상위 5%의 느린 요청) 지표로 눈을 돌려봤습니다. 이쪽은 상황이 좀 달랐습니다. 일부 API에서 tail latency가 수 초대에 머물고 있었거든요.&lt;/p>
&lt;p>P95가 수 초라는 건 뭘 의미할까요? 20명의 유저분들 중 1분은 수초의 응답을 기다리고 있다는 뜻입니다. 솔직히 예전에는 &amp;ldquo;상위 5%니까 대부분은 괜찮은 거 아닌가?&amp;rdquo; 싶기도 했습니다. 근데 생각해보면 트래픽이 높은 API일수록 그 &amp;ldquo;1명&amp;quot;의 절대 수는 결코 적지 않게 됩니다. 하루에 수만 건씩 들어오는 API에서 5%면, 매일 수천 명의 사용자가 느린 응답을 경험하고 있다는 계산이 나오니까요. 제가 서비스를 이용하는 유저라면 그런 경험을 하고 싶지 않을 거라 확신합니다.&lt;/p>
&lt;p>그러다보니 당연히 그냥 넘어갈 수가 없었습니다. 약 10일간 집중적으로 성능 최적화 작업을 진행했고, 그 과정에서 했던 고민과 선택, 결과를 정리해보려 합니다. 제 경험이 비슷한 상황을 겪고 계신 분들에게 조금이나마 도움이 되면 좋겠습니다. 다만 저도 아직 열심히 공부하며 일하는 입장이라, 더 나은 방법이 있다면 편하게 의견 주시면 감사하겠습니다.&lt;/p>
&lt;h2>출발점: 어디서부터 손을 대야 할까&lt;span class="hx:absolute hx:-mt-20" id="출발점-어디서부터-손을-대야-할까">&lt;/span>
&lt;a href="#%ec%b6%9c%eb%b0%9c%ec%a0%90-%ec%96%b4%eb%94%94%ec%84%9c%eb%b6%80%ed%84%b0-%ec%86%90%ec%9d%84-%eb%8c%80%ec%95%bc-%ed%95%a0%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>성능 개선이 필요하다는 건 알겠는데, 막상 시작하려니 어디서부터 건드려야 할지가 고민이였습니다. &amp;ldquo;느리다&amp;quot;라는 단순한 감만으로 방향을 잡을 수는 없으니까요.&lt;/p>
&lt;p>여기서 먼저 한 가지 짚고 넘어가고 싶은 부분이 있습니다. 성능 최적화에서 가장 위험한 건 &lt;strong>&amp;ldquo;아마 여기가 느릴 거야&amp;quot;라는 추측으로 시작하는 것&lt;/strong> 이지 않나 싶습니다. 제가 말하는 &amp;ldquo;여기&amp;quot;라는건 API자체 뿐만 아니라 코드의 특정 부분, 데이터베이스 쿼리, 네트워크 병목, 외부 API 호출일 수도 있습니다.&lt;/p>
&lt;p>저도 처음에는 &amp;ldquo;병목이 발생하는 API에 캐시를 도입하면 나아지지 않나?&amp;rdquo; 싶었는데, 실제로 측정해보니 병목이 생각했던 곳과 다른 경우가 꽤 있었거든요. 결국 가장 먼저 한 건 &lt;strong>현재 상태를 정확하게 파악하는 것&lt;/strong>이었습니다.&lt;/p>
&lt;p>먼저 Prometheus 메트릭과 Grafana 대시보드, 그리고 Tempo의 분산 트레이싱을 활용해서 병목 지점을 하나씩 분석하기 시작했습니다. 그런 후에 DB에 병목이 있는지, 코드의 특정 부분이 느린지, 외부 API 호출이 문제인지 등을 구체적으로 파악했습니다.&lt;/p>
&lt;p>만약 DB의 쿼리가 문제라면, EXPLAIN으로 쿼리 실행 계획을 뜯어봤죠. 코드만 봐서는 절대 보이지 않던 것들이, 숫자 앞에서는 너무나 명확하게 드러났습니다.&lt;/p>
&lt;p>분석 결과를 정리해보니 대부분 병목의 원인은 크게 세 가지로 분류할 수 있었습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
graph LR
Root[&amp;#34;성능 병목&amp;#34;] --&amp;gt; A[&amp;#34;쿼리 비효율&amp;#34;]
Root --&amp;gt; B[&amp;#34;순차 처리&amp;#34;]
Root --&amp;gt; C[&amp;#34;반복 조회&amp;#34;]
A --&amp;gt; A1[&amp;#34;Non-sargable WHERE&amp;#34;]
A --&amp;gt; A2[&amp;#34;N+1 쿼리&amp;#34;]
A --&amp;gt; A3[&amp;#34;Full Table Scan&amp;#34;]
B --&amp;gt; B1[&amp;#34;API 순차 호출&amp;#34;]
B --&amp;gt; B2[&amp;#34;독립적 API 직렬 처리&amp;#34;]
C --&amp;gt; C1[&amp;#34;동일 데이터 반복 DB 조회&amp;#34;]
C --&amp;gt; C2[&amp;#34;동일 데이터 중복 조회&amp;#34;]
style A fill:#f85149,color:#fff
style B fill:#b35000,color:#fff
style C fill:#1f6feb,color:#fff
&lt;/pre>&lt;ol>
&lt;li>&lt;strong>쿼리 비효율&lt;/strong> — 인덱스를 타지 못하는 WHERE 절, N+1 쿼리, 누락된 인덱스&lt;/li>
&lt;li>&lt;strong>순차 처리&lt;/strong> — 독립적인 API 호출을 순서대로 하고 있는 구조&lt;/li>
&lt;li>&lt;strong>반복 조회&lt;/strong> — 같은 데이터를 매 요청마다 DB에서 새로 가져오는 구조&lt;/li>
&lt;/ol>
&lt;p>자 이제 병목지점을 파악했으니 하나하나씩 자세히 이야기해보겠습니다.&lt;/p>
&lt;h2>쿼리 최적화 — 인덱스를 걸어도 소용없는 이유가 있었다&lt;span class="hx:absolute hx:-mt-20" id="쿼리-최적화--인덱스를-걸어도-소용없는-이유가-있었다">&lt;/span>
&lt;a href="#%ec%bf%bc%eb%a6%ac-%ec%b5%9c%ec%a0%81%ed%99%94--%ec%9d%b8%eb%8d%b1%ec%8a%a4%eb%a5%bc-%ea%b1%b8%ec%96%b4%eb%8f%84-%ec%86%8c%ec%9a%a9%ec%97%86%eb%8a%94-%ec%9d%b4%ec%9c%a0%ea%b0%80-%ec%9e%88%ec%97%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>랭킹 API: P95 tail latency가 비정상적으로 높았던 이유&lt;span class="hx:absolute hx:-mt-20" id="랭킹-api-p95-tail-latency가-비정상적으로-높았던-이유">&lt;/span>
&lt;a href="#%eb%9e%ad%ed%82%b9-api-p95-tail-latency%ea%b0%80-%eb%b9%84%ec%a0%95%ec%83%81%ec%a0%81%ec%9c%bc%eb%a1%9c-%eb%86%92%ec%95%98%eb%8d%98-%ec%9d%b4%ec%9c%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>저희 회사는 부동산 플랫폼이다보니 부동산의 &amp;ldquo;거래량 랭킹&amp;rdquo;, &amp;ldquo;단가 랭킹&amp;rdquo; 같은 API가 존재합니다. 해당 API들이 대부분의 단일 월 조회 요청은 정상 범위 내에서 처리되고 있었지만, &lt;strong>연도를 걸치는 기간 조회&lt;/strong>가 들어오면 상황이 달라졌습니다. 이 경우 P95가 &lt;strong>7.24초&lt;/strong>까지 치솟는 것이 관측됐습니다.&lt;/p>
&lt;p>7초요. API 응답이 7초. 사용자분 입장에서는 화면이 멈춘 것처럼 느껴졌을 겁니다. 아마 참지 못하고 이탈하셨을 것 같습니다.&lt;/p>
&lt;blockquote>
&lt;p>여기서 그러면 어떻게 이상태로 서비스를 운영할 수 있었냐는 질문이 나올 수 있을 것 같습니다. 그에대한 부가 설명을 드리자면
기존에는 클라이언트단에서 월간 조회만 허용하도록하여 &lt;strong>연도를 걸치는 기간 조회&lt;/strong>가 요청되지 않았었지만 &amp;ldquo;연도를 걸치는 기간 조회도 필요하다&amp;quot;는 고객분들의 피드백이 있었고, 결국 이 기능을 추가하기로 결정했습니다. 백엔드는 이미 &lt;strong>연도를 걸치는 기간 조회&lt;/strong>가 &lt;strong>기능은 하도록&lt;/strong> 개발되어 있는 상태에서 클라이언트(프론트)만 업뎃이 필요한 상황이었고, 프론트 업데이트가 완료된 후에야 이 문제가 발견됐습니다. 그래서 &amp;ldquo;서비스 운영은 가능했지만, 고객분들이 느린 응답을 경험하셨던 상황&amp;quot;이었던 거죠.&lt;/p>
&lt;/blockquote>
&lt;p>데이터는 월별 가격 테이블이 120만 건, 월별 거래 테이블이 87만 건이었습니다. 백만 건의 데이터 수준에서 인덱스만 제대로 탄다면 이 정도 지연이 발생할 리가 없었습니다. 그래서 뭔가 다른 원인이 있을 거라고 생각했습니다.&lt;/p>
&lt;p>먼저 이 테이블들의 스키마를 짚고 가야 할 것 같습니다. 연월 정보가 &lt;code>DATE&lt;/code>나 &lt;code>TIMESTAMP&lt;/code> 같은 단일 컬럼이 아니라 &lt;code>aggregation_year&lt;/code>(INT)와 &lt;code>aggregation_month&lt;/code>(INT)로 &lt;strong>년 정보와 월 정보가 분리된 구조&lt;/strong>였습니다.&lt;/p>
&lt;p>EXPLAIN을 찍어보고 나서야 원인을 찾았습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- 기존 쿼리의 WHERE 절
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">aggregation_year&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">100&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">+&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">aggregation_month&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">BETWEEN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AND&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 쿼리의 문제가 보이시나요?&lt;/p>
&lt;p>코드만 보면 문제가 없어보일 수 있습니다. &lt;code>year * 100 + month&lt;/code>로 &lt;code>202603&lt;/code> 같은 정수를 만들어서 &lt;code>BETWEEN&lt;/code>으로 범위를 잡는 거죠.&lt;/p>
&lt;p>하지만 문제는 &lt;strong>MySQL 옵티마이저 입장&lt;/strong>에서 봐야 보입니다. &lt;code>aggregation_year * 100 + aggregation_month&lt;/code>이라는 &lt;strong>컬럼 연산&lt;/strong>이 WHERE 절에 들어가 있으면, 옵티마이저는 인덱스를 사용할 수 없습니다. 컬럼 값을 가공한 결과가 인덱스에 저장된 게 아니니까요. 이런 조건을 &lt;strong>Non-sargable(Search ARGument ABLE이 아닌) expression&lt;/strong>이라고 합니다.&lt;/p>
&lt;p>EXPLAIN 결과를 보면 명확합니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>항목&lt;/th>
&lt;th>값&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>type&lt;/td>
&lt;td>&lt;strong>ALL&lt;/strong> (풀 테이블 스캔)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>rows&lt;/td>
&lt;td>&lt;strong>1,195,038&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Extra&lt;/td>
&lt;td>Using where; Using temporary; Using filesort&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>120만 건을 &lt;strong>전부 읽고&lt;/strong>, 임시 테이블을 만들고, 정렬까지 하고 있었습니다. 인덱스가 있어도 이 WHERE 절 때문에 아무 소용이 없었던 거죠. 어떠신가요? 인덱스를 걸어놓고 &amp;ldquo;이제 괜찮겠지&amp;rdquo; 하고 안심하신 적 없으신가요? 저는 있었습니다&amp;hellip;&lt;/p>
&lt;p>만약 단일 날짜 컬럼이었다면 &lt;code>BETWEEN '2025-01' AND '2026-03'&lt;/code> 같은 단순한 범위 조건으로 인덱스를 탈 수 있었겠지만, 이미 운영 중인 테이블이라 스키마를 바꾸기는 어려운 상황이었습니다. 결국 이 분리된 구조 안에서 최선의 쿼리를 짜야 했습니다.&lt;/p>
&lt;h4>1차 개선: Sargable 조건으로 변환&lt;span class="hx:absolute hx:-mt-20" id="1차-개선-sargable-조건으로-변환">&lt;/span>
&lt;a href="#1%ec%b0%a8-%ea%b0%9c%ec%84%a0-sargable-%ec%a1%b0%ea%b1%b4%ec%9c%bc%eb%a1%9c-%eb%b3%80%ed%99%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>원인을 알았으니 방향은 하나였습니다. 컬럼 연산을 제거해서 옵티마이저가 인덱스를 탈 수 있게 만드는 거죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- 변경 후: 컬럼 연산 없이 각 컬럼을 직접 비교
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">aggregation_year&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="n">start_year&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">OR&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">aggregation_year&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="n">start_year&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AND&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">aggregation_month&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">&amp;gt;=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="n">start_month&lt;/span>&lt;span class="p">))&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">AND&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">aggregation_year&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="n">end_year&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">OR&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">aggregation_year&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="n">end_year&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AND&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">aggregation_month&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">&amp;lt;=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="n">end_month&lt;/span>&lt;span class="p">))&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>원래 하나의 수식으로 깔끔하게 표현되던 걸 풀어 쓰니 코드가 길어졌지만, 옵티마이저 입장에서는 이제 &lt;code>aggregation_year&lt;/code>와 &lt;code>aggregation_month&lt;/code> 컬럼을 직접 비교할 수 있게 되었습니다.&lt;/p>
&lt;p>여기에 &lt;code>(aggregation_year, aggregation_month)&lt;/code> 복합 인덱스를 추가했고, 세대수 랭킹 API에는 불필요한 GROUP BY를 제거하고 최근 1개월만 조회하도록 변경했습니다. 세대수는 아파트의 고유 속성이라 매월 같은 값이거든요. 굳이 전 기간을 GROUP BY할 이유가 없었습니다.&lt;/p>
&lt;h4>2차 개선: 조회 패턴에 맞는 조건 분기&lt;span class="hx:absolute hx:-mt-20" id="2차-개선-조회-패턴에-맞는-조건-분기">&lt;/span>
&lt;a href="#2%ec%b0%a8-%ea%b0%9c%ec%84%a0-%ec%a1%b0%ed%9a%8c-%ed%8c%a8%ed%84%b4%ec%97%90-%eb%a7%9e%eb%8a%94-%ec%a1%b0%ea%b1%b4-%eb%b6%84%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>1차 개선으로 EXPLAIN이 개선됐지만, 실제 사용 패턴을 분석해보니 한 가지 더 최적화할 수 있는 포인트가 보였습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
graph TB
Request[&amp;#34;기간 조회 요청&amp;#34;] --&amp;gt; Check{&amp;#34;조건 분석&amp;#34;}
Check --&amp;gt;|&amp;#34;단일 월 (가장 빈번)&amp;#34;| Single[&amp;#34;year = ? AND month = ?&amp;lt;br/&amp;gt;→ ref 인덱스 (등호 조건)&amp;#34;]
Check --&amp;gt;|&amp;#34;같은 해 범위&amp;#34;| SameYear[&amp;#34;year = ? AND month BETWEEN ? AND ?&amp;lt;br/&amp;gt;→ range 스캔&amp;#34;]
Check --&amp;gt;|&amp;#34;연도 걸침 (드묾)&amp;#34;| CrossYear[&amp;#34;OR 패턴 유지&amp;lt;br/&amp;gt;→ range 스캔&amp;#34;]
style Single fill:#3fb950,color:#fff
style SameYear fill:#1f6feb,color:#fff
style CrossYear fill:#484f58,color:#fff
&lt;/pre>&lt;p>실제 트래픽의 대부분은 &lt;strong>&amp;ldquo;이번 달&amp;rdquo;&lt;/strong>, &lt;strong>&amp;ldquo;1개월 전&amp;rdquo;&lt;/strong> 과 같은 단일 월 조회였습니다. 단일 월이면 &lt;code>year = ? AND month = ?&lt;/code>라는 &lt;strong>등호 조건&lt;/strong>만으로 충분한데, 범용적인 기간 조회 로직을 타고 있으니 옵티마이저가 &lt;code>range&lt;/code> 스캔을 하고 있었습니다.&lt;/p>
&lt;p>그래서 조회 패턴에 따라 분기를 추가했습니다. 단일 월이면 등호 조건으로 &lt;code>ref&lt;/code> 인덱스 룩업을, 같은 해 범위면 &lt;code>BETWEEN&lt;/code>을, 연도가 걸치는 드문 경우에만 기존 OR 패턴을 사용하도록 쿼리를 분기한거죠.&lt;/p>
&lt;h4>결과&lt;span class="hx:absolute hx:-mt-20" id="결과">&lt;/span>
&lt;a href="#%ea%b2%b0%ea%b3%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>EXPLAIN에 그 결과가 바로 나오게 됐습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>항목&lt;/th>
&lt;th>Before&lt;/th>
&lt;th>After&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>type&lt;/td>
&lt;td>ALL&lt;/td>
&lt;td>&lt;strong>ref&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>rows&lt;/td>
&lt;td>1,195,038&lt;/td>
&lt;td>&lt;strong>14,122&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Extra&lt;/td>
&lt;td>Using temporary; Using filesort&lt;/td>
&lt;td>—&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>120만 건 풀 스캔이 1.4만 건 인덱스 룩업으로 바뀌었습니다.&lt;/p>
&lt;p>아래는 운영 환경 Grafana 대시보드에서 캡처한 거래량 랭킹 API의 P95 응답시간입니다. 첫 번째 이미지에서 배포 시점(점선)을 기준으로 응답시간이 급락하는 것을 확인할 수 있고, 두 번째 이미지에서 최적화 후 5일간 안정적으로 유지되고 있는 것을 볼 수 있습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/9murattffr40rdve4k8ep/query-optimization-before.png?rlkey=lunzfzlps6qaabp5uxi831xvd&amp;amp;st=cq0s9rok&amp;amp;raw=1" alt="거래량 랭킹 API — 쿼리 최적화 전 P95 (배포 시점 표시)" loading="lazy" />&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/rmg3tt6pif9070r3qvq2o/query-optimization-result.png?rlkey=lg663dcyrd4rj54fkno8unxvw&amp;amp;st=mwtfokri&amp;amp;raw=1" alt="거래량 랭킹 API — 쿼리 최적화 후 P95 모니터링 (5일간)" loading="lazy" />&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>API&lt;/th>
&lt;th>req/s&lt;/th>
&lt;th>Before&lt;/th>
&lt;th>P50 (운영)&lt;/th>
&lt;th>P95 (운영)&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>거래량 랭킹&lt;/td>
&lt;td>16.0&lt;/td>
&lt;td>1.9~2.4s&lt;/td>
&lt;td>&lt;strong>49ms&lt;/strong>&lt;/td>
&lt;td>&lt;strong>95ms&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>단가 랭킹&lt;/td>
&lt;td>1.2&lt;/td>
&lt;td>7.24s&lt;/td>
&lt;td>&lt;strong>126ms&lt;/strong>&lt;/td>
&lt;td>3.1s&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>세대수 랭킹&lt;/td>
&lt;td>0.8&lt;/td>
&lt;td>6.33s&lt;/td>
&lt;td>&lt;strong>125ms&lt;/strong>&lt;/td>
&lt;td>792ms&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>거래량 랭킹은 P50·P95 모두 100ms 이내로 안정적입니다. 단가·세대수 랭킹의 경우 대부분의 요청(P50)은 &lt;strong>~125ms&lt;/strong>로 개선됐지만, 연도를 걸치는 기간 조회에서 아직 tail latency가 남아있습니다. 근본적으로는 &lt;code>year&lt;/code>와 &lt;code>month&lt;/code>가 분리된 스키마 구조의 한계입니다. MySQL의 Generated Column으로 &lt;code>year_month&lt;/code>(INT, 예: &lt;code>202603&lt;/code>) 같은 단일 컬럼을 추가하면 단순 &lt;code>BETWEEN&lt;/code>으로 해결할 수 있지만, 120만 건 이상의 운영 테이블 마이그레이션이 수반되는 작업이라 시간을 두고 진행할 계획입니다.&lt;/p>
&lt;p>코드만 보면 깔끔해 보이는 &lt;code>year * 100 + month&lt;/code> 같은 표현이, 실은 120만 건 풀 스캔의 원인이 될 수 있다는 걸 이번에 제대로 체감했습니다. 쿼리 최적화는 단순히 인덱스가 있느냐 없느냐의 문제가 아니라, &lt;strong>인덱스를 탈 수 있는 쿼리를 짜느냐&lt;/strong>의 문제라는 걸 다시 한 번 깨달았습니다. 인덱스가 있어도 옵티마이저가 탈 수 없는 쿼리를 짜놓으면, 결국 인덱스가 없는 것과 다름없게 된다는 거죠.&lt;/p>
&lt;hr>
&lt;h3>배치 N+1: 1,000건을 처리하는 데 쿼리가 4,000개씩 나가고 있었다&lt;span class="hx:absolute hx:-mt-20" id="배치-n1-1000건을-처리하는-데-쿼리가-4000개씩-나가고-있었다">&lt;/span>
&lt;a href="#%eb%b0%b0%ec%b9%98-n1-1000%ea%b1%b4%ec%9d%84-%ec%b2%98%eb%a6%ac%ed%95%98%eb%8a%94-%eb%8d%b0-%ec%bf%bc%eb%a6%ac%ea%b0%80-4000%ea%b0%9c%ec%94%a9-%eb%82%98%ea%b0%80%ea%b3%a0-%ec%9e%88%ec%97%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>저희 플랫폼에는 매일 오전에 실행되는 배치 작업이 있습니다. 사용자가 관심 등록한 아파트에 새로운 거래가 발생하면 알림을 보내주는 기능인데, 평균 실행 시간이 &lt;strong>약 50분&lt;/strong>에 달하고 있었습니다. 평소에는 30분대로 끝나기도 했지만, 신규 거래 데이터가 몰리는 날에는 70~87분까지 치솟는 패턴이 반복되고 있었습니다(&lt;code>BATCH_JOB_EXECUTION&lt;/code> 메타 테이블 기준).&lt;/p>
&lt;p>평균 50분, 최대 87분이면 꽤 긴 시간이죠. 배치가 도는 동안 새로 발생한 거래 알림이 밀리게 되고, 사용자 입장에서는 &amp;ldquo;거래가 체결됐는데 알림이 늦게 오네&amp;rdquo; 하는 상황이 계속되고 있었습니다.&lt;/p>
&lt;p>배치가 처리해야 하는 관심 아파트는 &lt;strong>수만 건&lt;/strong>. 문제는 이 수만 건을 처리하면서 발생하는 쿼리의 수였습니다.&lt;/p>
&lt;p>기존 코드의 흐름을 단순화하면 이랬습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant Batch as 배치 Job
participant DB as Database
loop 관심 아파트 1건마다
Batch-&amp;gt;&amp;gt;DB: 알림 히스토리 조회
Batch-&amp;gt;&amp;gt;DB: 평형 정보 조회
Batch-&amp;gt;&amp;gt;DB: 신규 거래 조회 (400만~700만 건 테이블)
Batch-&amp;gt;&amp;gt;DB: 알림 설정 조회
end
Note over Batch,DB: 1,000건 처리 시 → 약 4,001개 쿼리
&lt;/pre>&lt;p>전형적인 &lt;strong>N+1 문제&lt;/strong>였습니다. 1,000건의 관심 아파트를 처리하려면 약 4,001개의 쿼리가 발생하고 있었던 거죠. 수만 건이면&amp;hellip; 계산하기도 싫을 정도입니다.&lt;/p>
&lt;p>거기에 더해 관심 아파트를 읽는 Reader 쿼리 자체도 문제가 있었습니다. 중복 제거를 위해 &lt;code>SELECT MAX(id)&lt;/code> 서브쿼리를 사용하고 있었는데, 이 서브쿼리가 매 페이지마다 &lt;strong>풀 테이블 스캔&lt;/strong>을 유발하고 있었습니다. 데이터가 쌓일수록 점점 느려지는 구조였고, 한 페이지를 읽는 데만 &lt;strong>35.6초&lt;/strong>가 걸리는 지경이었습니다.&lt;/p>
&lt;h4>해결: 페이지 레벨 프리페치 + 배치 조회&lt;span class="hx:absolute hx:-mt-20" id="해결-페이지-레벨-프리페치--배치-조회">&lt;/span>
&lt;a href="#%ed%95%b4%ea%b2%b0-%ed%8e%98%ec%9d%b4%ec%a7%80-%eb%a0%88%eb%b2%a8-%ed%94%84%eb%a6%ac%ed%8e%98%ec%b9%98--%eb%b0%b0%ec%b9%98-%ec%a1%b0%ed%9a%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>N+1을 잡는 방법은 여러 가지가 있습니다. 각각의 트레이드오프를 먼저 정리해보겠습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>전략&lt;/th>
&lt;th>장점&lt;/th>
&lt;th>단점&lt;/th>
&lt;th>적합한 경우&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>@BatchSize&lt;/code>&lt;/td>
&lt;td>어노테이션 하나로 적용 가능&lt;/td>
&lt;td>엔티티 연관관계를 통한 접근이어야 함&lt;/td>
&lt;td>JPA lazy loading에 의한 N+1&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>JOIN FETCH&lt;/code>&lt;/td>
&lt;td>한 번의 쿼리로 해결&lt;/td>
&lt;td>페이징 불가, 카테시안 곱 위험&lt;/td>
&lt;td>연관 엔티티가 적고 소량일 때&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>프리페치 + IN 절&lt;/td>
&lt;td>구조적 제약 없음&lt;/td>
&lt;td>직접 구현 필요, 캐시 관리 책임&lt;/td>
&lt;td>Repository 직접 호출 구조&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>처음에는 &lt;code>@BatchSize&lt;/code>를 떠올렸습니다. 가장 간단하니까요. 하지만 이 배치의 구조를 자세히 들여다보니 걸림돌이 있었습니다. Spring Batch의 Reader가 페이지 단위로 관심 아파트를 읽어오고, Processor에서 건별로 부가 데이터(알림 히스토리, 평형 정보 등)를 &lt;strong>별도 쿼리&lt;/strong>로 조회하는 구조였거든요. 엔티티 연관관계를 통한 접근이 아니라 직접 Repository를 호출하는 방식이었기 때문에, JPA 레벨의 페치 전략으로는 손을 댈 수가 없었습니다. &lt;code>JOIN FETCH&lt;/code>도 같은 이유로 적용 불가였고요.&lt;/p>
&lt;p>그래서 남은 선택지는 프리페치밖에 없었습니다. &lt;strong>Reader가 페이지를 읽어올 때, 그 페이지에 필요한 부가 데이터를 IN 절로 한꺼번에 조회&lt;/strong>해서 &lt;code>ConcurrentHashMap&lt;/code>에 올려두는 프리페치 캐시를 직접 구현하는 거였습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant Batch as 배치 Job
participant Cache as 프리페치 캐시
participant DB as Database
Batch-&amp;gt;&amp;gt;DB: 관심 아파트 페이지 조회 (배치 단위)
Batch-&amp;gt;&amp;gt;DB: 알림 히스토리 일괄 조회 (IN 절)
Batch-&amp;gt;&amp;gt;DB: 평형 정보 일괄 조회 (IN 절)
Batch-&amp;gt;&amp;gt;Cache: 캐시에 적재
loop 관심 아파트 1건마다
Batch-&amp;gt;&amp;gt;Cache: 캐시에서 조회 (DB 호출 없음)
end
Note over Batch,DB: 1,000건 처리 시 → 2개 배치 쿼리
&lt;/pre>&lt;p>건별로 4개씩 나가던 쿼리가 페이지당 2개의 배치 쿼리로 줄었습니다.&lt;/p>
&lt;p>그리고 Reader의 중복 제거 쿼리도 &lt;code>NOT EXISTS&lt;/code> 패턴으로 변경하고 복합 인덱스를 활용하도록 했습니다.&lt;/p>
&lt;p>알림 설정 조회의 경우에는 같은 사용자의 알림 설정이 반복 조회되는 패턴이 있어서 &lt;code>ConcurrentHashMap&lt;/code> 기반의 인메모리 캐시를 적용했고, 중복 알림 필터링도 건별 &lt;code>EXISTS&lt;/code> 쿼리에서 배치 조회 + 인메모리 필터링으로 변경했습니다.&lt;/p>
&lt;h4>결과&lt;span class="hx:absolute hx:-mt-20" id="결과-1">&lt;/span>
&lt;a href="#%ea%b2%b0%ea%b3%bc-1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>항목&lt;/th>
&lt;th>Before&lt;/th>
&lt;th>After&lt;/th>
&lt;th>개선율&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Reader 1페이지 조회&lt;/td>
&lt;td>&lt;strong>35.6초&lt;/strong>&lt;/td>
&lt;td>&lt;strong>15ms&lt;/strong>&lt;/td>
&lt;td>&lt;strong>~2,400배&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>쿼리 수 (1,000건 기준)&lt;/td>
&lt;td>&lt;strong>~4,001개&lt;/strong>&lt;/td>
&lt;td>&lt;strong>2개&lt;/strong>&lt;/td>
&lt;td>&lt;strong>~2,000배&lt;/strong>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Reader 최적화와 N+1 해결이 합산되면서, 전체 배치 실행시간도 평균 &lt;strong>약 21분&lt;/strong>으로 줄었습니다(&lt;code>BATCH_JOB_EXECUTION&lt;/code> 메타 테이블 기준). 최적화 전 70~87분대 스파이크가 완전히 사라졌고, 최대치도 25분 이내로 안정화됐습니다.&lt;/p>
&lt;p>여기서 한 가지 의아한 부분이 있으실 수 있습니다. 쿼리 수는 2,000배나 줄었는데 전체 실행시간은 59%밖에 안 줄었다고요? 최적화 후에도 아이템 하나당 평균 10초 이상이 걸리고 있었는데, 원인을 공유드리자면 이 시간의 대부분은 이메일·알림톡·푸시 등 &lt;strong>외부 알림 발송 API 호출&lt;/strong>이 차지하고 있었습니다. DB 병목은 해소됐지만, 외부 API 호출이라는 구간은 우리 쪽에서 줄일 수 없는 영역이었던 거죠. 결국 &amp;ldquo;DB 쿼리를 아무리 최적화해도 전체 시간의 대부분이 외부 호출이면 한계가 있다&amp;quot;는, 어찌 보면 당연한 사실을 숫자로 확인한 셈이었습니다.&lt;/p>
&lt;p>테스트 코드도 충분히 작성했습니다. 솔직히 배치 코드를 수정할 때가 가장 긴장됐습니다. 한번 문제가 생기면 수만 건의 사용자에게 잘못된 알림이 가거나 알림이 누락될 수 있거든요. 그래서 테스트 커버리지를 넉넉히 확보해두는 게 중요하다고 생각합니다.&lt;/p>
&lt;hr>
&lt;h3>계약 통계 API: 코드에서 집계하고 있었다&lt;span class="hx:absolute hx:-mt-20" id="계약-통계-api-코드에서-집계하고-있었다">&lt;/span>
&lt;a href="#%ea%b3%84%ec%95%bd-%ed%86%b5%ea%b3%84-api-%ec%bd%94%eb%93%9c%ec%97%90%ec%84%9c-%ec%a7%91%ea%b3%84%ed%95%98%ea%b3%a0-%ec%9e%88%ec%97%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>계약 관련 통계 API도 P95 기준으로 &lt;strong>2.4초&lt;/strong>의 tail latency가 관측되고 있었습니다. 단순히 건수와 합계를 보여주는 API인데, 왜 이렇게 오래 걸릴까요? 솔직히 이건 Grafana에서 P95 정렬을 걸지 않았으면 지나쳤을 겁니다. 평균 응답시간만 봤을 때는 멀쩡했거든요. 평균의 함정이라는 게 이런 거구나 싶었습니다.&lt;/p>
&lt;p>코드를 열어보니 두 가지 문제가 있었습니다.&lt;/p>
&lt;p>첫째, 정산일 기준으로 조회하는데 정산일 컬럼에 &lt;strong>인덱스가 없었습니다&lt;/strong>. EXPLAIN을 찍어보니 랭킹 API와 같은 패턴이었습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>항목&lt;/th>
&lt;th>값&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>type&lt;/td>
&lt;td>&lt;strong>ALL&lt;/strong> (풀 테이블 스캔)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>rows&lt;/td>
&lt;td>&lt;strong>2,021&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>key&lt;/td>
&lt;td>&lt;strong>NULL&lt;/strong> (인덱스 미사용)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>2천 건밖에 안 되는 테이블인데 풀 스캔을 하고 있었습니다. 데이터 규모가 작다 보니 인덱스 없이도 응답이 돌아오긴 했고, 그래서 개발 시점에 인덱스 설계가 누락된 것으로 보입니다. 하지만 데이터가 적어서 체감이 덜했을 뿐, 구조적으로는 랭킹 API와 같은 문제였습니다.&lt;/p>
&lt;p>둘째, 더 근본적인 문제가 있었습니다. SQL에서 &lt;code>COUNT&lt;/code>와 &lt;code>SUM&lt;/code>을 하면 될 것을 &lt;strong>전체 데이터를 코드로 가져와서&lt;/strong> &lt;code>.size&lt;/code>로 카운트하고 &lt;code>.sumOf {}&lt;/code>로 합산하고 있었습니다. DB에서 집계하면 결과 1행만 전송하면 되는데, 전체 행을 애플리케이션으로 가져온 뒤 메모리에서 집계하고 있었던 거죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Before: DB에서 전체 목록을 가져온 뒤 코드에서 집계
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">val&lt;/span> &lt;span class="py">settlements&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">repository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">findAllSettlementAmount&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">from&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">to&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">val&lt;/span> &lt;span class="py">totalCount&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">settlements&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">size&lt;/span> &lt;span class="c1">// COUNT를 코드에서
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">val&lt;/span> &lt;span class="py">totalAmount&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">settlements&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">sumOf&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="k">it&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="c1">// SUM을 코드에서&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// After: DB에서 직접 집계
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">val&lt;/span> &lt;span class="py">summary&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">repository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">findSettlementSummary&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">from&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">to&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// → SELECT COUNT(*), SUM(amount) FROM ... WHERE ...&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>정산일 컬럼에 인덱스를 추가하고 SQL 집계로 변경했습니다. EXPLAIN을 다시 찍어보니 &lt;code>type&lt;/code>이 &lt;code>ref&lt;/code>로 바뀌고, 인덱스를 정확히 타고 있었습니다. P95가 &lt;strong>2.4초에서 100ms 이하&lt;/strong>로 떨어졌습니다.&lt;/p>
&lt;p>수정한 코드는 50줄도 안 됐습니다. 그런데 불필요한 데이터 전송과 애플리케이션 메모리 사용을 한 번에 줄인 셈이었습니다. 이런 케이스를 보면 &amp;ldquo;DB가 잘하는 일은 DB에게 맡기자&amp;quot;라는 기본적인 원칙이 왜 중요한지 새삼 느끼게 됩니다.&lt;/p>
&lt;h2>병렬화 — 순서가 필요 없는 것들을 왜 순서대로 하고 있었을까&lt;span class="hx:absolute hx:-mt-20" id="병렬화--순서가-필요-없는-것들을-왜-순서대로-하고-있었을까">&lt;/span>
&lt;a href="#%eb%b3%91%eb%a0%ac%ed%99%94--%ec%88%9c%ec%84%9c%ea%b0%80-%ed%95%84%ec%9a%94-%ec%97%86%eb%8a%94-%ea%b2%83%eb%93%a4%ec%9d%84-%ec%99%9c-%ec%88%9c%ec%84%9c%eb%8c%80%eb%a1%9c-%ed%95%98%ea%b3%a0-%ec%9e%88%ec%97%88%ec%9d%84%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>쿼리 최적화를 끝내고 다음으로 눈을 돌린 건 &lt;strong>순차 처리&lt;/strong> 구간이었습니다. Tempo 트레이스의 span waterfall을 보면 이런 패턴이 자주 보이더라구요. 서로 의존성이 없는 호출들이 일렬로 늘어서 있는 거죠.&lt;/p>
&lt;h3>알림 발송: 이메일과 알림톡을 직렬로 보내고 있었다&lt;span class="hx:absolute hx:-mt-20" id="알림-발송-이메일과-알림톡을-직렬로-보내고-있었다">&lt;/span>
&lt;a href="#%ec%95%8c%eb%a6%bc-%eb%b0%9c%ec%86%a1-%ec%9d%b4%eb%a9%94%ec%9d%bc%ea%b3%bc-%ec%95%8c%eb%a6%bc%ed%86%a1%ec%9d%84-%ec%a7%81%eb%a0%ac%eb%a1%9c-%eb%b3%b4%eb%82%b4%ea%b3%a0-%ec%9e%88%ec%97%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>저희 회사 서비스는 중개사분과 사용자분의 매칭을 이어주는 플랫폼 입니다. 매칭이 성사되면 사용자에게 이메일과 알림톡으로 매칭 알림을 보내드리고 있는데, 매칭시에 알림 발송 API도 P95 기준으로 tail latency가 높았습니다.&lt;/p>
&lt;p>이메일과 알림톡을 모두 발송하는 경우, 두 외부 서비스의 응답 지연이 &lt;strong>직렬로 합산&lt;/strong>되면서 &lt;strong>느린경우 4.9초&lt;/strong>까지 올라가고 있었습니다. Tempo 트레이스를 펼쳐보니 원인이 바로 보였습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant Client
participant Server as 알림 서비스
participant Email as 이메일 발송
participant Alim as 알림톡 발송
Client-&amp;gt;&amp;gt;Server: POST /matching-alarm
Server-&amp;gt;&amp;gt;Server: 매칭 정보 조회 (91ms)
Server-&amp;gt;&amp;gt;Server: 중개사 정보 조회 (27ms)
Server-&amp;gt;&amp;gt;Email: 이메일 발송 (~1.3s)
Note over Server,Email: 완료 대기
Email--&amp;gt;&amp;gt;Server: 완료
Server-&amp;gt;&amp;gt;Alim: 알림톡 발송 (~1.3s)
Note over Server,Alim: 완료 대기
Alim--&amp;gt;&amp;gt;Server: 완료
Server--&amp;gt;&amp;gt;Client: 응답 (P95 ~4.9s)
&lt;/pre>&lt;p>이메일 발송이 끝나야 알림톡 발송이 시작되는 &lt;strong>순차 실행&lt;/strong> 구조였습니다. 이메일과 알림톡은 서로 의존성이 전혀 없는데 말이죠. 물론 알림과 같은 기능은 매칭에 의존성이 없기때문에 꼭 실시간으로 발송할 필요는 없지만 병목이 발생하게 되는 구조는 피하는 게 좋다고 생각했습니다.&lt;/p>
&lt;p>이메일 결과가 알림톡에 영향을 줄까요? 일반적으로는 그렇지 않을겁니다. 그런데 왜 순서대로 실행하고 있었을까요? 아마 코드를 처음 작성할 때 자연스럽게 위에서 아래로 작성하다 보니 그렇게 된 것 같습니다. 사실 저도 코드를 작성할 때 의식하지 않으면 이렇게 되는 경우가 있어서, 남일 같지 않았습니다.&lt;/p>
&lt;h4>해결: 코루틴으로 병렬 실행&lt;span class="hx:absolute hx:-mt-20" id="해결-코루틴으로-병렬-실행">&lt;/span>
&lt;a href="#%ed%95%b4%ea%b2%b0-%ec%bd%94%eb%a3%a8%ed%8b%b4%ec%9c%bc%eb%a1%9c-%eb%b3%91%eb%a0%ac-%ec%8b%a4%ed%96%89" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>의존성이 없으니 답은 명확했습니다. 코루틴의 &lt;code>async&lt;/code>로 병렬 실행하도록 변경했습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant Client
participant Server as 알림 서비스
participant Email as 이메일 발송
participant Alim as 알림톡 발송
Client-&amp;gt;&amp;gt;Server: POST /matching-alarm
Server-&amp;gt;&amp;gt;Server: 매칭/중개사 정보 조회 (~120ms)
par 병렬 실행
Server-&amp;gt;&amp;gt;Email: 이메일 발송 (~1.3s)
and
Server-&amp;gt;&amp;gt;Alim: 알림톡 발송 (~1.3s)
end
Email--&amp;gt;&amp;gt;Server: 완료
Alim--&amp;gt;&amp;gt;Server: 완료
Server--&amp;gt;&amp;gt;Client: 응답 (P95 ~2s)
&lt;/pre>&lt;p>&lt;code>coroutineScope&lt;/code> 안에서 두 작업을 &lt;code>async&lt;/code>로 동시에 시작하고, &lt;code>awaitAll()&lt;/code>로 둘 다 완료될 때까지 기다리도록 변경했습니다.&lt;/p>
&lt;p>여기서 한 가지 고민이 있었습니다. 이메일 발송이 실패하면 알림톡까지 같이 실패해야 할까요? 기본 &lt;code>coroutineScope&lt;/code>에서는 하나의 자식 코루틴이 실패하면 나머지도 취소됩니다. 하지만 이메일과 알림톡은 &lt;strong>서로 다른 채널&lt;/strong>이죠. 이메일이 실패했다고 알림톡까지 안 보내면, 사용자는 아무 알림도 받지 못하게 됩니다. 그래서 &lt;code>supervisorScope&lt;/code>를 사용해서 한쪽이 실패해도 다른 쪽에는 영향을 주지 않도록 했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="n">supervisorScope&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">emailJob&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">async&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="n">sendEmail&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">matching&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">agent&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">alimtalkJob&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">async&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="n">sendAlimtalk&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">matching&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">agent&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">awaitAll&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">emailJob&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">alimtalkJob&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>응답시간이 &lt;code>sum(이메일, 알림톡)&lt;/code>에서 &lt;code>max(이메일, 알림톡)&lt;/code>으로 바뀌니, 실측 기준 &lt;strong>P95가 4.9초에서 약 2초대로&lt;/strong> 떨어졌습니다. 이런식으로 병렬 처리로 개선할 수 있는 부분들을 찾아 개선하는 작업들을 이어갔죠.&lt;/p>
&lt;h3>독립적인 DB 조회도 병렬로&lt;span class="hx:absolute hx:-mt-20" id="독립적인-db-조회도-병렬로">&lt;/span>
&lt;a href="#%eb%8f%85%eb%a6%bd%ec%a0%81%ec%9d%b8-db-%ec%a1%b0%ed%9a%8c%eb%8f%84-%eb%b3%91%eb%a0%ac%eb%a1%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>비슷한 패턴이 DB 조회에서도 발견됐습니다. 하나의 API 내에서 3건의 DB 조회가 순차로 실행되고 있었는데, 분석해보니 세 번째 조회는 첫 번째, 두 번째 조회 결과에 &lt;strong>의존성이 없었습니다&lt;/strong>.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
graph LR
subgraph Before[&amp;#34;Before: 직렬 실행 (~150ms)&amp;#34;]
direction LR
B1[&amp;#34;1. 조회 A&amp;lt;br/&amp;gt;~50-80ms&amp;#34;] --&amp;gt; B2[&amp;#34;2. 조회 B (A 결과 필요)&amp;lt;br/&amp;gt;~30-50ms&amp;#34;]
B2 --&amp;gt; B3[&amp;#34;3. 조회 C (독립적)&amp;lt;br/&amp;gt;~30-50ms&amp;#34;]
end
subgraph After[&amp;#34;After: 부분 병렬 실행 (~100ms)&amp;#34;]
direction LR
A1[&amp;#34;1. 조회 A&amp;lt;br/&amp;gt;~50-80ms&amp;#34;] --&amp;gt; A2[&amp;#34;2. 조회 B (A 결과 필요)&amp;lt;br/&amp;gt;~30-50ms&amp;#34;]
A3[&amp;#34;3. 조회 C (독립적)&amp;lt;br/&amp;gt;~30-50ms&amp;#34;]
end
style B3 fill:#f85149,color:#fff
style A3 fill:#3fb950,color:#fff
&lt;/pre>&lt;p>조회 B는 조회 A의 결과가 필요하니 순차 실행이 맞지만, 조회 C는 A·B와 무관하게 실행할 수 있었습니다. 조회 C를 A+B와 병렬 실행하도록 변경했고, 이 로직의 소요시간이 약 &lt;strong>150ms에서 100ms&lt;/strong>로 줄었습니다. 절대적인 시간 차이는 크지 않지만, 이 로직이 여러 모듈에서 공통으로 사용되고 있어서 한 번의 수정으로 여러 API의 P95가 약 30% 개선되는 효과가 있었습니다.&lt;/p>
&lt;h2>캐싱 — 같은 데이터를 왜 매번 새로 가져올까&lt;span class="hx:absolute hx:-mt-20" id="캐싱--같은-데이터를-왜-매번-새로-가져올까">&lt;/span>
&lt;a href="#%ec%ba%90%ec%8b%b1--%ea%b0%99%ec%9d%80-%eb%8d%b0%ec%9d%b4%ed%84%b0%eb%a5%bc-%ec%99%9c-%eb%a7%a4%eb%b2%88-%ec%83%88%eb%a1%9c-%ea%b0%80%ec%a0%b8%ec%98%ac%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>쿼리를 고치고, 독립적인 호출을 병렬화하고 나니, 다음으로 눈에 들어온 건 &lt;strong>같은 데이터를 매번 DB에서 새로 가져오는 패턴&lt;/strong>이었습니다.&lt;/p>
&lt;h3>아파트 상세정보: 매 요청마다 13건 이상의 DB 조회&lt;span class="hx:absolute hx:-mt-20" id="아파트-상세정보-매-요청마다-13건-이상의-db-조회">&lt;/span>
&lt;a href="#%ec%95%84%ed%8c%8c%ed%8a%b8-%ec%83%81%ec%84%b8%ec%a0%95%eb%b3%b4-%eb%a7%a4-%ec%9a%94%ec%b2%ad%eb%a7%88%eb%8b%a4-13%ea%b1%b4-%ec%9d%b4%ec%83%81%ec%9d%98-db-%ec%a1%b0%ed%9a%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>상세 페이지 하나를 구성하려면 여러 종류의 데이터가 필요합니다. 기본정보, 주변 편의시설, 교통, 대출 정보 등이 각각 다른 모듈과 DB에 분산되어 있거든요. 이 API들의 내부를 들여다보니 &lt;strong>한 번의 요청에 13건 이상의 DB 조회&lt;/strong>와 6개 이상의 테이블을 JOIN하는 무거운 쿼리가 실행되고 있었습니다. 처음 Tempo 트레이스에서 이 span 목록을 봤을 때 &amp;ldquo;이게 한 번의 요청에서 다 나가는 거야?&amp;rdquo; 싶었습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
graph TB
User[&amp;#34;사용자 요청&amp;#34;] --&amp;gt; Detail[&amp;#34;상세 페이지&amp;#34;]
Detail --&amp;gt; Basic[&amp;#34;기본정보&amp;lt;br/&amp;gt;DB JOIN 6개 테이블&amp;#34;]
Detail --&amp;gt; Fac[&amp;#34;편의시설/교통&amp;lt;br/&amp;gt;12건 DB 조회&amp;#34;]
Detail --&amp;gt; Loan[&amp;#34;대출정보&amp;lt;br/&amp;gt;DB 조회&amp;#34;]
Detail --&amp;gt; Type[&amp;#34;평형정보&amp;lt;br/&amp;gt;DB 조회&amp;#34;]
Detail --&amp;gt; Recon[&amp;#34;재건축 일정&amp;lt;br/&amp;gt;DB 조회&amp;#34;]
style Fac fill:#f85149,color:#fff
style Basic fill:#b35000,color:#fff
&lt;/pre>&lt;p>편의시설/교통 정보가 특히 심했습니다. 학교, 병원, 마트, 공원, 버스, 지하철, 고속도로 등 POI(Point of Interest) 정보를 가져오기 위해 &lt;strong>12건의 DB 조회&lt;/strong>가 발생하고 있었거든요. 캐시가 없는 상태에서 이 12건의 조회가 모두 발생하면, P95 기준으로 tail latency가 수 초대까지 올라가는 건 당연한 결과였습니다.&lt;/p>
&lt;p>그런데 여기서 한 가지 질문을 던져보고 싶습니다. 아파트 주변의 학교나 지하철역이 매 요청마다 바뀔까요? 아마 그렇지 않을 겁니다. 주변 학교가 하루 사이에 이전하거나 지하철 노선이 갑자기 바뀌는 일은 거의 없으니까요. 이런 데이터는 &lt;strong>변경 빈도가 극히 낮은 준정적(semi-static) 데이터&lt;/strong>입니다. 그런데 매 요청마다 12건의 DB 조회를 하고 있었던 거죠. 매번 DB를 조회할 이유가 없지 않나 싶었습니다.&lt;/p>
&lt;h4>Redis Cache-Aside 패턴 적용&lt;span class="hx:absolute hx:-mt-20" id="redis-cache-aside-패턴-적용">&lt;/span>
&lt;a href="#redis-cache-aside-%ed%8c%a8%ed%84%b4-%ec%a0%81%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>캐싱 전략을 고민할 때 Write-Through와 Cache-Aside 중 어느 쪽이 맞을지 먼저 따져봤습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>전략&lt;/th>
&lt;th>동작 방식&lt;/th>
&lt;th>장점&lt;/th>
&lt;th>단점&lt;/th>
&lt;th>적합한 경우&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Write-Through&lt;/td>
&lt;td>쓰기 시 캐시도 함께 갱신&lt;/td>
&lt;td>캐시-DB 정합성 높음&lt;/td>
&lt;td>쓰기가 드문 데이터에 불필요한 오버헤드&lt;/td>
&lt;td>읽기/쓰기 모두 빈번한 데이터&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Cache-Aside&lt;/td>
&lt;td>읽을 때 캐시 먼저 확인&lt;/td>
&lt;td>읽기 성능 극대화, 구현 단순&lt;/td>
&lt;td>TTL 만료 시 일시적 stale 가능&lt;/td>
&lt;td>변경 빈도 낮은 조회 위주 데이터&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>저희가 캐싱하려는 데이터는 &lt;strong>변경 빈도가 낮은 조회 위주의 데이터&lt;/strong>였습니다. 쓰기 시점에 캐시를 갱신해야 하는 경우가 거의 없는 거죠. &lt;a href="https://jeongil.dev/ko/blog/backend/performance/look-aside-cache-api-perf/">이전에 캐싱을 적용한 경험&lt;/a>에서도 Cache-Aside가 이런 패턴에 잘 맞았고, 이번에도 같은 판단이었습니다. 다만 이번에는 데이터 특성에 따라 TTL 전략을 세분화하는 게 필요했습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant Client
participant App as 애플리케이션
participant Redis
participant DB
rect rgb(35, 134, 54)
Note over Client,DB: Cache Hit
Client-&amp;gt;&amp;gt;App: GET /aparts/{id}/facilities
App-&amp;gt;&amp;gt;Redis: GET apart:detail:facilities:{id}
Redis--&amp;gt;&amp;gt;App: 캐시 데이터 반환
App--&amp;gt;&amp;gt;Client: 응답 (~2ms)
end
rect rgb(248, 81, 73)
Note over Client,DB: Cache Miss
Client-&amp;gt;&amp;gt;App: GET /aparts/{id}/facilities
App-&amp;gt;&amp;gt;Redis: GET apart:detail:facilities:{id}
Redis--&amp;gt;&amp;gt;App: null
App-&amp;gt;&amp;gt;DB: 12건 DB 조회
DB--&amp;gt;&amp;gt;App: 데이터
App--)Redis: SET (비동기, TTL 14일 ± 1일)
App--&amp;gt;&amp;gt;Client: 응답 (~500ms)
end
&lt;/pre>&lt;p>처음에는 단순하게 모든 캐시에 TTL 24시간을 일괄 적용하려고 했습니다. 하지만 아파트 주변 학교나 지하철 정보가 하루만에 만료되는 건 비효율적이지 않나 싶었습니다. 반대로 금리가 포함된 대출 정보에 14일과 같이 너무 오래 TTL을 걸면 사용자 분들이 오래된 금리를 보게 되지 않을까? 싶었습니다. 결국 &amp;ldquo;일괄 TTL은 안 되겠다&amp;quot;라는 결론에 이르렀고, 데이터의 변경 주기를 하나하나 따져보고 TTL을 나누게 됐습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>데이터&lt;/th>
&lt;th>TTL&lt;/th>
&lt;th>근거&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>POI (학교, 병원, 마트, 공원)&lt;/td>
&lt;td>&lt;strong>14일&lt;/strong> ± 1일&lt;/td>
&lt;td>변경 빈도 극히 낮음&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>교통 (버스, 지하철, 고속도로)&lt;/td>
&lt;td>&lt;strong>14일&lt;/strong> ± 1일&lt;/td>
&lt;td>노선 변경 빈도 낮음&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>대출 정보&lt;/td>
&lt;td>&lt;strong>7일&lt;/strong> ± 1일&lt;/td>
&lt;td>금리 변동 주기 고려&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>기본 정보 (DB JOIN)&lt;/td>
&lt;td>&lt;strong>6시간&lt;/strong> ± 30분&lt;/td>
&lt;td>거래 데이터 반영 필요&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>재건축 일정&lt;/td>
&lt;td>&lt;strong>7일&lt;/strong> ± 1일&lt;/td>
&lt;td>일정 업데이트 비교적 드묾&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>평형 정보&lt;/td>
&lt;td>&lt;strong>7일&lt;/strong> ± 1일&lt;/td>
&lt;td>구조 변경 드묾&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>혹시 TTL 옆에 붙은 &lt;strong>± 랜덤 지터(Jitter)&lt;/strong> 가 눈에 띄셨나요? 이걸 넣은 이유가 있습니다. 인기 있는 아파트는 많은 사용자가 동시에 조회합니다. 만약 같은 TTL을 가진 캐시들이 동시에 만료되면 어떻게 될까요? 수십 개의 요청이 한꺼번에 DB로 몰리는 &lt;strong>Cache Stampede&lt;/strong> 현상이 발생할 수 있습니다.&lt;/p>
&lt;p>실제 구현에서는 TTL을 enum으로 정의하고, 조회 시점에 &lt;code>ThreadLocalRandom&lt;/code>으로 지터를 계산하도록 했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="k">enum&lt;/span> &lt;span class="k">class&lt;/span> &lt;span class="nc">DetailCacheTtl&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">baseMinutes&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">Long&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">jitterMinutes&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">Long&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">FACILITIES_TRANSPORT&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="m">20160L&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="m">1440L&lt;/span>&lt;span class="p">),&lt;/span> &lt;span class="c1">// 14일 ± 1일
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">LOANS&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="m">10080L&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="m">1440L&lt;/span>&lt;span class="p">),&lt;/span> &lt;span class="c1">// 7일 ± 1일
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">TYPES&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="m">10080L&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="m">1440L&lt;/span>&lt;span class="p">),&lt;/span> &lt;span class="c1">// 7일 ± 1일
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">RECONSTRUCTION&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="m">10080L&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="m">1440L&lt;/span>&lt;span class="p">),&lt;/span> &lt;span class="c1">// 7일 ± 1일
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">BASIC_INFO&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="m">360L&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="m">30L&lt;/span>&lt;span class="p">),&lt;/span> &lt;span class="c1">// 6시간 ± 30분
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">PRICE&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="m">360L&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="m">30L&lt;/span>&lt;span class="p">);&lt;/span> &lt;span class="c1">// 6시간 ± 30분
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">fun&lt;/span> &lt;span class="nf">toDuration&lt;/span>&lt;span class="p">():&lt;/span> &lt;span class="n">Duration&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">jitter&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="nc">ThreadLocalRandom&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">current&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">.&lt;/span>&lt;span class="n">nextLong&lt;/span>&lt;span class="p">(-&lt;/span>&lt;span class="n">jitterMinutes&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">jitterMinutes&lt;/span> &lt;span class="p">+&lt;/span> &lt;span class="m">1&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="nc">Duration&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">ofMinutes&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">baseMinutes&lt;/span> &lt;span class="p">+&lt;/span> &lt;span class="n">jitter&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>같은 데이터라도 인스턴스마다, 요청 시점마다 만료 시각이 달라지기 때문에 Stampede를 자연스럽게 분산시킬 수 있습니다.&lt;/p>
&lt;p>또 해당 데이터들이 업데이트 되는 시점에 캐시를 비워줄 수 있도록 했습니다. 예를 들어 대출 정보는 금리가 변동되는 시점에 캐시를 삭제하도록 했고, 재건축 일정은 일정이 변경되는 시점에 캐시를 삭제하도록 했습니다. 이렇게 하면 TTL이 만료되기 전에 캐시가 갱신될 수 있어서, 사용자들이 오래된 정보를 보는 상황을 줄일 수 있습니다.&lt;/p>
&lt;p>여기까지가 &amp;ldquo;무엇을, 얼마나 오래&amp;rdquo; 캐싱할지에 대한 이야기였습니다. 사실 여기서 끝이면 좋겠지만, 캐시를 도입하면서 고민해야 할 건 TTL만이 아니었습니다. &amp;ldquo;캐시를 넣었는데 오히려 장애가 나면?&amp;rdquo;, &amp;ldquo;진짜 효과가 있는 건 맞나?&amp;rdquo; 같은 질문들이 꼬리를 물었고, 이 고민들이 생각보다 중요했습니다.&lt;/p>
&lt;h4>캐시 저장은 비동기로&lt;span class="hx:absolute hx:-mt-20" id="캐시-저장은-비동기로">&lt;/span>
&lt;a href="#%ec%ba%90%ec%8b%9c-%ec%a0%80%ec%9e%a5%ec%9d%80-%eb%b9%84%eb%8f%99%ea%b8%b0%eb%a1%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>아파트 및 지하철역 검색시에 사용하는 자동완성(Autocomplete)기능 API에도 캐싱을 적용했는데, 여기서 한 가지 더 고민이 생기더라구요.&lt;/p>
&lt;p>자동완성은 사용자가 &lt;strong>글자를 입력할 때마다&lt;/strong> 호출되는 API입니다. 타이핑하는 속도보다 응답이 느리면 사용자 경험이 급격히 떨어지는, 응답 지연에 굉장히 민감한 API인 거죠. 그런데 캐시 미스가 발생했을 때 DB에서 데이터를 가져온 뒤 Redis에 저장하는 과정까지 동기적으로 실행되면, Redis 저장 시간만큼 응답이 늦어집니다.&lt;/p>
&lt;p>여기서 한 가지 질문을 던져봤습니다. 캐시 저장이 실패하면 어떻게 되나? 다음 요청에서 다시 시도하면 그만이지 않을까? 그렇다면 사용자 응답을 블로킹할 이유가 없지 않나 싶었고, &lt;strong>비동기(fire-and-forget)&lt;/strong> 로 전환했습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant User as 사용자
participant App as 애플리케이션
participant DB
participant Redis
rect rgb(248, 81, 73)
Note over User,Redis: Before: 동기 저장
User-&amp;gt;&amp;gt;App: &amp;#34;래미안&amp;#34; 입력
App-&amp;gt;&amp;gt;Redis: GET (miss)
App-&amp;gt;&amp;gt;DB: 검색
DB--&amp;gt;&amp;gt;App: 결과
App-&amp;gt;&amp;gt;Redis: SET (블로킹 대기)
Redis--&amp;gt;&amp;gt;App: OK
App--&amp;gt;&amp;gt;User: 응답
Note over App,Redis: Redis SET 시간만큼 응답 지연
end
rect rgb(35, 134, 54)
Note over User,Redis: After: 비동기 저장 (fire-and-forget)
User-&amp;gt;&amp;gt;App: &amp;#34;래미안&amp;#34; 입력
App-&amp;gt;&amp;gt;Redis: GET (miss)
App-&amp;gt;&amp;gt;DB: 검색
DB--&amp;gt;&amp;gt;App: 결과
App--&amp;gt;&amp;gt;User: 응답 (즉시 반환)
App--)Redis: SET (별도 코루틴, 논블로킹)
end
&lt;/pre>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 캐시 전용 코루틴 스코프
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">private&lt;/span> &lt;span class="k">val&lt;/span> &lt;span class="py">cacheScope&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">CoroutineScope&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nc">Dispatchers&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">IO&lt;/span> &lt;span class="p">+&lt;/span> &lt;span class="n">SupervisorJob&lt;/span>&lt;span class="p">())&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">fun&lt;/span> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nc">T&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> &lt;span class="nf">setAsync&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">key&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">String&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="k">value&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">T&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">ttl&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">Duration&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">cacheType&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">String&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">cacheScope&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">launch&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="c1">// fire-and-forget: 응답을 블로킹하지 않음
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">set&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">key&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="k">value&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">ttl&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">cacheType&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 애플리케이션 종료 시 코루틴 정리
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">override&lt;/span> &lt;span class="k">fun&lt;/span> &lt;span class="nf">destroy&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">cacheScope&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">cancel&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>솔직히 처음에는 단순하게 &lt;code>GlobalScope.launch&lt;/code>로 구현했었습니다. 동작은 잘 됐거든요. 그런데 코드 리뷰에서 두 가지 문제를 지적받았습니다. 하나는 애플리케이션이 셧다운될 때 실행 중인 코루틴이 제대로 정리되지 않는다는 점, 다른 하나는 일반 &lt;code>Job&lt;/code>을 사용하면 하나의 캐시 저장이 실패할 때 같은 스코프의 다른 코루틴까지 취소될 수 있다는 점이었습니다. 돌아가니까 괜찮다고 넘어갈 뻔했는데, 리뷰를 보고나니 운영 환경에서 충분히 터질 수 있는 문제였습니다. 이런 부분은 코드 리뷰의 힘이 크다고 느꼈습니다. 그래서 &lt;code>SupervisorJob&lt;/code>으로 실패를 격리하고, &lt;code>DisposableBean&lt;/code>의 &lt;code>destroy()&lt;/code>에서 스코프를 cancel하도록 수정했습니다.&lt;/p>
&lt;h4>캐시 장애 시에도 서비스는 계속되어야 한다&lt;span class="hx:absolute hx:-mt-20" id="캐시-장애-시에도-서비스는-계속되어야-한다">&lt;/span>
&lt;a href="#%ec%ba%90%ec%8b%9c-%ec%9e%a5%ec%95%a0-%ec%8b%9c%ec%97%90%eb%8f%84-%ec%84%9c%eb%b9%84%ec%8a%a4%eb%8a%94-%ea%b3%84%ec%86%8d%eb%90%98%ec%96%b4%ec%95%bc-%ed%95%9c%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>캐싱을 도입하면서 또 중요한 점은 &lt;strong>&amp;ldquo;캐싱(ex.Redis)이 죽어도 서비스는 계속 돼야한다는 점 입니다.&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>성능 최적화를 위한 캐시는 어디까지나 &lt;strong>수단&lt;/strong>으로만 취급하고, Redis에 문제가 생기면 자연스럽게 DB로 폴백하도록 설계하는 게 중요하다고 생각합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="k">fun&lt;/span> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nc">T&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> &lt;span class="nf">get&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">key&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">String&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">type&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">Class&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">T&lt;/span>&lt;span class="p">&amp;gt;,&lt;/span> &lt;span class="n">cacheType&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">String&lt;/span>&lt;span class="p">):&lt;/span> &lt;span class="n">T&lt;/span>&lt;span class="p">?&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="k">try&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">json&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">redisTemplate&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">opsForValue&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="k">get&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">key&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">json&lt;/span> &lt;span class="o">!=&lt;/span> &lt;span class="k">null&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">hitCounter&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">cacheType&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="n">increment&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">objectMapper&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">readValue&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">json&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">type&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span> &lt;span class="k">else&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">missCounter&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">cacheType&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="n">increment&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">null&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span> &lt;span class="k">catch&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">Exception&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// Redis 장애 시 캐시 미스로 처리 → DB 직접 조회로 폴백
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">log&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">warn&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;Redis cache read failed: key={}&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">key&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">e&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">missCounter&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">cacheType&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="n">increment&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">null&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>Redis 조회와 저장을 모두 try-catch로 감싸서, Redis에 문제가 생기면 캐시 미스로 처리하고 원래 경로(DB 직접 조회)로 동작하도록 했습니다. 느려지는 건 감수할 수 있지만, 서비스 자체가 죽어버리면 안 되니까요. 저는 캐시의 역할은 &amp;ldquo;있으면 빠르고, 없으면 원래대로&amp;quot;라고 생각합니다. 캐시 때문에 오히려 장애가 나는 상황은 만들고 싶지 않았습니다.&lt;/p>
&lt;h4>캐시 관측성 확보&lt;span class="hx:absolute hx:-mt-20" id="캐시-관측성-확보">&lt;/span>
&lt;a href="#%ec%ba%90%ec%8b%9c-%ea%b4%80%ec%b8%a1%ec%84%b1-%ed%99%95%eb%b3%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>캐시를 도입하고 나니 &lt;strong>&amp;ldquo;이거 진짜 효과가 있는 건 맞는건가?&amp;rdquo;&lt;/strong> 를 검증하고 싶었습니다. TTL이 적절한지, 히트율은 어떤지, Redis가 느려지고 있진 않은지 숫자, 데이터로 확인할 수 없으면 그냥 감으로 운영하는 거니까요.&lt;/p>
&lt;p>그래서 Micrometer 카운터로 캐시 히트/미스 횟수를 수집하고, 캐시 타입별(&lt;code>basic&lt;/code>, &lt;code>facilities&lt;/code>, &lt;code>loans&lt;/code>, &lt;code>types&lt;/code>, &lt;code>reconstruction&lt;/code>, &lt;code>price&lt;/code>)로 태그를 달아서 Grafana에서 모니터링할 수 있도록 구성했습니다. Redis GET/SET 소요시간도 타이머 메트릭으로 수집하구요. Cache Hit Rate Monitor라는 별도 대시보드를 만들어서 캐시 타입별 히트율 추이를 실시간으로 확인할 수 있게 했는데, 이게 나중에 TTL을 조정할 때 판단 근거가 되어서 꽤 유용했습니다. 결국 모니터링은 배포 전에도, 배포 후에도, 계속 필요한 것 같습니다.&lt;/p>
&lt;h4>결과&lt;span class="hx:absolute hx:-mt-20" id="결과-2">&lt;/span>
&lt;a href="#%ea%b2%b0%ea%b3%bc-2" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>운영 환경 Prometheus 메트릭 기준 결과입니다. 캐시 히트와 미스가 혼합된, 실제 사용자가 체감하는 P95 응답시간입니다. 첫 번째 이미지에서 캐싱 배포 전 스파이크가 보이고, 두 번째 이미지에서 배포 후 안정적인 현재 상태를 확인할 수 있습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/h8opmv88dssfweymrpg9h/caching-before.png?rlkey=akdbj2qvmllu4402satlf8t7f&amp;amp;st=s0mplh17&amp;amp;raw=1" alt="기본정보·편의시설 API — 캐싱 적용 전 P95 (배포 시점 표시)" loading="lazy" />&lt;/p>
&lt;blockquote>
&lt;p>Prometheus 스토리지 용량 제한(4GB) 특성상, 위 Before 이미지는 배포 직전 수일간의 기록입니다. 아래 테이블의 Before P95(4,045ms, 4,840ms)는 캐싱 도입 전 피크 트래픽 시간대에 기록한 수치로, 최적화 작업 기간 중 이미 Prometheus에서 만료되었습니다.&lt;/p>
&lt;/blockquote>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/v0efinc70k3streovsbkc/caching-result.png?rlkey=b7llkitaul7jvzqhbds8khg86&amp;amp;st=o415mjfo&amp;amp;raw=1" alt="기본정보·편의시설 API — 캐싱 적용 후 P95 모니터링 (5일간)" loading="lazy" />&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>API&lt;/th>
&lt;th>req/s&lt;/th>
&lt;th>Before P50&lt;/th>
&lt;th>After P50&lt;/th>
&lt;th>Before P95&lt;/th>
&lt;th>After P95&lt;/th>
&lt;th>After P99&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>기본정보&lt;/td>
&lt;td>&lt;strong>568&lt;/strong>&lt;/td>
&lt;td>183ms&lt;/td>
&lt;td>&lt;strong>43ms&lt;/strong>&lt;/td>
&lt;td>4,045ms&lt;/td>
&lt;td>&lt;strong>50ms&lt;/strong>&lt;/td>
&lt;td>50ms&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>편의시설/교통&lt;/td>
&lt;td>&lt;strong>525&lt;/strong>&lt;/td>
&lt;td>497ms&lt;/td>
&lt;td>&lt;strong>119ms&lt;/strong>&lt;/td>
&lt;td>4,840ms&lt;/td>
&lt;td>&lt;strong>168ms&lt;/strong>&lt;/td>
&lt;td>205ms&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>재건축 일정&lt;/td>
&lt;td>29&lt;/td>
&lt;td>124ms&lt;/td>
&lt;td>&lt;strong>42ms&lt;/strong>&lt;/td>
&lt;td>—&lt;/td>
&lt;td>&lt;strong>50ms&lt;/strong>&lt;/td>
&lt;td>55ms&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>평형정보&lt;/td>
&lt;td>28&lt;/td>
&lt;td>147ms&lt;/td>
&lt;td>&lt;strong>46ms&lt;/strong>&lt;/td>
&lt;td>—&lt;/td>
&lt;td>&lt;strong>63ms&lt;/strong>&lt;/td>
&lt;td>109ms&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>기본정보와 편의시설/교통 API는 각각 &lt;strong>초당 568건, 525건&lt;/strong>의 요청을 처리하고 있습니다. 일 기준으로 환산하면 약 &lt;strong>4,900만 건, 4,500만 건&lt;/strong>에 해당하는 트래픽입니다. P95 기준으로 기본정보는 4초대에서 &lt;strong>50ms&lt;/strong>로, 편의시설/교통은 4.8초대에서 &lt;strong>168ms&lt;/strong>로 떨어졌고, P99에서도 200ms 이내를 유지하고 있습니다.&lt;/p>
&lt;p>혹시 &amp;ldquo;캐시 미스가 나면 Redis 조회 시간만큼 오히려 느려지는 거 아닌가?&amp;rdquo; 하는 생각이 들기도 했습니다. 그러나 확인해보니 Redis GET이 null을 반환하는 데 걸리는 시간은 &lt;strong>1~5ms&lt;/strong> 수준이었습니다. 캐시 미스가 나더라도 기존 대비 성능 저하는 거의 무시할 수 있는 수준인 것 같습니다. 다만 Redis에서 응답 지연이 조기에 끊을 수 있도록 타임아웃을 100ms로 설정해뒀는데, 이 타임아웃이 걸리는 경우는 거의 없지만, 만약 발생한다면 그때는 캐시 조회가 실패한 것으로 간주하고 DB로 폴백하도록 되어 있습니다.&lt;/p>
&lt;h2>전체 결과 정리&lt;span class="hx:absolute hx:-mt-20" id="전체-결과-정리">&lt;/span>
&lt;a href="#%ec%a0%84%ec%b2%b4-%ea%b2%b0%ea%b3%bc-%ec%a0%95%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>약 10일간의 작업을 마치고, 전체 결과를 정리해봤습니다. 숫자를 나열하기 전에 하나 말씀드리고 싶은 건, 이 수치들은 전부 운영 환경 Prometheus 메트릭 기준이라는 점입니다. 아래 Grafana 대시보드에서 최적화 전후를 한눈에 비교할 수 있습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/335mnm3b9ardbtqqkcxvp/performance-before.png?rlkey=qwd7xz01g26qwexox8at2fubx&amp;amp;st=x5zhqpwh&amp;amp;raw=1" alt="전체 API — 최적화 전 P95 (배포 시점 표시)" loading="lazy" />&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/01p3zk422klgohvrzznz1/performance-summary.png?rlkey=7yqpdmu40qus5c7ay5tvgm9aw&amp;amp;st=j4a4wg9t&amp;amp;raw=1" alt="전체 API — 최적화 후 P95 모니터링 현황" loading="lazy" />&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>영역&lt;/th>
&lt;th>API / 컴포넌트&lt;/th>
&lt;th>Before&lt;/th>
&lt;th>After (운영)&lt;/th>
&lt;th>개선율&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>쿼리&lt;/td>
&lt;td>거래량 랭킹&lt;/td>
&lt;td>P95 1.9~2.4s&lt;/td>
&lt;td>95ms&lt;/td>
&lt;td>&lt;strong>~21배&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>쿼리&lt;/td>
&lt;td>단가 랭킹&lt;/td>
&lt;td>P50 7.24s&lt;/td>
&lt;td>126ms&lt;/td>
&lt;td>&lt;strong>~57배&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>쿼리&lt;/td>
&lt;td>세대수 랭킹&lt;/td>
&lt;td>P50 6.33s&lt;/td>
&lt;td>125ms&lt;/td>
&lt;td>&lt;strong>~51배&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>쿼리&lt;/td>
&lt;td>계약 요약&lt;/td>
&lt;td>P95 2.4s&lt;/td>
&lt;td>&amp;lt;100ms&lt;/td>
&lt;td>&lt;strong>~24배&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>배치&lt;/td>
&lt;td>Reader 1페이지&lt;/td>
&lt;td>35.6s&lt;/td>
&lt;td>15ms&lt;/td>
&lt;td>&lt;strong>~2,400배&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>배치&lt;/td>
&lt;td>쿼리 수 (1K건)&lt;/td>
&lt;td>~4,001개&lt;/td>
&lt;td>2개&lt;/td>
&lt;td>&lt;strong>~2,000배&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>배치&lt;/td>
&lt;td>전체 실행시간&lt;/td>
&lt;td>~50분 (최대 87분)&lt;/td>
&lt;td>~21분 (최대 25분)&lt;/td>
&lt;td>&lt;strong>~59%&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>병렬화&lt;/td>
&lt;td>알림 발송 (P95)&lt;/td>
&lt;td>4.9s&lt;/td>
&lt;td>~2s&lt;/td>
&lt;td>&lt;strong>~59%&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>병렬화&lt;/td>
&lt;td>독립적 DB 조회 병렬화&lt;/td>
&lt;td>~150ms&lt;/td>
&lt;td>~100ms&lt;/td>
&lt;td>&lt;strong>~30%&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>캐싱&lt;/td>
&lt;td>기본정보 (P95, 568 req/s)&lt;/td>
&lt;td>4,045ms&lt;/td>
&lt;td>50ms&lt;/td>
&lt;td>&lt;strong>~99%&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>캐싱&lt;/td>
&lt;td>편의시설/교통 (P95, 525 req/s)&lt;/td>
&lt;td>4,840ms&lt;/td>
&lt;td>168ms&lt;/td>
&lt;td>&lt;strong>~97%&lt;/strong>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;blockquote>
&lt;p>단가/세대수 랭킹은 P50 기준입니다. 대부분의 요청(중앙값)조차 7초대였기 때문에, P95가 아닌 P50을 Before 기준으로 잡았습니다.&lt;/p>
&lt;/blockquote>
&lt;pre class="mermaid hx:mt-6">
graph LR
subgraph 쿼리최적화[&amp;#34;1. 쿼리 최적화&amp;#34;]
Q1[&amp;#34;Non-sargable → Sargable&amp;#34;]
Q2[&amp;#34;N+1 → 배치 프리페치&amp;#34;]
Q3[&amp;#34;코드 집계 → SQL 집계&amp;#34;]
end
subgraph 병렬화[&amp;#34;2. 병렬화&amp;#34;]
P1[&amp;#34;직렬 호출 → 병렬&amp;#34;]
P2[&amp;#34;독립 API 병렬 처리&amp;#34;]
end
subgraph 캐싱[&amp;#34;3. 캐싱&amp;#34;]
C1[&amp;#34;Redis Cache-Aside&amp;#34;]
C2[&amp;#34;데이터별 TTL + Jitter&amp;#34;]
C3[&amp;#34;비동기 캐시 저장&amp;#34;]
end
쿼리최적화 --&amp;gt; 결과[&amp;#34;전체 P95&amp;lt;br/&amp;gt;대폭 개선&amp;#34;]
병렬화 --&amp;gt; 결과
캐싱 --&amp;gt; 결과
style 쿼리최적화 fill:#238636,color:#fff
style 병렬화 fill:#1f6feb,color:#fff
style 캐싱 fill:#8957e5,color:#fff
&lt;/pre>&lt;h2>느낀 점&lt;span class="hx:absolute hx:-mt-20" id="느낀-점">&lt;/span>
&lt;a href="#%eb%8a%90%eb%82%80-%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>&amp;ldquo;인덱스가 있다&amp;quot;와 &amp;ldquo;인덱스를 타고 있다&amp;quot;는 다른 문제였다&lt;span class="hx:absolute hx:-mt-20" id="인덱스가-있다와-인덱스를-타고-있다는-다른-문제였다">&lt;/span>
&lt;a href="#%ec%9d%b8%eb%8d%b1%ec%8a%a4%ea%b0%80-%ec%9e%88%eb%8b%a4%ec%99%80-%ec%9d%b8%eb%8d%b1%ec%8a%a4%eb%a5%bc-%ed%83%80%ea%b3%a0-%ec%9e%88%eb%8b%a4%eb%8a%94-%eb%8b%a4%eb%a5%b8-%eb%ac%b8%ec%a0%9c%ec%98%80%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이번 작업 전에도 EXPLAIN을 사용하긴 했지만, 솔직히 말씀드리면 &amp;ldquo;인덱스 있으니까 괜찮겠지&amp;rdquo; 하고 넘어간 적이 있었습니다. 아마 저만 그런 건 아닐 거라고 생각합니다. 이번에 Non-sargable 쿼리 문제를 직접 겪고 나서야, 인덱스가 존재하는 것과 옵티마이저가 실제로 그 인덱스를 사용하는 것은 완전히 다른 문제라는 걸 다시금 느끼게 됐습니다. 앞으로 더 꼼꼼히 봐야겠다는 생각이 들더라구요.&lt;/p>
&lt;p>또 코드 리뷰만으로는 성능 문제를 잡기 어렵다는 것도 느꼈습니다. 코드상 깔끔해 보이는 쿼리라고 하더라도 풀 스캔을 유발하고, 잘 돌아가는 것처럼 보이는 배치가 수천 개의 불필요한 쿼리를 날리고 있을 수 있거든요. 저도 처음에는 추측으로 접근했다가 엉뚱한 곳을 파고 있었던 경험이 있습니다. ㅎㅎ.. 결국 EXPLAIN이든 Tempo 트레이스든 Prometheus 메트릭이든, &lt;strong>도구가 보여주는 숫자, 데이터&lt;/strong>를 기반으로 접근하는 수밖에 없지 않나 싶습니다.&lt;/p>
&lt;h3>어떤 기술을 쓸지보다, 지금 뭐가 문제인지가 먼저였다&lt;span class="hx:absolute hx:-mt-20" id="어떤-기술을-쓸지보다-지금-뭐가-문제인지가-먼저였다">&lt;/span>
&lt;a href="#%ec%96%b4%eb%96%a4-%ea%b8%b0%ec%88%a0%ec%9d%84-%ec%93%b8%ec%a7%80%eb%b3%b4%eb%8b%a4-%ec%a7%80%ea%b8%88-%eb%ad%90%ea%b0%80-%eb%ac%b8%ec%a0%9c%ec%9d%b8%ec%a7%80%ea%b0%80-%eb%a8%bc%ec%a0%80%ec%98%80%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>캐싱을 도입할 때도 처음에는 &amp;ldquo;어떤 캐시 전략이 최적인가&amp;quot;부터 고민했었습니다. Write-Through가 나은지, Cache-Aside가 나은지, TTL은 어떻게 잡을지. 기술 선택부터 들어갔던 거죠. 그런데 돌이켜보면 그보다 &amp;ldquo;지금 어떤 데이터가 반복 조회되고 있는가&amp;quot;를 먼저 파악하는 게 훨씬 중요했던 것 같습니다. 문제를 정확히 알면 기술 선택은 자연스럽게 따라오는 것 같습니다.&lt;/p>
&lt;p>병렬화도 마찬가지였습니다. 어떤 비동기 프레임워크를 쓸지보다, 지금 순차로 실행되고 있는 것 중에 독립적인 게 뭔지를 먼저 찾는 게 핵심이었습니다. 결국 성능 최적화의 시작점은 더 좋은 기술을 찾는 게 아니라, 현재의 비효율을 정확하게 찾아내는 데 있지 않나 싶습니다. 너무 당연한 이야기처럼 들릴 수 있지만, 문제를 특정해야 그에 맞는 개선방법이 나오니까요.&lt;/p>
&lt;h3>모니터링이 없었으면 시작도 못 했다&lt;span class="hx:absolute hx:-mt-20" id="모니터링이-없었으면-시작도-못-했다">&lt;/span>
&lt;a href="#%eb%aa%a8%eb%8b%88%ed%84%b0%eb%a7%81%ec%9d%b4-%ec%97%86%ec%97%88%ec%9c%bc%eb%a9%b4-%ec%8b%9c%ec%9e%91%eb%8f%84-%eb%aa%bb-%ed%96%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;a href="https://jeongil.dev/ko/blog/infrastructure/building-a-monitoring-system/">이전에 구축한 모니터링 시스템&lt;/a>이 이번 작업의 전제 조건이었습니다. 이 부분은 아무리 강조해도 부족하다고 느껴지네요. 편의시설/교통 API가 12건의 DB 조회를 하고 있다는 사실도, 코드만 봐서는 여러 모듈에 걸쳐 분산되어 있어 전체 그림이 한번에 보이지 않았는데, Tempo 트레이스의 span waterfall을 펼쳐보고 나서야 &amp;ldquo;아, 이게 한 요청에서 다 나가는 거였구나&amp;rdquo; 하고 발견할 수 있었습니다. &amp;ldquo;측정할 수 없으면 개선할 수 없다&amp;quot;는 말이, 이번만큼 체감된 적이 없었던 것 같습니다.&lt;/p>
&lt;h2>마치며&lt;span class="hx:absolute hx:-mt-20" id="마치며">&lt;/span>
&lt;a href="#%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>돌이켜보면 이번 작업에서 사용한 기법들 — Non-sargable 쿼리 수정, N+1 해결, 인덱스 추가, 병렬화, Cache-Aside — 은 어느 것 하나 새로운 기술이 아니었습니다. 전부 어디선가 한 번쯤은 들어본 기본적인 기법들이죠. 너무 진부한 말일 수 있지만, 결국 돌고 돌아 기본이 가장 강력한 것 같습니다.&lt;/p>
&lt;p>다만 기본적인 것이라고 해서 적용이 쉬운 건 아니었습니다. 오히려 &lt;strong>어디가 느린지 찾는 과정&lt;/strong>이 가장 어려웠고, 일단 원인을 찾고 나니 해결 자체는 명확한 경우가 많았습니다. EXPLAIN 한 줄, 코루틴 async 몇 줄, Redis 캐시 설정 몇 줄. 수정한 코드의 양은 많지 않았지만 효과는 꽤 컸습니다. 이 글의 제목을 &amp;ldquo;느린 곳을 찾는 게 고치는 것보다 어려웠다&amp;quot;로 정한 이유이기도 합니다.&lt;/p>
&lt;p>그리고 이번 작업을 마치면서 한 가지 더 한 것이 있습니다. 이번에는 습관적으로 대시보드를 들여다보다가 우연히 발견한 거였는데, 다음에도 이런 식으로 우연에 의존할 수는 없지 않나 싶었습니다. 그래서 &lt;strong>P95가 특정 임계치를 넘는 API가 발생하면 Grafana Alert으로 알림을 받도록&lt;/strong> 설정해뒀습니다. 다음부터는 시스템이 먼저 알려주도록요.&lt;/p>
&lt;p>물론 아직 남아있는 숙제도 있습니다. 무거운 쿼리 패턴 중 아직 손대지 못한 것들이 있고, 레거시 서비스의 Stored Procedure에서 발생하는 N+1도 남아있습니다. 이 부분들은 스코프가 커서 시간을 두고 점진적으로 개선해 나갈 계획입니다. 완벽하게 끝냈다고 말할 수 없는 상태라서 조금 아쉽기도 하지만, 성능 최적화라는 게 원래 &amp;ldquo;끝&amp;quot;이 없는 영역이지 않나 싶습니다. 정답은 없고, 지금 우리 서비스 상황에 맞는 선택들이 있을 뿐이라고 생각합니다.&lt;/p>
&lt;p>혹시 비슷한 상황을 겪고 계신 분이 있다면, 일단 EXPLAIN부터 찍어보시는 걸 추천드립니다. 느린 쿼리의 원인은 생각보다 단순한 곳에 있을 수 있거든요. 저도 이번에 그걸 제대로 경험했으니까요.&lt;/p>
&lt;p>긴 글 읽어주셔서 감사합니다.&lt;/p>
&lt;h2>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>관련 글&lt;span class="hx:absolute hx:-mt-20" id="관련-글">&lt;/span>
&lt;a href="#%ea%b4%80%eb%a0%a8-%ea%b8%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/infrastructure/building-a-monitoring-system/">서비스 장애는 사용자가 알려주지 않아도 알아야한다 — 사내 모니터링 시스템 구축기&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>쿼리 최적화&lt;span class="hx:absolute hx:-mt-20" id="쿼리-최적화">&lt;/span>
&lt;a href="#%ec%bf%bc%eb%a6%ac-%ec%b5%9c%ec%a0%81%ed%99%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://use-the-index-luke.com/sql/where-clause/functions"target="_blank" rel="noopener">Use The Index, Luke — Functions in WHERE Clause&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> — Non-sargable 쿼리와 인덱스 무효화 패턴&lt;/li>
&lt;li>&lt;a href="https://dev.mysql.com/doc/refman/8.4/en/explain-output.html"target="_blank" rel="noopener">MySQL Official Docs — EXPLAIN Output Format&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> — EXPLAIN 출력 해석 가이드&lt;/li>
&lt;li>&lt;a href="https://dev.mysql.com/doc/refman/8.4/en/optimization-indexes.html"target="_blank" rel="noopener">MySQL Official Docs — Optimization and Indexes&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> — 복합 인덱스 설계 전략&lt;/li>
&lt;/ul>
&lt;h3>캐싱&lt;span class="hx:absolute hx:-mt-20" id="캐싱">&lt;/span>
&lt;a href="#%ec%ba%90%ec%8b%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://docs.aws.amazon.com/whitepapers/latest/database-caching-strategies-using-redis/caching-patterns.html"target="_blank" rel="noopener">AWS — Database Caching Strategies Using Redis&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> — Cache-Aside vs Write-Through 비교&lt;/li>
&lt;li>&lt;a href="https://instagram-engineering.com/thundering-herds-promises-82191c8af57d"target="_blank" rel="noopener">Cache Stampede 문제와 해결 방법&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> — Instagram의 Thundering Herd 대응&lt;/li>
&lt;/ul>
&lt;h3>병렬화 / 비동기&lt;span class="hx:absolute hx:-mt-20" id="병렬화--비동기">&lt;/span>
&lt;a href="#%eb%b3%91%eb%a0%ac%ed%99%94--%eb%b9%84%eb%8f%99%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://kotlinlang.org/docs/coroutines-basics.html"target="_blank" rel="noopener">Kotlin Official Docs — Coroutines Basics&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> — 코루틴 기초와 structured concurrency&lt;/li>
&lt;li>&lt;a href="https://kotlinlang.org/docs/shared-mutable-state-and-concurrency.html"target="_blank" rel="noopener">Kotlin Official Docs — Shared Mutable State and Concurrency&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> — SupervisorJob, 예외 전파와 격리&lt;/li>
&lt;/ul>
&lt;h3>모니터링&lt;span class="hx:absolute hx:-mt-20" id="모니터링">&lt;/span>
&lt;a href="#%eb%aa%a8%eb%8b%88%ed%84%b0%eb%a7%81" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://docs.micrometer.io/micrometer/reference/reference/cache.html"target="_blank" rel="noopener">Micrometer Official Docs — Cache Instrumentations&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> — 캐시 히트/미스 메트릭 수집&lt;/li>
&lt;/ul></description></item><item><title>모듈러 모놀리식 전환 후 CI가 45분이 걸렸다 - Spring 테스트 파이프라인 77% 최적화하기</title><link>https://jeongil.dev/ko/blog/backend/performance/ci-test-build-optimization/</link><pubDate>Fri, 27 Feb 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/backend/performance/ci-test-build-optimization/</guid><description>
&lt;p>안녕하세요. 프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 정정일입니다.&lt;/p>
&lt;p>&lt;a href="https://jeongil.dev/ko/blog/architecture/msa-to-modular-monolith/">이전 글&lt;/a>에서 혼자 남은 백엔드 개발자가 13개 마이크로서비스를 모듈러 모놀리식으로 통합한 과정을 다뤘습니다. 그 글 마지막에 이렇게 적었었는데요.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;전환 후에 CI 테스트 빌드 시간이 45분으로 급증하는 문제를 겪기도 했는데, 이 부분은 후속 글에서 다루겠습니다&amp;rdquo;&lt;/p>
&lt;/blockquote>
&lt;p>이 글이 바로 그 후속 글입니다.&lt;/p>
&lt;h2>문제: CI가 45분이나 걸렸다&lt;span class="hx:absolute hx:-mt-20" id="문제-ci가-45분이나-걸렸다">&lt;/span>
&lt;a href="#%eb%ac%b8%ec%a0%9c-ci%ea%b0%80-45%eb%b6%84%ec%9d%b4%eb%82%98-%ea%b1%b8%eb%a0%b8%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>전환을 마치고 CI를 돌려봤을 때였습니다. 저희는 GitHub Actions로 CI를 구성하고 있는데, PR이 올라오면 변경된 모듈의 테스트를 돌리고 JaCoCo(테스트 커버리지 측정 도구)로 커버리지 리포트를 생성하는 워크플로우가 자동으로 실행됩니다. 이 워크플로우의 &amp;ldquo;Build test reports&amp;rdquo; 단계가 끝나질 않더라구요. 뭔가 이상하다 싶어서 로그를 확인해봤는데, 눈을 의심했습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>브랜치&lt;/th>
&lt;th>CI 소요시간&lt;/th>
&lt;th>결과&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>기존 MSA 브랜치&lt;/td>
&lt;td>&lt;strong>2분 1초&lt;/strong>&lt;/td>
&lt;td>SUCCESS&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>모듈러 모놀리식 전환 브랜치&lt;/td>
&lt;td>&lt;strong>45분 31초&lt;/strong>&lt;/td>
&lt;td>FAILED&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>22배. 게다가 실패까지.&lt;/p>
&lt;p>아래는 실제 GitHub Actions CI 실행 결과입니다. &amp;ldquo;Build test reports&amp;rdquo; 단계 하나가 &lt;strong>45분 31초&lt;/strong>를 잡아먹고 있습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/i4skoyz1jhhg8f1475865/ci-before-45min.png?rlkey=jukpe5zp4c2shmftgw0d3y371&amp;amp;st=sy9eld9g&amp;amp;raw=1" alt="모듈러 모놀리식 전환 브랜치 CI 실행 결과 — Build test reports 45m 31s, FAILED" loading="lazy" />&lt;/p>
&lt;p>로그를 펼쳐보니 &amp;ldquo;BUILD FAILED in 45m 30s&amp;quot;가 찍혀있었습니다. 153개 태스크를 전부 실행하고도 실패.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/qt5vi0wqwyor0dwrtoosj/ci-before-log.png?rlkey=rtwkqs9f192tmnsfy6uo22uyj&amp;amp;st=n0qi2yog&amp;amp;raw=1" alt="CI 빌드 로그 — BUILD FAILED in 45m 30s, 153 actionable tasks: 153 executed" loading="lazy" />&lt;/p>
&lt;p>여기서 한 가지 짚고 넘어갈 부분이 있습니다. 기존 MSA에서 2분 1초라는 건 전체 테스트가 2분 걸렸다는 뜻이 아닙니다. MSA 구조에서는 각 서비스가 독립된 애플리케이션이라 CI도 서비스별로 각각 돌아가거든요. PR에서 변경된 서비스만 테스트하니까, 한 서비스의 테스트가 2분이면 그냥 2분인 겁니다. 다른 서비스는 변경되지 않았으니 CI에서 건너뛰구요.&lt;/p>
&lt;p>모듈러 모놀리식은 다릅니다. 11개 서비스가 하나의 Spring Boot 애플리케이션 안에 모듈로 통합되어 있고, 여기에 공통 모듈 등을 합치면 총 15개 모듈이 존재합니다. 이번처럼 전환 PR에서 모든 모듈의 파일이 변경되면 15개 모듈 전체의 테스트가 한꺼번에 돌아갑니다. 비교 자체가 공정하지 않다는 건 알고 있었습니다.&lt;/p>
&lt;p>다만 비교가 적절하든 아니든, &lt;strong>현실적으로 CI를 돌리면 45분이 걸린다는 사실 자체가 문제&lt;/strong>였습니다. 전환 PR이라 모든 파일이 변경된 특수한 케이스이긴 했지만, 앞으로도 &lt;code>common&lt;/code> 모듈이나 루트 &lt;code>build.gradle.kts&lt;/code>를 수정하면 전체 테스트가 돌아가는 상황은 충분히 발생할 수 있었거든요.&lt;/p>
&lt;p>위에서 언급했듯이 저는 현재 혼자 남은 백엔드 개발자입니다. 빠르게 개발하고 빠르게 배포하는 게 중요한 상황인데, CI가 45분이나 걸리면 PR 올리고 머지될 때까지 한참을 기다려야 합니다. 이건 생산성에 직접적으로 타격이 오는 문제였습니다.&lt;/p>
&lt;p>&amp;ldquo;이거 지금 안 잡으면 나중에 계속 발목 잡히겠다&amp;rdquo; 싶어서 원인을 분석하기 시작했습니다.&lt;/p>
&lt;h2>원인 파악: 왜 이렇게 느렸나&lt;span class="hx:absolute hx:-mt-20" id="원인-파악-왜-이렇게-느렸나">&lt;/span>
&lt;a href="#%ec%9b%90%ec%9d%b8-%ed%8c%8c%ec%95%85-%ec%99%9c-%ec%9d%b4%eb%a0%87%ea%b2%8c-%eb%8a%90%eb%a0%b8%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>CI 로그를 열어서 어디서 시간이 잡아먹히는지 추적하고, Gradle 설정 파일을 뒤지고, 테스트 구조를 살펴봤습니다. 뒤져보니 원인이 한두 가지가 아니더라구요. 총 7가지 병목 지점을 발견했습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>&lt;code>maxParallelForks&lt;/code>가 Spring Context 캐싱을 무효화&lt;/strong> — 각 JVM 프로세스가 독립 메모리를 가져 Context 공유 불가&lt;/li>
&lt;li>&lt;strong>&lt;code>--no-daemon&lt;/code> + &lt;code>git clean -ffdx&lt;/code>로 매번 콜드 스타트&lt;/strong> — 빌드 캐시, Gradle 데몬 전부 제거&lt;/li>
&lt;li>&lt;strong>&lt;code>spring.main.lazy-initialization&lt;/code> 미설정&lt;/strong> — 테스트에서 사용하지 않는 빈까지 전부 초기화&lt;/li>
&lt;li>&lt;strong>JUnit5 스레드 병렬 실행 미설정&lt;/strong> — 테스트 클래스를 동시에 실행하는 병렬 설정이 없었음&lt;/li>
&lt;li>&lt;strong>13개 Smoke Test가 불필요하게 전체 Context 로딩&lt;/strong> — CI에서 이미 통합 테스트로 검증하는 부분을 중복 실행&lt;/li>
&lt;li>&lt;strong>~90개 &lt;code>@MockBean&lt;/code>/&lt;code>@MockkBean&lt;/code>이 Context 캐시 미스 유발&lt;/strong> — 각 테스트 클래스마다 다른 캐시 키 생성&lt;/li>
&lt;li>&lt;strong>self-hosted MacBook Pro(M1, 8코어, 16GB) 러너의 리소스 제약&lt;/strong> — 여러 JVM 프로세스가 CPU/메모리 경쟁&lt;/li>
&lt;/ol>
&lt;pre class="mermaid hx:mt-6">
graph TB
CI[&amp;#34;CI 45분&amp;#34;] --&amp;gt; A[&amp;#34;1. maxParallelForks&amp;lt;br/&amp;gt;Context 캐시 무효화&amp;#34;]
CI --&amp;gt; B[&amp;#34;2. --no-daemon&amp;lt;br/&amp;gt;+ git clean&amp;#34;]
CI --&amp;gt; C[&amp;#34;3. lazy-init&amp;lt;br/&amp;gt;미설정&amp;#34;]
CI --&amp;gt; D[&amp;#34;4. JUnit5 병렬&amp;lt;br/&amp;gt;미설정&amp;#34;]
CI --&amp;gt; E[&amp;#34;5. Smoke Test&amp;lt;br/&amp;gt;중복&amp;#34;]
CI --&amp;gt; F[&amp;#34;6. @MockBean&amp;lt;br/&amp;gt;90개+&amp;#34;]
CI --&amp;gt; G[&amp;#34;7. 러너&amp;lt;br/&amp;gt;리소스 제약&amp;#34;]
style A fill:#238636,color:#fff
style B fill:#238636,color:#fff
style C fill:#238636,color:#fff
style D fill:#238636,color:#fff
style E fill:#238636,color:#fff
style F fill:#b35000,color:#fff
style G fill:#484f58,color:#fff
&lt;/pre>&lt;p style="text-align: center; color: #8b949e; font-size: 0.85em;">
초록: 이번에 해결 / 주황: 스코프가 커서 보류 / 회색: 하드웨어 제약
&lt;/p>
&lt;p>원인을 전부 정리해놓고 보니 &amp;ldquo;이러니 45분이 걸렸지&amp;hellip;&amp;rdquo; 라는 생각이 들었습니다. 하나하나는 각각의 이유가 있었지만, 이것들이 전부 겹치니까 45분이라는 결과가 나온 거였죠.&lt;/p>
&lt;p>이 중 6번(&lt;code>@MockBean&lt;/code> 통합)은 스코프가 너무 컸습니다. Spring TestContext는 빈 구성이 동일한 테스트끼리 컨텍스트를 캐시해서 재사용하는데, &lt;code>@MockBean&lt;/code>을 쓰면 &amp;ldquo;어떤 빈을 Mock으로 교체했는지&amp;quot;가 캐시 키에 포함됩니다. A 테스트가 &lt;code>ServiceA&lt;/code>를, B 테스트가 &lt;code>ServiceB&lt;/code>를 Mock하면 캐시 키가 달라져서 같은 컨텍스트를 또 로딩하게 되는 거죠. 약 90개의 &lt;code>@MockBean&lt;/code>이 제각각 다른 조합으로 선언되어 있으니 캐시 히트율이 바닥이었는데, 이걸 고치려면 테스트 베이스 클래스의 Mock 조합을 통합해야 해서 당장은 보류했습니다. 7번은 하드웨어 문제라 손댈 수 있는 영역이 아니었구요. 나머지 5가지를 하나씩 잡기로 했습니다.&lt;/p>
&lt;h2>해결: 하나씩 잡아나가기&lt;span class="hx:absolute hx:-mt-20" id="해결-하나씩-잡아나가기">&lt;/span>
&lt;a href="#%ed%95%b4%ea%b2%b0-%ed%95%98%eb%82%98%ec%94%a9-%ec%9e%a1%ec%95%84%eb%82%98%ea%b0%80%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>총 66개 파일을 수정하는 꽤 큰 작업이었습니다. 가장 간단한 것부터 시작해서 점점 복잡한 것으로 넘어가는 방식으로 접근했습니다.&lt;/p>
&lt;h3>1. Lazy Initialization 적용&lt;span class="hx:absolute hx:-mt-20" id="1-lazy-initialization-적용">&lt;/span>
&lt;a href="#1-lazy-initialization-%ec%a0%81%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>가장 간단하면서도 바로 효과를 볼 수 있는 것부터 시작했습니다.&lt;/p>
&lt;p>Spring Boot는 기본적으로 애플리케이션이 시작될 때 등록된 모든 빈(Bean)을 한꺼번에 초기화하거든요. 프로덕션에서는 이게 맞지만, 테스트에서는 문제가 됩니다. 특정 서비스 하나만 테스트하는데 그 테스트와 전혀 관련 없는 다른 모듈의 빈까지 전부 초기화되면서 시간이 낭비되는 거죠.&lt;/p>
&lt;p>&lt;code>lazy-initialization&lt;/code>은 이름 그대로 빈을 &amp;ldquo;게으르게&amp;rdquo; 초기화하는 설정입니다. 시작 시점에 모든 빈을 만드는 대신, 실제로 사용되는 시점에 필요한 빈만 초기화하는 거죠. 이렇게 하면 &lt;code>@SpringBootTest&lt;/code>가 돌 때 전체 빈을 한꺼번에 올리는 게 아니라 해당 테스트에서 필요한 빈만 그때그때 올리기 때문에 컨텍스트 로딩 시간이 줄어듭니다. 15개 모듈의 테스트 설정 파일(&lt;code>application-test.yml&lt;/code>)에 한 줄씩만 추가하면 됐습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">spring&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">main&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">lazy-initialization&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>테스트 환경에서만 적용되니 프로덕션에는 영향이 없고, 리스크도 낮았습니다.&lt;/p>
&lt;p>&lt;strong>결과:&lt;/strong> 모듈당 10~20초 정도 빨라졌는데, 15개 모듈에 다 적용하니 합산 &lt;strong>약 5분&lt;/strong> 정도 단축. 한 줄 추가한 것 치고는 꽤 괜찮은 효과였습니다.&lt;/p>
&lt;h3>2. 과거의 내가 심어둔 지뢰 — 프로세스 병렬에서 스레드 병렬로&lt;span class="hx:absolute hx:-mt-20" id="2-과거의-내가-심어둔-지뢰--프로세스-병렬에서-스레드-병렬로">&lt;/span>
&lt;a href="#2-%ea%b3%bc%ea%b1%b0%ec%9d%98-%eb%82%b4%ea%b0%80-%ec%8b%ac%ec%96%b4%eb%91%94-%ec%a7%80%eb%a2%b0--%ed%94%84%eb%a1%9c%ec%84%b8%ec%8a%a4-%eb%b3%91%eb%a0%ac%ec%97%90%ec%84%9c-%ec%8a%a4%eb%a0%88%eb%93%9c-%eb%b3%91%eb%a0%ac%eb%a1%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이번 최적화의 핵심이자, 가장 아이러니한 부분이었습니다.&lt;/p>
&lt;p>이전 &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-to-multi-module/">멀티모듈 전환&lt;/a> 때 빌드 성능 개선을 위해 &lt;strong>제가 직접&lt;/strong> 넣었던 설정이 문제의 원인이었거든요.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// build.gradle.kts (멀티모듈 전환 때 추가했던 설정)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="n">tasks&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">withType&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">Test&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">useJUnitPlatform&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">maxParallelForks&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="nc">Runtime&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">getRuntime&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="n">availableProcessors&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">/&lt;/span> &lt;span class="m">2&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="n">takeIf&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="k">it&lt;/span> &lt;span class="p">&amp;gt;&lt;/span> &lt;span class="m">0&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="o">?:&lt;/span> &lt;span class="m">1&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>당시에는 &amp;ldquo;CPU 코어 절반으로 병렬 실행하면 빨라지겠지&amp;quot;라고 생각했습니다. 실제로 전체 빌드 시간이 27분에서 8분으로 줄었거든요. &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-to-multi-module/">멀티모듈 전환 글&lt;/a>에서도 이 부분을 언급했었구요.&lt;/p>
&lt;p>그런데 이게 테스트에서는 오히려 독이 됐습니다. &lt;code>maxParallelForks&lt;/code>는 &lt;strong>별도 JVM 프로세스&lt;/strong>를 생성하는데, 각 프로세스는 독립된 메모리 공간을 가지기 때문에 &lt;strong>Spring TestContext 캐시를 공유할 수 없거든요.&lt;/strong> 같은 &lt;code>@SpringBootTest&lt;/code> 컨텍스트를 여러 프로세스에서 중복으로 로딩하게 되는 겁니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
graph TB
subgraph before[&amp;#34;Before: maxParallelForks = CPU/2&amp;#34;]
direction TB
G1[&amp;#34;Gradle&amp;#34;] --&amp;gt; P1[&amp;#34;JVM Process 1&amp;#34;]
G1 --&amp;gt; P2[&amp;#34;JVM Process 2&amp;#34;]
G1 --&amp;gt; P3[&amp;#34;JVM Process 3&amp;#34;]
P1 --&amp;gt; C1[&amp;#34;Spring Context 로딩&amp;lt;br/&amp;gt;30초&amp;#34;]
P2 --&amp;gt; C2[&amp;#34;Spring Context 로딩&amp;lt;br/&amp;gt;30초 (중복!)&amp;#34;]
P3 --&amp;gt; C3[&amp;#34;Spring Context 로딩&amp;lt;br/&amp;gt;30초 (중복!)&amp;#34;]
end
subgraph after[&amp;#34;After: JUnit5 Thread Parallel&amp;#34;]
direction TB
G2[&amp;#34;Gradle&amp;#34;] --&amp;gt; P4[&amp;#34;JVM Process (1개)&amp;#34;]
P4 --&amp;gt; C4[&amp;#34;Spring Context 로딩&amp;lt;br/&amp;gt;30초 (1회만)&amp;#34;]
C4 --&amp;gt; T1[&amp;#34;Thread 1&amp;#34;]
C4 --&amp;gt; T2[&amp;#34;Thread 2&amp;#34;]
C4 --&amp;gt; T3[&amp;#34;Thread 3&amp;#34;]
end
style C1 fill:#f85149,color:#fff
style C2 fill:#f85149,color:#fff
style C3 fill:#f85149,color:#fff
style C4 fill:#3fb950,color:#fff
&lt;/pre>&lt;p>핵심 차이는 &lt;strong>Spring TestContext 캐시 공유 여부&lt;/strong>입니다. &lt;code>maxParallelForks&lt;/code>는 별도 JVM 프로세스를 생성하기 때문에 각 프로세스가 독립된 메모리 공간을 가지고, 같은 컨텍스트를 프로세스 수만큼 중복 로딩합니다. 반면 JUnit5 스레드 병렬은 단일 JVM 내에서 동작하므로 컨텍스트를 한 번만 로딩하고 여러 스레드가 공유합니다.&lt;/p>
&lt;p>빌드와 테스트는 다릅니다. 빌드는 컴파일이라 프로세스별 상태 공유가 필요 없지만, Spring 테스트는 Context 캐싱이 성능의 핵심입니다. 프로세스를 나누면 캐시를 공유할 수 없어서 동일한 컨텍스트를 프로세스 수만큼 반복 로딩하게 되는 거죠. 과거의 제가 미래의 저한테 지뢰를 심어둔 셈이었습니다.&lt;/p>
&lt;p>해결 방향은 명확했습니다. &lt;code>maxParallelForks&lt;/code>를 1로 줄여 JVM 프로세스를 하나로 만들되, JUnit5의 스레드 레벨 병렬 실행을 켜서 &lt;strong>하나의 JVM 안에서 여러 테스트 클래스를 동시에&lt;/strong> 돌리는 것이었습니다. 같은 JVM이니까 Spring TestContext 캐시를 공유할 수 있게 되거든요.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="n">tasks&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">withType&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">Test&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">useJUnitPlatform&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">maxParallelForks&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="m">1&lt;/span> &lt;span class="c1">// JVM 프로세스는 1개로
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">systemProperty&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;junit.jupiter.execution.parallel.enabled&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;true&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">systemProperty&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;junit.jupiter.execution.parallel.mode.default&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;same_thread&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">systemProperty&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;junit.jupiter.execution.parallel.mode.classes.default&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;concurrent&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">systemProperty&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;junit.jupiter.execution.parallel.config.strategy&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;dynamic&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">systemProperty&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;junit.jupiter.execution.parallel.config.dynamic.factor&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;1&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>그런데 여기서 꽤 삽질을 했습니다. 처음에는 &lt;code>mode.default&lt;/code>도 &lt;code>concurrent&lt;/code>로 설정했었거든요. 클래스도 병렬, 메서드도 병렬이면 더 빨라지지 않을까 싶어서요. 그랬더니 테스트가 와르르 깨지기 시작했습니다. 몇 개가 아니라 여기저기서 터져서 뭐가 문제인지 파악하는 것부터 쉽지 않았습니다.&lt;/p>
&lt;p>원인을 추적해보니 단위 테스트에서 MockK(Kotlin용 Mocking 라이브러리)를 많이 사용하고 있었는데, MockK의 &lt;code>every { }&lt;/code> 블록이 Thread-safe하지 않았습니다. 메서드 레벨까지 병렬로 돌리니까 같은 Mock 객체에 대해 여러 스레드가 동시에 &lt;code>every { }&lt;/code>를 호출하면서 테스트끼리 간섭하는 거였죠.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant T1 as Thread 1 (TestA)
participant M as Mock 객체
participant T2 as Thread 2 (TestB)
T1-&amp;gt;&amp;gt;M: every { doSomething() } returns &amp;#34;A&amp;#34;
T2-&amp;gt;&amp;gt;M: every { doSomething() } returns &amp;#34;B&amp;#34;
Note over M: Mock 설정이 &amp;#34;B&amp;#34;로 덮어씌워짐
T1-&amp;gt;&amp;gt;M: doSomething()
M--&amp;gt;&amp;gt;T1: &amp;#34;B&amp;#34; 반환 (기대값: &amp;#34;A&amp;#34;)
Note over T1: 테스트 실패!
&lt;/pre>&lt;p>그래서 전략을 바꿨습니다. &lt;strong>클래스 단위로는 병렬 실행하되, 같은 클래스 안의 테스트 메서드는 순차 실행&lt;/strong>하도록요.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>mode.default = same_thread → 메서드는 순차 (MockK 안전)
mode.classes.default = concurrent → 클래스는 병렬 (속도 확보)&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이렇게 하면 서로 다른 테스트 클래스는 동시에 실행되면서도, 같은 클래스 안에서는 Mock이 간섭하지 않게 됩니다.&lt;/p>
&lt;p>병렬 실행을 켜니까 기쁜 것도 잠시, 이번엔 Spring REST Docs(테스트 코드 기반으로 API 문서를 자동 생성하는 도구) 관련 테스트가 간헐적으로 실패하기 시작했습니다. 여러 테스트 클래스가 동시에 &lt;code>build/generated-snippets/&lt;/code> 디렉토리에 문서 스니펫 파일을 쓰면서 파일이 꼬이는 문제였거든요. &amp;ldquo;간헐적&amp;quot;이라는 게 특히 골치 아팠습니다. 돌릴 때마다 깨지는 테스트가 달라졌으니까요.&lt;/p>
&lt;p>JUnit5의 &lt;code>@ResourceLock&lt;/code>을 활용해서 해결했습니다. 같은 리소스를 사용하는 테스트끼리 동시에 실행되지 않도록 잠금을 거는 어노테이션인데, 33개 테스트 베이스 클래스(IntegrationTest 13개, WebTest 13개, JpaTest 7개)에 &lt;code>@ResourceLock(&amp;quot;spring-restdocs&amp;quot;)&lt;/code>를 추가해서 REST Docs 관련 테스트들이 순차적으로 실행되도록 보장했습니다.&lt;/p>
&lt;p>&lt;strong>결과:&lt;/strong> 프로세스 병렬에서 스레드 병렬로 바꿨을 뿐인데 &lt;strong>약 15분&lt;/strong>이 줄었습니다. Context 캐시를 공유하게 되면서 동일 컨텍스트를 여러 번 로딩하던 오버헤드가 사라진 게 결정적이었습니다. (&lt;code>@ResourceLock&lt;/code> 자체는 직접적인 시간 단축 효과는 없었지만, 병렬 실행을 안정적으로 가져가기 위한 전제 조건이었습니다.)&lt;/p>
&lt;h3>3. Smoke Test 태그 분리&lt;span class="hx:absolute hx:-mt-20" id="3-smoke-test-태그-분리">&lt;/span>
&lt;a href="#3-smoke-test-%ed%83%9c%ea%b7%b8-%eb%b6%84%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>13개 &lt;code>*ApplicationTests.kt&lt;/code>이 각각 &lt;code>@SpringBootTest&lt;/code>로 전체 Context를 로딩하고 있었습니다. 이 테스트들은 &amp;ldquo;애플리케이션이 정상적으로 뜨는지&amp;rdquo; 확인하는 Smoke Test일 뿐인데, CI에서는 이미 전체 통합 테스트를 돌리면서 컨텍스트가 정상적으로 로딩되는지 검증하고 있었거든요. 완전히 중복이었습니다.&lt;/p>
&lt;p>&lt;code>@Tag(&amp;quot;smoke&amp;quot;)&lt;/code>를 추가하고 CI에서 제외했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Tag&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;smoke&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@SpringBootTest&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">SomeModuleApplicationTests&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nd">@Test&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">fun&lt;/span> &lt;span class="nf">contextLoads&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="n">tasks&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">test&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="nc">System&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">getenv&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;CI&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">==&lt;/span> &lt;span class="s2">&amp;#34;true&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">useJUnitPlatform&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="n">excludeTags&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;smoke&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>로컬에서는 여전히 돌아가니까 개발 중 빠른 검증용으로는 유지하되, CI에서만 건너뛰는 방식입니다.&lt;/p>
&lt;p>&lt;strong>결과:&lt;/strong> 13개 모듈의 불필요한 Spring Context 로딩을 제거하니 &lt;strong>약 5분&lt;/strong> 정도 단축.&lt;/p>
&lt;h3>4. CI 워크플로우 캐싱 개선&lt;span class="hx:absolute hx:-mt-20" id="4-ci-워크플로우-캐싱-개선">&lt;/span>
&lt;a href="#4-ci-%ec%9b%8c%ed%81%ac%ed%94%8c%eb%a1%9c%ec%9a%b0-%ec%ba%90%ec%8b%b1-%ea%b0%9c%ec%84%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>CI 워크플로우를 열어보니 &lt;code>git clean -ffdx&lt;/code>로 &lt;code>.gradle/&lt;/code> 빌드 캐시를 전부 삭제하고, &lt;code>--no-daemon&lt;/code>으로 매번 Gradle JVM을 새로 시작하고 있었습니다. Gradle 데몬은 백그라운드에서 JVM을 띄워놓고 재사용하는 건데, &lt;code>--no-daemon&lt;/code>은 그걸 끄고 매번 새 JVM을 띄우겠다는 뜻이거든요. JVM 웜업도 없고, 클래스 캐시도 없고, 모든 게 콜드 스타트.&lt;/p>
&lt;p>&amp;ldquo;CI에서는 당연히 클린 빌드해야지&amp;quot;라는 생각에서 나온 설정인 것 같은데, 이게 GitHub-hosted 러너에서는 맞는 말입니다. 매번 새 환경이 주어지니까요. 그런데 저희는 self-hosted 러너(MacBook Pro)를 사용하고 있었습니다. 환경이 유지되는 self-hosted에서는 오히려 캐시를 재활용하는 게 훨씬 효율적이었죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># Before&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>- &lt;span class="nt">run&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">git clean -ffdx&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>- &lt;span class="nt">run&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">./gradlew --no-daemon $TASKS&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c"># After&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>- &lt;span class="nt">uses&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">actions/setup-java@v4&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">with&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">cache&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;gradle&amp;#39;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>- &lt;span class="nt">run&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">./gradlew --build-cache $TASKS&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">env&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">CI&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;code>git clean -ffdx&lt;/code>를 제거하고, &lt;code>--no-daemon&lt;/code> 대신 &lt;code>--build-cache&lt;/code>를 추가했습니다. &lt;code>actions/setup-java&lt;/code>의 &lt;code>cache: 'gradle'&lt;/code> 설정으로 &lt;code>.gradle/&lt;/code> 디렉토리를 보존하도록 했구요.&lt;/p>
&lt;p>&lt;strong>결과:&lt;/strong> 매번 콜드 스타트를 하던 것에서 Gradle 데몬과 빌드 캐시를 재활용하게 되니 &lt;strong>약 5분&lt;/strong> 단축. 특히 두 번째 실행부터 캐시 효과가 눈에 띄게 좋더라구요.&lt;/p>
&lt;h2>방법별 결과 정리&lt;span class="hx:absolute hx:-mt-20" id="방법별-결과-정리">&lt;/span>
&lt;a href="#%eb%b0%a9%eb%b2%95%eb%b3%84-%ea%b2%b0%ea%b3%bc-%ec%a0%95%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>각 최적화별 기여도와 전체 결과입니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>최적화&lt;/th>
&lt;th>단축 시간&lt;/th>
&lt;th>비고&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>JUnit5 스레드 병렬 실행 전환&lt;/td>
&lt;td>&lt;strong>약 15분&lt;/strong>&lt;/td>
&lt;td>Context 캐시 공유가 핵심&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Lazy Initialization&lt;/td>
&lt;td>&lt;strong>약 5분&lt;/strong>&lt;/td>
&lt;td>모듈당 10~20초 × 15개 모듈&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Smoke Test 태그 분리&lt;/td>
&lt;td>&lt;strong>약 5분&lt;/strong>&lt;/td>
&lt;td>13개 불필요한 컨텍스트 로딩 제거&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>CI 워크플로우 캐싱&lt;/td>
&lt;td>&lt;strong>약 5분&lt;/strong>&lt;/td>
&lt;td>콜드 스타트 제거&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>REST Docs &lt;code>@ResourceLock&lt;/code>&lt;/td>
&lt;td>직접 단축 효과 없음&lt;/td>
&lt;td>병렬 실행의 전제 조건&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>합계&lt;/strong>&lt;/td>
&lt;td>&lt;strong>약 30분&lt;/strong>&lt;/td>
&lt;td>&lt;strong>45분 → 10분 (약 77% 단축)&lt;/strong>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/ogf76f6wx1tip009xlee6/optimization-waterfall-en.png?rlkey=cfgtatjdno42jsdwxyooobzmb&amp;amp;st=w90uxhoz&amp;amp;raw=1" alt="최적화별 기여도 워터폴 — 45분에서 시작해 각 최적화를 적용할 때마다 시간이 줄어드는 과정" loading="lazy" />&lt;/p>
&lt;p>각 최적화를 하나씩 적용하면서 매번 CI를 돌려본 건 아니고, 로컬 테스트 실행과 CI 로그의 task별 소요시간을 기반으로 추정한 수치입니다. 다만 체감상 가장 임팩트가 컸던 건 역시 &lt;code>maxParallelForks&lt;/code>를 1로 줄이고 JUnit5 스레드 병렬 실행으로 전환한 것이었습니다. 이것 하나로 전체 개선의 절반을 가져간 셈이죠.&lt;/p>
&lt;p>실제 CI 실행 결과로도 확인할 수 있습니다. 아래는 최적화 후의 GitHub Actions 워크플로우입니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/smy7tqol2hkjojh9qpxs5/ci-after-7min.png?rlkey=n2kehlw3hiv5t5yfd2ldfgnv7&amp;amp;st=m6riwrwf&amp;amp;raw=1" alt="최적화 후 CI 실행 결과 — 동일 PR에서 7분 8초로 단축, SUCCESS" loading="lazy" />&lt;/p>
&lt;p>로그를 펼쳐보면 &amp;ldquo;Build test reports&amp;rdquo; 단계가 정상 완료되고, 이어서 Jacoco Report까지 생성되는 걸 확인할 수 있습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/mcry395cxvfvxk0q95dj8/ci-after-log.png?rlkey=ca72rys19nlkmd77hx2ekeb0e&amp;amp;st=4mxowo9h&amp;amp;raw=1" alt="최적화 후 CI 빌드 로그 — BUILD SUCCESSFUL" loading="lazy" />&lt;/p>
&lt;p>최적화 전에는 &amp;ldquo;Build test reports&amp;rdquo; 단계 하나가 45분 31초를 잡아먹으면서 전체 워크플로우가 실패했지만, 최적화 후에는 같은 단계가 7분 8초로 줄면서 Jacoco Report 생성과 커버리지 체크까지 정상 완료됐습니다.&lt;/p>
&lt;p>주요 모듈별 테스트도 전부 PASSED. 깨지는 테스트 없이 전체 통과를 확인하고 PR을 올렸습니다.&lt;/p>
&lt;p>비슷한 상황에서 어디부터 손대야 할지 고민이라면, Spring Context 로딩 관련 최적화를 먼저 잡는 걸 추천합니다. 테스트에서 시간을 가장 많이 잡아먹는 건 결국 Context 로딩이고, 불필요한 테스트 제거나 CI 캐싱은 그 다음에 해도 충분합니다.&lt;/p>
&lt;h3>덤: 최적화 중에 발견한 버그들&lt;span class="hx:absolute hx:-mt-20" id="덤-최적화-중에-발견한-버그들">&lt;/span>
&lt;a href="#%eb%8d%a4-%ec%b5%9c%ec%a0%81%ed%99%94-%ec%a4%91%ec%97%90-%eb%b0%9c%ea%b2%ac%ed%95%9c-%eb%b2%84%ea%b7%b8%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>최적화 작업을 하다 보니 기존에 숨어있던 버그도 발견했습니다. MSA 때는 서비스별로 따로 테스트를 돌리다 보니 드러나지 않았던 문제가, 모듈러 모놀리식에서 전체를 한꺼번에 돌리니까 나타나는 거더라구요.&lt;/p>
&lt;p>한 모듈의 테스트 베이스 클래스에서 파일 유틸리티 빈을 주입받고 있었는데, 모듈러 모놀리식에서는 같은 이름의 빈이 여러 모듈에 존재하면서 잘못된 빈이 주입되고 있었습니다. &lt;code>@Qualifier&lt;/code>를 붙여서 정확한 빈을 지정하도록 수정했구요. 다른 모듈에서도 테스트 2개가 실패하고 있었는데, 추적해보니 이전에 URL 충돌 때문에 다른 모듈로 이전된 엔드포인트의 테스트가 그대로 남아있었습니다. 엔드포인트가 없으니 Spring Security가 401을 반환하면서 실패한 거였죠. 해당 테스트 클래스를 삭제하면서 정리했습니다.&lt;/p>
&lt;h2>느낀 점&lt;span class="hx:absolute hx:-mt-20" id="느낀-점">&lt;/span>
&lt;a href="#%eb%8a%90%eb%82%80-%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>빌드 최적화 ≠ 테스트 최적화&lt;span class="hx:absolute hx:-mt-20" id="빌드-최적화--테스트-최적화">&lt;/span>
&lt;a href="#%eb%b9%8c%eb%93%9c-%ec%b5%9c%ec%a0%81%ed%99%94--%ed%85%8c%ec%8a%a4%ed%8a%b8-%ec%b5%9c%ec%a0%81%ed%99%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이번에 가장 크게 와닿은 건 이 부분이었습니다.&lt;/p>
&lt;p>멀티모듈 전환 때 &lt;code>maxParallelForks&lt;/code>를 넣고 빌드 시간이 27분에서 8분으로 줄었을 때, 저는 이 설정이 만능인 줄 알았습니다. &amp;ldquo;병렬화하면 빨라진다&amp;quot;가 아니라 **&amp;ldquo;무엇을 병렬화하느냐에 따라 최적의 단위가 다르다&amp;rdquo;**는 걸 이번에 제대로 배웠습니다. 컴파일은 프로세스끼리 상태를 공유할 필요가 없으니 프로세스 병렬이 맞지만, Spring 테스트는 Context 캐시를 같이 써야 빠르니까 스레드 병렬이 맞는 거였죠. 같은 &amp;ldquo;병렬&amp;quot;이라도 대상에 따라 전략이 달라야 한다는 걸, 직접 삽질하고 나서야 체감했습니다.&lt;/p>
&lt;h3>&amp;ldquo;당연한&amp;rdquo; 설정을 의심하자&lt;span class="hx:absolute hx:-mt-20" id="당연한-설정을-의심하자">&lt;/span>
&lt;a href="#%eb%8b%b9%ec%97%b0%ed%95%9c-%ec%84%a4%ec%a0%95%ec%9d%84-%ec%9d%98%ec%8b%ac%ed%95%98%ec%9e%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;code>--no-daemon&lt;/code>이나 &lt;code>git clean -ffdx&lt;/code> 같은 설정은 &amp;ldquo;CI에서는 당연히 클린 빌드해야지&amp;quot;라는 생각에서 나온 것 같습니다. 틀린 말은 아닙니다. GitHub-hosted 러너라면요. 하지만 저희는 self-hosted 러너를 쓰고 있었고, 환경이 유지되는 self-hosted에서는 캐시를 활용하는 게 훨씬 효율적이었습니다.&lt;/p>
&lt;p>&amp;ldquo;다들 이렇게 하니까&amp;quot;가 아니라 &lt;strong>&amp;ldquo;우리 환경에서는 어떤 게 최적인지&amp;rdquo;&lt;/strong> 생각해봤어야 했습니다.&lt;/p>
&lt;h3>다음엔 CI 파이프라인도 같이 볼 것&lt;span class="hx:absolute hx:-mt-20" id="다음엔-ci-파이프라인도-같이-볼-것">&lt;/span>
&lt;a href="#%eb%8b%a4%ec%9d%8c%ec%97%94-ci-%ed%8c%8c%ec%9d%b4%ed%94%84%eb%9d%bc%ec%9d%b8%eb%8f%84-%ea%b0%99%ec%9d%b4-%eb%b3%bc-%ea%b2%83" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;a href="https://jeongil.dev/ko/blog/architecture/msa-to-modular-monolith/">전환기 글&lt;/a>에서도 다뤘지만, 모듈러 모놀리식 전환 후에는 &lt;code>@Transactional&lt;/code> TransactionManager 불일치, 빈 이름 충돌, 순환 참조 같은 예상치 못한 문제들이 연쇄적으로 터졌습니다. 그리고 이번에는 CI 테스트 빌드 시간까지.&lt;/p>
&lt;p>돌이켜보면 전환 작업의 &amp;ldquo;완료 조건&amp;quot;을 코드가 컴파일되고 테스트가 통과하는 것까지로만 잡았던 게 실수였습니다. 만약 다시 큰 아키텍처 전환을 한다면, 아래 항목들도 같이 확인할 것 같습니다.&lt;/p>
&lt;ul>
&lt;li>CI 전체 테스트 실행 시간이 기존 대비 얼마나 증가했는지&lt;/li>
&lt;li>테스트 병렬화 전략이 새 구조에서도 유효한지&lt;/li>
&lt;li>빌드 캐시와 Gradle 데몬 설정이 러너 환경에 맞는지&lt;/li>
&lt;li>중복 테스트(Smoke Test 등)가 새 구조에서 여전히 필요한지&lt;/li>
&lt;/ul>
&lt;p>코드가 돌아간다고 끝이 아니라, 코드를 돌리는 환경까지 함께 봤어야 했다는 걸 이번에 확실히 느꼈습니다.&lt;/p>
&lt;h2>마치며&lt;span class="hx:absolute hx:-mt-20" id="마치며">&lt;/span>
&lt;a href="#%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>돌이켜보면 이 문제는 모듈러 모놀리식 전환이라는 큰 변화의 당연한 부작용이었습니다. MSA에서는 서비스별로 CI가 돌아가니까 하나의 서비스 테스트가 2분이면 2분이 걸렸을 뿐이고, 모듈러 모놀리식에서는 전체가 한꺼번에 돌아가니까 시간이 길어질 수밖에 없었죠.&lt;/p>
&lt;p>다만 45분은 너무 길었고, 원인을 분석해보니 구조 변경만 하고 테스트 인프라는 그대로 두면서 생긴 비효율이 대부분이었습니다. 멀티모듈 시절에 넣었던 &lt;code>maxParallelForks&lt;/code>가 Context 캐시를 무효화시키고, 매번 클린 빌드를 하고, 의미 없는 Smoke Test를 13개나 돌리고&amp;hellip; 이런 것들을 하나하나 잡았더니 10분까지 줄어든 겁니다.&lt;/p>
&lt;p>솔직히 아직 남아있는 숙제도 있습니다. 원인 파악에서도 다뤘던 6번, 약 90개 이상의 &lt;code>@MockBean&lt;/code>/&lt;code>@MockkBean&lt;/code>이 Context 캐시 미스를 유발하고 있는 문제인데요. 이건 테스트 베이스 클래스의 Mock 조합을 통합해야 해서 시간이 좀 걸릴 것 같습니다. 이것까지 정리하면 10분도 더 줄일 수 있지 않을까 기대하고 있습니다.&lt;/p>
&lt;p>레거시에서 MSA로, 16개 레포에서 멀티모듈로, MSA에서 모듈러 모놀리식으로. 아키텍처가 바뀔 때마다 예상치 못한 문제가 터지지만, 45분짜리 CI를 디버깅하면서 Spring TestContext 캐싱, Gradle 데몬, JUnit5 병렬 실행의 동작 방식을 전보다 훨씬 깊게 이해하게 된 것도 사실입니다. 결국 삽질이 가장 좋은 공부였던 셈이죠.&lt;/p>
&lt;p>비슷한 상황을 겪고 계신 분이 있다면, 이 글이 조금이나마 도움이 되었으면 합니다.&lt;/p>
&lt;h2>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>관련 글&lt;span class="hx:absolute hx:-mt-20" id="관련-글">&lt;/span>
&lt;a href="#%ea%b4%80%eb%a0%a8-%ea%b8%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/architecture/msa-to-modular-monolith/">MSA, 우리에겐 과했다 - 모듈러 모놀리식 전환기&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/architecture/msa-to-multi-module/">16개 레포지토리를 하나로 - MSA 멀티모듈 전환기&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>외부 자료&lt;span class="hx:absolute hx:-mt-20" id="외부-자료">&lt;/span>
&lt;a href="#%ec%99%b8%eb%b6%80-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://paramount.tech/blog/2023/12/11/a-little-more-on-spring-tests-our-optimizations.html"target="_blank" rel="noopener">Paramount Tech: Spring Boot Test 32분 → 10분 최적화&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://engineering.zalando.com/posts/2023/11/mastering-testing-efficiency-in-spring-boot-optimization-strategies-and-best-practices.html"target="_blank" rel="noopener">Zalando Engineering: JUnit5 병렬 실행으로 60% 단축&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://dev.to/mchoraine/speeding-up-spring-integration-tests-lessons-from-context-caching-d6p"target="_blank" rel="noopener">DEV Community: Spring Context 캐싱으로 50% 개선&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>MSA, 우리에겐 과했다 - 모듈러 모놀리식 전환기</title><link>https://jeongil.dev/ko/blog/architecture/msa-to-modular-monolith/</link><pubDate>Fri, 20 Feb 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/architecture/msa-to-modular-monolith/</guid><description>
&lt;p>안녕하세요.&lt;/p>
&lt;p>저는 프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 정정일입니다.&lt;/p>
&lt;p>저희 회사는 모놀리식 아키텍처로 이루어진 자바 서블릿 레거시 서비스를 MSA로 무중단 마이그레이션을 성공적으로 완료하고 운영 중에 있었습니다. 그 과정이 쉽지는 않았지만, MSA의 장점과 단점을 몸소 체험하면서 많은 것을 배울 수 있었죠.&lt;/p>
&lt;p>이와 관련된 경험을 곱씹어 보면서 MSA에 관한 고찰 시리즈도 블로그에 작성했는데, &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-7-conclusion/">MSA 시리즈 마지막 편&lt;/a>에서 저는 이런 이야기를 했습니다.&lt;/p>
&lt;blockquote>
&lt;p>저는 &lt;strong>&amp;ldquo;처음부터 MSA&amp;rdquo;&lt;/strong> 보다는 &lt;strong>&amp;ldquo;모듈러 모놀리식에서 시작해서 필요할 때 MSA로&amp;rdquo;&lt;/strong> 가 좀 더 현명한 선택이지 않나 싶습니다.&lt;/p>
&lt;/blockquote>
&lt;p>이 문장을 적게된 이유가 단순히 이론에 기반해 적은게 아닌 회사에서 모놀리식 아키텍처를 MSA로 전환하는 과정들 속에 &amp;ldquo;과연 이게 우리 팀 상황에서 맞는 구조인가?&amp;ldquo;라는 질문이 계속 떠올랐기 때문입니다.&lt;/p>
&lt;p>그런데 고심끝에 결국 운영 중인 MSA를 모듈러 모놀리식으로 전환하기로 결정했습니다. 어떤 이유에서 이런 결정을 내리게 됐는지, 전환 과정에서 어떤 고민과 문제들이 있었는지, 그리고 어떻게 해결했는지 공유하고자 합니다&lt;/p>
&lt;p>먼저 이 결정을 이해하려면 저희 팀의 아키텍처가 걸어온 길부터 이야기해야 할 것 같습니다.&lt;/p>
&lt;h2>아키텍처가 걸어온 길&lt;span class="hx:absolute hx:-mt-20" id="아키텍처가-걸어온-길">&lt;/span>
&lt;a href="#%ec%95%84%ed%82%a4%ed%85%8d%ec%b2%98%ea%b0%80-%ea%b1%b8%ec%96%b4%ec%98%a8-%ea%b8%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>저희 회사 서비스의 아키텍처는 제가 팀에 합류하기 전부터 계속 변화해왔습니다.&lt;/p>
&lt;h3>레거시에서 MSA로&lt;span class="hx:absolute hx:-mt-20" id="레거시에서-msa로">&lt;/span>
&lt;a href="#%eb%a0%88%ea%b1%b0%ec%8b%9c%ec%97%90%ec%84%9c-msa%eb%a1%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>저는 2025년 3월에 팀에 합류했는데, 합류 시점에 팀은 레거시 모놀리식 서비스를 MSA로 전환하는 과정 중에 있었습니다. 당시 개발자는 총 5명, 그 중 백엔드는 저 포함 2명이었습니다. 16개 서비스가 각각 개별 Git 레포지토리로 관리되고 있었는데, 이 인원으로 16개 레포를 관리한다는 건 맞지 않다고 생각했습니다.&lt;/p>
&lt;h3>멀티모듈로, 그리고 K8s로&lt;span class="hx:absolute hx:-mt-20" id="멀티모듈로-그리고-k8s로">&lt;/span>
&lt;a href="#%eb%a9%80%ed%8b%b0%eb%aa%a8%eb%93%88%eb%a1%9c-%ea%b7%b8%eb%a6%ac%ea%b3%a0-k8s%eb%a1%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>공통 코드 하나 수정하는 데 16개 레포에 PR을 16개 올려야 하는 구조였습니다. 팀 합류 한 달쯤 됐을 때 &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-to-multi-module/">멀티모듈 전환을 제안&lt;/a>해서 하나의 모노레포로 통합했습니다. 배포는 각 서비스별로 따로해 MSA는 유지하며 공통 코드 관리를 편하게 하는 구조로 바꿨죠.&lt;/p>
&lt;p>비슷한 시기에 &lt;a href="https://jeongil.dev/ko/blog/infrastructure/docker-compose-to-k8s/">쿠버네티스 도입&lt;/a>도 제안했습니다. 큰 인스턴스 하나에 모든 컨테이너를 올려 운영하던 구조가 한계에 달했는데, 마침 GCP 스타트업 프로그램에 선정되면서 크레딧으로 비용 문제가 해결돼 도입을 결정할 수 있었습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
graph LR
A[&amp;#34;레거시 모놀리식&amp;#34;] --&amp;gt;|&amp;#34;MSA 전환&amp;#34;| B[&amp;#34;MSA&amp;lt;br/&amp;gt;(16개 레포)&amp;#34;]
B --&amp;gt;|&amp;#34;모노레포 통합&amp;#34;| C[&amp;#34;멀티모듈&amp;lt;br/&amp;gt;(개별 배포 MSA 유지)&amp;#34;]
C --&amp;gt;|&amp;#34;인프라 전환&amp;#34;| D[&amp;#34;K8s 도입&amp;#34;]
&lt;/pre>&lt;p>이후 MSA 서비스를 Bounded Context에 따라 합치기도 하고, 또 &lt;a href="https://jeongil.dev/ko/blog/architecture/is-gradual-msa-transition-an-illusion/">강결합된 레거시 서비스를 MSA로 마이그레이션&lt;/a> 하기도 하면서 최종적으로 서비스 수가 13개로 줄어들게 됐습니다.&lt;/p>
&lt;h3>그리고 모듈러 모놀리식으로&lt;span class="hx:absolute hx:-mt-20" id="그리고-모듈러-모놀리식으로">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%a6%ac%ea%b3%a0-%eb%aa%a8%eb%93%88%eb%9f%ac-%eb%aa%a8%eb%86%80%eb%a6%ac%ec%8b%9d%ec%9c%bc%eb%a1%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>돌이켜보면 각 전환마다 항상 같은 질문을 던졌던 것 같습니다. &lt;strong>&amp;ldquo;지금 우리 팀 상황에서 이 구조가 정말 맞나?&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>멀티레포가 맞지 않아서 멀티모듈로 바꿨고, 단일 인스턴스의 한계에 달해서 K8s를 도입했습니다. 그리고 이번에는 MSA 자체를 돌아보게 됐습니다.&lt;/p>
&lt;h2>MSA, 우리에게 맞았는가&lt;span class="hx:absolute hx:-mt-20" id="msa-우리에게-맞았는가">&lt;/span>
&lt;a href="#msa-%ec%9a%b0%eb%a6%ac%ec%97%90%ea%b2%8c-%eb%a7%9e%ec%95%98%eb%8a%94%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>혼자서 MSA를 운영한다는 것&lt;span class="hx:absolute hx:-mt-20" id="혼자서-msa를-운영한다는-것">&lt;/span>
&lt;a href="#%ed%98%bc%ec%9e%90%ec%84%9c-msa%eb%a5%bc-%ec%9a%b4%ec%98%81%ed%95%9c%eb%8b%a4%eb%8a%94-%ea%b2%83" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>MSA에 관한 고찰 시리즈를 적으면서 &amp;ldquo;팀이 그리고 회사가 작다면 MSA는 오버엔지니어링이라고 생각한다&amp;quot;라는 제 주관을 이야기 했었는데, 제가 저희 팀 상황에 의해 느낀 그대로를 적은 것이었습니다.&lt;/p>
&lt;p>합류 당시에는 개발자 5명에 백엔드 개발자가 저 포함 2명이었는데, 2025년 하반기에 경영 악화로 인원이 감축되면서 개발자 2명만 남게 됐습니다. 저는 백엔드, 나머지 한 분은 프론트엔드를 담당하고 계시거든요. 즉 모든 백엔드 서비스를 운영하는 사람은 저 혼자가 된 겁니다. 거기에 K8s 인프라 관리까지 제가 병행하고 있구요.&lt;/p>
&lt;p>글로 적을 때는 &amp;ldquo;소규모 팀에서는 모놀리식이 맞지 않나 싶습니다&amp;rdquo; 정도로 가볍게 적었지만, 실제로 몸으로 겪고 있는 저는 &amp;ldquo;이건 진짜 바꿔야 한다&amp;quot;라는 확신에 가까운 생각을 하고 있었습니다.&lt;/p>
&lt;p>혼자서 13개가 넘는 서비스를 운영하면서 기능 개발까지 한다는 건 생각보다 쉽지 않았습니다. 서비스 간 호출 관계를 파악하는 것도, 장애가 발생했을 때 어떤 서비스에서 시작된 문제인지 추적하는 것도, 배포 파이프라인을 13개나 관리해야 하는 것도 부담으로 다가왔습니다. 또 Config Server, Elastic Search, Redis와 같은 공통 인프라 서비스도 따로 운영해야 했죠.&lt;/p>
&lt;h3>비용, 더 이상 미룰 수 없는 문제&lt;span class="hx:absolute hx:-mt-20" id="비용-더-이상-미룰-수-없는-문제">&lt;/span>
&lt;a href="#%eb%b9%84%ec%9a%a9-%eb%8d%94-%ec%9d%b4%ec%83%81-%eb%af%b8%eb%a3%b0-%ec%88%98-%ec%97%86%eb%8a%94-%eb%ac%b8%ec%a0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>사실 운영 부담만으로는 전환을 결정하기 어려웠습니다. 솔직히 &amp;ldquo;좀 힘들어도 제가 조금 고생하면 돌아는 가니까&amp;rdquo; 하면서 버틸 수도 있었으니까요. 그런데 비용 문제가 겹치면서 상황이 달라졌습니다.&lt;/p>
&lt;p>위에서 잠깐 언급했지만 저희는 GCP 스타트업 프로그램으로 1년간 크레딧을 지원받고 있었습니다. 꽤나 여유 있는 금액이였고 덕분에 제대로 된 인프라를 구축해서 운영할 수 있었는데, 이 크레딧이 2026년 4월에 끝나게 됩니다.&lt;/p>
&lt;p>저희 회사는 스타트업입니다. 당연하게도 금전적 여유가 없는 상태인데 K8s로 전환하면서 개발서버까지 도입해 인프라 비용이 약 2.5~3배 증가한 상태였죠.&lt;/p>
&lt;p>보통 K8s, MSA 구조에서는 고가용성을 위해 서비스별로 최소 2개씩 파드를 운영하곤 합니다. 13개 서비스면 최소 26개 파드가 필요한 거죠. 여기에 위에서 언급한 공통 인프라 서비스까지 더하면 리소스는 더 늘어납니다.&lt;/p>
&lt;p>크레딧이 있으니까 부담없이 이런 운영이 가능했던 거지 크레딧이 없어지면 이 구조를 유지하기가 현실적으로 어려웠습니다.&lt;/p>
&lt;p>&lt;strong>MSA는 돈이 많이 들어갑니다.&lt;/strong> &lt;a href="https://www.docker.com/blog/do-you-really-need-microservices/"target="_blank" rel="noopener">Amazon Prime Video 팀이 MSA를 모놀리식으로 전환하면서 비용을 90% 절감했다는 사례&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>가 있는데, 이게 남의 이야기가 아니라 저희의 현실이 된 거죠.&lt;/p>
&lt;h3>우리가 누리지 못하고 있던 MSA의 장점&lt;span class="hx:absolute hx:-mt-20" id="우리가-누리지-못하고-있던-msa의-장점">&lt;/span>
&lt;a href="#%ec%9a%b0%eb%a6%ac%ea%b0%80-%eb%88%84%eb%a6%ac%ec%a7%80-%eb%aa%bb%ed%95%98%ea%b3%a0-%ec%9e%88%eb%8d%98-msa%ec%9d%98-%ec%9e%a5%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>비용 문제를 생각하며 그리고 MSA에 관한 고찰을 하며 한 가지를 돌아보게 됐습니다. MSA의 핵심 장점은 &lt;strong>독립성&lt;/strong>이라고 생각합니다. 서비스별 독립 배포, 독립 확장, 장애 격리. 그런데 이 장점들이 저희 팀 상황에서 정말 의미가 있었는지에 대해 말이죠.&lt;/p>
&lt;p>솔직히 말씀드리면 아무리 생각해봐도 &amp;ldquo;과연 우리 서비스가 복잡성이라는 트레이드 오프를 통해 이 독립성을 확보해야할 정도의 서비스인가?&amp;rdquo; 라는 질문에 저는 &amp;ldquo;그렇진 않다&amp;quot;라는 답이 나왔습니다.&lt;/p>
&lt;p>&lt;strong>독립 배포&lt;/strong>라고 하지만 어차피 소규모(1~2명 팀원이 늘어봐야 5명)이기 때문에 서로 다른 서비스를 동시에 배포해야하는 일도 간단하게 의사소통하여 어려움없이 가능했습니다. &lt;strong>독립 확장&lt;/strong>이라고 하지만 트래픽이 서비스별로 극단적으로 차이나는 상황이 아니었습니다. &lt;strong>장애 격리&lt;/strong>라고 하지만 오히려 서비스 간 HTTP 통신 자체가 장애 포인트가 되는 경우도 많았습니다.&lt;/p>
&lt;p>반면 MSA 때문에 감수하고 있던 것들은 꽤 있었습니다. 서비스 간 통신에서 네트워크 레이턴시와 실패 가능성을 항상 고려해야 했고, 오케스트레이터 기반의 분산 트랜잭션을 구현해서 관리해야 했으며, 서비스간 객체 타입 검증 문제도 있었습니다.&lt;/p>
&lt;p>제가 개인적으로 느낀 MSA의 &lt;strong>독립성이 필요한 순간은 회사가 너무 커져서 한 팀이 모든 서비스를 다루기 어려워지는 시점&lt;/strong>이였습니다. 서비스가 너무 커지고 트래픽을 한 서비스가 감당하기 어려워지는 시점이 오면, 그때 가서 MSA로 전환해도 늦지 않다고 생각합니다. 이때는 회사가 잘됐다며 덩실덩실 기쁜 마음으로 전환할 수 있을 거라고 생각합니다.&lt;/p>
&lt;p>결국 &lt;strong>운영 부담과 비용 문제, 그리고 우리가 실제로 누리고 있던 MSA의 장점을 종합적으로 고려했을 때, 지금이 모듈러 모놀리식으로 전환할 적기라는 판단이 들었습니다.&lt;/strong>&lt;/p>
&lt;h2>전환 설계&lt;span class="hx:absolute hx:-mt-20" id="전환-설계">&lt;/span>
&lt;a href="#%ec%a0%84%ed%99%98-%ec%84%a4%ea%b3%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>그렇다면 왜 모듈러 모놀리식인가&lt;span class="hx:absolute hx:-mt-20" id="그렇다면-왜-모듈러-모놀리식인가">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%a0%87%eb%8b%a4%eb%a9%b4-%ec%99%9c-%eb%aa%a8%eb%93%88%eb%9f%ac-%eb%aa%a8%eb%86%80%eb%a6%ac%ec%8b%9d%ec%9d%b8%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>전환을 결정하고 나서 가장 먼저 고민했던 건 어떤 구조로 전환할 것인가였습니다. 모놀리식으로 가는 건 결정했지만, 단순한 모놀리식 아키텍처로 갈지, 아니면 모듈러 모놀리식으로 갈지를 선택해야했죠.&lt;/p>
&lt;p>사실 고민은 길지 않았습니다. 이미 MSA로 운영하면서 각 서비스가 모듈화 되어 있었고, 모듈러 모놀리식으로 가면 기존의 모듈 구조를 최대한 살릴 수 있을 거라고 생각했거든요. 단일 애플리케이션이지만 내부적으로는 모듈로 나누어서 관리하는 구조가 저희 팀 상황에 가장 잘 맞는다고 판단했습니다.&lt;/p>
&lt;p>기존에 서비스간 Http 통신을 통해 동기적으로 호출하던 부분들은 추상화하여 모듈간 메소드 호출로만 바꿔주면 되니까, 전환 작업도 비교적 수월할 거라고 판단했습니다.&lt;/p>
&lt;p>그리고 이전에 멀티모듈 전환을 해놓은 것도 컸습니다. 만약 16개 개별 레포가 그대로였다면 레포 통합, 버전 통일, 공통 모듈 추출까지 이번에 함께 해야 했을 텐데, 이미 그 작업들을 마쳐놓은 덕분에 모듈 간 통신 방식을 바꾸고 하나의 애플리케이션으로 합치는 데만 집중할 수 있었습니다.&lt;/p>
&lt;h3>무엇을 합치고, 무엇을 남길 것인가&lt;span class="hx:absolute hx:-mt-20" id="무엇을-합치고-무엇을-남길-것인가">&lt;/span>
&lt;a href="#%eb%ac%b4%ec%97%87%ec%9d%84-%ed%95%a9%ec%b9%98%ea%b3%a0-%eb%ac%b4%ec%97%87%ec%9d%84-%eb%82%a8%ea%b8%b8-%ea%b2%83%ec%9d%b8%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>모듈러 모놀리식으로 전환을 결정하고 나서는 어떤 서비스를 통합하고 어떤 서비스를 독립으로 유지할지 고민해야했습니다. 결론부터 말씀드리자면 저희는 여러 서비스를 하나의 애플리케이션으로 통합하되, &lt;strong>notification-service(알림 서비스)와 batch-service는 독립 배포 단위로 유지&lt;/strong>하기로 결정했습니다.&lt;/p>
&lt;p>notification-service는 알림톡/메일/SMS와 같은 알림을 발송하는 역할을 맡고있는 서비스로 특성상 트래픽 패턴이 다른 서비스와 크게 달랐습니다. 특정 시간에 대량 발송이 필요한 경우가 있기도 해 독립적으로 스케일링할 수 있어야 했거든요. 무조건 전부 합치는 게 아니라 필요한 건 남겨둬야 한다고 생각했습니다.&lt;/p>
&lt;p>또 batch-service는 배치 작업을 담당하는 서비스로, 배치 작업은 일반적으로 트랜잭션과는 다른 특성을 가지고 있기 때문에 독립적으로 관리하는 게 낫다고 판단했습니다. 그리고 batch 작업중에 실행 시간이 오래 걸리는 작업이 있을 수 있는데, 이런 작업이 다른 서비스의 성능에 영향을 주지 않도록 격리하는 게 좋다고 생각했습니다.&lt;/p>
&lt;p>나머지 서비스들은 하나의 Spring Boot 애플리케이션(&lt;code>ModularMonolithApplication&lt;/code>)으로 통합하기로 했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>기존 MSA (13개 독립 서비스)
├── agent-service (Hexagonal &amp;#43; CQRS)
├── apart-service (Hexagonal &amp;#43; CQRS)
├── ai-service (Layered)
├── chat-service (Layered)
├── ... 총 13개 독립 배포 단위
전환 후 모듈러 모놀리식
├── app/ # 단일 배포 단위
│ ├── agent-module/
│ ├── apart-module/
│ ├── ai-module/
│ ├── ... 11개 모듈
│ └── common/
├── notification-service/ # 독립 배포 유지
└── batch-service/ # 독립 배포 유지&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>DB는 왜 통합하지 않았나&lt;span class="hx:absolute hx:-mt-20" id="db는-왜-통합하지-않았나">&lt;/span>
&lt;a href="#db%eb%8a%94-%ec%99%9c-%ed%86%b5%ed%95%a9%ed%95%98%ec%a7%80-%ec%95%8a%ec%95%98%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>기존에 저희 회사 DB는 Schema-per-service 구조로 되어 있었습니다. MSA 전환을 하는 의사결정 과정에 제가 팀에 있지 않았다보니 어떤 연유로 Schema-per-service 구조로 시작하게 됐는지는 정확히 알 수 없지만, 아마도 서비스 간 독립성을 최대한 보장하되 비용적인 측면을 고려해 그렇게 설계하지 않았을까 추측해봅니다.&lt;/p>
&lt;p>이런 상황에서 서비스를 통합하면서 DB도 하나의 Schema로 합쳐야 하는지 역시 고민했습니다. 그러나 결론부터 말하면 &lt;strong>기존의 스키마 분리(schema-per-service)를 그대로 유지&lt;/strong>하기로 했습니다.&lt;/p>
&lt;p>이유는 두 가지였습니다.&lt;/p>
&lt;p>첫째, 언제든 다시 MSA로 전환할 수 있는 유연성을 남겨두고 싶었습니다. DB가 이미 서비스별로 분리되어 있으니 나중에 다시 서비스를 분리해야 할 상황이 오더라도 DB 쪽에서는 추가 작업 없이 넘어갈 수 있거든요. 이미 되어 있는 걸 굳이 합칠 이유가 없다 판단했습니다.&lt;/p>
&lt;p>둘째, DB 마이그레이션 과정에서 발생할 문제들이 우려됐습니다. 테이블 이름 충돌, 마이그레이션 스크립트 작성, 데이터 정합성 검증&amp;hellip; 애플리케이션 레벨의 통합만으로도 충분히 해야 할 일이 많은데 DB까지 건드리면 리스크가 너무 커진다고 판단했습니다. 또 CQRS 패턴을 적용한 서비스들도 있어서, 읽기 모델과 쓰기 모델이 서로 다른 스키마에 존재하는 상황이었는데, 이걸 하나로 합치는 작업도 생각보다 복잡할 것 같았습니다.&lt;/p>
&lt;p>다만 이 결정이 멀티 DataSource 설정이라는 새로운 도전으로 이어지게 되는데, 이 부분은 뒤에서 따로 이야기하겠습니다.&lt;/p>
&lt;h3>ModuleApi 설계&lt;span class="hx:absolute hx:-mt-20" id="moduleapi-설계">&lt;/span>
&lt;a href="#moduleapi-%ec%84%a4%ea%b3%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>위에서 잠깐 언급하긴 했지만, 어떻게 모듈간 호출할지 역시 정해야 했습니다. 기존 MSA에서는 동기 통신은 FeignClient를 통해 HTTP로 구성하고 있었는데, 모듈러 모놀리식에서는 같은 JVM 안에 있으니 HTTP 통신이 필요 없게 됩니다.&lt;/p>
&lt;p>그래서 &lt;code>common&lt;/code> 모듈에 ModuleApi 인터페이스를 정의해 추상화하고, 각 모듈에서 구현체를 만드는 방식을 선택했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;span class="lnt">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 기존: FeignClient를 통한 HTTP 호출
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="nd">@FeignClient&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">name&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;agent-service&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">interface&lt;/span> &lt;span class="nc">AgentFeignClient&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nd">@GetMapping&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;/api/v1/agents/{id}&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">fun&lt;/span> &lt;span class="nf">getAgent&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nd">@PathVariable&lt;/span> &lt;span class="n">id&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">Long&lt;/span>&lt;span class="p">):&lt;/span> &lt;span class="n">ApiResponse&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">AgentDetailResponse&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 호출하는 쪽
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">val&lt;/span> &lt;span class="py">agent&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">agentFeignClient&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">getAgent&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="k">data&lt;/span>&lt;span class="o">!!&lt;/span> &lt;span class="c1">// ApiResponse 언래핑 필요&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 변경: ModuleApi 직접 호출
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">interface&lt;/span> &lt;span class="nc">AgentModuleApi&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">fun&lt;/span> &lt;span class="nf">getAgent&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">Long&lt;/span>&lt;span class="p">):&lt;/span> &lt;span class="n">AgentDetailResponse&lt;/span> &lt;span class="c1">// 데이터 직접 반환
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 호출하는 쪽
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">val&lt;/span> &lt;span class="py">agent&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">agentModuleApi&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">getAgent&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="c1">// 래핑/언래핑 없음&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>여기서 한 가지 설계적인 결정을 내렸는데, FeignClient가 &lt;code>ApiResponse&amp;lt;T&amp;gt;&lt;/code>를 통해 Http 응답을 반환하던 것과 달리 ModuleApi는 &lt;strong>데이터를 직접 반환&lt;/strong>하도록 설계했습니다. 같은 프로세스 안에서 &lt;code>ApiResponse&lt;/code>로 감싸고 다시 &lt;code>.data!!&lt;/code>로 꺼내는 건 의미 없는 오버헤드라고 생각했거든요.&lt;/p>
&lt;p>총 9개의 ModuleApi 인터페이스를 만들었고, 이 결정 덕분에 호출측 코드에서 &lt;code>.data!!&lt;/code> 언래핑 코드가 일괄 제거됐습니다.&lt;/p>
&lt;h3>11개 서비스를 하나하나&lt;span class="hx:absolute hx:-mt-20" id="11개-서비스를-하나하나">&lt;/span>
&lt;a href="#11%ea%b0%9c-%ec%84%9c%eb%b9%84%ec%8a%a4%eb%a5%bc-%ed%95%98%eb%82%98%ed%95%98%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>ModuleApi 인터페이스 설계를 마치고 나서는 11개 서비스를 하나하나 라이브러리 모듈로 전환하는 작업을 진행했습니다. 각 서비스마다 같은 패턴의 작업을 반복했습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;code>build.gradle.kts&lt;/code>에서 bootJar를 비활성화하고 jar를 활성화&lt;/li>
&lt;li>Application 클래스에서 &lt;code>@SpringBootApplication&lt;/code>을 제거&lt;/li>
&lt;li>ModuleApiImpl을 구현&lt;/li>
&lt;li>FeignClient 참조를 ModuleApi로 교체&lt;/li>
&lt;li>테스트 코드에서 &lt;code>ApiResponse.ofSuccess()&lt;/code> 래핑 제거&lt;/li>
&lt;/ol>
&lt;p>11개 서비스에 대해 이 작업을 반복하는 건 솔직히 노동에 가까웠습니다. 기계적인 작업이라 어렵지는 않았지만 양이 꽤 됐거든요. 변환하고, 빌드 확인하고, 테스트 돌리고&amp;hellip; 를 최소 11번 반복해야 했죠.&lt;/p>
&lt;p>이 과정에서 가장 큰 변화 중 하나는 분산 트랜잭션이 사라진 것이었습니다. MSA에서는 서비스 간 데이터 정합성을 보장하기 위해 오케스트레이터 기반의 분산 트랜잭션을 구현해서 관리하고 있었는데, 같은 JVM 안에서 동작하게 되면서 로컬 트랜잭션으로 대체할 수 있게 됐습니다. 분산 트랜잭션의 복잡한 보상 로직이 필요 없어지고 그냥 &lt;code>@Transactional&lt;/code> 하나로 원자성이 보장되는 거죠.&lt;/p>
&lt;p>참고로 notification-service는 외부 알림 발송 특성상 보상 트랜잭션을 해도 이미 발송된 알림에 영향을 줄 수 없어서 원래부터 분산 트랜잭션에서 제외되어 있었습니다. 그래서 이 서비스를 독립으로 분리해도 분산 트랜잭션 측면에서는 문제가 없었습니다.&lt;/p>
&lt;p>처음에 &amp;ldquo;생각보다 금방끝나지 않을까&amp;quot;라고 가볍게 생각했는데, 코드 통합 자체보다 통합 후에 터지는 문제들이 훨씬 많았습니다.&lt;/p>
&lt;h2>전환하면서 마주한 문제들&lt;span class="hx:absolute hx:-mt-20" id="전환하면서-마주한-문제들">&lt;/span>
&lt;a href="#%ec%a0%84%ed%99%98%ed%95%98%eb%a9%b4%ec%84%9c-%eb%a7%88%ec%a3%bc%ed%95%9c-%eb%ac%b8%ec%a0%9c%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>빈 이름 충돌&lt;span class="hx:absolute hx:-mt-20" id="빈-이름-충돌">&lt;/span>
&lt;a href="#%eb%b9%88-%ec%9d%b4%eb%a6%84-%ec%b6%a9%eb%8f%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>11개 서비스를 전부 라이브러리 모듈로 전환하고 &lt;code>ModularMonolithApplication&lt;/code>을 올려봤습니다. &amp;ldquo;이제 되겠지&amp;rdquo; 싶었는데 &lt;code>ConflictingBeanDefinitionException&lt;/code>이 터졌습니다.&lt;/p>
&lt;p>원인을 보니 S3Config, SnsEventPublisher 같은 클래스들이 여러 모듈에 동일한 이름으로 존재하고 있었습니다. &lt;strong>Spring의 빈 이름 레지스트리는 flat합니다.&lt;/strong> 아무래도 스프링이 HashMap 구조로 빈 이름과 빈 정의를 관리하다보니 다른 패키지에 있어도 클래스명이 같으면 충돌합니다.&lt;/p>
&lt;p>MSA에서는 각 서비스가 독립된 Spring Context를 가지니까 여러 서비스에 &lt;code>S3Config&lt;/code>라는 클래스가 각각 있어도 아무 문제가 없었거든요. 그런데 모듈러 모놀리식에서는 11개 모듈의 빈이 전부 하나의 Context에 올라가니 충돌이 날 수밖에 없었습니다.&lt;/p>
&lt;p>클래스명을 변경하거나(&lt;code>S3Config&lt;/code> → &lt;code>AgentS3Config&lt;/code>), 명시적으로 빈 이름을 부여하는 방식(&lt;code>@Component(&amp;quot;agentSnsEventPublisher&amp;quot;)&lt;/code>)으로 해결했습니다. MSA에서는 네이밍에 크게 신경 쓸 필요가 없었는데, 모놀리식에서는 따로 관리해줘야 하는 부분이 생긴 거죠.&lt;/p>
&lt;h3>순환 참조&lt;span class="hx:absolute hx:-mt-20" id="순환-참조">&lt;/span>
&lt;a href="#%ec%88%9c%ed%99%98-%ec%b0%b8%ec%a1%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이제 빈 이름 충돌을 해결하고 다시 기동했더니 이번엔 무한 순환 참조 에러가 나오게 됩니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>agentModuleApiImpl → contractService → aiModuleApiImpl → ... → agentModuleApiImpl&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>각 서비스가 ModuleApi 인터페이스를 참조하고, ModuleApiImpl이 다시 다른 서비스의 ModuleApi를 참조하는 구조가 되면서 무한 순환 참조가 발생한거죠.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
graph LR
A[AgentModuleApiImpl] --&amp;gt; B[ContractService]
B --&amp;gt; C[AiModuleApiImpl]
C --&amp;gt; D[Other Beans...]
D --&amp;gt; E[AgentService]
E --&amp;gt; A
style A fill:#ff6b6b,color:#fff
style E fill:#ff6b6b,color:#fff
&lt;/pre>&lt;p>MSA에서의 HTTP 통신은 빈 의존성 그래프에 나타나지 않습니다. A 서비스가 B 서비스를 HTTP로 호출할 때 B의 빈 초기화와는 전혀 무관하니까요. 런타임에 네트워크 호출을 할 뿐이지 Spring이 관리하는 의존성 관계에는 포함되지 않습니다.&lt;/p>
&lt;p>그런데 모듈러 모놀리식에서는 A 모듈이 B 모듈의 빈을 직접 참조하기 때문에 양방향으로 참조하면 그게 곧 순환 참조가 됩니다. 모듈간 서로 의존성이 생기면서 순환 참조가 발생하게 되는겁니다. &lt;strong>MSA에서는 HTTP 통신 덕에 순환 참조가 발생하지 않았는데, 직접 호출로 바꾸면서 그게 드러난 거죠.&lt;/strong>&lt;/p>
&lt;p>처음에 &lt;code>allow-circular-references=true&lt;/code> 설정을 고려했습니다만 이건 진짜 순환 참조를 감추는 것이라 사용하지 않기로 했습니다. 대신 모든 ModuleApi 주입 지점에 &lt;code>@Lazy&lt;/code>를 추가하는 방식을 선택했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Service&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">ContractService&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nd">@Lazy&lt;/span> &lt;span class="k">private&lt;/span> &lt;span class="k">val&lt;/span> &lt;span class="py">aiModuleApi&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">AiModuleApi&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nd">@Lazy&lt;/span> &lt;span class="k">private&lt;/span> &lt;span class="k">val&lt;/span> &lt;span class="py">agentModuleApi&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">AgentModuleApi&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="o">..&lt;/span>&lt;span class="p">.&lt;/span> &lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;code>@Lazy&lt;/code>를 사용하면 실제 빈 대신 프록시가 주입되고, 처음 사용할 때 비로소 실제 빈을 가져옵니다. 초기화 시점의 순환은 방지하면서 런타임에는 정상 동작하는 거죠.&lt;/p>
&lt;p>약 50곳에 &lt;code>@Lazy&lt;/code>를 추가했고, 이후에 9개 ModuleApi 인터페이스에 KDoc으로 &lt;code>@Lazy&lt;/code> 필수 이유와 사용 예시를 문서화했습니다. 나중에 새로운 ModuleApi를 추가할 때 같은 문제를 겪지 않도록요.&lt;/p>
&lt;p>솔직히 &lt;code>@Lazy&lt;/code>는 근본적인 해결이라기보다는 우회에 가깝다는 걸 알고 있습니다. 순환 참조 자체를 없앤 게 아니라 초기화 시점에서 런타임으로 미룬 것이니까요. 근본적으로 해결하려면 모듈 간 의존 방향을 단방향으로 정리하거나, 역방향 호출이 필요한 부분은 이벤트 기반으로 분리하는 게 맞습니다. 또한 &lt;code>@Lazy&lt;/code>는 빈 연결 문제가 기동 시점이 아닌 런타임에 터진다는 리스크도 있구요.&lt;/p>
&lt;p>다만 현실적으로 기존 MSA에서 서비스 간 양방향 호출이 이미 존재하는 상태에서, 전환 과정에서 의존 방향까지 전부 재설계하는 건 스코프가 너무 커진다고 판단했습니다. 지금은 &lt;code>@Lazy&lt;/code>로 전환을 안정적으로 마무리하고, 이후 점진적으로 모듈 간 의존 방향을 정리해나가는 게 현실적인 선택이라고 생각했습니다.&lt;/p>
&lt;h4>@Lazy가 숨긴 문제&lt;span class="hx:absolute hx:-mt-20" id="lazy가-숨긴-문제">&lt;/span>
&lt;a href="#lazy%ea%b0%80-%ec%88%a8%ea%b8%b4-%eb%ac%b8%ec%a0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>그런데 위에서 언급한 &lt;code>@Lazy&lt;/code>의 리스크가 실제로 문제를 일으켰습니다.&lt;/p>
&lt;p>전환 후 개발 서버에 배포하고 테스트하는 과정에서 SQS 이벤트 처리가 100% 실패하는 현상이 발생했습니다. 로그를 추적해보니 &lt;code>NotificationModuleApi&lt;/code> 빈이 존재하지 않아서 런타임에 &lt;code>NoSuchBeanDefinitionException&lt;/code>이 터지고 있었습니다.&lt;/p>
&lt;p>원인은 이랬습니다. notification-service는 독립 배포 서비스로 유지하기로 했기 때문에 모듈러 모놀리식 앱에는 notification-module이 없었습니다. 대신 &lt;code>common&lt;/code> 모듈에 &lt;code>NotificationModuleApiFeignImpl&lt;/code>이라는 Feign 기반 폴백 구현체를 두고, notification-module이 없을 때 자동으로 등록되도록 &lt;code>@Service&lt;/code> + &lt;code>@ConditionalOnMissingBean&lt;/code>을 붙여놨었거든요.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Service&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@ConditionalOnMissingBean&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">NotificationModuleApi&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="k">class&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">NotificationModuleApiFeignImpl&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">private&lt;/span> &lt;span class="k">val&lt;/span> &lt;span class="py">notificationFeignClient&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">NotificationFeignClient&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">)&lt;/span> &lt;span class="p">:&lt;/span> &lt;span class="n">NotificationModuleApi&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="o">..&lt;/span>&lt;span class="p">.&lt;/span> &lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>그런데 이게 동작하지 않았습니다. 로컬에서 &lt;code>@Lazy&lt;/code>를 제거하고 앱을 띄워보니 바로 원인이 나왔습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>@ConditionalOnMissingBean found beans of type &amp;#39;NotificationModuleApi&amp;#39; notificationModuleApiFeignImpl&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;code>@ConditionalOnMissingBean&lt;/code>이 &lt;strong>자기 자신을 감지&lt;/strong>하고 있었습니다. 모듈러 모놀리식에서는 루트 패키지를 여러 모듈이 중복으로 component scan하면서, 먼저 scan된 자기 자신을 &amp;ldquo;이미 있는 빈&amp;quot;으로 인식해서 등록을 건너뛰어 버린 거였습니다. &lt;code>@Configuration&lt;/code> + &lt;code>@Bean&lt;/code> 메서드로 변경하면 &lt;code>@ConditionalOnMissingBean&lt;/code>의 평가 시점이 달라지기 때문에 이 문제가 해결됩니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// @Service가 아닌 @Configuration + @Bean으로 변경
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="nd">@Configuration&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">NotificationModuleApiConfig&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nd">@Bean&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nd">@ConditionalOnMissingBean&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">NotificationModuleApi&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="k">class&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">fun&lt;/span> &lt;span class="nf">notificationModuleApi&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">feignClient&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">NotificationFeignClient&lt;/span>&lt;span class="p">):&lt;/span> &lt;span class="n">NotificationModuleApi&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">NotificationModuleApiFeignImpl&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">feignClient&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이렇게 고치고 나니 빈이 정상 등록됐습니다. 하지만 더 중요한 건 &lt;strong>이 문제가 왜 배포 시점에 발견되지 않았는가&lt;/strong>였습니다.&lt;/p>
&lt;p>만약 &lt;code>@Lazy&lt;/code>가 없었다면 앱 기동 시점에 &lt;code>NoSuchBeanDefinitionException&lt;/code>이 터지면서 배포 자체가 실패했을 겁니다. 즉, 배포 단계에서 바로 문제를 발견하고 고칠 수 있었을 텐데 말이죠. 그런데 &lt;code>@Lazy&lt;/code>가 빈 해석을 런타임으로 미뤄버렸기 때문에 앱은 정상 기동되고, 실제로 해당 API가 호출되는 시점에서야 에러가 발생한 겁니다. 개발 서버에서 발견해서 다행이지, 운영에서 터졌으면 장애로 이어졌을 겁니다.&lt;/p>
&lt;p>&lt;code>@Lazy&lt;/code>가 순환 참조는 해결해줬지만, &lt;strong>빈 누락 문제를 런타임으로 숨겨버리는 부작용&lt;/strong>이 있었던 거죠. 앞서 이야기한 &lt;code>@Transactional&lt;/code> 불일치처럼, 기동 시점에 안 터지는 문제가 가장 무섭다는 걸 다시 한번 느꼈습니다.&lt;/p>
&lt;h4>SmartInitializingSingleton으로 startup 검증&lt;span class="hx:absolute hx:-mt-20" id="smartinitializingsingleton으로-startup-검증">&lt;/span>
&lt;a href="#smartinitializingsingleton%ec%9c%bc%eb%a1%9c-startup-%ea%b2%80%ec%a6%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>이 장애를 겪고 나서 &lt;code>@Lazy&lt;/code>를 유지하면서도 빈 누락을 기동 시점에 잡을 수 있는 방법을 고민했습니다. 결론적으로 &lt;code>SmartInitializingSingleton&lt;/code>을 활용한 startup 검증을 도입했습니다.&lt;/p>
&lt;p>Spring의 빈 생명주기를 보면, &lt;code>SmartInitializingSingleton.afterSingletonsInstantiated()&lt;/code>는 &lt;strong>모든 singleton 빈 생성이 완료된 후&lt;/strong>에 호출됩니다. 이 시점에서는 순환 참조도 이미 해소된 상태이기 때문에, &lt;code>@Lazy&lt;/code> 프록시를 강제로 resolve해도 순환 참조 문제가 발생하지 않습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Component&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@ConditionalOnProperty&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">name&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;app.module-api.startup-validation&amp;#34;&lt;/span>&lt;span class="p">],&lt;/span> &lt;span class="n">havingValue&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;true&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">ModuleApiStartupValidator&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">private&lt;/span> &lt;span class="k">val&lt;/span> &lt;span class="py">applicationContext&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">ApplicationContext&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">)&lt;/span> &lt;span class="p">:&lt;/span> &lt;span class="n">SmartInitializingSingleton&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">override&lt;/span> &lt;span class="k">fun&lt;/span> &lt;span class="nf">afterSingletonsInstantiated&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">moduleApiTypes&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">listOf&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">AgentModuleApi&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="k">class&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">AiModuleApi&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="k">class&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">ApartModuleApi&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="k">class&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// ... 총 9개 ModuleApi
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">missing&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">moduleApiTypes&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">filter&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="n">type&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">applicationContext&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">getBeanNamesForType&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">type&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">java&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="n">isEmpty&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">missing&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">isNotEmpty&lt;/span>&lt;span class="p">())&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">throw&lt;/span> &lt;span class="n">IllegalStateException&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;ModuleApi bean 누락: &lt;/span>&lt;span class="si">$missing&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>동작 원리를 정리하면 이렇습니다.&lt;/p>
&lt;ol>
&lt;li>빈 생성 단계: &lt;code>@Lazy&lt;/code>가 프록시를 주입해서 순환 참조를 방지 (기존과 동일)&lt;/li>
&lt;li>모든 빈 생성 완료 후: &lt;code>SmartInitializingSingleton&lt;/code>이 실행되어 모든 ModuleApi 빈 존재를 검증&lt;/li>
&lt;li>빈이 없으면 앱 기동 실패 → 배포 단계에서 즉시 발견&lt;/li>
&lt;/ol>
&lt;p>&lt;code>@Lazy&lt;/code>로 순환 참조를 해결하되, 빈 누락 문제는 런타임이 아닌 기동 시점에 잡는 거죠. 이걸 도입한 뒤로는 ModuleApi 빈 설정에 문제가 있으면 배포 단계에서 바로 실패하게 됐습니다.&lt;/p>
&lt;h3>멀티 DataSource 설정&lt;span class="hx:absolute hx:-mt-20" id="멀티-datasource-설정">&lt;/span>
&lt;a href="#%eb%a9%80%ed%8b%b0-datasource-%ec%84%a4%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>앞서 DB를 통합하지 않기로 했다고 말씀드렸습니다. 그 결정 자체는 맞았다고 생각하는데, 대신 각 스키마를 독립적으로 연결해줘야했기 때문에 11개 DB를 하나의 애플리케이션에서 동시에 연결해야 하는 것과 같은 과제가 생겼습니다.&lt;/p>
&lt;p>MSA에서는 각 서비스가 자기 DB 하나만 연결하면 됐습니다. agent-service는 agent DB, chat-service는 chat DB, 이런 식이었거든요. 그런데 모듈러 모놀리식에서는 11개 DB를 하나의 애플리케이션에서 동시에 연결해야 했습니다.&lt;/p>
&lt;p>각 모듈별로 DataSourceConfig, EntityManagerFactory, TransactionManager를 설정하고, &lt;code>@EnableJpaRepositories(basePackages=...)&lt;/code>로 스캔 범위를 한정했습니다. 여기서 하나에는 &lt;code>@Primary&lt;/code>를 붙여야 했는데, &lt;code>agentTransactionManager&lt;/code>가 그 역할을 맡게 됐습니다.&lt;/p>
&lt;p>여기까지는 큰 문제 없이 진행됐습니다. 다만 이 &lt;code>@Primary&lt;/code> 설정이 나중에 가장 무서운 문제로 돌아오게 됩니다.&lt;/p>
&lt;h3>빌드 관련 문제들&lt;span class="hx:absolute hx:-mt-20" id="빌드-관련-문제들">&lt;/span>
&lt;a href="#%eb%b9%8c%eb%93%9c-%ea%b4%80%eb%a0%a8-%eb%ac%b8%ec%a0%9c%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>모듈 전환, 빈 충돌, 순환 참조를 해결하고 나니 이번엔 빌드에서 문제가 나왔습니다.&lt;/p>
&lt;p>&lt;strong>REST Docs 빌드 순환 의존&lt;/strong> 문제가 있었는데, 라이브러리 모듈에서 &lt;code>jar.dependsOn(&amp;quot;buildDocument&amp;quot;)&lt;/code> 체인이 processResources를 다시 호출하면서 빌드 태스크간 순환이 발생한 거였습니다. 이 문제를 해결하면서 Gradle의 &lt;code>dependsOn&lt;/code>과 &lt;code>mustRunAfter&lt;/code>의 차이를 확실히 알게 됐습니다. &lt;code>dependsOn&lt;/code>은 의존 관계를 만들어서 순환이 생길 수 있지만, &lt;code>mustRunAfter&lt;/code>는 실행 순서만 보장하고 의존 엣지를 만들지 않거든요.&lt;/p>
&lt;p>&lt;strong>QuerydslConfig + MyBatis 충돌&lt;/strong> 문제도 있었습니다. data-module은 MyBatis만 사용하는데, 공통 QuerydslConfig가 &lt;code>@Configuration&lt;/code>으로 모든 모듈에 스캔되면서 &lt;code>EntityManagerFactory&lt;/code>를 찾지 못해 실패했습니다. &lt;code>@AutoConfiguration&lt;/code> + &lt;code>@ConditionalOnBean(EntityManagerFactory::class)&lt;/code>로 JPA를 사용하는 모듈에서만 활성화되도록 바꿔서 해결했습니다.&lt;/p>
&lt;p>이 밖에도 불필요한 의존성을 정리하면서 전이 의존성으로 사용되던 Apache &lt;code>ContentType&lt;/code>이 함께 사라져 컴파일 에러가 나거나, URL 매핑이 충돌하거나, ConfigurationProperties 스캔이 안 되는 등의 문제들이 줄줄이 나왔습니다. 하나 고치면 또 하나가 터지고, 그걸 고치면 또 다른 게 터지고&amp;hellip; 솔직히 이 시점에서는 끝이 보이지 않는 느낌이었습니다.&lt;/p>
&lt;h2>@Transactional 불일치 - 가장 무서웠던 문제&lt;span class="hx:absolute hx:-mt-20" id="transactional-불일치---가장-무서웠던-문제">&lt;/span>
&lt;a href="#transactional-%eb%b6%88%ec%9d%bc%ec%b9%98---%ea%b0%80%ec%9e%a5-%eb%ac%b4%ec%84%9c%ec%9b%a0%eb%8d%98-%eb%ac%b8%ec%a0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>앞서 이야기한 문제들은 빌드나 기동 시점에 에러가 터지기 때문에 어찌됐든 발견은 됩니다. 발견이 되면 해결하면 되니까요. 그런데 이 문제는 달랐습니다.&lt;/p>
&lt;p>앱 기동이 성공하고, 테스트도 통과해서 끝난 줄 알았는데 개발서버에서 런타임 예외가 발생했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>TransactionRequiredException: no transaction is in progress&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>처음 에러가 터진 건 ai-module이었습니다. &lt;code>@Qualifier(&amp;quot;aiEntityManager&amp;quot;)&lt;/code>로 EntityManager를 직접 주입받는 코드에서 bare &lt;code>@Transactional&lt;/code>을 쓰고 있었는데, 원인을 추적해보니 &lt;strong>모든 bare &lt;code>@Transactional&lt;/code>이 &lt;code>agentTransactionManager&lt;/code>를 사용&lt;/strong>하고 있었습니다.&lt;/p>
&lt;h3>왜 이런 일이 발생했나&lt;span class="hx:absolute hx:-mt-20" id="왜-이런-일이-발생했나">&lt;/span>
&lt;a href="#%ec%99%9c-%ec%9d%b4%eb%9f%b0-%ec%9d%bc%ec%9d%b4-%eb%b0%9c%ec%83%9d%ed%96%88%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>앞서 멀티 DataSource를 설정할 때 &lt;code>agentTransactionManager&lt;/code>에 &lt;code>@Primary&lt;/code>를 붙였다고 말씀드렸습니다. &lt;code>@Primary&lt;/code>가 붙어있으면 Spring은 어떤 TransactionManager를 써야 할지 모를 때 &lt;code>@Primary&lt;/code>인 빈을 기본으로 사용합니다.&lt;/p>
&lt;p>MSA에서는 각 서비스에 TransactionManager가 하나뿐이니까 &lt;code>@Transactional&lt;/code>만 붙이면 됐습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
graph TB
subgraph S1[&amp;#34;agent-service&amp;#34;]
T1[&amp;#34;@Transactional&amp;#34;] --&amp;gt; TM1[&amp;#34;agentTM ✅&amp;#34;]
end
subgraph S2[&amp;#34;event-service&amp;#34;]
T2[&amp;#34;@Transactional&amp;#34;] --&amp;gt; TM2[&amp;#34;eventTM ✅&amp;#34;]
end
subgraph S3[&amp;#34;ai-service&amp;#34;]
T3[&amp;#34;@Transactional&amp;#34;] --&amp;gt; TM3[&amp;#34;aiTM ✅&amp;#34;]
end
&lt;/pre>&lt;p>그런데 모듈러 모놀리식에서는 11개 TransactionManager가 하나의 Context에 올라갑니다. bare &lt;code>@Transactional&lt;/code>(transactionManager를 명시하지 않은)을 사용하면 &lt;code>@Primary&lt;/code>인 &lt;code>agentTransactionManager&lt;/code>가 모든 걸 가져가는 거죠.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
graph LR
subgraph MSA[&amp;#34;MSA - 각 서비스별 독립 Context&amp;#34;]
direction LR
T1[&amp;#34;agent-module&amp;lt;br/&amp;gt;@Transactional&amp;#34;] --&amp;gt; TM[&amp;#34;agentTM&amp;lt;br/&amp;gt;@Primary&amp;#34;]
T2[&amp;#34;event-module&amp;lt;br/&amp;gt;@Transactional&amp;#34;] --&amp;gt; TM
T3[&amp;#34;ai-module&amp;lt;br/&amp;gt;@Transactional&amp;#34;] --&amp;gt; TM
TM2[&amp;#34;eventTM ❌&amp;#34;] ~~~ TM
TM3[&amp;#34;aiTM ❌&amp;#34;] ~~~ TM
end
style TM fill:#ff6b6b,color:#fff
style TM2 fill:#999,color:#fff
style TM3 fill:#999,color:#fff
&lt;/pre>&lt;h3>이게 진짜 무서웠던 이유&lt;span class="hx:absolute hx:-mt-20" id="이게-진짜-무서웠던-이유">&lt;/span>
&lt;a href="#%ec%9d%b4%ea%b2%8c-%ec%a7%84%ec%a7%9c-%eb%ac%b4%ec%84%9c%ec%9b%a0%eb%8d%98-%ec%9d%b4%ec%9c%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이 문제가 정말 무서웠던 건 &lt;strong>대부분의 경우 에러 없이 동작하는 것처럼 보인다&lt;/strong>는 점이었습니다. 서비스 레벨에서 agentTM 트랜잭션이 열리고, Repository 내부에서 모듈별 TM 트랜잭션이 별도로 열리기 때문에 겉보기에는 잘 동작합니다. 다만 JPA dirty checking이 안 되고, 여러 Repository 호출 간 원자성이 보장되지 않는 &lt;strong>사일런트 버그&lt;/strong>가 되는 거죠.&lt;/p>
&lt;p>실제로 에러가 터진 건 ai-module과 event-module 딱 두 곳이었습니다. ai-module은 &lt;code>@Qualifier&lt;/code>로 EntityManager를 직접 주입받는 경우였고, event-module은 &lt;code>@Lock(PESSIMISTIC_WRITE)&lt;/code> + bare &lt;code>@Transactional&lt;/code> 조합이었습니다. 비관적 락은 트랜잭션 안에서만 동작하는데, agentTM 트랜잭션은 eventDB 세션에 대한 트랜잭션이 아니니까요. 이렇게 명시적으로 트랜잭션을 요구하는 경우에만 에러가 터졌고, 나머지 모듈들은 모른 채 운영될 뻔했습니다.&lt;/p>
&lt;p>8개 모듈 중에 에러로 발견된 건 단 2개뿐이었다고 생각하니 꽤 아찔했습니다.&lt;/p>
&lt;h3>메타 어노테이션으로 해결&lt;span class="hx:absolute hx:-mt-20" id="메타-어노테이션으로-해결">&lt;/span>
&lt;a href="#%eb%a9%94%ed%83%80-%ec%96%b4%eb%85%b8%ed%85%8c%ec%9d%b4%ec%85%98%ec%9c%bc%eb%a1%9c-%ed%95%b4%ea%b2%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>해결 방법으로 모듈별 커스텀 &lt;code>@Transactional&lt;/code> 메타 어노테이션을 만들었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Target&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nc">AnnotationTarget&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">FUNCTION&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nc">AnnotationTarget&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">CLASS&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Retention&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nc">AnnotationRetention&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">RUNTIME&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Transactional&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">transactionManager&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;eventTransactionManager&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">annotation&lt;/span> &lt;span class="k">class&lt;/span> &lt;span class="nc">EventTransactional&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>8개 모듈에 걸쳐 약 121개의 bare &lt;code>@Transactional&lt;/code>을 모듈별 메타 어노테이션으로 교체했습니다. &lt;code>@EventTransactional&lt;/code>, &lt;code>@CommunityTransactional&lt;/code>, &lt;code>@ApartTransactional&lt;/code> 같은 식으로요.&lt;/p>
&lt;p>이 방식의 장점은 자기 문서화가 된다는 점이라고 생각합니다. &lt;code>@Transactional&lt;/code>만 보면 어떤 TM을 쓰는지 모르지만, &lt;code>@EventTransactional&lt;/code>은 이름만 봐도 event TM을 사용한다는 걸 알 수 있죠. 컨벤션이 되니까 새로운 코드를 작성할 때도 실수할 여지가 줄어들구요.&lt;/p>
&lt;h2>전환 결과&lt;span class="hx:absolute hx:-mt-20" id="전환-결과">&lt;/span>
&lt;a href="#%ec%a0%84%ed%99%98-%ea%b2%b0%ea%b3%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>전환 결과를 정리하면 이렇습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
graph LR
subgraph BEFORE[&amp;#34;AS-IS: MSA&amp;#34;]
direction TB
B1[&amp;#34;13개 독립 서비스&amp;#34;]
B2[&amp;#34;26개+ 파드&amp;#34;]
B3[&amp;#34;13개 CI/CD 파이프라인&amp;#34;]
B4[&amp;#34;서비스 간 HTTP 통신&amp;#34;]
B5[&amp;#34;분산 트랜잭션&amp;#34;]
end
BEFORE --&amp;gt;|전환| AFTER
subgraph AFTER[&amp;#34;TO-BE: 모듈러 모놀리식&amp;#34;]
direction TB
A1[&amp;#34;1개 통합 앱 + 2개 독립 서비스&amp;#34;]
A2[&amp;#34;5~7개 파드&amp;#34;]
A3[&amp;#34;3개 CI/CD 파이프라인&amp;#34;]
A4[&amp;#34;모듈 간 메서드 호출&amp;#34;]
A5[&amp;#34;로컬 트랜잭션&amp;#34;]
end
&lt;/pre>&lt;p>비즈니스 로직 변경 없이 앱이 정상 기동되는 것을 확인했습니다. 기존에는 서비스별로 K8s Ingress 라우팅을 통해 트래픽을 나눠주고 있었는데, Ingress 레벨에서 모두 모듈러 모놀리식 서비스로 향하게 변경하여 외부 클라이언트에 영향 없이 전환할 수 있었습니다.&lt;/p>
&lt;p>notification-service, batch-service만 독립 배포 단위로 유지하고, 나머지 11개 서비스는 하나의 &lt;code>ModularMonolithApplication&lt;/code>으로 통합하게 됐죠. 서비스별 CI/CD 워크플로우 파일도 정리했고, 단일 배포 파이프라인으로 통합했습니다.&lt;/p>
&lt;p>인프라 측면에서 가장 큰 변화는 파드 수입니다. 기존에는 서비스별 최소 2개씩 26개 이상의 파드가 필요했는데, 단일 애플리케이션으로 통합하면서 &lt;code>ModularMonolithApplication&lt;/code> 파드 2~3개면 충분해졌습니다. 전체 파드 수가 1/5 이하로 줄었습니다. 크레딧이 끝나는 4월 이후에도 감당 가능한 수준이 된 거죠.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/9to7251qma6g4z7crjeta/before-moduler-credit.png?rlkey=5ll2xme9maze9ltwha94ss1pl&amp;amp;st=vci6m584&amp;amp;raw=1" alt="before-modular-credit" loading="lazy" />&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/xpsueudcdebbiw6v7csad/after-moduler-credit.png?rlkey=7nsgpgge7crevuitprl1fl78w&amp;amp;st=v9ldtz7k&amp;amp;raw=1" alt="after-modular-credit" loading="lazy" />&lt;/p>
&lt;p>실제 GCP 비용을 비교해보니 효과가 확실했습니다. MSA로 운영하던 1월 기준 일일 비용은 Compute Engine ₩96,505 + Kubernetes Engine ₩6,885로 &lt;strong>약 ₩103,000 수준&lt;/strong>이었는데, 모듈러 모놀리식 전환 후인 2월 말 기준으로는 Compute Engine ₩58,768 + Kubernetes Engine ₩6,864로 &lt;strong>약 ₩65,000 수준&lt;/strong>으로 떨어졌습니다.&lt;/p>
&lt;p>Compute Engine 비용이 약 39% 절감된 거죠. Kubernetes Engine 비용은 GKE 클러스터 자체 운영 비용이라 거의 변하지 않았지만, 실제 워크로드를 처리하는 Compute Engine 비용이 크게 줄었습니다. 월 단위로 환산하면 &lt;strong>약 ₩310만에서 ₩197만으로, 매달 약 ₩113만 정도의 비용 절감&lt;/strong> 효과가 있었습니다.&lt;/p>
&lt;h2>배운 점&lt;span class="hx:absolute hx:-mt-20" id="배운-점">&lt;/span>
&lt;a href="#%eb%b0%b0%ec%9a%b4-%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>모듈러 모놀리식이라고 문제가 사라지는 건 아니다&lt;span class="hx:absolute hx:-mt-20" id="모듈러-모놀리식이라고-문제가-사라지는-건-아니다">&lt;/span>
&lt;a href="#%eb%aa%a8%eb%93%88%eb%9f%ac-%eb%aa%a8%eb%86%80%eb%a6%ac%ec%8b%9d%ec%9d%b4%eb%9d%bc%ea%b3%a0-%eb%ac%b8%ec%a0%9c%ea%b0%80-%ec%82%ac%eb%9d%bc%ec%a7%80%eb%8a%94-%ea%b1%b4-%ec%95%84%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이번 전환을 하면서 가장 크게 느낀 건 &lt;strong>MSA의 컨텍스트 분리 덕에 발생하지 않았던 문제들이 하나로 합치는 순간 발생한다&lt;/strong>는 점이었습니다. 당연하게도 아키텍처가 달라지면 마주하는 문제들도 달라지는 거죠.&lt;/p>
&lt;p>원래라면 각기 다른 서비스이기 때문에 빈 이름이 같다해도 충돌은 발생하지 않죠. 서비스 간 양방향 호출을 해도 HTTP 통신은 빈 의존성 그래프에 나타나지 않으니 순환 참조가 발생하지 않았고, bare &lt;code>@Transactional&lt;/code>을 써도 서비스당 TM이 하나니까 항상 올바른 TM이 사용됐습니다.&lt;/p>
&lt;p>MSA에서는 이런 것들을 신경 쓸 필요가 없었는데, 모듈러 모놀리식으로 통합하는 순간 컨텍스트 분리가 사라지면서 하나의 Context에서 모든 게 공존해야 하는 상황이 오게 됩니다. MSA에서 발생하는 문제들은 더이상 고민하지 않아도 되지만 다른 고민을 해야하는거죠.&lt;/p>
&lt;p>전환을 고려하시는 분들이 계시다면 이 부분은 미리 인지하고 계시면 좋겠습니다.&lt;/p>
&lt;p>별개로 전환 후에 CI 테스트 빌드 시간이 45분으로 급증하는 문제를 겪기도 했는데, 이 부분은 &lt;a href="https://jeongil.dev/ko/blog/backend/performance/ci-test-build-optimization/">후속 글&lt;/a>에서 다루고 있습니다.&lt;/p>
&lt;h3>에러가 안 터지는 버그가 제일 무섭다&lt;span class="hx:absolute hx:-mt-20" id="에러가-안-터지는-버그가-제일-무섭다">&lt;/span>
&lt;a href="#%ec%97%90%eb%9f%ac%ea%b0%80-%ec%95%88-%ed%84%b0%ec%a7%80%eb%8a%94-%eb%b2%84%ea%b7%b8%ea%b0%80-%ec%a0%9c%ec%9d%bc-%eb%ac%b4%ec%84%ad%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>개인적으로 이번 전환에서 가장 아찔했던 건 &lt;code>@Transactional&lt;/code> TM 불일치 문제였습니다. 빌드 에러나 기동 실패는 어찌됐든 눈에 보이니까 고치면 되는데, 이 문제는 겉으로는 아무 문제 없이 돌아가는 것처럼 보이면서 내부적으로는 트랜잭션이 엉뚱한 DataSource에 걸려있는 거였거든요.&lt;/p>
&lt;p>8개 모듈 중에 에러가 터진 건 ai-module과 event-module 단 2개뿐이었고, 나머지 6개는 사일런트 버그로 남아있었습니다. 큰 아키텍처 변경을 하고 나서 &amp;ldquo;잘 되는 것 같은데?&amp;rdquo; 하고 넘어가는 게 얼마나 위험한지 이번에 다시금 확실히 느꼈습니다.&lt;/p>
&lt;p>개발자들이 컴파일 에러를 좋아할 수 밖에 없는 이유가 여기에 있는 것 같아요. 컴파일 에러는 &amp;ldquo;이 부분이 문제야&amp;quot;라고 명확히 알려주지만, &lt;strong>사일런트 버그는 &amp;ldquo;문제가 있는지 없는지 조차 모르는&amp;rdquo; 최악의 상태&lt;/strong>로 남아있으니까요.&lt;/p>
&lt;h3>그때그때 최선의 선택을 하는 게 중요하다&lt;span class="hx:absolute hx:-mt-20" id="그때그때-최선의-선택을-하는-게-중요하다">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%95%8c%ea%b7%b8%eb%95%8c-%ec%b5%9c%ec%84%a0%ec%9d%98-%ec%84%a0%ed%83%9d%ec%9d%84-%ed%95%98%eb%8a%94-%ea%b2%8c-%ec%a4%91%ec%9a%94%ed%95%98%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>위에서 겪은 문제들만 보면 &amp;ldquo;과연 모듈러 모놀리식으로 바꿔야 했는가?&amp;rdquo; 라고 여쭤보실 수 있겠지만, 저는 전환하길 잘했다고 생각합니다.&lt;/p>
&lt;p>서비스 간 통신의 복잡성이 확 줄었고, 코드를 따라갈 때 HTTP 호출을 추적하는 게 아니라 메서드 호출을 따라가면 되니까 디버깅이 훨씬 수월해졌습니다. 분산 트랜잭션이 가지는 복잡성도 로컬 트랜잭션으로 대체됐고, 배포 파이프라인도 하나만 관리하면 되구요.&lt;/p>
&lt;p>무엇보다 비용 문제를 해결하지 않았으면 크레딧이 끝나는 4월 부터 저희 회사는 비용 부담이 컸을 겁니다. 회사 수익과도 직결되는 중요한 문제였는데, 파드 수가 26개 이상에서 몇 개로 줄었다는 것만으로도 지금이라도 정리해둔 게 다행이라고 생각합니다.&lt;/p>
&lt;p>실제로 위에서 언급한 것처럼 Compute Engine 비용이 일일 약 ₩96,000에서 ₩58,000으로 약 39% 줄었고, 월 기준으로는 약 ₩113만의 비용 절감 효과가 있었습니다. 물론 서버 비용을 더 줄일 수 있는 방안들을 더 고민해 개선할 예정입니다. 가령 K8s가 꼭 필요한가, 정말 항상 켜져 있어야 하는 서비스인가, 등등을 말이죠.&lt;/p>
&lt;h2>마치며&lt;span class="hx:absolute hx:-mt-20" id="마치며">&lt;/span>
&lt;a href="#%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>돌이켜보면 저희 서비스의 아키텍처는 팀 합류 이후로 계속 변화해왔습니다. 레거시 모놀리식에서 MSA로, 개별 레포에서 멀티모듈로, Docker Compose에서 K8s로, 그리고 이번에 MSA에서 모듈러 모놀리식으로.&lt;/p>
&lt;p>매번 같은 질문을 던졌습니다. &lt;strong>&amp;ldquo;지금 우리 팀 상황에서 이게 정말 최선인가?&amp;rdquo;&lt;/strong> 그리고 매번 그 답은 달랐습니다. 팀 규모도, 서비스 규모도, 비용 구조도 시간이 지나면서 계속 달라졌으니까요.&lt;/p>
&lt;p>서비스는 시간이 지남에 따라 그리고 요구사항이 바뀌면서 아키텍처도 바뀌는 게 자연스러운 일이라고 생각합니다. 그렇기에 어떤 아키텍처냐가 중요한게 아니라 변화에 유연하게 대응할 수 있는 구조가 더욱 중요하다고 생각합니다.&lt;/p>
&lt;p>또 필요에 의해 MSA로 전환해야하는 순간이 다시금 올수도 있겠죠. 그 때 더 유연하게 대응할 수 있도록 구조를 잘 설계해두는 것도 이번 전환에서 얻은 중요한 교훈중 하나입니다.&lt;/p>
&lt;p>이 글이 비슷한 고민을 하고 계신 분들께 조금이나마 도움이 되었으면 좋겠습니다.&lt;/p>
&lt;p>긴 글 읽어주셔서 감사합니다.&lt;/p>
&lt;h2>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>관련 글&lt;span class="hx:absolute hx:-mt-20" id="관련-글">&lt;/span>
&lt;a href="#%ea%b4%80%eb%a0%a8-%ea%b8%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/architecture/is-gradual-msa-transition-an-illusion/">점진적 MSA 전환은 환상일까? - 사내 강결합 레거시 서비스와의 사투기&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/architecture/msa-to-multi-module/">16개 레포지토리를 하나로 - MSA 멀티모듈 전환기&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-7-conclusion/">[MSA에 관한 고찰 7/7편] 우리는 정말 MSA가 필요한가?&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/infrastructure/docker-compose-to-k8s/">개발 서버도 없던 팀이 GitOps를 갖추기까지: 맨땅에서 시작한 쿠버네티스 도입기&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>매일 바뀌는 AI 코딩 에이전트 생태계: oh-my-opencode, oh-my-claudecode, OpenClaw, Agent Teams</title><link>https://jeongil.dev/ko/blog/trends/claude-code-agent-teams/</link><pubDate>Mon, 09 Feb 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/trends/claude-code-agent-teams/</guid><description>
&lt;p>안녕하세요. 프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 3년차 백엔드 개발자 정정일입니다.&lt;/p>
&lt;p>최근 AI 코딩 도구 생태계가 정말 빠르게 변하고 있습니다. 며칠 전까지 유행하던 도구가 다음 주에는 차단되고, 그 다음 주에는 공식 기능으로 출시되는&amp;hellip; 마치 롤러코스터 같은 한 달이었습니다.&lt;/p>
&lt;p>이번 글에서는 &lt;strong>oh-my-opencode&lt;/strong>라는 커뮤니티 도구가 유행하고, Anthropic이 이를 차단하고, 결국 &lt;strong>Agent Teams&lt;/strong>라는 공식 기능이 출시되기까지의 이야기를 시간 순서대로 정리해보려 합니다.&lt;/p>
&lt;p>저도 이 흐름을 지켜보면서 많은 생각이 들었고, 개인적인 의견도 함께 녹여보려 합니다.&lt;/p>
&lt;h2>배경: Claude Code의 Sub-Agent&lt;span class="hx:absolute hx:-mt-20" id="배경-claude-code의-sub-agent">&lt;/span>
&lt;a href="#%eb%b0%b0%ea%b2%bd-claude-code%ec%9d%98-sub-agent" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>본격적인 이야기에 앞서 간단히 배경을 짚고 넘어가겠습니다.&lt;/p>
&lt;p>2025년 중반부터 Anthropic의 Claude Code에는 &lt;strong>Sub-Agent&lt;/strong>라는 기능이 있었습니다. 하나의 Claude Code 세션 안에서 특정 작업을 별도의 에이전트에게 맡기고, 결과만 받아오는 방식이었죠.&lt;/p>
&lt;p>예를 들어 코드베이스를 탐색하는 &lt;strong>Explore&lt;/strong> 에이전트, 구현 계획을 세우는 &lt;strong>Plan&lt;/strong> 에이전트 등이 있었고, &lt;code>.claude/agents/&lt;/code> 디렉토리에 마크다운 파일을 만들면 커스텀 에이전트도 정의할 수 있었습니다.&lt;/p>
&lt;p>하지만 Sub-Agent에는 한계가 있었습니다. &lt;strong>하나의 세션 안에서만&lt;/strong> 동작하고, 에이전트끼리 서로 대화할 수 없고, 결과를 메인 에이전트에게만 보고하는 구조였죠. 복잡한 작업을 여러 에이전트가 &lt;strong>병렬로 협업&lt;/strong>하며 처리하기에는 부족했습니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;여러 AI 에이전트가 동시에 다른 작업을 하면서 서로 소통할 수는 없을까?&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>이런 니즈를 가진 개발자들이 있었고, 커뮤니티에서 직접 해결책을 만들기 시작합니다.&lt;/p>
&lt;h2>커뮤니티의 혁신: oh-my-opencode&lt;span class="hx:absolute hx:-mt-20" id="커뮤니티의-혁신-oh-my-opencode">&lt;/span>
&lt;a href="#%ec%bb%a4%eb%ae%a4%eb%8b%88%ed%8b%b0%ec%9d%98-%ed%98%81%ec%8b%a0-oh-my-opencode" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>OpenCode와 oh-my-opencode&lt;span class="hx:absolute hx:-mt-20" id="opencode와-oh-my-opencode">&lt;/span>
&lt;a href="#opencode%ec%99%80-oh-my-opencode" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;a href="https://github.com/anomalyco/opencode"target="_blank" rel="noopener">OpenCode&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>는 SST 팀이 만든 오픈소스 AI 코딩 에이전트입니다. Anthropic의 Claude Code와 비슷하지만 &lt;strong>프로바이더에 독립적&lt;/strong>이라는 점이 차별점이었죠. Claude, OpenAI, Google, 심지어 로컬 모델까지 자유롭게 사용할 수 있었습니다. GitHub 스타가 100,000개가 넘을 정도로 인기를 끌었습니다.&lt;/p>
&lt;p>여기에 한국 개발자 &lt;strong>김영규(code-yeongyu)&lt;/strong> 님이 &lt;a href="https://github.com/code-yeongyu/oh-my-opencode"target="_blank" rel="noopener">oh-my-opencode&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>라는 플러그인을 만들었습니다. oh-my-zsh가 Zsh 셸을 강화하듯, oh-my-opencode는 OpenCode에 &lt;strong>멀티 에이전트 오케스트레이션&lt;/strong>을 더해줬죠.&lt;/p>
&lt;p>&lt;strong>oh-my-opencode의 핵심 기능&lt;/strong>을 살펴보면&lt;/p>
&lt;ul>
&lt;li>멀티 모델 에이전트 오케스트레이션&lt;/li>
&lt;li>병렬 백그라운드 에이전트&lt;/li>
&lt;li>LSP/AST 도구 통합&lt;/li>
&lt;li>전문화된 에이전트 (Oracle, Librarian, Frontend Engineer 등)&lt;/li>
&lt;li>&amp;ldquo;Ultrawork&amp;rdquo; 모드로 병렬 실행&lt;/li>
&lt;/ul>
&lt;p>김영규 님은 최적의 멀티 에이전트 구조를 연구하는 데 &lt;strong>24,000달러(약 3,400만원)&lt;/strong> 상당의 토큰을 사용했다고 합니다.&lt;/p>
&lt;h3>왜 이렇게 인기를 끌었나?&lt;span class="hx:absolute hx:-mt-20" id="왜-이렇게-인기를-끌었나">&lt;/span>
&lt;a href="#%ec%99%9c-%ec%9d%b4%eb%a0%87%ea%b2%8c-%ec%9d%b8%ea%b8%b0%eb%a5%bc-%eb%81%8c%ec%97%88%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>핵심은 &lt;strong>경제적 구조&lt;/strong>에 있었습니다.&lt;/p>
&lt;p>Claude Max 구독(&lt;code>$100~200&lt;/code>/월)은 Pro 대비 5배~20배의 높은 사용량 한도를 제공했지만, 공식 Claude Code CLI를 통해서만 사용할 수 있었습니다. 같은 수준의 API 사용료는 수천 달러에 달할 수 있었죠. 실제 테스트에서 한 달 &lt;code>$3,650&lt;/code> 이상 나온 사례도 있더라구요.&lt;/p>
&lt;p>개발자들이 OpenCode + oh-my-opencode 조합을 사용하면 Claude Max 구독의 사용량 한도를 훨씬 더 적극적으로 소진할 수 있었습니다. 밤새 자율 에이전트를 돌리며 코딩/테스트/수정 루프를 실행하는 것도 가능했죠.&lt;/p>
&lt;p>비유하자면 &lt;strong>뷔페에서 먹는 속도 제한이 풀린&lt;/strong> 것과 같았습니다. Anthropic이 &amp;ldquo;올-유-캔-잇(all-you-can-eat)&amp;rdquo; 뷔페를 제공하되, 공식 CLI를 통해 먹는 속도를 제한하고 있었는데, 써드파티 도구들이 그 속도 제한을 풀어버린 셈이었죠.&lt;/p>
&lt;p>실제로 사용해봤을 때 별다른 세팅 없이도 멀티 에이전트를 활용할 수 있어서 굉장히 편리했습니다.&lt;/p>
&lt;p>다만 제 경우에는 토큰을 너무 빠르게 소진하는 바람에 금방 사용을 중단했습니다. 저는 Max 20x 구독을 사용 중인데, 단 한번의 질의로 Current session 토큰 한도에 도달해버리는 등의 문제가 있었거든요.&lt;/p>
&lt;p>그 때문에 Anthropic에 문의를 남기기도 했었습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/qy9n2v19lqo4d5gsifz59/03ED9941-21BF-414C-A7B9-66AF1F49FE65.jpg?rlkey=swq9dkrbvlbjh2sf5kt8urlh7&amp;amp;st=kb1lvzh3&amp;amp;raw=1" alt="" loading="lazy" />&lt;/p>
&lt;blockquote>
&lt;p>&amp;hellip; Although, we currently don&amp;rsquo;t have a tool to investigate usage specifically, I see that your usage significantly increased on 2026-01-06 and 2026-01-04. We do encourage you to review our Usage Limits Best Practices documentation if you haven&amp;rsquo;t already as this outlines strategies to help optimize your usage and get the most out of your subscription.&lt;/p>
&lt;/blockquote>
&lt;p>oh-my-opencode를 사용해봤던 1월 4일과 6일에 사용량이 급증한 것을 확인했다는 답변이었죠. 토큰 사용 최적화 가이드 문서를 참고하라는 안내도 있었습니다.&lt;/p>
&lt;p>이런 토큰 과다 소진 문제는 저만 겪은 게 아니었습니다. &lt;a href="https://github.com/code-yeongyu/oh-my-opencode/issues/115"target="_blank" rel="noopener">GitHub Issue&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에서도 &lt;em>&amp;ldquo;API로 전환하면 30분 만에 $15~20을 태운다&amp;rdquo;&lt;/em>, &lt;em>&amp;ldquo;rate limit에 금방 걸려서 사용을 중단했다&amp;rdquo;&lt;/em> 는 보고가 여럿 올라왔고, 메인테이너도 이 문제를 인정하고 task queue 제한을 추가하겠다고 밝혔을 정도였습니다.&lt;/p>
&lt;h3>oh-my-claudecode: Claude Code 전용 멀티 에이전트&lt;span class="hx:absolute hx:-mt-20" id="oh-my-claudecode-claude-code-전용-멀티-에이전트">&lt;/span>
&lt;a href="#oh-my-claudecode-claude-code-%ec%a0%84%ec%9a%a9-%eb%a9%80%ed%8b%b0-%ec%97%90%ec%9d%b4%ec%a0%84%ed%8a%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>oh-my-opencode가 OpenCode 기반이었다면, &lt;a href="https://github.com/Yeachan-Heo/oh-my-claudecode"target="_blank" rel="noopener">oh-my-claudecode&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>는 &lt;strong>Claude Code 전용&lt;/strong>으로 만들어진 별도의 프로젝트입니다. 원래 &amp;ldquo;oh-my-claude-sisyphus&amp;quot;라는 이름이었다가 v3.0.0에서 oh-my-claudecode로 리브랜딩됐죠. 에이전트 이름도 그리스 신화에서 직관적인 이름(planner, architect, critic 등)으로 바뀌었습니다.&lt;/p>
&lt;p>&lt;strong>oh-my-claudecode의 핵심 기능&lt;/strong>도 인상적이었습니다.&lt;/p>
&lt;ul>
&lt;li>7가지 실행 모드: Autopilot, Ultrawork, Ralph, Ultrapilot(3~5배 병렬), Ecomode, Swarm, Pipeline&lt;/li>
&lt;li>32개의 전문 에이전트와 40개 이상의 스킬&lt;/li>
&lt;li>Claude Code의 네이티브 Hooks(쉘 스크립트)를 활용해 ToS를 위반하지 않는 구조&lt;/li>
&lt;/ul>
&lt;p>특히 &lt;strong>Ultrapilot 모드&lt;/strong>는 3~5개의 에이전트를 병렬로 실행시켜 작업 속도를 극적으로 끌어올리는 기능인데, Agent Teams가 나오기 전까지는 이게 Claude Code에서 멀티 에이전트를 사용하는 가장 강력한 방법이었습니다.&lt;/p>
&lt;p>이렇게 커뮤니티에서 멀티 에이전트 도구들이 활발하게 만들어지고 있었습니다. 저도 이 도구들을 보면서 &amp;ldquo;어떻게 하면 AI를 더 잘 활용할 수 있을까에 대한 고민을 많은 개발자들이 하고 있구나&amp;rdquo; 싶었죠.&lt;/p>
&lt;h2>Anthropic의 대응: 차단&lt;span class="hx:absolute hx:-mt-20" id="anthropic의-대응-차단">&lt;/span>
&lt;a href="#anthropic%ec%9d%98-%eb%8c%80%ec%9d%91-%ec%b0%a8%eb%8b%a8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>2026년 1월 5일 - 첫 번째 밴 보고&lt;span class="hx:absolute hx:-mt-20" id="2026년-1월-5일---첫-번째-밴-보고">&lt;/span>
&lt;a href="#2026%eb%85%84-1%ec%9b%94-5%ec%9d%bc---%ec%b2%ab-%eb%b2%88%ec%a7%b8-%eb%b0%b4-%eb%b3%b4%ea%b3%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>첫 번째 신호는 &lt;a href="https://github.com/anomalyco/opencode/issues/6930"target="_blank" rel="noopener">GitHub Issue #6930&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에서 올라왔습니다. 한 사용자가 OpenCode에서 Anthropic OAuth를 사용했다가 &lt;strong>ToS(이용약관) 위반으로 밴&lt;/strong>당했다는 보고였죠.&lt;/p>
&lt;p>해당 사용자는 Claude Max 5x에서 Max 20x로 업그레이드한 직후 리뷰가 트리거됐다고 합니다. Twitter에서 Anthropic 엔지니어에게 연락한 결과, Claude 구독을 OpenCode를 통해 사용하는 것이 ToS 위반이라는 답변을 받았습니다.&lt;/p>
&lt;h3>2026년 1월 9일 - 대규모 차단&lt;span class="hx:absolute hx:-mt-20" id="2026년-1월-9일---대규모-차단">&lt;/span>
&lt;a href="#2026%eb%85%84-1%ec%9b%94-9%ec%9d%bc---%eb%8c%80%ea%b7%9c%eb%aa%a8-%ec%b0%a8%eb%8b%a8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>2026년 1월 9일 UTC 02:20경, Anthropic은 &lt;strong>써드파티 도구에서 Claude Pro/Max 구독 OAuth 토큰 사용을 차단하는 기술적 조치&lt;/strong>를 배포했습니다.&lt;/p>
&lt;p>여기서 중요한 건 &lt;strong>API 접근 자체를 막은 건 아니라는 점&lt;/strong>입니다. 종량제 API 키를 사용하는 써드파티 도구는 아무 문제 없이 동작했습니다. 차단된 건 Claude Max 구독에 포함된 OAuth 토큰을 Claude Code가 아닌 도구에서 사용하는 것이었죠.&lt;/p>
&lt;p>OpenCode(당시 GitHub 스타 56,000개)를 비롯해 구독 인증을 사용하는 모든 써드파티 도구가 영향을 받았습니다.&lt;/p>
&lt;p>에러 메시지는 이랬습니다.&lt;/p>
&lt;blockquote>
&lt;p>&lt;em>&amp;ldquo;This credential is only authorized for use with Claude Code and cannot be used for other API requests.&amp;rdquo;&lt;/em>&lt;/p>
&lt;/blockquote>
&lt;p>&lt;strong>아무런 경고도, 마이그레이션 경로도 없이&lt;/strong> 하루아침에 차단됐습니다.&lt;/p>
&lt;h3>개발자 커뮤니티의 반발&lt;span class="hx:absolute hx:-mt-20" id="개발자-커뮤니티의-반발">&lt;/span>
&lt;a href="#%ea%b0%9c%eb%b0%9c%ec%9e%90-%ec%bb%a4%eb%ae%a4%eb%8b%88%ed%8b%b0%ec%9d%98-%eb%b0%98%eb%b0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>반발은 거셌습니다. 저도 관련 커뮤니티를 살펴봤는데, 거의 모든 스레드가 이 이슈로 뜨겁더라구요.&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://news.ycombinator.com/item?id=46625918"target="_blank" rel="noopener">Hacker News에서 170개 이상의 업보트와 150개 이상의 댓글&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>Ruby on Rails 창시자 &lt;strong>DHH(David Heinemeier Hansson)&lt;/strong> 가 &lt;a href="https://x.com/dhh/status/2009716350374293963"target="_blank" rel="noopener">트위터에&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> 이런 글을 올리기도 했습니다.&lt;/p>
&lt;blockquote>
&lt;p>&lt;em>&amp;ldquo;Anthropic이 의도적으로 OpenCode와 모든 써드파티 도구를 차단하고 있다는 확인. 개발자들을 Claude Code에 강제로 가두려는 편집증적 시도. 우리의 코드, 우리의 글, 우리의 모든 것으로 모델을 학습시킨 회사가 취할 정책으로서는 끔찍하다.&amp;rdquo;&lt;/em>&lt;/p>
&lt;/blockquote>
&lt;p>t3.gg의 &lt;strong>Theo&lt;/strong>도 &lt;a href="https://x.com/theo/status/2009464346846621700"target="_blank" rel="noopener">트위터에서&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> &lt;em>&amp;ldquo;Anthropic is now cracking down on utilizing Claude subs in 3rd party apps like OpenCode and Clawdbot. Oh boy.&amp;rdquo;&lt;/em> 라며 우려를 표했습니다.&lt;/p>
&lt;p>개인적으로 DHH의 &amp;ldquo;편집증적 시도&amp;quot;라는 표현은 과하다고 생각하지만, 월 $200을 내면서 도구 선택권을 원하는 개발자들의 감정 자체는 충분히 이해가 됩니다.&lt;/p>
&lt;p>반면 이해를 표하는 의견도 있었습니다. Yearn Finance 개발자 &lt;strong>@banteg&lt;/strong>는 &lt;a href="https://x.com/banteg/status/2009587028728713647"target="_blank" rel="noopener">트위터에서&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> 이렇게 말했죠.&lt;/p>
&lt;blockquote>
&lt;p>&lt;em>&amp;ldquo;구독 인증을 악용하는 사람들에 대한 Anthropic의 단속은 가능한 한 가장 부드러운 방식이었다. 계정을 삭제하거나 소급해서 API 가격을 청구하는 대신 정중한 메시지만 보냈으니까.&amp;rdquo;&lt;/em>&lt;/p>
&lt;/blockquote>
&lt;h3>Anthropic의 공식 입장&lt;span class="hx:absolute hx:-mt-20" id="anthropic의-공식-입장">&lt;/span>
&lt;a href="#anthropic%ec%9d%98-%ea%b3%b5%ec%8b%9d-%ec%9e%85%ec%9e%a5" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Claude Code 팀의 &lt;strong>Thariq Shihipar&lt;/strong>가 &lt;a href="https://x.com/trq212/status/2009689809875591565"target="_blank" rel="noopener">트위터에서&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> 공식 입장을 밝혔습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>차단 사유&lt;/strong>: 인증되지 않은 도구들이 버그와 비정상적인 사용 패턴을 야기하고, 문제가 생기면 사용자들이 Claude 탓을 해서 신뢰도가 떨어진다.&lt;/li>
&lt;li>써드파티 도구 개발자들에게 DM으로 논의할 것을 제안&lt;/li>
&lt;li>해당 이슈로 밴된 사용자들의 &lt;strong>밴은 모두 해제&lt;/strong>됨을 확인&lt;/li>
&lt;li>써드파티 도구의 지원 경로는 &lt;strong>API(종량제 과금)&lt;/strong> 이며, 구독 OAuth 토큰은 아님&lt;/li>
&lt;/ul>
&lt;p>Anthropic의 입장을 정리하면, &lt;strong>구독 Plan은 Claude Code 전용이고, 써드파티 도구는 종량제 API를 사용하는 것이 정상적인 경로&lt;/strong>라는 것이었습니다. 기술적으로도 Claude Code는 프롬프트 캐싱 최적화(세션당 약 90% 캐시 적중률)가 적용돼 있어 Anthropic 입장에서 비용이 낮지만, 써드파티 도구는 이런 최적화가 없어 같은 구독이라도 실제 서버 비용이 훨씬 높다는 주장이었죠.&lt;/p>
&lt;p>커뮤니티 반응은 갈렸습니다. &amp;ldquo;구독은 Claude Code 전용이니 당연한 조치다&amp;quot;라는 의견도 있었지만, &lt;strong>&amp;quot;$200 내고 쓰는데 도구는 내가 선택하게 해달라&amp;rdquo;&lt;/strong> 는 반발도 컸습니다. 다만 원칙 자체보다는 &lt;strong>사전 경고 없는 실행 방식&lt;/strong>에 대한 비판이 더 크더라구요.&lt;/p>
&lt;p>돌이켜보면 Anthropic의 대응 전략 변화가 흥미롭습니다. 1월 5일에는 개별 사용자를 밴하는 &lt;strong>&amp;ldquo;처벌&amp;rdquo;&lt;/strong> 방식이었는데, 밴을 해제한 뒤 OAuth 토큰 자체를 기술적으로 차단하는 &lt;strong>&amp;ldquo;원천 봉쇄&amp;rdquo;&lt;/strong> 로 전환한 겁니다. 한 명씩 잡아내는 것보다 시스템 레벨에서 아예 막는 게 효율적이라고 판단한 것 같습니다.&lt;/p>
&lt;h2>커뮤니티의 적응&lt;span class="hx:absolute hx:-mt-20" id="커뮤니티의-적응">&lt;/span>
&lt;a href="#%ec%bb%a4%eb%ae%a4%eb%8b%88%ed%8b%b0%ec%9d%98-%ec%a0%81%ec%9d%91" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>oh-my-claudecode의 부상&lt;span class="hx:absolute hx:-mt-20" id="oh-my-claudecode의-부상">&lt;/span>
&lt;a href="#oh-my-claudecode%ec%9d%98-%eb%b6%80%ec%83%81" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>차단 이후, oh-my-claudecode가 더욱 주목받게 됩니다. oh-my-opencode는 OpenCode 기반이라 구독 OAuth 사용 시 ToS 위반 리스크가 있었지만, oh-my-claudecode는 &lt;strong>Claude Code의 네이티브 Hooks(쉘 스크립트)&lt;/strong> 를 활용해 구현됐기 때문에 Max 구독과 완전히 호환되면서 ToS를 위반하지 않는 구조였습니다.&lt;/p>
&lt;p>개발자들은 빠르게 oh-my-claudecode로 옮겨갔습니다. 공식 Claude Code 안에서 멀티 에이전트 오케스트레이션을 사용하면서도 밴 리스크 없이 쓸 수 있었으니까요.&lt;/p>
&lt;h3>Clawdbot → OpenClaw 이야기&lt;span class="hx:absolute hx:-mt-20" id="clawdbot--openclaw-이야기">&lt;/span>
&lt;a href="#clawdbot--openclaw-%ec%9d%b4%ec%95%bc%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>여담이지만 이 시기에 &lt;strong>Clawdbot&lt;/strong>이라는 오픈소스 AI 어시스턴트 프로젝트도 Anthropic으로부터 상표권 관련 이메일을 받아 &lt;strong>&lt;a href="https://openclaw.ai/"target="_blank" rel="noopener">OpenClaw&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/strong> 로 리브랜딩한 일이 있었습니다. 이 프로젝트는 뒤에서 다시 다루겠습니다.&lt;/p>
&lt;h2>숨겨진 카드: 이미 만들어져 있었다&lt;span class="hx:absolute hx:-mt-20" id="숨겨진-카드-이미-만들어져-있었다">&lt;/span>
&lt;a href="#%ec%88%a8%ea%b2%a8%ec%a7%84-%ec%b9%b4%eb%93%9c-%ec%9d%b4%eb%af%b8-%eb%a7%8c%eb%93%a4%ec%96%b4%ec%a0%b8-%ec%9e%88%ec%97%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>2026년 1월 24일 - Swarm 발견&lt;span class="hx:absolute hx:-mt-20" id="2026년-1월-24일---swarm-발견">&lt;/span>
&lt;a href="#2026%eb%85%84-1%ec%9b%94-24%ec%9d%bc---swarm-%eb%b0%9c%ea%b2%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이 시점에서 정말 흥미로운 일이 벌어집니다.&lt;/p>
&lt;p>개발자 &lt;strong>kieranklaassen&lt;/strong>이 Claude Code 바이너리에 &lt;code>strings&lt;/code> 명령어를 실행했다가 &lt;strong>이미 구현되어 있지만 숨겨진&lt;/strong> 멀티 에이전트 기능을 발견한 겁니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">strings ~/.local/share/claude/versions/2.1.29 &lt;span class="p">|&lt;/span> grep TeammateTool&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>&amp;ldquo;TeammateTool&amp;rdquo;&lt;/strong> 이라는 이름으로, 13개의 오퍼레이션을 가진 완전한 오케스트레이션 레이어가 이미 코드 안에 있었습니다. 에이전트를 생성하고, 관리하고, 조율하는 기능이 피처 플래그 뒤에 숨겨져 있었던 거죠.&lt;/p>
&lt;p>이 발견을 바탕으로 &lt;strong>Mike Kelly&lt;/strong>가 &lt;a href="https://github.com/mikekelly/claude-sneakpeek"target="_blank" rel="noopener">claude-sneakpeek&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>이라는 프로젝트를 만들어 피처 플래그를 우회하고 Swarm 기능을 사용할 수 있게 공개했고, 커뮤니티는 발칵 뒤집혔습니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;써드파티 멀티 에이전트 도구를 차단하면서, 동시에 자체 멀티 에이전트 시스템을 이미 만들고 있었다고?&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>이 발견은 많은 개발자들에게 불편한 질문을 남겼습니다. 커뮤니티의 혁신에서 영감을 받은 건지, 독자적으로 개발하고 있었는지는 알 수 없지만, &lt;strong>타이밍이 너무 절묘했기 때문이죠.&lt;/strong> 저도 이 소식을 보고 &amp;ldquo;결국 이렇게 되는구나&amp;rdquo; 싶었습니다.&lt;/p>
&lt;h2>공식 출시: Agent Teams&lt;span class="hx:absolute hx:-mt-20" id="공식-출시-agent-teams">&lt;/span>
&lt;a href="#%ea%b3%b5%ec%8b%9d-%ec%b6%9c%ec%8b%9c-agent-teams" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>2026년 2월 5일 - Opus 4.6과 함께 발표&lt;span class="hx:absolute hx:-mt-20" id="2026년-2월-5일---opus-46과-함께-발표">&lt;/span>
&lt;a href="#2026%eb%85%84-2%ec%9b%94-5%ec%9d%bc---opus-46%ea%b3%bc-%ed%95%a8%ea%bb%98-%eb%b0%9c%ed%91%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그리고 2026년 2월 5일, Anthropic은 &lt;a href="https://www.anthropic.com/news/claude-opus-4-6"target="_blank" rel="noopener">Claude Opus 4.6&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>을 발표하면서 &lt;strong>Agent Teams&lt;/strong>를 Research Preview로 공식 출시했습니다.&lt;/p>
&lt;p>Agent Teams는 &lt;strong>여러 Claude Code 인스턴스가 동시에 작업하면서 서로 소통하는&lt;/strong> 기능입니다.&lt;/p>
&lt;p>기존 Sub-Agent와의 가장 큰 차이점을 정리하면 이렇습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>특성&lt;/th>
&lt;th>Sub-Agent&lt;/th>
&lt;th>Agent Teams&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>컨텍스트&lt;/strong>&lt;/td>
&lt;td>자체 컨텍스트, 결과만 호출자에게 반환&lt;/td>
&lt;td>자체 컨텍스트, 완전히 독립적&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>커뮤니케이션&lt;/strong>&lt;/td>
&lt;td>메인 에이전트에게만 보고&lt;/td>
&lt;td>팀원끼리 직접 메시지 교환&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>조율&lt;/strong>&lt;/td>
&lt;td>메인 에이전트가 모든 작업 관리&lt;/td>
&lt;td>공유 Task 리스트로 자율 조율&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>적합한 작업&lt;/strong>&lt;/td>
&lt;td>결과만 중요한 집중 작업&lt;/td>
&lt;td>논의와 협업이 필요한 복잡한 작업&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>토큰 비용&lt;/strong>&lt;/td>
&lt;td>낮음 (결과가 요약돼서 반환)&lt;/td>
&lt;td>높음 (각 팀원이 별도 Claude 인스턴스)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3>핵심 아키텍처&lt;span class="hx:absolute hx:-mt-20" id="핵심-아키텍처">&lt;/span>
&lt;a href="#%ed%95%b5%ec%8b%ac-%ec%95%84%ed%82%a4%ed%85%8d%ec%b2%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Agent Teams의 구조는 이렇습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>구성요소&lt;/th>
&lt;th>역할&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Team Lead&lt;/strong>&lt;/td>
&lt;td>팀을 생성하고, 팀원을 배치하고, 작업을 조율하는 메인 세션&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Teammates&lt;/strong>&lt;/td>
&lt;td>할당된 작업을 수행하는 독립 Claude Code 인스턴스&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Task List&lt;/strong>&lt;/td>
&lt;td>팀원들이 공유하는 작업 목록 (의존성 관리 포함)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Mailbox&lt;/strong>&lt;/td>
&lt;td>에이전트 간 메시징 시스템&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>팀 설정 파일은 &lt;code>~/.claude/teams/{team-name}/config.json&lt;/code>에, 작업 목록은 &lt;code>~/.claude/tasks/{team-name}/&lt;/code>에 저장됩니다.&lt;/p>
&lt;h3>Agent Teams 활성화하기&lt;span class="hx:absolute hx:-mt-20" id="agent-teams-활성화하기">&lt;/span>
&lt;a href="#agent-teams-%ed%99%9c%ec%84%b1%ed%99%94%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Agent Teams는 아직 실험적 기능이라 기본적으로 비활성화돼 있습니다. 활성화 방법은 간단합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// settings.json
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;env&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;1&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>팀 생성과 사용&lt;span class="hx:absolute hx:-mt-20" id="팀-생성과-사용">&lt;/span>
&lt;a href="#%ed%8c%80-%ec%83%9d%ec%84%b1%ea%b3%bc-%ec%82%ac%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>팀 생성은 자연어로 요청하면 됩니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>프로젝트의 전체 아키텍처를 분석해줘.
백엔드, 프론트엔드, 인프라, 데이터베이스 각각 분석하는 팀원을 배치해서
동시에 분석하고 통합 문서를 만들어줘.&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이렇게 요청하면 Claude Code가 Team Lead 역할을 맡아서 팀원을 생성하고 작업을 배분합니다.&lt;/p>
&lt;p>저는 실제로 회사의 &lt;strong>MSA 환경 전체 아키텍처 문서&lt;/strong>를 Agent Teams로 작성시켜 봤습니다. 백엔드 서비스 흐름, 프론트엔드 구조, 인프라 구성, DB 스키마까지 한 번에 분석하고 통합 문서를 만드는 작업이었죠.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/8vd9sanjohc53atch3dry/3A2B94B2-A1D9-47C7-BCF1-4602FD3D0B74.jpg?rlkey=d8g83pstkzuy7xbdki0p2n3wv&amp;amp;st=xdtzpg4n&amp;amp;raw=1" alt="Agent Teams 팀 생성 및 에이전트 실행 모습" loading="lazy" />&lt;/p>
&lt;p>4개의 분석 에이전트(backend-analyzer, frontend-analyzer, infra-analyzer, db-analyzer)가 병렬로 실행되는 모습입니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/v2s0iatowdap9js3auq5r/C4DE224D-95DB-44D9-89CB-B82212F0202A.jpg?rlkey=dqzjoovpi223pbyuj4q2yvuzq&amp;amp;st=k1a0x50y&amp;amp;raw=1" alt="Agent Teams 실행 중인 모습" loading="lazy" />&lt;/p>
&lt;p>물론 기존 Sub-Agent도 독립된 컨텍스트로 병렬 실행은 가능했습니다. 하지만 Sub-Agent는 결과를 메인 에이전트에게만 보고하는 구조라, 분석 도중에 팀원끼리 &amp;ldquo;이 서비스가 네 쪽 DB 스키마랑 연관 있는데 확인해봐&amp;quot;같은 소통이 안 됐죠. Agent Teams는 팀원끼리 직접 메시지를 교환하고 공유 Task 리스트로 자율 조율하니까, &lt;strong>분석 결과의 정합성이 눈에 띄게 올라갔습니다.&lt;/strong> Team Lead가 각 분석 결과를 취합해서 통합 문서를 만들어주는 과정도 깔끔했고요.&lt;/p>
&lt;p>별도 도구 설치 없이 설정 하나로 네이티브 멀티 에이전트를 바로 쓸 수 있다는 점도 좋았습니다.&lt;/p>
&lt;p>다만 아쉬운 점도 있었습니다. oh-my-claudecode는 32개의 전문화된 에이전트(planner, architect, critic 등)와 7가지 실행 모드가 &lt;strong>검증된 패턴으로 미리 정의&lt;/strong>돼 있어서 바로 쓸 수 있는데, Agent Teams는 팀 구성을 LLM이 매번 즉석에서 판단합니다. 물론 &amp;ldquo;이거 해줘&amp;quot;라고 하면 알아서 팀을 짜주긴 하지만, oh-my-claudecode의 Ultrapilot 모드처럼 &lt;strong>이미 최적화된 패턴을 바로 적용하는 경험&lt;/strong>과는 차이가 있었습니다.&lt;/p>
&lt;h3>그 외 기능들&lt;span class="hx:absolute hx:-mt-20" id="그-외-기능들">&lt;/span>
&lt;a href="#%ea%b7%b8-%ec%99%b8-%ea%b8%b0%eb%8a%a5%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이 외에도 팀원마다 다른 모델을 지정하거나(Lead는 Opus, 팀원은 Sonnet), 팀원이 계획을 먼저 세우고 승인을 받은 후에만 구현하게 하거나, Hook 이벤트(TeammateIdle, TaskCompleted)로 자동화된 품질 검증을 걸 수도 있습니다. &lt;code>.claude/agents/&lt;/code> 디렉토리에 마크다운 파일을 만들면 커스텀 에이전트 정의도 가능하고요.&lt;/p>
&lt;p>자세한 사용법은 &lt;a href="https://code.claude.com/docs/en/agent-teams"target="_blank" rel="noopener">공식 문서&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>를 참고하시면 됩니다.&lt;/p>
&lt;h3>알려진 한계&lt;span class="hx:absolute hx:-mt-20" id="알려진-한계">&lt;/span>
&lt;a href="#%ec%95%8c%eb%a0%a4%ec%a7%84-%ed%95%9c%ea%b3%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>아직 Research Preview인 만큼 한계도 있습니다. 세션 재개 시 팀원이 복원되지 않고, 세션당 하나의 팀만 운영 가능하며, Split Pane 모드는 tmux 또는 iTerm2에서만 동작합니다. 팀원이 작업 완료를 표시하지 못하는 경우도 간혹 있었습니다.&lt;/p>
&lt;h2>비교: oh-my-opencode vs oh-my-claudecode vs Agent Teams&lt;span class="hx:absolute hx:-mt-20" id="비교-oh-my-opencode-vs-oh-my-claudecode-vs-agent-teams">&lt;/span>
&lt;a href="#%eb%b9%84%ea%b5%90-oh-my-opencode-vs-oh-my-claudecode-vs-agent-teams" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>지금까지 이야기한 도구들을 비교해보겠습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>특성&lt;/th>
&lt;th>oh-my-opencode&lt;/th>
&lt;th>oh-my-claudecode&lt;/th>
&lt;th>Agent Teams&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>플랫폼&lt;/strong>&lt;/td>
&lt;td>OpenCode (써드파티)&lt;/td>
&lt;td>Claude Code (네이티브 Hooks)&lt;/td>
&lt;td>Claude Code (공식 기능)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>프로바이더&lt;/strong>&lt;/td>
&lt;td>다중 (Claude, OpenAI, Google 등)&lt;/td>
&lt;td>Claude 전용&lt;/td>
&lt;td>Claude 전용&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>설치&lt;/strong>&lt;/td>
&lt;td>OpenCode 플러그인&lt;/td>
&lt;td>&lt;code>.claude/hooks/&lt;/code> 스크립트&lt;/td>
&lt;td>설정값 1개 변경&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>에이전트 수&lt;/strong>&lt;/td>
&lt;td>다양한 전문 에이전트&lt;/td>
&lt;td>32개 전문 에이전트, 40+ 스킬&lt;/td>
&lt;td>사용자 정의&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>실행 모드&lt;/strong>&lt;/td>
&lt;td>Ultrawork 모드&lt;/td>
&lt;td>7가지 (Autopilot, Ultrapilot, Swarm 등)&lt;/td>
&lt;td>Team Lead + Teammates&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>에이전트 간 통신&lt;/strong>&lt;/td>
&lt;td>플러그인 SDK&lt;/td>
&lt;td>Hooks 기반&lt;/td>
&lt;td>내장 메일박스 시스템&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Task 관리&lt;/strong>&lt;/td>
&lt;td>자체 구현&lt;/td>
&lt;td>자체 구현&lt;/td>
&lt;td>내장 Task 리스트 (의존성 포함)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>안정성&lt;/strong>&lt;/td>
&lt;td>커뮤니티 유지보수&lt;/td>
&lt;td>커뮤니티 유지보수&lt;/td>
&lt;td>Anthropic 공식 지원&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>ToS 호환&lt;/strong>&lt;/td>
&lt;td>구독 OAuth로 사용 시 위반 가능&lt;/td>
&lt;td>Claude Code 네이티브라 호환&lt;/td>
&lt;td>공식 기능이니 당연히 호환&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>비용&lt;/strong>&lt;/td>
&lt;td>구독 or API&lt;/td>
&lt;td>구독&lt;/td>
&lt;td>구독&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;strong>개인적인 판단:&lt;/strong>&lt;/p>
&lt;p>oh-my-opencode와 oh-my-claudecode는 Agent Teams 이전에 정말 훌륭한 혁신이었습니다. 특히 oh-my-claudecode는 Anthropic의 차단 이후에도 Claude Code의 공식 기능만 활용해서 멀티 에이전트를 구현했다는 점에서 대단하다고 생각합니다.&lt;/p>
&lt;p>하지만 Agent Teams가 공식 출시된 지금, 장기적으로는 &lt;strong>공식 기능을 사용하는 게 안정적&lt;/strong>이라고 생각합니다. 커뮤니티 도구는 업데이트가 중단될 수 있고, Claude Code의 내부 구조가 바뀌면 호환성 문제가 생길 수 있으니까요. 다만 현 시점에서는 oh-my-claudecode의 사전 정의된 에이전트와 실행 모드가 편의성 면에서 앞서 있는 건 사실입니다.&lt;/p>
&lt;h2>개인적인 생각: Anthropic은 어디로 향하고 있나&lt;span class="hx:absolute hx:-mt-20" id="개인적인-생각-anthropic은-어디로-향하고-있나">&lt;/span>
&lt;a href="#%ea%b0%9c%ec%9d%b8%ec%a0%81%ec%9d%b8-%ec%83%9d%ea%b0%81-anthropic%ec%9d%80-%ec%96%b4%eb%94%94%eb%a1%9c-%ed%96%a5%ed%95%98%ea%b3%a0-%ec%9e%88%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이 한 달간의 흐름을 지켜보면서 꽤 많은 생각이 들었습니다.&lt;/p>
&lt;h3>구독 Plan 차단, 어떻게 볼 것인가&lt;span class="hx:absolute hx:-mt-20" id="구독-plan-차단-어떻게-볼-것인가">&lt;/span>
&lt;a href="#%ea%b5%ac%eb%8f%85-plan-%ec%b0%a8%eb%8b%a8-%ec%96%b4%eb%96%bb%ea%b2%8c-%eb%b3%bc-%ea%b2%83%ec%9d%b8%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>솔직히 말하면, 저는 Anthropic의 &lt;strong>원칙 자체&lt;/strong>는 이해할 수 있다고 생각합니다.&lt;/p>
&lt;p>앞서 정리한 것처럼 Claude Code와 써드파티 도구 사이에는 프롬프트 캐싱 최적화로 인한 실제 서버 비용 차이가 있고, &lt;strong>&amp;ldquo;구독 Plan은 Claude Code 전용, 써드파티는 API로&amp;rdquo;&lt;/strong> 라는 구분은 비즈니스적으로 합리적이죠.&lt;/p>
&lt;p>커뮤니티에서도 이 점을 인정하는 목소리가 있었습니다. Yearn Finance 개발자 &lt;a href="https://x.com/banteg/status/2009587028728713647"target="_blank" rel="noopener">@banteg&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>는 &lt;em>&amp;ldquo;계정을 삭제하거나 소급해서 API 가격을 청구하는 대신 정중한 메시지만 보냈으니 가능한 한 부드러운 방식이었다&amp;rdquo;&lt;/em> 고 평가했고, &lt;a href="https://lobste.rs/s/mhgog9/anthropic_blocks_third_party_tools_using"target="_blank" rel="noopener">Lobsters&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에서는 &lt;em>&amp;ldquo;OAuth 토큰 발급자가 해당 토큰의 용도를 제한하는 건 일반적인 보안 관행&amp;rdquo;&lt;/em> 이라는 의견도 있었습니다.&lt;/p>
&lt;p>다만 &lt;strong>실행 방식&lt;/strong>은 아쉬웠습니다. 앞서 커뮤니티 반응에서도 봤듯이, 원칙 자체보다 사전 경고 없는 실행에 대한 분노가 컸죠. 저도 같은 생각인데, 여기서 한 발 더 나가면 — Anthropic이 놓친 건 &lt;strong>&amp;ldquo;이 사람들은 잠재적 API 고객이다&amp;rdquo;&lt;/strong> 라는 관점인 것 같습니다. 써드파티 도구 사용자들은 멀티 에이전트에 월 수백 달러를 쓸 의향이 있는 사람들이었거든요. 차단만 하고 대안을 동시에 제시하지 못한 건, 고객을 잃는 방식이었다고 봅니다.&lt;/p>
&lt;p>&lt;a href="https://news.ycombinator.com/item?id=46625918"target="_blank" rel="noopener">HN의 한 유저&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>는 &lt;em>&amp;ldquo;올-유-캔-잇 레스토랑에서 자기네 플라스틱 포크로만 먹으라고 강요하면서, 내가 가져온 수저는 쓰지 못하게 하는 꼴&amp;rdquo;&lt;/em> 이라고 비유했는데, 이게 불만의 핵심을 잘 보여준다고 생각합니다. 원칙이 맞더라도, 실행 방식이 거칠면 신뢰가 깎이는 거죠.&lt;/p>
&lt;p>그리고 솔직히 말하면, Anthropic이 진짜 두려웠던 건 서버 비용만이 아니라고 생각합니다. &lt;strong>써드파티 도구가 UX를 장악하면, 모델 회사는 뒤에서 돌아가는 인프라로 추락합니다.&lt;/strong> 개발자가 매일 쓰는 도구가 OpenCode가 되면, Claude는 그냥 &amp;ldquo;OpenCode가 호출하는 API 중 하나&amp;quot;가 되는 거죠. 개발자와의 접점을 잃는다는 건, 락인도 브랜드도 잃는다는 뜻입니다. Anthropic 입장에서 이건 비용 문제보다 훨씬 무서운 시나리오였을 겁니다.&lt;/p>
&lt;p>&lt;strong>Anthropic이 개발자 커뮤니티의 신뢰로 성장한 회사&lt;/strong>라는 점에서 더 아쉽습니다. Claude가 GPT-4와 경쟁할 수 있었던 건 모델 성능도 있지만, 개발자 친화적인 이미지도 한몫했거든요.&lt;/p>
&lt;h3>커뮤니티의 혁신을 흡수하는 패턴&lt;span class="hx:absolute hx:-mt-20" id="커뮤니티의-혁신을-흡수하는-패턴">&lt;/span>
&lt;a href="#%ec%bb%a4%eb%ae%a4%eb%8b%88%ed%8b%b0%ec%9d%98-%ed%98%81%ec%8b%a0%ec%9d%84-%ed%9d%a1%ec%88%98%ed%95%98%eb%8a%94-%ed%8c%a8%ed%84%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>시간순으로 보면&lt;/p>
&lt;ol>
&lt;li>커뮤니티가 멀티 에이전트 도구 만듦 (oh-my-opencode, oh-my-claudecode)&lt;/li>
&lt;li>도구들이 큰 인기를 끔&lt;/li>
&lt;li>Anthropic이 차단 (2026년 1월 9일)&lt;/li>
&lt;li>Claude Code에 숨겨진 Swarm 기능 발견 (2026년 1월 24일)&lt;/li>
&lt;li>Agent Teams 공식 출시 (2026년 2월 5일)&lt;/li>
&lt;/ol>
&lt;p>Anthropic이 커뮤니티의 혁신에서 영감을 받았는지, 독자적으로 개발하고 있었는지는 알 수 없습니다. 하지만 결과적으로 보면, &lt;strong>커뮤니티가 먼저 가능성을 증명하고, 플랫폼이 이를 공식 기능으로 흡수하는 패턴&lt;/strong>이 반복되고 있습니다.&lt;/p>
&lt;p>사실 이건 플랫폼 비즈니스에서 흔히 보는 모습이기도 합니다. 브라우저 확장 프로그램으로 인기를 끌던 광고 차단이나 다크 모드가 결국 브라우저 기본 기능이 된 것처럼요. iOS에서 써드파티 앱이 먼저 보여준 손전등, 화면 녹화 같은 기능이 나중에 기본 탑재된 것도 비슷한 맥락입니다.&lt;/p>
&lt;p>물론 이번 경우는 &amp;ldquo;써드파티를 차단한 뒤 비슷한 기능을 출시했다&amp;quot;고 단정하기는 어렵습니다. 차단한 것은 &lt;strong>구독 Plan의 무단 사용&lt;/strong>이지, 써드파티 도구의 존재 자체가 아니었으니까요. API를 통한 써드파티 도구 사용은 여전히 가능합니다.&lt;/p>
&lt;p>저는 &lt;strong>Anthropic이 개발자 생태계에서 사람들이 바라는 기능을 빠르게 포착해서 추가하려 한다&lt;/strong>고 느껴집니다. 그 자체는 좋은 일이고, 구독 Plan과 API의 구분도 비즈니스적으로 이해할 수 있습니다. 다만 과정에서 커뮤니티와의 소통이 더 투명했으면 합니다.&lt;/p>
&lt;h3>다음은 메신저 통합과 에러 자동화?&lt;span class="hx:absolute hx:-mt-20" id="다음은-메신저-통합과-에러-자동화">&lt;/span>
&lt;a href="#%eb%8b%a4%ec%9d%8c%ec%9d%80-%eb%a9%94%ec%8b%a0%ec%a0%80-%ed%86%b5%ed%95%a9%ea%b3%bc-%ec%97%90%eb%9f%ac-%ec%9e%90%eb%8f%99%ed%99%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>앞서 잠깐 언급한 &lt;a href="https://openclaw.ai/"target="_blank" rel="noopener">OpenClaw&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>는 Telegram, Discord, Slack, WhatsApp, Signal, Email 등 &lt;strong>다양한 메신저 채널을 통해 AI 에이전트와 작업&lt;/strong>할 수 있는 오픈소스 도구입니다. 로컬 머신에서 셀프호스팅되며, 코드 수정 요청, 작업 모니터링, 브라우저 자동화까지 메신저에서 바로 할 수 있죠.&lt;/p>
&lt;p>출퇴근 길에 Telegram으로 &amp;ldquo;PR 리뷰 결과 어때?&amp;ldquo;라고 물어보면 에이전트가 바로 답해주는 것, &lt;strong>이건 이미 OpenClaw로 가능한 현실입니다.&lt;/strong> GitHub Copilot도 &lt;a href="https://github.blog/changelog/2024-10-29-copilot-chat-in-github-mobile/"target="_blank" rel="noopener">Copilot Chat in GitHub Mobile&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>을 통해 모바일에서 코드 관련 질문을 할 수 있게 했고요. &amp;ldquo;터미널 앞에 앉아있지 않아도 에이전트와 소통한다&amp;quot;는 니즈는 이미 업계 전반에서 검증된 셈입니다.&lt;/p>
&lt;p>Agent Teams가 커뮤니티의 멀티 에이전트 니즈를 공식 기능으로 흡수한 것처럼, &lt;strong>메신저를 통한 에이전트 작업도 곧 Claude Code의 공식 기능으로 지원되지 않을까&lt;/strong> 하는 생각이 듭니다.&lt;/p>
&lt;p>그리고 백엔드 개발자로서 또 하나 기대하는 게 있습니다. 저는 얼마 전에 &lt;a href="https://jeongil.dev/ko/blog/trends/openclaw-error-autopilot/">OpenClaw로 새벽 에러 알림 대응을 자동화한 경험&lt;/a>을 공유한 적이 있는데요. Loki에서 에러를 감지하면 AI가 분석하고, trace를 추적하고, 코드를 수정해서 PR까지 올리는 파이프라인이었습니다. 만약 Claude Code에서 OpenClaw처럼 &lt;strong>메신저 채널을 네이티브로 지원&lt;/strong>하게 된다면, 이런 에러 감지 → 분석 → 자동 수정 흐름도 별도 도구 없이 Claude Code 안에서 바로 가능해지지 않을까 싶습니다. 에러 알림이 오면 Agent Teams가 알아서 팀을 구성해서, 한 팀원은 로그를 분석하고, 다른 팀원은 관련 코드를 찾고, 또 다른 팀원은 수정 PR을 작성하는 식으로요.&lt;/p>
&lt;p>커뮤니티가 먼저 보여준 패턴이 공식 기능이 되는 흐름이 계속된다면, 이런 운영 자동화도 결국 Claude Code에 녹아들 거라고 생각합니다.&lt;/p>
&lt;h2>마치며: 그래서 지금 뭘 선택해야 하나&lt;span class="hx:absolute hx:-mt-20" id="마치며-그래서-지금-뭘-선택해야-하나">&lt;/span>
&lt;a href="#%eb%a7%88%ec%b9%98%eb%a9%b0-%ea%b7%b8%eb%9e%98%ec%84%9c-%ec%a7%80%ea%b8%88-%eb%ad%98-%ec%84%a0%ed%83%9d%ed%95%b4%ec%95%bc-%ed%95%98%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이 글을 읽고 &amp;ldquo;그래서 나는 뭘 써야 해?&amp;ldquo;라는 질문이 남을 수 있을 것 같습니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;지금 당장은&amp;rdquo;&lt;/strong> Agent Teams로 시작하는 걸 추천합니다. 공식 기능이라 밴 리스크가 없고, 설정 하나면 바로 쓸 수 있고, Anthropic이 계속 개선할 거니까요. oh-my-claudecode의 사전 정의된 에이전트가 편리한 건 사실이지만, 커뮤니티 도구는 결국 공식 기능이 따라잡으면 유지보수가 멈추는 경우가 많습니다.&lt;/p>
&lt;p>다만 &amp;ldquo;지금 당장&amp;quot;이라고 표현한 이유가 있습니다. 위 모든 일이 한 달 만에 벌어졌다는 점에서 알 수 있듯이, AI 에이전트 생태계는 매우 빠르게 변하고 있습니다. 오늘 유행했던 게, 혁신이라 말했던 게 내일 뒤쳐지고 있는 상황들이 벌어지고 있는 것 같습니다. 정말 미친 세상이다 싶기도 하고 이 속도가 말이되나 싶기도 합니다. 앞서진 못해도 뒤쳐지지 않으려면 빠르게 적응하는 수밖에 없다고 생각합니다.&lt;/p>
&lt;p>결국 지금 상황에서 &amp;ldquo;멀티 에이전트를 어떻게 하면 잘 쓰느냐&amp;quot;는 건 &lt;strong>작업을 어떻게 분할하고, 각 에이전트에게 어떤 역할과 맥락을 줄 것인가&lt;/strong>의 문제라고 생각합니다. 도구가 공식이든 커뮤니티든, 이 설계 능력이 없으면 에이전트 여러 개를 돌려도 결과물 품질이 안 나옵니다. 저도 MSA 아키텍처 문서를 만들면서 느꼈는데, 팀 구성을 어떻게 잡느냐에 따라 결과 차이가 컸습니다.&lt;/p>
&lt;p>이번 한 달간의 흐름에서 제가 가장 크게 느낀 건 이겁니다. &lt;strong>커뮤니티 도구는 &amp;ldquo;이런 게 가능하다&amp;quot;를 증명하는 프로토타입이고, 플랫폼 기능은 그걸 안정적으로 쓸 수 있게 만든 제품입니다.&lt;/strong> 둘 다 필요하고, 이 순환이 생태계를 발전시킵니다. 다만 Anthropic이 이 순환에서 커뮤니티와 더 투명하게 소통했으면 하는 바람은 여전히 있습니다.&lt;/p>
&lt;p>이전에 &lt;a href="https://jeongil.dev/ko/blog/trends/ai-agent-co-work/">AI 코딩 툴과 협업하는 법&lt;/a>에서 AI와 협업하는 방법에 대해 쓴 적이 있는데, 그때는 &amp;ldquo;에이전트 하나를 잘 쓰는 법&amp;quot;이었습니다. 지금은 &lt;strong>&amp;ldquo;여러 에이전트를 어떻게 설계하느냐&amp;rdquo;&lt;/strong> 로 한달만에 질문이 바뀌게 되었네요.&lt;/p>
&lt;p>긴 글 읽어주셔서 감사합니다.&lt;/p>
&lt;h2>Reference&lt;span class="hx:absolute hx:-mt-20" id="reference">&lt;/span>
&lt;a href="#reference" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;ul>
&lt;li>&lt;a href="https://code.claude.com/docs/en/agent-teams"target="_blank" rel="noopener">Claude Code Agent Teams 공식 문서&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://code.claude.com/docs/en/sub-agents"target="_blank" rel="noopener">Claude Code Sub-Agents 공식 문서&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://code.claude.com/docs/en/custom-agents"target="_blank" rel="noopener">Claude Code Custom Agents 공식 문서&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.anthropic.com/news/claude-opus-4-6"target="_blank" rel="noopener">Claude Opus 4.6 발표&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/code-yeongyu/oh-my-opencode"target="_blank" rel="noopener">oh-my-opencode GitHub&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/Yeachan-Heo/oh-my-claudecode"target="_blank" rel="noopener">oh-my-claudecode GitHub&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/anomalyco/opencode"target="_blank" rel="noopener">OpenCode GitHub&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://openclaw.ai/"target="_blank" rel="noopener">OpenClaw&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/anomalyco/opencode/issues/6930"target="_blank" rel="noopener">GitHub Issue #6930 - OpenCode ToS Ban&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://news.ycombinator.com/item?id=46625918"target="_blank" rel="noopener">Hacker News - Anthropic Blocking OpenCode&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://venturebeat.com/technology/anthropic-cracks-down-on-unauthorized-claude-usage-by-third-party-harnesses"target="_blank" rel="noopener">VentureBeat - Anthropic Cracks Down on Unauthorized Claude Usage&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/mikekelly/claude-sneakpeek"target="_blank" rel="noopener">claude-sneakpeek GitHub&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://x.com/dhh/status/2009716350374293963"target="_blank" rel="noopener">DHH 트위터 - Anthropic 차단 비판&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://paddo.dev/blog/anthropic-walled-garden-crackdown/"target="_blank" rel="noopener">Paddo.dev - Anthropic&amp;rsquo;s Walled Garden Crackdown&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://paddo.dev/blog/claude-code-hidden-swarm/"target="_blank" rel="noopener">Paddo.dev - Claude Code Hidden Swarm&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.cnbc.com/2026/02/02/openclaw-open-source-ai-agent-rise-controversy-clawdbot-moltbot-moltbook.html"target="_blank" rel="noopener">CNBC - OpenClaw: Open-source AI agent rise, controversy&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.blog/changelog/2024-10-29-copilot-chat-in-github-mobile/"target="_blank" rel="noopener">GitHub Blog - Copilot Chat in GitHub Mobile&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>새벽 3시 에러 알림, 이제 AI가 알아서 고치게 하기: OpenClaw와 에러 자동화 이야기</title><link>https://jeongil.dev/ko/blog/trends/openclaw-error-autopilot/</link><pubDate>Fri, 06 Feb 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/trends/openclaw-error-autopilot/</guid><description>
&lt;p>안녕하세요. 프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 3년차 백엔드 개발자 정정일입니다.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>TL;DR&lt;/strong>&lt;br>
새벽 에러 알림 대응을 OpenClaw로 자동화했습니다.&lt;br>
Loki/Tempo 폴링 + 텔레그램 Forward 하이브리드 방식으로 AI가 에러 분석부터 PR 생성까지 처리하고, 사람은 코드리뷰만 합니다.&lt;/p>
&lt;/blockquote>
&lt;p>요즘 AI Agent가 개발자들의 협업 방식에서 점점 중심이 되어가고 있는 것 같습니다.&lt;/p>
&lt;p>커뮤니티를 살펴보면, 핫한 키워드는 전부 AI, AI Agent 등과 관련되어 있더라구요. &lt;a href="https://github.blog/news-insights/research/survey-ai-wave-grows/"target="_blank" rel="noopener">GitHub의 2024년 개발자 조사&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에 따르면, 미국·브라질·인도·독일 2,000명의 개발자 중 &lt;strong>97% 이상이 AI 코딩 도구를 사용한 경험&lt;/strong>이 있다고 답했고, 조직 차원에서도 &lt;strong>59~88%&lt;/strong> 가 AI 도구 사용을 허용하거나 적극 장려하고 있다고 합니다.&lt;/p>
&lt;p>기존에는 보안, 프라이버시, 정확성 문제 때문에 AI 도구 도입을 꺼리는 회사들도 많았는데, 이제는 GitHub Copilot, Claude Code 같은 AI Agent를 도입하는 회사들도 점점 늘어나고 있는 것 같습니다. 이제 AI는 단순히 &amp;ldquo;코드 자동완성&amp;rdquo; 수준을 넘어서, &lt;strong>자율적으로 파일을 읽고, 명령어를 실행하고, 코드를 수정하고, PR을 올리는&lt;/strong> 수준까지 왔습니다.&lt;/p>
&lt;p>이런 상황에서 어떻게하면 반복 작업들을 AI에게 맡기고, 더 중요한 일에 집중할 수 있을까 고민하게 되더라구요.&lt;/p>
&lt;p>이 글에서는 제가 어떻게 매일 겪는 &lt;strong>에러 알림 대응 작업&lt;/strong>을 AI 에이전트를 활용해 &lt;strong>자동화&lt;/strong>했는지 이야기해보려 합니다.&lt;/p>
&lt;h2>서비스 운영 개발자의 일상: 에러 알림과 씨름하기&lt;span class="hx:absolute hx:-mt-20" id="서비스-운영-개발자의-일상-에러-알림과-씨름하기">&lt;/span>
&lt;a href="#%ec%84%9c%eb%b9%84%ec%8a%a4-%ec%9a%b4%ec%98%81-%ea%b0%9c%eb%b0%9c%ec%9e%90%ec%9d%98-%ec%9d%bc%ec%83%81-%ec%97%90%eb%9f%ac-%ec%95%8c%eb%a6%bc%ea%b3%bc-%ec%94%a8%eb%a6%84%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>서비스를 운영하는 개발자라면 새벽 3시, 오후 7시, 아침 10시 등 언제나 불규칙적으로 휴대폰이 울리는 경험, 다들 한 번쯤은 겪어보셨을 겁니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>🚨 legacy-service - ERROR LOG!!! is Firing
Description: Pls Check it ASAP&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 알림이 오게 되면 눈 비비며 노트북을 켜고, Grafana 대시보드를 열고, Loki에서 에러 로그를 뒤지고, trace_id를 찾아 Tempo에서 요청 흐름을 추적하고, 코드베이스에서 해당 부분을 찾아 원인을 분석하게 됩니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
A[&amp;#34;🚨 에러 알림&amp;#34;] --&amp;gt; B[&amp;#34;Loki 로그 확인&amp;#34;]
B --&amp;gt; C[&amp;#34;Tempo 트레이스 추적&amp;#34;]
C --&amp;gt; D[&amp;#34;코드 분석&amp;#34;]
D --&amp;gt; E[&amp;#34;원인 특정&amp;#34;]
E --&amp;gt; F[&amp;#34;이슈/티켓 생성&amp;#34;]
F --&amp;gt; G[&amp;#34;코드 수정&amp;#34;]
G --&amp;gt; H[&amp;#34;PR 생성&amp;#34;]
&lt;/pre>&lt;p>&lt;strong>30분에서 1시간.&lt;/strong> 단순 버그라도 이 정도는 걸리게 됩니다. 복잡한 케이스면 훨씬 더 걸릴 수도 있겠죠.&lt;/p>
&lt;p>이런 과정은 서비스를 운영하는 개발자라면 누구나 하는 작업이지 않을까 싶습니다. 회사마다, 서비스마다 조금씩 도구나 템플릿은 다르겠지만 큰 틀은 비슷하죠.&lt;/p>
&lt;p>그렇다면 이 과정을 &lt;strong>AI가 대신하게 할 수 있지 않을까?&lt;/strong>&lt;/p>
&lt;p>매번 똑같은 패턴으로 에러를 처리하다 보니 이런 생각이 들었습니다. 로그 확인, 트레이스 추적, 코드 분석&amp;hellip; 이런 단계들은 정형화되어 있습니다. 그렇다면 AI에게 시킬 수 있지 않을까? 이 질문에서 모든 과정이 시작되었습니다.&lt;/p>
&lt;h2>과제 정의하기&lt;span class="hx:absolute hx:-mt-20" id="과제-정의하기">&lt;/span>
&lt;a href="#%ea%b3%bc%ec%a0%9c-%ec%a0%95%ec%9d%98%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>우선 제가 평소에 하던 작업을 쪼개봤습니다. 어떻게 자동화할 수 있을지 알려면 먼저 뭘 하는지 알아야 하니까요.&lt;/p>
&lt;p>먼저 &lt;strong>에러 로그가 오면 확인합니다.&lt;/strong>&lt;/p>
&lt;p>여기서 &amp;ldquo;확인&amp;quot;은 두 가지 의미를 포함합니다. 에러 Alert이 오면 이를 &lt;strong>인지&lt;/strong>하고, Loki/Tempo에서 관련 로그와 트레이스를 &lt;strong>조회&lt;/strong>해 파악할 수 있어야 한다는 거죠.&lt;/p>
&lt;p>또 에러 로그를 기반으로 코드베이스를 탐색해 &lt;strong>원인 분석&lt;/strong>을 하고 &lt;strong>에러 지점을 특정&lt;/strong>할 수 있어야 합니다. 문제는 저희 회사 서비스는 마이크로서비스 아키텍처로 구성되어 있어서, 에러가 발생한 서비스뿐만 아니라 연관된 다른 서비스들도 함께 살펴봐야 할 때가 많다는 점입니다.&lt;/p>
&lt;p>그리고 나아가, &lt;strong>이슈/티켓 생성 → 코드 수정 → PR 생성&lt;/strong>까지 해야하죠.&lt;/p>
&lt;p>그렇다면 AI가 저 대신 모든 작업을 마치기 위한 과제를 정리하면 이렇습니다.&lt;/p>
&lt;ol>
&lt;li>에러 인지&lt;/li>
&lt;li>로그/트레이스 조회&lt;/li>
&lt;li>원인 분석 및 에러 지점 특정&lt;/li>
&lt;li>이슈/티켓 생성&lt;/li>
&lt;li>코드 수정&lt;/li>
&lt;li>PR 생성&lt;/li>
&lt;/ol>
&lt;h2>첫 번째 시도: MCP로 반자동화&lt;span class="hx:absolute hx:-mt-20" id="첫-번째-시도-mcp로-반자동화">&lt;/span>
&lt;a href="#%ec%b2%ab-%eb%b2%88%ec%a7%b8-%ec%8b%9c%eb%8f%84-mcp%eb%a1%9c-%eb%b0%98%ec%9e%90%eb%8f%99%ed%99%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>그래서 처음에는 MCP(Model Context Protocol)를 사용해서 &lt;strong>&lt;a href="https://github.com/12OneTwo12/error-autopilot-mcp"target="_blank" rel="noopener">error-autopilot&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/strong> 이라는 도구를 만들었습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
subgraph MCP[&amp;#34;MCP 기반 반자동화&amp;#34;]
Human[&amp;#34;👨‍💻 개발자&amp;#34;] --&amp;gt;|&amp;#34;수동 트리거&amp;lt;br/&amp;gt;(/autopilot)&amp;#34;| Claude[&amp;#34;Claude Code&amp;#34;]
Claude &amp;lt;--&amp;gt;|&amp;#34;JSON-RPC&amp;#34;| Server[&amp;#34;error-autopilot&amp;lt;br/&amp;gt;MCP Server&amp;#34;]
Server --&amp;gt; Loki[&amp;#34;Loki&amp;#34;]
Server --&amp;gt; Tempo[&amp;#34;Tempo&amp;#34;]
Claude --&amp;gt;|&amp;#34;분석 결과&amp;#34;| Issue[&amp;#34;GitHub Issue&amp;#34;]
end
&lt;/pre>&lt;p>MCP 서버가 Loki/Tempo API를 호출해 로그를 조회하는 도구였습니다. 개발자가 Agent에게 &lt;code>/autopilot&lt;/code> 명령어를 치면, MCP 서버가 Loki/Tempo에서 에러 로그와 트레이스를 조회해 분석합니다.&lt;/p>
&lt;p>이를 통해 &lt;strong>로그 조회 및 트레이스 분석&lt;/strong>은 가능해졌습니다. 그렇다면 어떻게 세번째 과제인 &lt;strong>원인 분석 및 에러 지점 특정&lt;/strong>을 할 수 있을까요?&lt;/p>
&lt;p>저는 조금 무식한 방법을 사용했습니다. 어차피 나만 사용할 MCP였으니 로컬에 이미 가지고 있는 코드베이스를 Claude Code가 읽도록 한 거죠.&lt;/p>
&lt;p>MCP Skills 기능을 활용해 에러로그를 확인하고 나면 탐색해야 할 서비스들의 코드베이스 경로를 매핑해뒀습니다. 이렇게 되면 마이크로서비스 아키텍처라도 관련된 서비스들의 코드를 모두 읽을 수 있었습니다.&lt;/p>
&lt;p>APM인 Tempo를 통해 관련 서비스들을 파악하고, 미리 매핑해둔 코드베이스 경로를 통해 코드를 읽고 분석하는 방식이었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-markdown" data-lang="markdown">&lt;span class="line">&lt;span class="cl">| 서비스명 | 로컬 코드베이스 경로 | GitHub 리포 |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">|---------|----------------|-------------|
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| example-user-service | /Users/jeongjeong-il/Desktop/projects/example-user-service | 12OneTwo12/example-user-service |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| example-order-service | /Users/jeongjeong-il/Desktop/projects/example-order-service | 12OneTwo12/example-order-service |&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>코드베이스를 분석하고 원인을 특정하면 GitHub 이슈를 만들어주는 방식이었습니다.&lt;/p>
&lt;p>꽤 유용했습니다. 로그 뒤지는 시간이 확 줄었거든요.&lt;/p>
&lt;h3>MCP Action Screen&lt;span class="hx:absolute hx:-mt-20" id="mcp-action-screen">&lt;/span>
&lt;a href="#mcp-action-screen" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align: center">Triger&lt;/th>
&lt;th style="text-align: center">Action&lt;/th>
&lt;th style="text-align: center">Result&lt;/th>
&lt;th style="text-align: center">Created ISSUE&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align: center">&lt;img src="https://github.com/user-attachments/assets/99f4c410-70b6-4e03-8ef8-1bca025e2049" alt="" loading="lazy" />&lt;/td>
&lt;td style="text-align: center">&lt;img src="https://github.com/user-attachments/assets/b46760a5-f8e9-4967-9665-4b591325b9bb" alt="" loading="lazy" />&lt;/td>
&lt;td style="text-align: center">&lt;img src="https://github.com/user-attachments/assets/e95a5460-ea5a-498b-88a2-ae197e3ff621" alt="" loading="lazy" />&lt;/td>
&lt;td style="text-align: center">&lt;img src="https://github.com/user-attachments/assets/befff3df-fe3b-495d-aff3-f284afc38c67" alt="" loading="lazy" />&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3>하지만 한계가 명확했습니다&lt;span class="hx:absolute hx:-mt-20" id="하지만-한계가-명확했습니다">&lt;/span>
&lt;a href="#%ed%95%98%ec%a7%80%eb%a7%8c-%ed%95%9c%ea%b3%84%ea%b0%80-%eb%aa%85%ed%99%95%ed%96%88%ec%8a%b5%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>사용하면서 점점 아쉬운 부분이 보이기 시작했습니다. 문제는 &lt;strong>수동 트리거&lt;/strong>였습니다.&lt;/p>
&lt;p>알림이 오면 제가 직접 &lt;code>/autopilot&lt;/code> 명령어를 치거나 &amp;ldquo;에러 로그 확인해봐&amp;quot;와 같은 질의를 명령해야 했습니다. 로그 조회와 분석은 자동화됐지만, &lt;strong>시작은 여전히 제 손으로&lt;/strong> 해야 했죠.&lt;/p>
&lt;p>&lt;strong>6가지 과제 중 첫 번째인 &amp;ldquo;에러 인지&amp;rdquo; 부분이 자동화되지 않은 겁니다.&lt;/strong>&lt;/p>
&lt;p>진짜 자동화라고 하기엔 뭔가 부족했습니다. 이건 &amp;ldquo;반&amp;quot;자동화였습니다. 자동화를 위해서는 에러가 발생했을 때 AI가 스스로 인지하고 시작할 수 있어야 했습니다.&lt;/p>
&lt;h2>OpenClaw 발견: Notification을 트리거로&lt;span class="hx:absolute hx:-mt-20" id="openclaw-발견-notification을-트리거로">&lt;/span>
&lt;a href="#openclaw-%eb%b0%9c%ea%b2%ac-notification%ec%9d%84-%ed%8a%b8%eb%a6%ac%ea%b1%b0%eb%a1%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>그러다 개발자 커뮤니티 최근 굉장히 뜨거운 주제인 &lt;a href="https://github.com/openclaw/openclaw"target="_blank" rel="noopener">OpenClaw&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>를 발견했습니다.&lt;/p>
&lt;p>OpenClaw란 최근 화두가 되고 있는 오픈소스로 로컬 환경에서 실행되어 사용자의 쉘·파일 시스템 접근권한과 컴퓨터 제어 능력을 갖춘 LLM 기반 개인 비서입니다.&lt;/p>
&lt;p>쉽게 생각하면 &amp;ldquo;내 컴퓨터에 설치된 AI 비서&amp;quot;라고 할 수 있죠. 그러면 지금까지 AI Agent와 뭐가 다른 걸까요? Clade Code 같은 AI Agent도 로컬에서 실행되잖아요? 쉘, 파일 시스템 접근권한도 있고요.&lt;/p>
&lt;p>OpenClaw의 진짜 차별점은 &lt;strong>24시간 대기 상태로 텔레그램, 슬랙, 디스코드 등에서 오는 메시지를 실시간으로 감지&lt;/strong>한다는 점입니다 (로컬이 계속 켜져있다는 가정하에).&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>Telegram ──┐
WhatsApp ──┤
Slack ──┼──▶ [ Gateway ] ──▶ AI 모델 (Claude/OpenAI)
Discord ──┤ │
웹 UI ───┘ ▼
파일, 브라우저,
명령어 실행 등&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;ul>
&lt;li>&lt;strong>Gateway&lt;/strong>: 모든 채널 연결을 관리하는 중앙 프로세스&lt;/li>
&lt;li>&lt;strong>Workspace&lt;/strong>: AI 에이전트의 &amp;ldquo;집&amp;rdquo; (&lt;code>~/.openclaw/workspace/&lt;/code>)&lt;/li>
&lt;li>&lt;strong>Skills&lt;/strong>: 워크플로우를 마크다운으로 정의&lt;/li>
&lt;/ul>
&lt;p>기존 Agent들은 제가 명령어를 쳐야 AI가 반응했습니다. 하지만 OpenClaw는 &lt;strong>메시지가 오면 AI가 자동으로 반응&lt;/strong>합니다.&lt;/p>
&lt;p>여기서 눈치채신 분들도 있겠지만, 이렇게 되면 &lt;strong>에러 알림 → AI 에이전트 자동 분석 → PR 생성&lt;/strong>까지 자동화가 가능해질 거라 판단했습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph After[&amp;#34;OpenClaw (자동화)&amp;#34;]
Alert2[&amp;#34;Grafana Alert&amp;#34;] --&amp;gt; TG2[&amp;#34;Telegram&amp;#34;]
TG2 --&amp;gt;|&amp;#34;자동 트리거&amp;#34;| AI2[&amp;#34;AI Agent&amp;#34;]
AI2 --&amp;gt; PR[&amp;#34;PR 생성&amp;#34;]
end
subgraph Before[&amp;#34;MCP (반자동화)&amp;#34;]
Alert1[&amp;#34;Grafana Alert&amp;#34;] --&amp;gt; TG1[&amp;#34;Telegram&amp;#34;]
TG1 --&amp;gt; Human1[&amp;#34;👨‍💻 개발자&amp;#34;]
Human1 --&amp;gt;|&amp;#34;수동 트리거&amp;#34;| AI1[&amp;#34;AI&amp;#34;]
end
&lt;/pre>&lt;p>이렇게 구성해두면 Grafana Alert에 의해 특정 메신저에 Alert이 오면 &lt;strong>그 메시지 자체가 트리거&lt;/strong>가 되고 사람이 개입하지 않아도 에이전트가 알아서 분석을 시작하고, 코드를 수정하고, PR까지 올릴 수 있게 될거라 생각했습니다.&lt;/p>
&lt;h2>구현 시도: Grafana Alert를 트리거로&lt;span class="hx:absolute hx:-mt-20" id="구현-시도-grafana-alert를-트리거로">&lt;/span>
&lt;a href="#%ea%b5%ac%ed%98%84-%ec%8b%9c%eb%8f%84-grafana-alert%eb%a5%bc-%ed%8a%b8%eb%a6%ac%ea%b1%b0%eb%a1%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>바로 구현에 들어갔습니다. OpenClaw로 어떻게 error-autopilot을 만들었는지 핵심만 정리하면 이렇습니다.&lt;/p>
&lt;p>우선 &lt;code>~/.openclaw/workspace/&lt;/code> 에 페르소나를 정의해줍니다.&lt;/p>
&lt;p>Openclaw는 처음 키면 본인의 이름이나 페르소나를 정의해달라고 요청합니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/j7oj177lzy262n6y7i6b5/FB3C6358-5926-42C9-8D39-38965192BB61.jpg?rlkey=bimb8175chh3vko1evvwc4zh3&amp;amp;st=3mg5fqvv&amp;amp;raw=1" alt="페르소나 지정" loading="lazy" />&lt;/p>
&lt;p>정체성을 정의하면 다음 파일들을 자동으로 생성해줍니다. 저는 Son of Victor라는 이름을 붙여줬습니다. 미국 드라마 Silicon Valley에 나오는 AI 이름 Son of Anton에서 따온 이름입니다. ㅎㅎ&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>~/.openclaw/workspace/
├── SOUL.md # 성격과 말투
├── USER.md # 사용자 정보
├── IDENTITY.md # 이름과 정체성
├── BOOTSTRAP.md # 최초 실행 시 읽고 삭제
├── MEMORY.md # 장기 기억
├── memory/ # 일별 메모
└── skills/ # 워크플로우 정의&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/ipx47vuifreio2pmkbgu3/5C66C2FA-7678-41B9-849A-FEC66EE076CD.jpg?rlkey=b2sp8xq4n6o9q2xzfsxvifuek&amp;amp;st=r3dn3ypi&amp;amp;raw=1" alt="페르소나 생성" loading="lazy" />&lt;/p>
&lt;p>이렇게 기본적인 셋업이 끝나면, 다음으로는 &lt;strong>메시지를 받을 채널 설정&lt;/strong>과 &lt;strong>에러 자동 분석 Skill 정의&lt;/strong>를 했습니다.&lt;/p>
&lt;p>먼제 기존에 회사에서 운영 중인 Grafana Alert가 텔레그램으로 통해 전송되도록 설정돼 있기때문에 OpenClaw를 위한 텔레그램 봇을 하나 만들고 OpenClaw에 연결했습니다.&lt;/p>
&lt;h3>1. 텔레그램 채널 설정&lt;span class="hx:absolute hx:-mt-20" id="1-텔레그램-채널-설정">&lt;/span>
&lt;a href="#1-%ed%85%94%eb%a0%88%ea%b7%b8%eb%9e%a8-%ec%b1%84%eb%84%90-%ec%84%a4%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>텔레그램에 Grafana Alert 전용 그룹도 OpenClaw에 연결해줬습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;channels&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;telegram&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;groups&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;-100XXXXXXXXXX&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;enabled&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="kc">true&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;requireMention&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="kc">false&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;-100YYYYYYYYYY&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;enabled&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="kc">true&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;requireMention&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="kc">false&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;code>requireMention: false&lt;/code>를 설정하면 그룹에 메시지가 오는 순간, 멘션 없이도 OpenClaw가 바로 반응합니다.&lt;/p>
&lt;p>계획은 생각보다 간단했습니다.&lt;/p>
&lt;ol>
&lt;li>Grafana가 텔레그램 그룹에 에러 알림 전송&lt;/li>
&lt;li>OpenClaw가 메시지 감지&lt;/li>
&lt;li>자동으로 error-autopilot Skill 실행&lt;/li>
&lt;li>에러 원인 파악 및 이슈생성, PR 생성&lt;/li>
&lt;/ol>
&lt;h3>2. Skill 정의&lt;span class="hx:absolute hx:-mt-20" id="2-skill-정의">&lt;/span>
&lt;a href="#2-skill-%ec%a0%95%ec%9d%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>OpenClaw에서는 워크플로우를 &lt;strong>마크다운 문서(Skill)&lt;/strong> 로 정의합니다.&lt;/p>
&lt;p>MCP처럼 TypeScript로 서버를 만들 필요가 없습니다. 마크다운 파일 하나면 됩니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;span class="lnt">45
&lt;/span>&lt;span class="lnt">46
&lt;/span>&lt;span class="lnt">47
&lt;/span>&lt;span class="lnt">48
&lt;/span>&lt;span class="lnt">49
&lt;/span>&lt;span class="lnt">50
&lt;/span>&lt;span class="lnt">51
&lt;/span>&lt;span class="lnt">52
&lt;/span>&lt;span class="lnt">53
&lt;/span>&lt;span class="lnt">54
&lt;/span>&lt;span class="lnt">55
&lt;/span>&lt;span class="lnt">56
&lt;/span>&lt;span class="lnt">57
&lt;/span>&lt;span class="lnt">58
&lt;/span>&lt;span class="lnt">59
&lt;/span>&lt;span class="lnt">60
&lt;/span>&lt;span class="lnt">61
&lt;/span>&lt;span class="lnt">62
&lt;/span>&lt;span class="lnt">63
&lt;/span>&lt;span class="lnt">64
&lt;/span>&lt;span class="lnt">65
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-markdown" data-lang="markdown">&lt;span class="line">&lt;span class="cl">&lt;span class="gh"># Error Autopilot Skill
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gh">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">## Trigger
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>&lt;span class="k">-&lt;/span> Heartbeat (주기적 자동 실행)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">-&lt;/span> 또는 사람이 텔레그램에서 메시지 Forward
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">## Workflow
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">### 1. Fetch logs from Loki and Tempo
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>&lt;span class="gh"># 마지막 체크 시간 이후의 에러 조회
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gh">&lt;/span>START_TIME=$(jq -r &amp;#39;.lastCheckTime.dev&amp;#39; memory/error-autopilot-state.json)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gh"># DEV 환경
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gh">&lt;/span>curl -s &amp;#34;https://example.com/loki/loki/api/v1/query_range&amp;#34; \
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> -H &amp;#34;X-Scope-OrgID: default&amp;#34; \
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> --data-urlencode &amp;#39;query={deployment_environment=&amp;#34;dev&amp;#34;} |~ &amp;#34;error|ERROR&amp;#34; | level=~&amp;#34;error|ERROR&amp;#34;&amp;#39; \
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> --data-urlencode &amp;#34;start=${START_TIME}000000&amp;#34; \
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> --data-urlencode &amp;#34;end=$(date +%s)000000000&amp;#34; \
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> --data-urlencode &amp;#34;limit=20&amp;#34;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">새 에러 발견 시:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">1.&lt;/span> trace_id 추출
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">2.&lt;/span> 이미 처리된 trace_id인지 확인 (&lt;span class="sb">`processedTraceIds`&lt;/span>)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">3.&lt;/span> 새 에러면 분석 시작
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">### 1단계: 에러 파싱
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>&lt;span class="k">-&lt;/span> 로그에서 서비스명, trace_id, 에러 메시지 추출
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">-&lt;/span> 환경 확인 (dev/prod)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">### 2단계: Tempo 트레이스 조회 (필수!)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>⚠️ &lt;span class="gs">**이 단계를 건너뛰지 마세요!**&lt;/span> Loki 로그만 보고 추측하면 안 됩니다.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">#### 개발 환경
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>curl -s &amp;#34;https://dev.example.com/tempo/api/traces/${TRACE_ID}&amp;#34; \
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> -H &amp;#34;X-Scope-OrgID: default&amp;#34;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">##### 운영 환경
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>curl -s &amp;#34;https://prod.example.com/tempo/api/traces/${TRACE_ID}&amp;#34; \
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> -H &amp;#34;X-Scope-OrgID: default&amp;#34;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">### 2. Analyze codebase
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>서비스 매핑을 통한 로컬 코드베이스에서 에러 발생 지점 찾기
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| Service | Local Path | GitHub Repo |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">|---------|-----------|-------------|
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| example-user-service | /path/to/example-user | 12OneTwo12/example-user-service |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">### 3. Create GitHub Issue
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>gh CLI로 이슈 생성
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">### 4. Decide on auto-fix
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>**자동 수정 금지 조건:**
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">-&lt;/span> 비즈니스 로직 관련
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">-&lt;/span> 여러 파일 수정 필요
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">-&lt;/span> 보안 관련
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">-&lt;/span> 불확실한 경우
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**자동 수정 가능:**&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">-&lt;/span> 단순 NPE (명확한 null 체크 위치)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">-&lt;/span> 명백한 validation 누락
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">-&lt;/span> 오타나 설정 오류
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">### 5. Create PR (if approved)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>브랜치 생성 → 코드 수정 → 커밋 &lt;span class="err">&amp;amp;&lt;/span> 푸시 → PR 생성&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>AI가 이 가이드를 읽고 단계별로 실행합니다.&lt;/p>
&lt;h2>테스트: 예상대로 동작하는지 확인&lt;span class="hx:absolute hx:-mt-20" id="테스트-예상대로-동작하는지-확인">&lt;/span>
&lt;a href="#%ed%85%8c%ec%8a%a4%ed%8a%b8-%ec%98%88%ec%83%81%eb%8c%80%eb%a1%9c-%eb%8f%99%ec%9e%91%ed%95%98%eb%8a%94%ec%a7%80-%ed%99%95%ec%9d%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이렇게 설정을 마치고 테스트를 해봤습니다. 간단한 유효성 검사 실패 예외를 발생시키고 텔레그램 그룹에 직접 메시지를 발생했죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>🚨 chat-service - ERROR LOG!!!
Description: Pls Check it ASAP&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>OpenClaw가 즉시 반응했습니다.&lt;/strong> Loki를 조회하고, 코드를 분석하고, GitHub 이슈를 만들고 원인을 특정해 PR까지 생성했습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/iy75r7yid6wed7f6s7acd/E9955AA6-A06F-44D8-A6EB-C1DF4274B16E.jpg?rlkey=m2nssrzfm5uypia6kfvdgiqm6&amp;amp;st=dkcgc5gu&amp;amp;raw=1" alt="" loading="lazy" />&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/n7oc7ys210wu8h71f18sc/9E45A3DA-F469-4CE7-9A07-5E761F19FC6C.jpg?rlkey=nmn6yvo8hx4ng1ufp07mn88ge&amp;amp;st=oi8i9kxn&amp;amp;raw=1" alt="" loading="lazy" />&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/ke6gteppxzxh6bdald7c2/7E88D40F-92B8-4268-84DA-2A547451F7DC.jpg?rlkey=qqn2xrzzeiepm0kqw7ckwpdko&amp;amp;st=9bl69075&amp;amp;raw=1" alt="" loading="lazy" />&lt;/p>
&lt;p>테스트 환경에서는 정상적으로 동작했습니다. 이제 실제 에러가 발생했을 때 어떻게 동작하는지 확인할 차례였습니다.&lt;/p>
&lt;h2>실전: 텔레그램 봇 API의 제약&lt;span class="hx:absolute hx:-mt-20" id="실전-텔레그램-봇-api의-제약">&lt;/span>
&lt;a href="#%ec%8b%a4%ec%a0%84-%ed%85%94%eb%a0%88%ea%b7%b8%eb%9e%a8-%eb%b4%87-api%ec%9d%98-%ec%a0%9c%ec%95%bd" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>며칠 뒤, 실제로 에러가 발생했습니다.&lt;/p>
&lt;p>텔레그램에 다음과 같은 Grafana 예외 알림이 왔습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>🚨 legacy-service - ERROR LOG!!! is Firing
Description: Pls Check it ASAP&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>그런데 &lt;strong>Son of Victor(OpenClaw)가 반응하지 않았습니다.&lt;/strong>&lt;/p>
&lt;p>테스트에서는 분명히 작동했는데, 실제 환경에서는 왜 안 되는 걸까요? 설정을 다시 확인했습니다. 문제없었습니다. OpenClaw 로그를 열어봤습니다. 아무 메시지도 받지 못한 상태였습니다.&lt;/p>
&lt;p>테스트 환경과 실제 환경의 차이를 하나하나 따져보기 시작했습니다. 메시지 포맷도 같고, 텔레그램 그룹 ID도 같고&amp;hellip; 발신자가 다르다는 것밖에 차이가 없었습니다.&lt;/p>
&lt;h3>문제 발견: 텔레그램 봇 간 통신 제약&lt;span class="hx:absolute hx:-mt-20" id="문제-발견-텔레그램-봇-간-통신-제약">&lt;/span>
&lt;a href="#%eb%ac%b8%ec%a0%9c-%eb%b0%9c%ea%b2%ac-%ed%85%94%eb%a0%88%ea%b7%b8%eb%9e%a8-%eb%b4%87-%ea%b0%84-%ed%86%b5%ec%8b%a0-%ec%a0%9c%ec%95%bd" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>문서를 찾아보니 원인을 알 수 있었습니다.&lt;/p>
&lt;p>&lt;strong>텔레그램 Bot API는 다른 봇이 보낸 메시지를 받을 수 없었습니다.&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>Grafana Bot --[메시지 전송]--&amp;gt; Telegram Group
↓
OpenClaw Bot (수신 불가 ❌)
사람 --[메시지 전송]--&amp;gt; Telegram Group
↓
OpenClaw Bot (수신 가능 ✅)&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>제가 보낸 테스트 메시지는 &amp;ldquo;사람&amp;quot;이 보낸 거라 작동했고, Grafana 봇이 보낸 실제 알림은 &amp;ldquo;봇&amp;quot;이 보낸 거라 작동하지 않았던 겁니다.&lt;/p>
&lt;p>&lt;a href="https://core.telegram.org/bots/api#available-types"target="_blank" rel="noopener">텔레그램 봇 API 공식 문서&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>를 확인해보니, 이는 의도된 보안 정책이었습니다. 봇 간 무한 루프나 스팸을 방지하기 위한 설계였죠. 보안 정책상 당연한 선택이지만, 제 계획에는 꽤나 위협적이였습니다.&lt;/p>
&lt;h2>해결 방안 고민: 실시간 vs 폴링&lt;span class="hx:absolute hx:-mt-20" id="해결-방안-고민-실시간-vs-폴링">&lt;/span>
&lt;a href="#%ed%95%b4%ea%b2%b0-%eb%b0%a9%ec%95%88-%ea%b3%a0%eb%af%bc-%ec%8b%a4%ec%8b%9c%ea%b0%84-vs-%ed%8f%b4%eb%a7%81" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>텔레그램 트리거가 막혔으니, 다른 방법을 찾아야 했습니다. Slack과 Discord도 확인해봤지만 비슷한 제약이 있었습니다. Slack은 프레임워크가 봇 메시지를 필터링하고, Discord는 봇 간 통신 자체가 제한됩니다. 다른 메신저로 바꾸는 건 근본적인 해결책이 아니었습니다.&lt;/p>
&lt;p>크게 두 가지 접근 방식이 있었습니다.&lt;/p>
&lt;p>&lt;strong>1. Webhook 방식 (실시간)&lt;/strong>
Grafana가 에러 발생 시 직접 webhook을 보내는 방식입니다. Grafana Contact points에 OpenClaw webhook endpoint를 추가하는거죠. 이를 위해서는 &lt;strong>Tailscale Funnel&lt;/strong>를 통해 로컬 환경을 외부에 노출하거나 AWS Lambda, Cloud Run 등에 &lt;strong>Cloud 배포&lt;/strong>하는 방식을 선택해야했습니다.&lt;/p>
&lt;p>&lt;strong>2. Polling 방식 (지연)&lt;/strong>
주기적으로 Loki/Tempo를 직접 조회하는 방식입니다. CronJob과 같은 형태로 말이죠.&lt;/p>
&lt;p>하지만 실시간 트리거가 정말 필요한지부터 고민했습니다. 새벽 3시에 에러가 나도 어차피 아침에 확인할 텐데, 실시간성을 꼭 고집해야할까 싶었습니다.&lt;/p>
&lt;p>두 가지 방식을 비교해봤습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>방식&lt;/th>
&lt;th>응답 속도&lt;/th>
&lt;th>비용&lt;/th>
&lt;th>보안&lt;/th>
&lt;th>구현 난이도&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Polling&lt;/strong>&lt;/td>
&lt;td>Cron 시간에 따른 지연&lt;/td>
&lt;td>무료&lt;/td>
&lt;td>안전&lt;/td>
&lt;td>낮음&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Webhook + Tailscale Funnel&lt;/strong>&lt;/td>
&lt;td>실시간&lt;/td>
&lt;td>무료&lt;/td>
&lt;td>외부 노출 위험&lt;/td>
&lt;td>중간&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Webhook + Cloud 배포&lt;/strong>&lt;/td>
&lt;td>실시간&lt;/td>
&lt;td>$5-20/월&lt;/td>
&lt;td>관리 필요&lt;/td>
&lt;td>높음&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;strong>Polling 방식&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Cron 시간마다 Loki/Tempo를 직접 확인&lt;/li>
&lt;li>새 에러 발견 시 처리 시작&lt;/li>
&lt;li>외부 노출 없음, 로컬에서 안전하게 실행&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Webhook + Tailscale Funnel&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Grafana webhook을 받기 위해 로컬 환경을 인터넷에 노출&lt;/li>
&lt;li>실시간 트리거 가능하지만 보안 위험&lt;/li>
&lt;li>&lt;a href="https://tailscale.com/kb/1223/tailscale-funnel/"target="_blank" rel="noopener">Tailscale Funnel&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>로 로컬을 노출하면 편리하지만, OpenClaw가 공개 인터넷에 접근 가능해지면서 악의적인 webhook 요청을 통한 Prompt injection이나 무차별 API 호출 등의 위험이 있습니다.&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Webhook + Cloud 배포&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Grafana webhook을 받을 서버를 클라우드에 배포&lt;/li>
&lt;li>실시간 트리거 가능하지만 비용 발생&lt;/li>
&lt;li>인프라 관리 및 보안 설정 필요&lt;/li>
&lt;/ul>
&lt;h3>Polling 방식 선택&lt;span class="hx:absolute hx:-mt-20" id="polling-방식-선택">&lt;/span>
&lt;a href="#polling-%eb%b0%a9%ec%8b%9d-%ec%84%a0%ed%83%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>우선 Tailscale Funnel방식은 보안 위험이 컸습니다. Prompt Injection, 토큰 무차별 대입, DDoS 공격 등 다양한 위협에 노출될 수 있었기에 제외하고 생각했습니다.&lt;/p>
&lt;p>남은 방법은 Cloud 배포를 하거나 Polling 방식이었습니다. 굳이 실시간성이 필요하진 않겠다 싶어 비용과 관리 측면도 생각해 저는 &lt;strong>Polling 방식을 선택&lt;/strong>했습니다.&lt;/p>
&lt;h2>최종 구현: Heartbeat로 주기 체크&lt;span class="hx:absolute hx:-mt-20" id="최종-구현-heartbeat로-주기-체크">&lt;/span>
&lt;a href="#%ec%b5%9c%ec%a2%85-%ea%b5%ac%ed%98%84-heartbeat%eb%a1%9c-%ec%a3%bc%ea%b8%b0-%ec%b2%b4%ed%81%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>Polling 방식으로 결정했으니, 이제 어떻게 구현할지 고민해야 했습니다.&lt;/p>
&lt;p>OpenClaw 문서를 살펴보니 주기적 작업 실행을 위해 두 가지 방법을 제공하고 있었습니다.&lt;/p>
&lt;h3>구현 방식 비교&lt;span class="hx:absolute hx:-mt-20" id="구현-방식-비교">&lt;/span>
&lt;a href="#%ea%b5%ac%ed%98%84-%eb%b0%a9%ec%8b%9d-%eb%b9%84%ea%b5%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>1. Heartbeat (OpenClaw 내장)&lt;/strong>&lt;/p>
&lt;p>메인 프로세스가 스스로 깨어나는 방식입니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// agents.json
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;agents&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;defaults&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;heartbeat&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;intervalMs&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">1800000&lt;/span> &lt;span class="c1">// 30분
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>장점은 설정이 간단하고 OpenClaw 프로세스 내에서 관리된다는 점입니다.&lt;/p>
&lt;p>단점은 OpenClaw 프로세스가 종료되면 함께 멈추고 로컬 PC 재부팅 시 수동으로 재시작 필요하다는 점이였습니다.&lt;/p>
&lt;p>&lt;strong>2. Cron Job (외부 스케줄러)&lt;/strong>&lt;/p>
&lt;p>Cron Job 방식은 외부의 독립적인 알람이 깨워주는 방식입니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># OpenClaw cron 설정&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">cron add --schedule &lt;span class="s2">&amp;#34;*/30 * * * *&amp;#34;&lt;/span> --task &lt;span class="s2">&amp;#34;Loki에서 에러 체크하고 error-autopilot 실행&amp;#34;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>장점은 OpenClaw 메인 세션이 죽어도 Cron Job은 살아서 계속 실행되고 격리된 세션에서 독립적으로 동작하기 때문에 좀 더 안정적이다고 할 수 있을 것 같습니다.&lt;/p>
&lt;p>단점은 설정이 조금 더 복잡해지고 별도의 Cron Job 관리 필요합니다. 다만 OpenClaw는 UI로도 Cron Job을 관리하는 기능을 제공해주기 때문에 크게 어렵진 않았습니다.&lt;/p>
&lt;h3>선택 근거&lt;span class="hx:absolute hx:-mt-20" id="선택-근거">&lt;/span>
&lt;a href="#%ec%84%a0%ed%83%9d-%ea%b7%bc%ea%b1%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>처음에는 Cron Job이 안정적이라 매력적이었습니다. OpenClaw 프로세스와 독립적으로 실행되니까요.&lt;/p>
&lt;p>하지만 Heartbeat가 설정이 훨씬 간단하다는 점이 컸습니다. 그리고 &amp;ldquo;OpenClaw가 죽으면 Heartbeat도 멈춘다&amp;quot;는 단점은 사실 문제가 아니었습니다. OpenClaw는 설치 시 &lt;strong>OS 레벨의 서비스&lt;/strong>(macOS LaunchAgent, Linux systemd 등)로 등록되기 때문에 프로세스가 종료되거나 PC를 재부팅해도 자동으로 다시 실행됩니다.&lt;/p>
&lt;p>그래서 &lt;strong>Heartbeat를 선택했습니다.&lt;/strong> 설정이 간단하고, OpenClaw 자체가 프로세스 복구를 해주니 Cron Job 못지않게 안정적이었습니다. Heartbeat 주기는 30분으로 설정해 30분마다 에러를 체크하도록 했습니다.&lt;/p>
&lt;p>너무 자주 Heartbeat를 돌리게 되면 토큰 비용이 많이 들 수 있기 때문에 30분 주기가 적절하다고 판단했습니다.&lt;/p>
&lt;p>그런데 30분 지연이 여전히 찝찝하기도 했습니다. 완전 자동화라고 하기엔 뭔가 부족한 느낌이었죠. 고민 끝에 &lt;strong>하이브리드 방식&lt;/strong>으로도 가능하겠다 싶었습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph &amp;#34;일반 상황 (자동)&amp;#34;
Cron1[&amp;#34;⏰ 30분마다&amp;lt;br/&amp;gt;Heartbeat&amp;#34;] --&amp;gt; Auto[&amp;#34;자동 처리&amp;#34;]
end
subgraph &amp;#34;긴급 상황 (수동)&amp;#34;
Alert[&amp;#34;📱 에러 알림&amp;lt;br/&amp;gt;확인&amp;#34;] --&amp;gt; Forward[&amp;#34;메시지&amp;lt;br/&amp;gt;Forward&amp;#34;] --&amp;gt; Manual[&amp;#34;즉시 처리&amp;#34;]
end
&lt;/pre>&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/5spvynh7iwdx81v95amuy/73A570CA-50F4-4B16-A461-82715D359A29.jpg?rlkey=n958h679jpjvjhn78h8qgv4bu&amp;amp;st=zo71v7mj&amp;amp;raw=1" alt="" loading="lazy" />&lt;/p>
&lt;p>&lt;strong>일반 상황&lt;/strong>: Heartbeat가 30분마다 자동으로 폴링해서 처리
&lt;strong>긴급 상황&lt;/strong>: 텔레그램 그룹에서 메시지를 Forward하면 즉시 처리&lt;/p>
&lt;h3>텔레그램 Forward 메커니즘&lt;span class="hx:absolute hx:-mt-20" id="텔레그램-forward-메커니즘">&lt;/span>
&lt;a href="#%ed%85%94%eb%a0%88%ea%b7%b8%eb%9e%a8-forward-%eb%a9%94%ec%bb%a4%eb%8b%88%ec%a6%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>텔레그램은 봇 간 메시지를 차단하는 보안 정책이 있습니다. Grafana 봇이 보낸 메시지를 OpenClaw 봇이 직접 받을 수 없죠.&lt;/p>
&lt;p>그런데 &lt;strong>봇이 보낸 메시지를 &amp;lsquo;사람이&amp;rsquo; Forward하면?&lt;/strong>&lt;/p>
&lt;p>텔레그램 입장에서는 그게 사람이 보낸 메시지가 됩니다. 결국 OpenClaw가 받을 수 있는 거죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>Grafana Bot → [🚨 에러!] → 텔레그램 그룹
↓
사람이 Forward
↓
OpenClaw Bot ✅ 수신 가능&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;a href="https://core.telegram.org/bots/api#message"target="_blank" rel="noopener">텔레그램 봇 API 공식 문서&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>를 확인해보면, Forward된 메시지는 &lt;code>forward_from&lt;/code> 필드를 가지지만 메시지의 발신자는 Forward를 실행한 사람이 됩니다. 즉, 봇 간 통신 차단 정책을 우회하는 것이 아니라, &lt;strong>사람의 명시적인 액션이 개입되었기 때문에 정상적인 사용 사례로 간주&lt;/strong>되는 것입니다.&lt;/p>
&lt;p>이렇게 되면 일반 상황에서는 30분 폴링으로 자동 처리돼 비용 효율적이고 보안을 지키면서, 긴급 상황에서는 사람이 Forward로 즉시 처리를 요청할 수 있습니다.&lt;/p>
&lt;h3>실제 동작 시나리오&lt;span class="hx:absolute hx:-mt-20" id="실제-동작-시나리오">&lt;/span>
&lt;a href="#%ec%8b%a4%ec%a0%9c-%eb%8f%99%ec%9e%91-%ec%8b%9c%eb%82%98%eb%a6%ac%ec%98%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>시나리오 1: 자동 처리 (일반적인 경우)&lt;/strong>
새벽 3시 DEV 환경에서 에러가 발생하면:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>3:00&lt;/strong> - Grafana가 텔레그램으로 알림 (사람에게 즉시 알림)&lt;/li>
&lt;li>&lt;strong>3:30&lt;/strong> - Heartbeat가 Loki에서 새 에러 감지&lt;/li>
&lt;li>&lt;strong>3:35&lt;/strong> - OpenClaw가 분석 완료, PR 생성&lt;/li>
&lt;li>&lt;strong>3:36&lt;/strong> - DEV 텔레그램 그룹(-100XXXXXXXXXX)에 처리 결과 전송&lt;/li>
&lt;li>&lt;strong>9:00&lt;/strong> - 아침 출근, PR 확인 및 머지&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>시나리오 2: 수동 트리거 (긴급한 경우)&lt;/strong>
운영 환경에서 급한 에러가 발생하면:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>10:15&lt;/strong> - Grafana 알림 확인&lt;/li>
&lt;li>&lt;strong>10:16&lt;/strong> - 텔레그램에서 메시지 Forward&lt;/li>
&lt;li>&lt;strong>10:17&lt;/strong> - OpenClaw가 즉시 처리 시작&lt;/li>
&lt;li>&lt;strong>10:22&lt;/strong> - 분석 완료, PR 생성&lt;/li>
&lt;li>&lt;strong>10:23&lt;/strong> - PROD 텔레그램 그룹(-100YYYYYYYYYY)에 결과 전송&lt;/li>
&lt;/ul>
&lt;p>DEV/PROD 환경 모두 동일하게 작동하며, 30분 지연은 대부분의 경우 충분했습니다. 급한 에러는 Forward로 즉시 처리할 수 있고, AI 분석은 백그라운드에서 진행됩니다.&lt;/p>
&lt;p>&lt;strong>제가 자고 있어도&lt;/strong>, &lt;strong>회의 중이어도&lt;/strong>, &lt;strong>출근 전이어도&lt;/strong> AI가 알아서 분석하고 PR을 만들어 둡니다.&lt;/p>
&lt;h2>자동화 달성&lt;span class="hx:absolute hx:-mt-20" id="자동화-달성">&lt;/span>
&lt;a href="#%ec%9e%90%eb%8f%99%ed%99%94-%eb%8b%ac%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이렇게 해서 &lt;strong>자동화&lt;/strong>를 달성했습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
Alert[&amp;#34;🚨 새벽 3시&amp;lt;br/&amp;gt;에러 알림&amp;#34;] --&amp;gt; AI[&amp;#34;🤖 AI Agent&amp;lt;br/&amp;gt;(OpenClaw)&amp;#34;]
AI --&amp;gt; PR[&amp;#34;📝 PR 생성&amp;#34;]
PR --&amp;gt; Morning[&amp;#34;☀️ 아침 출근&amp;#34;]
Morning --&amp;gt; Review[&amp;#34;👨‍💻 PR 확인&amp;#34;]
Review --&amp;gt; Merge[&amp;#34;✅ 머지 혹은 반려&amp;#34;]
&lt;/pre>&lt;p>새벽 3시에 알림이 와도, 아침에 출근하면 이미&lt;/p>
&lt;ul>
&lt;li>에러 분석이 끝나있고&lt;/li>
&lt;li>이슈가 생성되어 있고&lt;/li>
&lt;li>코드 수정이 되어 있고&lt;/li>
&lt;li>PR까지 올라와 있습니다&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>저는 이슈와 PR을 확인하고 분석해 머지할지 반려할지 결정만 하면 됩니다.&lt;/strong>&lt;/p>
&lt;p>앞서 정의한 6가지 과제가 전부 자동화됐습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>과제&lt;/th>
&lt;th>MCP (반자동화)&lt;/th>
&lt;th>OpenClaw (자동화)&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>1. 에러 인지&lt;/td>
&lt;td>❌ 수동 트리거&lt;/td>
&lt;td>✅ Heartbeat 자동 폴링&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>2. 로그/트레이스 조회&lt;/td>
&lt;td>✅&lt;/td>
&lt;td>✅&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>3. 원인 분석&lt;/td>
&lt;td>✅&lt;/td>
&lt;td>✅&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>4. 이슈 생성&lt;/td>
&lt;td>✅&lt;/td>
&lt;td>✅&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>5. 코드 수정&lt;/td>
&lt;td>❌&lt;/td>
&lt;td>✅&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>6. PR 생성&lt;/td>
&lt;td>❌&lt;/td>
&lt;td>✅&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3>확장: 성능 병목도 같은 패턴으로&lt;span class="hx:absolute hx:-mt-20" id="확장-성능-병목도-같은-패턴으로">&lt;/span>
&lt;a href="#%ed%99%95%ec%9e%a5-%ec%84%b1%eb%8a%a5-%eb%b3%91%eb%aa%a9%eb%8f%84-%ea%b0%99%ec%9d%80-%ed%8c%a8%ed%84%b4%ec%9c%bc%eb%a1%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>에러 자동화가 안정적으로 동작하자, 같은 패턴을 &lt;strong>성능 병목 추적&lt;/strong>에도 적용했습니다. 모니터링 메트릭에서 응답 속도가 느린 API를 자동으로 탐색하고, 트레이스 분석을 통해 병목 구간을 찾아 개선 방향을 제안하도록 자동화했습니다. 이 부분에 대해서는 기회가 있으면 별도의 글에서 자세히 다뤄보겠습니다.&lt;/p>
&lt;h2>맹신은 금물: PR 코드리뷰는 필수&lt;span class="hx:absolute hx:-mt-20" id="맹신은-금물-pr-코드리뷰는-필수">&lt;/span>
&lt;a href="#%eb%a7%b9%ec%8b%a0%ec%9d%80-%ea%b8%88%eb%ac%bc-pr-%ec%bd%94%eb%93%9c%eb%a6%ac%eb%b7%b0%eb%8a%94-%ed%95%84%ec%88%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이렇게 자동화가 되니 정말 편리해진건 맞습니다. 그렇지만 절대 전적인 신뢰를 줘서는 안된다고 생각합니다.&lt;/p>
&lt;p>사람도 그렇지만 &lt;strong>AI역시 당연히 틀릴 수 있습니다. 잘못된 분석을 할 수 있고, 부적절한 수정을 제안할 수 있습니다.&lt;/strong>&lt;/p>
&lt;p>그렇기 때문에 사람의 개입이 반드시 필요하다고 생각합니다. 그래서 저는 &lt;strong>코드리뷰 프로세스를 반드시 거치도록&lt;/strong> 설정했습니다.&lt;/p>
&lt;p>저는 AI가 만든 코드도 반드시 검증 과정을 거치도록 Multi-agent 리뷰 시스템을 구축해뒀습니다. (&lt;a href="https://jeongil.dev/ko/blog/trends/ai-agent-co-work/">이전 글&lt;/a> 참고)&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
AI[&amp;#34;🤖 AI Agent&amp;lt;br/&amp;gt;(코드 작성)&amp;#34;] --&amp;gt; PR[&amp;#34;Pull Request&amp;#34;]
PR --&amp;gt; Gemini[&amp;#34;🤖 Gemini&amp;lt;br/&amp;gt;(코드 리뷰)&amp;#34;]
PR --&amp;gt; CI[&amp;#34;🔧 CI/CD&amp;lt;br/&amp;gt;(자동화 검증)&amp;#34;]
Gemini --&amp;gt; Comment[&amp;#34;리뷰 코멘트&amp;#34;]
CI --&amp;gt; Deco[&amp;#34;PR 데코레이션&amp;#34;]
Comment --&amp;gt; Human[&amp;#34;👨‍💻 개발자&amp;#34;]
Deco --&amp;gt; Human
Human --&amp;gt;|&amp;#34;확인 후 머지&amp;#34;| Merge[&amp;#34;✅ Merge&amp;#34;]
&lt;/pre>&lt;p>&lt;strong>PR이 올라가면 자동으로&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Gemini Assistant&lt;/strong>가 코드리뷰 코멘트 작성&lt;/li>
&lt;li>&lt;strong>CI/CD 도구들&lt;/strong>이 검증 (Jacoco, Detekt, ArchUnit, reviewDog)&lt;/li>
&lt;/ol>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/24ce66fa-7a1a-4872-9be6-64c01218d731/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>Claude가 놓친 부분을 Gemini가 잡아주고, Gemini가 놓친 부분을 자동화 도구들이 잡아줍니다. &lt;a href="https://arxiv.org/html/2312.13010v2"target="_blank" rel="noopener">AgentCoder 연구(2024)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>처럼 Multi-agent 교차검증이 효과적이더라구요.&lt;/p>
&lt;h2>Before &amp;amp; After&lt;span class="hx:absolute hx:-mt-20" id="before--after">&lt;/span>
&lt;a href="#before--after" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>자동화 전과 후를 비교하면 기존에는 직접 로그를 보고, 트레이스를 확인하고, 코드를 분석하고, 이슈를 만들고, 코드를 수정하고, PR을 만드는 모든 과정을 제가 직접 했습니다.&lt;/p>
&lt;p>새벽에 놓친 알림이 있다면 아침에 출근해서 확인해야했죠. 하지만 이제는 아침에 출근하면 새벽에 Son of Victor(OpenClaw)가 분석해놓은 이슈와 PR을 확인하고 잘했는지 검토만 하면 됩니다.&lt;/p>
&lt;p>물론 한계도 있었습니다.&lt;/p>
&lt;p>&lt;strong>잘 작동하는 케이스&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>NPE, 타입 오류 같은 단순 버그&lt;/li>
&lt;li>패턴이 명확한 반복 에러&lt;/li>
&lt;li>로그만 봐도 원인이 뻔한 경우&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>어려운 케이스&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>복잡한 비즈니스 로직 버그&lt;/li>
&lt;li>동시성/레이스 컨디션 문제&lt;/li>
&lt;li>보안 관련 이슈 (자동 수정 위험)&lt;/li>
&lt;/ul>
&lt;p>그래서 저는 &lt;strong>&amp;ldquo;자동 수정&amp;quot;보다 &amp;ldquo;자동 분석 + 이슈 생성&amp;quot;에 더 가치&lt;/strong>를 두고 있습니다. AI가 초기 분석을 해두면, 사람은 검토하고 판단하는 역할에 집중할 수 있거든요.&lt;/p>
&lt;h2>주의사항: 이것만은 알고 쓰자&lt;span class="hx:absolute hx:-mt-20" id="주의사항-이것만은-알고-쓰자">&lt;/span>
&lt;a href="#%ec%a3%bc%ec%9d%98%ec%82%ac%ed%95%ad-%ec%9d%b4%ea%b2%83%eb%a7%8c%ec%9d%80-%ec%95%8c%ea%b3%a0-%ec%93%b0%ec%9e%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>OpenClaw가 편리한 건 맞지만, &lt;strong>주의해야 할 점들&lt;/strong>도 분명히 있습니다.&lt;/p>
&lt;h3>1. 보안 이슈&lt;span class="hx:absolute hx:-mt-20" id="1-보안-이슈">&lt;/span>
&lt;a href="#1-%eb%b3%b4%ec%95%88-%ec%9d%b4%ec%8a%88" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>OpenClaw 에이전트는 &lt;strong>코드베이스, GitHub 토큰, API 키 등에 접근&lt;/strong>할 수 있습니다. 편리한 만큼 위험하기도 하죠.&lt;/p>
&lt;h4>실제로 발생한 보안 사고들&lt;span class="hx:absolute hx:-mt-20" id="실제로-발생한-보안-사고들">&lt;/span>
&lt;a href="#%ec%8b%a4%ec%a0%9c%eb%a1%9c-%eb%b0%9c%ec%83%9d%ed%95%9c-%eb%b3%b4%ec%95%88-%ec%82%ac%ea%b3%a0%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>2026년 1월에 보안 연구자들이 &lt;a href="https://www.vectra.ai/blog/clawdbot-to-moltbot-to-openclaw-when-automation-becomes-a-digital-backdoor"target="_blank" rel="noopener">Shodan에서 수많은 OpenClaw 인스턴스가 노출&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>되어 있는 것을 발견했다고 합니다. 인증 없이 공개 인터넷에 노출되어 API 키와 OAuth 토큰이 유출될 위험이 있었던 거죠.&lt;/p>
&lt;p>더 심각했던 건 2026년 1월 30일에 발견된 &lt;a href="https://thehackernews.com/2026/02/openclaw-bug-enables-one-click-remote.html"target="_blank" rel="noopener">CVE-2026-25253(CVSS 8.8)라는 원클릭 RCE 취약점&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>입니다. 악의적인 링크를 클릭하거나 특정 사이트를 방문하기만 해도 공격자가 로컬 게이트웨이에 접근해서 설정을 조작하고 권한 있는 작업을 실행할 수 있었어요.&lt;/p>
&lt;p>또 &lt;a href="https://thehackernews.com/2026/02/researchers-find-341-malicious-clawhub.html"target="_blank" rel="noopener">ClawHub(OpenClaw의 스킬 마켓플레이스)에서 341개의 악성 스킬&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>이 발견됐는데, 그 중 335개가 Atomic Stealer(AMOS)라는 macOS 정보 탈취 악성코드를 설치하려 했다고 하더라구요.&lt;/p>
&lt;p>&lt;strong>빠르게 성장하는 프로젝트의 한계&lt;/strong>&lt;/p>
&lt;p>OpenClaw는 Peter Steinberger의 사이드 프로젝트로 시작했고, &lt;a href="https://github.com/openclaw"target="_blank" rel="noopener">현재는 여러 메인테이너가 참여하는 organization으로 전환&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>되었습니다. 7명의 핵심 팀원이 있고, 보안 담당으로 Jamieson O&amp;rsquo;Reilly가 합류했으며, 10개 이상의 스폰서가 지원하고 있다고 하더라구요.&lt;/p>
&lt;p>하지만 폭발적인 성장 속도(일주일에 10만 스타, 200만 방문자)에 비하면 아직 리소스가 부족한 상황입니다. &lt;a href="https://github.com/openclaw/openclaw/security"target="_blank" rel="noopener">OpenClaw GitHub 보안 페이지&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에 이런 내용이 적혀 있더라구요.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;OpenClaw is a labor of love. There is no bug bounty program and no budget for paid reports.&amp;rdquo;&lt;/p>
&lt;/blockquote>
&lt;p>사랑으로 만드는 오픈소스 프로젝트라서 버그 바운티 프로그램도 없고 예산도 없다는 얘기입니다. 실제로 &lt;a href="https://www.aicerts.ai/news/openclaw-surge-exposes-thousands-prompts-swift-security-overhaul/"target="_blank" rel="noopener">한 보안 연구자가 여러 차례 연락했지만 &amp;ldquo;할 일이 너무 많다&amp;quot;며 대응이 늦어졌다&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>는 보고도 있었어요.&lt;/p>
&lt;p>이게 잘못된 건 아닙니다. 오픈소스 프로젝트는 대부분 이런 식으로 운영되니까요. 다만 &lt;strong>사용자 입장에서는 보안 이슈 대응이 기업 제품만큼 빠르지 않을 수 있다&lt;/strong>는 걸 알고 써야 한다는 거죠.&lt;/p>
&lt;p>이런 사고들을 보면서 OpenClaw 사용 시 주의해야 할 보안 위험이 명확해졌습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>민감정보 노출&lt;/strong>: &lt;code>.env&lt;/code> 파일이나 시크릿이 AI 컨텍스트에 들어갈 수 있음&lt;/li>
&lt;li>&lt;strong>GitHub 토큰 권한&lt;/strong>: PR 생성, 브랜치 생성 권한이 있으면 악용 가능성&lt;/li>
&lt;li>&lt;strong>프롬프트 인젝션&lt;/strong>: 에러 로그에 악의적인 내용이 포함되면 AI가 의도치 않은 동작을 할 수도&lt;/li>
&lt;li>&lt;strong>MCP Remote 취약점&lt;/strong>: &lt;a href="https://composio.dev/blog/secure-openclaw-moltbot-clawdbot-setup"target="_blank" rel="noopener">CVE-2025-6514&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> 같은 커맨드 인젝션 RCE 취약점&lt;/li>
&lt;/ul>
&lt;h4>그래서 저는 이렇게 대응했습니다&lt;span class="hx:absolute hx:-mt-20" id="그래서-저는-이렇게-대응했습니다">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%9e%98%ec%84%9c-%ec%a0%80%eb%8a%94-%ec%9d%b4%eb%a0%87%ea%b2%8c-%eb%8c%80%ec%9d%91%ed%96%88%ec%8a%b5%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>&lt;strong>1) 최소 권한 원칙 (Least Privilege)&lt;/strong>&lt;/p>
&lt;p>저는 먼저 별도의 GitHub 서비스 계정을 만들어서 최소 권한만 부여했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># GitHub Fine-grained Personal Access Token 생성&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 권한: Repository permissions만&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># - Contents: Read and write (코드 읽기/수정)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># - Pull requests: Read and write (PR 생성)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># - Issues: Read and write (이슈 생성)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># - 그 외 권한은 전부 제거&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>2) 파일 시스템 격리&lt;/strong>&lt;/p>
&lt;p>&lt;a href="https://docs.openclaw.ai/gateway/security"target="_blank" rel="noopener">OpenClaw 공식 문서&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에서 권장하는 샌드박스 설정을 적용했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// agents.json
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;agents&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;defaults&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;sandbox&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;enabled&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="kc">true&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;workspaceAccess&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;none&amp;#34;&lt;/span> &lt;span class="c1">// 에이전트 워크스페이스 격리
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이렇게 설정하면 에이전트가 &lt;code>~/.openclaw/sandboxes&lt;/code> 안에서만 작동하고, 호스트 파일 시스템 전체에는 접근할 수 없게 됩니다.&lt;/p>
&lt;p>&lt;strong>3) 환경변수 및 API 키 격리&lt;/strong>&lt;/p>
&lt;p>저는 API 키를 평문으로 &lt;code>~/.openclaw/.env&lt;/code>에 저장하지 않고, &lt;a href="https://composio.dev/blog/secure-openclaw-moltbot-clawdbot-setup"target="_blank" rel="noopener">시스템 키체인을 활용&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># openclaw onboard 명령으로 자동 구성&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">openclaw onboard
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 또는 시스템 키체인 수동 등록&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># macOS: Keychain Access&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Linux: gnome-keyring, KWallet&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>4) Brokered Authentication 패턴&lt;/strong>&lt;/p>
&lt;p>&lt;a href="https://composio.dev/blog/secure-openclaw-moltbot-clawdbot-setup"target="_blank" rel="noopener">Composio 같은 서비스&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>를 사용하면 에이전트가 실제 API 키를 보지 않고도 작업을 수행할 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>AI Agent → Composio Proxy → GitHub API
(API 키 주입)&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>에이전트는 Composio에 &amp;ldquo;PR 만들어줘&amp;quot;라고 요청하고, Composio가 백엔드에서 인증 후 결과만 반환합니다.&lt;/p>
&lt;p>&lt;strong>5) Docker 컨테이너 격리 (선택사항)&lt;/strong>&lt;/p>
&lt;p>좀 더 강력한 보안이 필요하다면 &lt;a href="https://www.docker.com/blog/mcp-security-explained/"target="_blank" rel="noopener">Docker 컨테이너로 격리&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>할 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># docker-compose.yml&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">services&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">openclaw&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">image&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">openclaw/openclaw:latest&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">user&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;1000:1000&amp;#34;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># non-root 사용자&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">read_only&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># 읽기 전용 파일시스템&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">cap_drop&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># 불필요한 권한 제거&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">ALL&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">cap_add&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">CHOWN&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">DAC_OVERRIDE&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">volumes&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">./workspace:/workspace:ro &lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># 읽기 전용 마운트&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>하지만 저는 로컬 환경에서 사용하기 때문에 Docker까지는 적용하지 않았습니다. 파일시스템 격리와 최소 권한 계정만으로도 충분하다고 판단했습니다.&lt;/p>
&lt;p>&lt;strong>6) 네트워크 격리&lt;/strong>&lt;/p>
&lt;p>외부 인터넷 노출은 절대 하지 않았습니다. Tailscale Funnel 같은 방식은 &lt;a href="https://www.penligent.ai/hackinglabs/openclaw-sovereign-ai-security-manifest-a-comprehensive-post-mortem-and-architectural-hardening-guide-for-openclaw-ai-2026/"target="_blank" rel="noopener">프롬프트 인젝션, DDoS 등의 위험&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>이 있기 때문에 제외했습니다.&lt;/p>
&lt;p>대신 위에서 언급한대로 Polling 방식을 선택해 외부 요청을 받지 않도록 했습니다.&lt;/p>
&lt;p>안전장치는 여러 겹 둘수록 좋다고 생각합니다. 특히 OpenClaw는 아직 초기 단계라 예상치 못한 취약점이 발견될 수 있으니 보수적으로 접근하는 게 좋습니다.&lt;/p>
&lt;h3>2. 비용&lt;span class="hx:absolute hx:-mt-20" id="2-비용">&lt;/span>
&lt;a href="#2-%eb%b9%84%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>매번 알림이 올 때마다 &lt;strong>LLM API 호출&lt;/strong>이 발생합니다. Claude API 비용이 만만치 않거든요.&lt;/p>
&lt;ul>
&lt;li>알림이 자주 오는 서비스라면 비용이 급격히 늘어날 수 있음&lt;/li>
&lt;li>특히 코드 분석까지 하면 토큰 소모가 큼&lt;/li>
&lt;/ul>
&lt;p>그렇기 때문에 주기를 적절히 설정해야 Token Limit에 걸리지 않고, 비용도 감당할 수 있습니다.&lt;/p>
&lt;h3>3. 잘못된 수정 위험&lt;span class="hx:absolute hx:-mt-20" id="3-잘못된-수정-위험">&lt;/span>
&lt;a href="#3-%ec%9e%98%eb%aa%bb%eb%90%9c-%ec%88%98%ec%a0%95-%ec%9c%84%ed%97%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>AI가 분석을 잘못하면, &lt;strong>오히려 더 큰 버그&lt;/strong>를 만들 수 있습니다.&lt;/p>
&lt;ul>
&lt;li>단순 NPE를 고치려다 비즈니스 로직을 망가뜨릴 수도&lt;/li>
&lt;li>테스트가 없는 코드베이스라면 더 위험&lt;/li>
&lt;/ul>
&lt;p>그래서 &lt;strong>자동 머지는 절대 안 하고&lt;/strong>, 반드시 사람이 리뷰 후 머지합니다. 앞서 말한 Gemini 코드리뷰 + 자동화 도구들도 이런 이유로 붙여둔 겁니다.&lt;/p>
&lt;h3>4. 아직 제대로 검증되지 않음&lt;span class="hx:absolute hx:-mt-20" id="4-아직-제대로-검증되지-않음">&lt;/span>
&lt;a href="#4-%ec%95%84%ec%a7%81-%ec%a0%9c%eb%8c%80%eb%a1%9c-%ea%b2%80%ec%a6%9d%eb%90%98%ec%a7%80-%ec%95%8a%ec%9d%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>마지막으로 제가 가장 중요하게 생각하는 부분인데 AI 생태계가 빠르게 발전하면서 하루하루 새로운 툴이 나오고 유행이 바뀌며 생각하지 않았던 문제가 발생할 수 있습니다.&lt;/p>
&lt;p>어제는 oh-my-opencode가 유행이더니 오늘은 OpenClaw가 뜨고, 내일은 또 뭐가 뜰지 아무도 모릅니다. 이처럼 빠르게 진화하는 환경에서 툴의 등장과 발전이 너무 빠르기 때문에, 초기단계의 툴에 어떤 버그가 있을지 아무도 알수가 없습니다.&lt;/p>
&lt;p>OpenClaw는 &lt;a href="https://newsletter.pragmaticengineer.com/p/the-creator-of-clawd-i-ship-code"target="_blank" rel="noopener">오스트리아 개발자 Peter Steinberger&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>가 2025년 11월 주말에 시작한 사이드 프로젝트더라구요. &lt;a href="https://www.superseed.com/journal/who-is-openclaw-anyway/"target="_blank" rel="noopener">AI 중심 개발 워크플로우로 빠르게 개발&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>했다고 합니다. Pragmatic Engineer 인터뷰에서 그는 &amp;ldquo;I ship code I don&amp;rsquo;t read&amp;rdquo;(읽지도 않은 코드를 배포한다)라고 언급했는데, AI에게 많은 부분을 맡기는 개발 방식이라는 거죠.&lt;/p>
&lt;p>&lt;a href="https://www.trendingtopics.eu/openclaw-2-million-visitors-in-a-week/"target="_blank" rel="noopener">일주일 만에 GitHub 10만 스타&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>를 달성하고, 한 주에 200만 방문자를 기록할 정도로 폭발적인 성장을 했는데 &lt;strong>불과 3개월 전에 시작된 프로젝트&lt;/strong>입니다. 현재는 &lt;a href="https://github.com/openclaw"target="_blank" rel="noopener">7명의 핵심 팀원이 있는 organization&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>으로 전환되었지만, 여전히 매우 빠르게 변화하고 있는 초기 단계 프로젝트입니다.&lt;/p>
&lt;p>이런 빠른 개발 속도와 짧은 역사 때문에 &lt;strong>예기치 않은 버그나 변경&lt;/strong>이 있을 수 있고 보안 취약점이 추가로 발견될 가능성도 있습니다.&lt;/p>
&lt;p>어떤 심각한 문제가 발생할지 아무도 예측할 수 없으니 조심 또 조심해야 한다고 생각합니다. 특히 프로덕션 환경에 적용할 때는 더욱 신중해야 하겠죠.&lt;/p>
&lt;h3>그런데 왜 리스크를 안고 도입했나?&lt;span class="hx:absolute hx:-mt-20" id="그런데-왜-리스크를-안고-도입했나">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%9f%b0%eb%8d%b0-%ec%99%9c-%eb%a6%ac%ec%8a%a4%ed%81%ac%eb%a5%bc-%ec%95%88%ea%b3%a0-%eb%8f%84%ec%9e%85%ed%96%88%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그렇다면 이렇게 여쭤보실 수도 있을 것 같습니다. 조심해야한다면서 왜 회사에 도입했냐고요.&lt;/p>
&lt;p>솔직히 말씀드리면 맞는 말씀이라고 생각합니다. 아무래도 초기 단계 툴이라 리스크가 있으니까요.&lt;/p>
&lt;p>솔직한 이유를 말씀드리자면 현재 저희 회사는 기존에 5명이던 개발팀에서 회사 경영난으로 프론트 1명, 백엔드 1명 이렇게 인원이 감축됐습니다.&lt;/p>
&lt;p>그중 혼자 남은 백엔드 개발자가 제가 됐는데 그렇다보니 할 일이 생각보다 너무 많아졌습니다.&lt;/p>
&lt;p>또 스타트업이다 보니 신규채용에 들어가는 비용보다 더 경제적인 AI를 적극 도입하기로 회사차원에서 결정을 하게 됐습니다.&lt;/p>
&lt;p>그러니 너그러히 봐주셨으면 좋겠습니다.&lt;/p>
&lt;h2>마무리: 개발자의 미래&lt;span class="hx:absolute hx:-mt-20" id="마무리-개발자의-미래">&lt;/span>
&lt;a href="#%eb%a7%88%eb%ac%b4%eb%a6%ac-%ea%b0%9c%eb%b0%9c%ec%9e%90%ec%9d%98-%eb%af%b8%eb%9e%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이번 작업을 하면서 느낀 건, &lt;strong>AI가 &amp;ldquo;도와주는 도구&amp;quot;에서 &amp;ldquo;위임할 수 있는 동료&amp;quot;로 진화하고 있다&lt;/strong>는 점입니다.&lt;/p>
&lt;p>예전에는 AI에게 질문하고 답을 받았습니다. 지금은 &lt;strong>AI에게 일을 시켜놓고 결과물을 받습니다.&lt;/strong> 그것도 코드 리뷰가 가능한 형태(PR)로요. AI가 할 수 있는 일의 범위가 점점 넓어지고 있다는 걸 체감하게 됩니다.&lt;/p>
&lt;p>솔직히 말하면 이런 자동화를 만들면서도 계속 드는 생각이 있습니다. &lt;strong>AI가 이렇게 발전하면 나같은 주니어 개발자는 어떻게 되는 걸까?&lt;/strong>&lt;/p>
&lt;p>지금은 제가 AI를 활용해서 생산성을 높이고 있지만, 회사 입장에서는 AI만으로도 충분하다고 판단할 수 있지 않을까요? 코드 짜는 일은 AI가 하고, 리뷰와 의사결정은 소수의 시니어 개발자들만 있으면 되는 거니까요.&lt;/p>
&lt;p>무섭기도 하지만 어쩔 수 없이 이 흐름에 올라타야 한다고 생각합니다. AI를 거부하면 도태될 것 같거든요. 그래서 이렇게 적극적으로 도입해보려 노력하고 있습니다.&lt;/p>
&lt;p>AI와 경쟁하는 게 아니라 AI를 잘 활용하는 개발자가 되는 게 살아남는 길이라고 믿고 싶습니다.&lt;/p>
&lt;p>긴 글 읽어주셔서 감사합니다.&lt;/p>
&lt;h2>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>OpenClaw&lt;span class="hx:absolute hx:-mt-20" id="openclaw">&lt;/span>
&lt;a href="#openclaw" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://github.com/openclaw/openclaw"target="_blank" rel="noopener">OpenClaw GitHub&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/openclaw"target="_blank" rel="noopener">OpenClaw Organization&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://docs.openclaw.ai"target="_blank" rel="noopener">OpenClaw Documentation&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://docs.openclaw.ai/gateway/security"target="_blank" rel="noopener">OpenClaw Security Documentation&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://newsletter.pragmaticengineer.com/p/the-creator-of-clawd-i-ship-code"target="_blank" rel="noopener">The creator of Clawd: &amp;ldquo;I ship code I don&amp;rsquo;t read&amp;rdquo; - Pragmatic Engineer&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.superseed.com/journal/who-is-openclaw-anyway/"target="_blank" rel="noopener">Who is OpenClaw Anyway? - SuperSeed&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.trendingtopics.eu/openclaw-2-million-visitors-in-a-week/"target="_blank" rel="noopener">OpenClaw: How a Weekend Project Became an Open-Source AI Sensation&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>Security&lt;span class="hx:absolute hx:-mt-20" id="security">&lt;/span>
&lt;a href="#security" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://www.vectra.ai/blog/clawdbot-to-moltbot-to-openclaw-when-automation-becomes-a-digital-backdoor"target="_blank" rel="noopener">From Clawdbot to OpenClaw: When Automation Becomes a Digital Backdoor - Vectra&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://thehackernews.com/2026/02/openclaw-bug-enables-one-click-remote.html"target="_blank" rel="noopener">OpenClaw Bug Enables One-Click Remote Code Execution - The Hacker News&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://thehackernews.com/2026/02/researchers-find-341-malicious-clawhub.html"target="_blank" rel="noopener">Researchers Find 341 Malicious ClawHub Skills - The Hacker News&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.aicerts.ai/news/openclaw-surge-exposes-thousands-prompts-swift-security-overhaul/"target="_blank" rel="noopener">OpenClaw surge exposes thousands, prompts swift security overhaul - AI CERTs&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://composio.dev/blog/secure-openclaw-moltbot-clawdbot-setup"target="_blank" rel="noopener">How to secure OpenClaw: Docker hardening, credential isolation - Composio&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.docker.com/blog/mcp-security-explained/"target="_blank" rel="noopener">MCP Security: Risks, Challenges, and How to Mitigate - Docker&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.penligent.ai/hackinglabs/openclaw-sovereign-ai-security-manifest-a-comprehensive-post-mortem-and-architectural-hardening-guide-for-openclaw-ai-2026/"target="_blank" rel="noopener">OpenClaw Sovereign AI Security Manifest - Penligent&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>Tools &amp;amp; Documentation&lt;span class="hx:absolute hx:-mt-20" id="tools--documentation">&lt;/span>
&lt;a href="#tools--documentation" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://github.com/12OneTwo12/error-autopilot-mcp"target="_blank" rel="noopener">error-autopilot MCP 저장소&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.blog/news-insights/research/survey-ai-wave-grows/"target="_blank" rel="noopener">GitHub 2024 Developer Survey: The AI wave continues to grow&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://grafana.com/docs/loki/latest/"target="_blank" rel="noopener">Grafana Loki Documentation&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://grafana.com/docs/tempo/latest/"target="_blank" rel="noopener">Grafana Tempo Documentation&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://core.telegram.org/bots/api"target="_blank" rel="noopener">Telegram Bot API Documentation&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://tailscale.com/kb/1223/tailscale-funnel/"target="_blank" rel="noopener">Tailscale Funnel Documentation&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://arxiv.org/html/2312.13010v2"target="_blank" rel="noopener">AgentCoder: Multiagent-Code Generation with Iterative Testing and Optimisation (2024)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>DB 정규화, 안 하면 어떻게 되는지 직접 겪어봤습니다</title><link>https://jeongil.dev/ko/blog/backend/troubleshooting/db-normalization-address-migration/</link><pubDate>Tue, 03 Feb 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/backend/troubleshooting/db-normalization-address-migration/</guid><description>
&lt;p>DB 정규화의 중요성은 누구나 알고 있지만, 실무에서는 의외로 간과하기 쉬운 것 같습니다. &amp;ldquo;JOIN 한 번 줄이면 성능이 좋아지니까&amp;rdquo;, &amp;ldquo;그냥 텍스트로 저장하면 편하니까&amp;rdquo; 하는 이유로 비정규화를 택하게 되는 순간이 꽤 있죠.&lt;/p>
&lt;p>저는 2025년 3월에 지금 팀에 합류했는데, 합류했을 때 이미 DB가 그런 상태였습니다. 당시에는 제가 서비스를 정확하게 파악하고 있지도 않을 뿐더러 &amp;ldquo;이미 이렇게 돌아가고 있으니까&amp;rdquo; 하고 넘어갔지만, 이번에 화성시 분구 마이그레이션을 겪으면서 비정규화가 어떤 대가를 만드는지를 뼈저리게 느끼게 되었습니다.&lt;/p>
&lt;blockquote>
&lt;p>이 글에 작성된 서비스명, 테이블명, 컬럼명 등은 실제와 다르게 변경되어 있습니다.&lt;/p>
&lt;/blockquote>
&lt;h2>화성시가 4개 구로 나뉘었습니다&lt;span class="hx:absolute hx:-mt-20" id="화성시가-4개-구로-나뉘었습니다">&lt;/span>
&lt;a href="#%ed%99%94%ec%84%b1%ec%8b%9c%ea%b0%80-4%ea%b0%9c-%ea%b5%ac%eb%a1%9c-%eb%82%98%eb%89%98%ec%97%88%ec%8a%b5%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>저는 부동산 관련 서비스를 개발하고 있습니다. 아파트 정보, 실거래가, 매물, 중개사무소 등 주소가 들어가지 않는 테이블을 찾기가 더 어려울 정도로 주소 데이터를 많이 다루는 서비스죠.&lt;/p>
&lt;p>2026년 2월 1일, 경기도 화성시가 4개의 일반구로 분구되었습니다. 인구 약 100만 명의 도시가 행정구역 개편을 거친, 꽤 큰 행정 이벤트였습니다.&lt;/p>
&lt;p>&lt;a href="https://www.mois.go.kr/frt/bbs/type001/commonSelectBoardArticle.do?bbsId=BBSMSTR_000000000052&amp;amp;nttId=122595"target="_blank" rel="noopener">행정기관(행정동) 및 관할구역(법정동) 변경내역 알림(2026.2.1. 시행) - 행정안전부&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>구&lt;/th>
&lt;th>주요 관할 지역&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>만세구&lt;/strong>&lt;/td>
&lt;td>우정읍, 향남읍, 남양읍, 마도면, 송산면, 서신면, 팔탄면, 장안면, 양감면, 새솔동&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>효행구&lt;/strong>&lt;/td>
&lt;td>봉담읍, 매송면, 비봉면, 정남면, 기배동&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>병점구&lt;/strong>&lt;/td>
&lt;td>진안동, 병점1동, 병점2동, 반월동, 화산동&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>동탄구&lt;/strong>&lt;/td>
&lt;td>동탄1동 ~ 동탄9동&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>이로 인해 주소 체계가 바뀌게 됐죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>변경 전: 경기도 화성시 진안동 908
변경 후: 경기도 화성시 병점구 진안동 908
변경 전: 경기도 화성시 반송동 973
변경 후: 경기도 화성시 동탄구 반송동 973&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&amp;ldquo;화성시&amp;rdquo; 바로 뒤에 &amp;ldquo;구&amp;quot;가 하나 추가됐고, 행정구역 코드(&lt;code>region_code&lt;/code>, &lt;code>dong_code&lt;/code>)도 전부 변경됐습니다.&lt;/p>
&lt;p>부동산 서비스에서 주소가 바뀐다는 건 곧 DB 마이그레이션이 필요하다는걸 의미합니다. 처음에는 &amp;ldquo;주소 데이터 좀 바꿔주면 되겠지&amp;rdquo; 정도로 가볍게 생각했는데 실제로 DB를 들여다보니 상황이 전혀 가볍지 않았습니다.&lt;/p>
&lt;h2>주소가 대체 어디에 있는 거야&lt;span class="hx:absolute hx:-mt-20" id="주소가-대체-어디에-있는-거야">&lt;/span>
&lt;a href="#%ec%a3%bc%ec%86%8c%ea%b0%80-%eb%8c%80%ec%b2%b4-%ec%96%b4%eb%94%94%ec%97%90-%ec%9e%88%eb%8a%94-%ea%b1%b0%ec%95%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>저희 서비스는 주소 데이터를 마스터 테이블의 코드로 참조하는 게 아니라, 각 테이블에 주소 텍스트를 직접 저장하는 구조였습니다. &lt;code>region_code&lt;/code>나 &lt;code>dong_code&lt;/code> 같은 코드 컬럼을 가지고 Join을 통해 주소를 조회하는 테이블도 있었지만, 그와 동시에 주소 문자열을 그대로 들고 있는 컬럼이 훨씬 많았습니다.&lt;/p>
&lt;p>그래서 마이그레이션의 첫 단계는 &lt;strong>&amp;ldquo;주소가 어디어디에 저장되어 있는지 찾는 것&amp;rdquo;&lt;/strong> 이었는데, 이게 생각보다 쉽지 않았습니다.&lt;/p>
&lt;p>먼저 쉽게 추측할 수 있는 &lt;code>addr&lt;/code>, &lt;code>address&lt;/code>, &lt;code>dong_code&lt;/code>와 같은 일반적인 컬럼명으로 DB를 조사하니 38개 테이블이 나왔습니다. 이 정도면 됐겠지 싶었는데, 조사를 계속하니 놓친 컬럼들이 하나둘씩 발견되기 시작했습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>컬럼명&lt;/th>
&lt;th>예시 데이터&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>place1_full_addr&lt;/td>
&lt;td>경기 화성시 석우동 2-4&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>complex_address&lt;/td>
&lt;td>경기도 화성시 목동 동탄2택지개발지구&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>jibun_addr&lt;/td>
&lt;td>경기 화성시 향남읍 구문천리&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;code>place1_full_addr&lt;/code>, &lt;code>complex_address&lt;/code>, &lt;code>jibun_addr&lt;/code>&amp;hellip; 컬럼명이 전부 제각각으로 주소로 저장되고 있는 테이블들이 있었습니다&amp;hellip;&lt;/p>
&lt;p>컨벤션 없이 개발자마다 다른 이름을 사용했고, 외부 API의 필드명을 그대로 가져다 쓴 경우도 있었습니다. 코드 컬럼도 마찬가지였는데, 같은 시군구 코드를 &lt;code>sigungu_cd&lt;/code>, &lt;code>arcode&lt;/code>, &lt;code>stcode&lt;/code>, &lt;code>sggcode&lt;/code> 등 제각각 다른 이름으로 저장하고 있었습니다.&lt;/p>
&lt;p>&lt;a href="https://jeongil.dev/ko/blog/culture/naming-convention/">네이밍 컨벤션의 부재는 장애로 이어진다.&lt;/a>에서 다뤘던 것과 유사한 문제였죠.&lt;/p>
&lt;p>표준화된 네이밍 컨벤션이 없었기 때문에, &lt;code>addr&lt;/code>이나 &lt;code>address&lt;/code>로 검색해서는 절대 전체를 찾을 수 없는 구조였습니다. 만약 주소 관련 컬럼은 &lt;code>addr_*&lt;/code>, 코드 관련 컬럼은 &lt;code>region_*&lt;/code>처럼 네이밍 규칙이 있었다면, 컬럼명 패턴만으로도 영향 범위의 대부분을 파악할 수 있었을 것 같습니다. 다시금 네이밍 컨벤션의 중요성을 느끼게 됐죠.&lt;/p>
&lt;p>결국 컬럼명으로 찾는 건 한계가 있다는 걸 받아들이고, 접근 방식을 바꿨습니다. 모든 DB의 모든 TEXT/VARCHAR 컬럼에서 &lt;code>LIKE '%화성시%'&lt;/code>를 직접 실행하는 방식으로요.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- 14개 DB의 모든 텍스트 컬럼에 대해 실행
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">COUNT&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">some_table&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">some_column&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">LIKE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;%화성시%&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>효율적인 방법은 아니었지만 확실했습니다. 제 리소스를 조금 갈아 넣더라도 정확하게 해야한다고 판단했습니다. 그리고 여기서 예상 못 한 오탐 케이스도 발견되었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>apt_title: &amp;#34;화성시청역센트럴파크스타힐스1단지&amp;#34;
sector_name: &amp;#34;화성시청역 2블록 서희스타힐스&amp;#34;&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&amp;ldquo;화성시&amp;quot;를 검색했더니 &amp;ldquo;화성시청역&amp;quot;이라는 아파트 브랜드명이 걸리는 겁니다. 이런 데이터는 행정구역 변경과 무관하게 아파트 이름이니 마이그레이션 대상에서 제외해야 했습니다. 결국 각 컬럼마다 샘플 데이터를 확인하고 해당 데이터가 주소를 의미하는지 파악하는 과정까지 필요했죠.&lt;/p>
&lt;p>최종 결과는 이랬습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>구분&lt;/th>
&lt;th>건수&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>영향받는 DB&lt;/td>
&lt;td>8개&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>영향받는 테이블&lt;/td>
&lt;td>&lt;strong>75개&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>영향받는 컬럼&lt;/td>
&lt;td>&lt;strong>120개 이상&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>마이그레이션 대상 레코드&lt;/td>
&lt;td>&lt;strong>약 280만 건&lt;/strong>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>처음 컬럼명 기반 조사에서 38개였던 테이블이, 전수조사를 하니 75개까지 늘어났습니다. &lt;strong>처음 조사의 절반밖에 못 찾았던 셈이죠.&lt;/strong> 시간이 꽤 걸렸지만 영향 범위를 정확히 파악한 건 전체 작업의 성공을 위해 꼭 필요한 단계였습니다.&lt;/p>
&lt;h2>75개 테이블을 어떻게 마이그레이션할 것인가&lt;span class="hx:absolute hx:-mt-20" id="75개-테이블을-어떻게-마이그레이션할-것인가">&lt;/span>
&lt;a href="#75%ea%b0%9c-%ed%85%8c%ec%9d%b4%eb%b8%94%ec%9d%84-%ec%96%b4%eb%96%bb%ea%b2%8c-%eb%a7%88%ec%9d%b4%ea%b7%b8%eb%a0%88%ec%9d%b4%ec%85%98%ed%95%a0-%ea%b2%83%ec%9d%b8%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>영향 범위를 파악한 건 전체 작업의 시작에 불과했습니다. 75개 테이블, 120개 이상의 컬럼을 찾았다고 해서 바로 UPDATE를 실행할 수 있는 게 아니었거든요.&lt;/p>
&lt;h3>단순 치환이 안 되는 이유&lt;span class="hx:absolute hx:-mt-20" id="단순-치환이-안-되는-이유">&lt;/span>
&lt;a href="#%eb%8b%a8%ec%88%9c-%ec%b9%98%ed%99%98%ec%9d%b4-%ec%95%88-%eb%90%98%eb%8a%94-%ec%9d%b4%ec%9c%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>처음에는 단순하게 생각했습니다. &amp;ldquo;화성시&amp;quot;를 &amp;ldquo;화성시 병점구&amp;quot;와 같이 REPLACE하면 되는 거 아닌가?&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">UPDATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">apartment&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">SET&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">addr&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">REPLACE&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">addr&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;화성시&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;화성시 병점구&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>하지만 이게 안 됩니다. 화성시가 &lt;strong>4개&lt;/strong> 구로 나뉘었기 때문입니다. 진안동은 병점구, 동탄1동은 동탄구, 향남읍은 만세구&amp;hellip; 같은 &amp;ldquo;화성시&amp;quot;라도 어떤 동이냐에 따라 들어가야 할 구가 다릅니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>경기도 화성시 진안동 908 → 경기도 화성시 병점구 진안동 908
경기도 화성시 동탄1동 123 → 경기도 화성시 동탄구 동탄1동 123
경기도 화성시 향남읍 구문천리 → 경기도 화성시 만세구 향남읍 구문천리&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>그래서 먼저 동→구 매핑 테이블을 만들고, 주소 텍스트에서 동 이름을 기준으로 어떤 구를 삽입할지 결정하는 방식으로 접근했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">UPDATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">apartment&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">JOIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dong_to_gu_mapping&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">m&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">addr&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">LIKE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">CONCAT&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;%화성시 &amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">m&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">dong_name&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;%&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">SET&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">addr&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">REPLACE&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">addr&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">CONCAT&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;화성시 &amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">m&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">dong_name&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">CONCAT&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;화성시 &amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">m&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">gu_name&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39; &amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">m&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">dong_name&lt;/span>&lt;span class="p">))&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">addr&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">LIKE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;%화성시%&amp;#39;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">AND&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">addr&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">NOT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">LIKE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;%화성시청역%&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>여기까지는 나름 정리가 됐다고 생각했습니다. 매핑 테이블만 잘 만들면 나머지는 기계적으로 처리할 수 있겠다 싶었거든요. 하지만 실제로 개발 환경에서 돌려보니 생각처럼 단순하지 않았습니다.&lt;/p>
&lt;h3>생각보다 까다로웠던 주소 파싱&lt;span class="hx:absolute hx:-mt-20" id="생각보다-까다로웠던-주소-파싱">&lt;/span>
&lt;a href="#%ec%83%9d%ea%b0%81%eb%b3%b4%eb%8b%a4-%ea%b9%8c%eb%8b%a4%eb%a1%9c%ec%9b%a0%eb%8d%98-%ec%a3%bc%ec%86%8c-%ed%8c%8c%ec%8b%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>가장 먼저 부딪힌 건 &lt;strong>주소 표기 형식이 통일되어 있지 않다&lt;/strong>는 점이었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>-- 같은 주소인데 저장 형태가 다르다
&amp;#39;경기도 화성시 진안동 908&amp;#39;
&amp;#39;경기 화성시 진안동 908&amp;#39;
&amp;#39;경기도 화성시 진안동 908&amp;#39; -- 공백이 두 개&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&amp;ldquo;경기도&amp;quot;를 쓴 곳도 있고, &amp;ldquo;경기&amp;quot;로 줄여 쓴 곳도 있고, 공백이 두 개인 데이터도 있었습니다. 외부 API에서 가져온 데이터와 직접 입력한 데이터가 섞여 있다 보니 형식이 제각각이었던 거죠. &lt;code>LIKE '%화성시 진안동%'&lt;/code>으로 매칭하면 공백이 두 개인 데이터는 잡히지 않았습니다.&lt;/p>
&lt;p>그리고 &lt;strong>도로명 주소에는 동 이름이 없습니다.&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>&amp;#39;경기도 화성시 병점4로 102&amp;#39;
&amp;#39;경기도 화성시 동탄중심상로 120&amp;#39;&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>동 이름 기반 매핑으로는 도로명 주소를 처리할 수 없습니다. 도로명 주소는 도로명→구 매핑을 별도로 만들어야 했는데, 화성시의 도로가 수백 개여서 이 매핑 테이블 자체를 만드는 것도 상당한 작업이었습니다.&lt;/p>
&lt;p>결국 지번 주소 컬럼과 도로명 주소 컬럼의 스크립트를 완전히 분리해서 작성해야 했습니다. 거기에 행정구역 코드만 저장하는 컬럼은 또 코드 매핑 테이블을 별도로 만들어서 처리해야 했고요. 주소를 변환하기 전에 데이터 클렌징부터 해야 하는 상황이었습니다. 마이그레이션이라기보다 비정규화된 데이터를 정리하는 작업에 더 가까웠습니다.&lt;/p>
&lt;h3>컬럼마다 다른 스크립트, 테이블마다 다른 오탐 조건&lt;span class="hx:absolute hx:-mt-20" id="컬럼마다-다른-스크립트-테이블마다-다른-오탐-조건">&lt;/span>
&lt;a href="#%ec%bb%ac%eb%9f%bc%eb%a7%88%eb%8b%a4-%eb%8b%a4%eb%a5%b8-%ec%8a%a4%ed%81%ac%eb%a6%bd%ed%8a%b8-%ed%85%8c%ec%9d%b4%eb%b8%94%eb%a7%88%eb%8b%a4-%eb%8b%a4%eb%a5%b8-%ec%98%a4%ed%83%90-%ec%a1%b0%ea%b1%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>정리하면, 컬럼의 저장 형태에 따라 최소 4가지 유형의 스크립트가 필요했습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>저장 형태&lt;/th>
&lt;th>처리 방식&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>전체 지번 주소&lt;/td>
&lt;td>동 이름 기반 매핑 → 구 삽입&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>도로명 주소&lt;/td>
&lt;td>도로명 기반 매핑 → 구 삽입&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>시군구명만&lt;/td>
&lt;td>변경 없음 (단, 서비스 로직 확인 필요)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>행정구역 코드&lt;/td>
&lt;td>코드 매핑 테이블로 변환&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>그리고 이 4가지 유형을 기본으로 하되, 테이블마다 오탐 조건이 달랐습니다. 아파트 테이블에는 &amp;ldquo;화성시청역&amp;rdquo; 같은 브랜드명이 있고, 거래 테이블에는 없고, 중개사 테이블에는 또 다른 형태의 오탐이 있을 수 있었습니다. 결국 각 테이블의 샘플 데이터를 확인하면서 스크립트마다 오탐 조건을 조정해야 했습니다.&lt;/p>
&lt;p>75개 테이블, 120개 컬럼에 대해 이 작업을 반복한다는 건, 비슷하지만 미묘하게 다른 스크립트를 수십 개 작성한다는 의미였습니다. 자동화할 수 있는 부분은 자동화했지만, 컬럼마다 저장 형태가 다르고 오탐 케이스가 다르다 보니 결국 하나하나 확인하면서 작성할 수밖에 없었습니다. 이쯤 되니 &amp;ldquo;어째서 주소를 왜 텍스트로 저장해둔 거지..&amp;ldquo;라는 생각이 계속 들었습니다.&lt;/p>
&lt;h3>검증: 끝이 안 보이는 반복 작업&lt;span class="hx:absolute hx:-mt-20" id="검증-끝이-안-보이는-반복-작업">&lt;/span>
&lt;a href="#%ea%b2%80%ec%a6%9d-%eb%81%9d%ec%9d%b4-%ec%95%88-%eb%b3%b4%ec%9d%b4%eb%8a%94-%eb%b0%98%eb%b3%b5-%ec%9e%91%ec%97%85" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>스크립트를 작성한 뒤에는 당연히 바로 운영에 실행할 수는 없었습니다. 280만 건의 데이터를 변경하는 작업에서 스크립트에 오류가 있으면 되돌리기가 어렵기 때문입니다.&lt;/p>
&lt;p>개발 환경에서 먼저 돌려보고, 변경 전후 데이터를 비교 검증했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;span class="lnt">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- 변경 전 스냅샷
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">CREATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">apartment_backup&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">addr&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">apartment&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">addr&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">LIKE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;%화성시%&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">-- 스크립트 실행 후 비교
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">b&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">addr&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">before_addr&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">addr&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">after_addr&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">apartment&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">JOIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">apartment_backup&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">b&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">b&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">addr&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">!=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">b&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">addr&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">LIMIT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">100&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 검증 과정에서 놓쳤던 문제들이 발견되기도 했습니다. 예를 들어, 동 이름이 다른 동 이름의 일부인 경우가 있었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>&amp;#39;반월동&amp;#39; 매핑을 적용하니 → &amp;#39;반월동&amp;#39;, &amp;#39;반월1동&amp;#39; 둘 다 매칭됨&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>LIKE 패턴의 매칭 순서나 정확도를 조정해야 하는 케이스들이 검증 과정에서 계속 나왔고, 그때마다 스크립트를 수정하고 다시 돌리고 다시 검증하는 과정을 반복했습니다.&lt;/p>
&lt;p>75개 테이블 각각에 대해 &lt;strong>스냅샷 → 실행 → 비교 → 수정 → 재실행&lt;/strong> 사이클을 돌린 겁니다. 솔직히 이 과정이 가장 시간이 많이 들었고, 가장 지치는 작업이었습니다.&lt;/p>
&lt;h3>운영 환경 적용&lt;span class="hx:absolute hx:-mt-20" id="운영-환경-적용">&lt;/span>
&lt;a href="#%ec%9a%b4%ec%98%81-%ed%99%98%ea%b2%bd-%ec%a0%81%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>개발 환경 검증을 마치고 나서도 한숨 돌릴 수 없었습니다. 진짜 긴장되는 건 운영 환경 적용이었거든요.&lt;/p>
&lt;p>개발 환경은 실수해도 다시 하면 그만이지만, 운영 환경은 다릅니다. 스크립트에 오류가 있으면 서비스에 잘못된 주소가 바로 노출됩니다. &amp;ldquo;경기도 화성시 병점구 병점구 진안동&amp;rdquo; 같은 이중 삽입이라도 발생하면 사용자께서 바로 알아차리시는 문제니까요.&lt;/p>
&lt;p>280만 건을 한 번에 UPDATE하면 테이블 락이 오래 잡힐 수 있기 때문에, 테이블 단위로 나누어 실행하되 데이터가 많은 테이블은 배치 단위로 끊어서 실행했습니다. 트래픽이 적은 시간대를 골라 진행했고, 한 테이블 실행할 때마다 서비스에서 변경된 주소가 정상적으로 노출되는지 확인한 뒤에 다음 테이블로 넘어갔습니다. 돌이켜보면 이 과정이 가장 신경이 곤두섰던 시간이었던 것 같습니다.&lt;/p>
&lt;p>전체 과정을 정리하면 이랬습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>영향 범위 파악&lt;/strong> — 컬럼명 기반 조사 + LIKE 전수조사&lt;/li>
&lt;li>&lt;strong>매핑 테이블 구축&lt;/strong> — 동→구 매핑, 도로명→구 매핑, 행정코드 매핑&lt;/li>
&lt;li>&lt;strong>오탐 필터링&lt;/strong> — 테이블별 샘플 확인 후 브랜드명 등 제외 조건 설정&lt;/li>
&lt;li>&lt;strong>컬럼 유형별 스크립트 작성&lt;/strong> — 지번 주소, 도로명 주소, 행정코드 등 각각 다른 로직&lt;/li>
&lt;li>&lt;strong>개발 환경 반복 검증&lt;/strong> — 스냅샷 비교 → 오류 발견 → 수정 → 재검증 반복&lt;/li>
&lt;li>&lt;strong>운영 환경 적용&lt;/strong> — 테이블 단위 분할, 대용량 테이블은 배치 처리, 트래픽 적은 시간대 실행&lt;/li>
&lt;li>&lt;strong>사후 검증&lt;/strong> — 서비스에서 변경된 주소가 정상 노출되는지 확인&lt;/li>
&lt;/ol>
&lt;h2>정규화가 되어 있었다면&lt;span class="hx:absolute hx:-mt-20" id="정규화가-되어-있었다면">&lt;/span>
&lt;a href="#%ec%a0%95%ea%b7%9c%ed%99%94%ea%b0%80-%eb%90%98%ec%96%b4-%ec%9e%88%ec%97%88%eb%8b%a4%eb%a9%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>전수조사에, 매핑 테이블 구축에, 컬럼별 스크립트 작성에, 반복 검증에, 운영 적용까지. 이 작업을 하는 내내 드는 생각이 있었습니다. 정규화가 되어 있었다면 이 작업이 얼마나 간단했을까?&lt;/p>
&lt;p>만약 행정구역 마스터 테이블에 주소 정보를 한 곳에서 관리하고, 각 서비스 테이블은 코드만 참조하는 구조였다면 어떨까요.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- 마스터 테이블 (Single Source of Truth)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">CREATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">area_code&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">region_code&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">10&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">PRIMARY&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">KEY&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">sido&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">20&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 경기도
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">sigungu&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">20&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 화성시
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dong&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">20&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 진안동
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">full_address&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">100&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">-- 서비스 테이블은 코드만 참조
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">CREATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">apartment&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">BIGINT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">PRIMARY&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">KEY&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">100&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">region_code&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">10&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">-- FK 참조
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FOREIGN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">KEY&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">region_code&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">REFERENCES&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">area_code&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">region_code&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">);&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 구조에서 화성시 분구 마이그레이션은 이렇게 됩니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- 마스터 테이블 40여 개 행 UPDATE. 끝.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">UPDATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">area_code&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">SET&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">region_code&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;4159551000&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">sigungu&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;병점구&amp;#39;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">region_code&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;4159052000&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>마스터 테이블 한 곳만 수정하면, 참조하는 모든 테이블이 자동으로 변경된 주소를 보여주게 됩니다. 앞서 이야기한 7단계 — 전수조사, 매핑 테이블, 오탐 필터링, 컬럼별 스크립트, 반복 검증, 운영 적용, 사후 검증 — 가 이 UPDATE 하나로 끝나는 겁니다.&lt;/p>
&lt;p>처음부터 이런 구조였다면 얼마나 좋았을까, 라는 생각이 들었습니다. 물론 일부는 그렇게 돼 있었지만, 주소 텍스트를 직접 저장하는 테이블이 너무 많아서 결국 이 작업을 피할 수 없었죠.&lt;/p>
&lt;p>&lt;strong>하나의 사실이 한 곳에만 존재해야 한다&lt;/strong>는 정규화의 기본 원칙, Single Source of Truth가 단순히 교과서적인 이야기가 아니라 실제로 지키지 않으면 큰 대가를 치를 수 있다는 걸 이번에 제대로 체감했습니다.&lt;/p>
&lt;h2>그렇다고 무조건 정규화?&lt;span class="hx:absolute hx:-mt-20" id="그렇다고-무조건-정규화">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%a0%87%eb%8b%a4%ea%b3%a0-%eb%ac%b4%ec%a1%b0%ea%b1%b4-%ec%a0%95%ea%b7%9c%ed%99%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>앞서 이야기했듯이, 마이그레이션을 하는 동안에는 비정규화된 구조에 대한 아쉬움밖에 없었습니다. 그런데 작업을 마치고 나서 좀 더 냉정하게 생각해보니, 처음에 텍스트로 저장한 선택에도 나름의 이유가 있었을 거라는 생각이 들었습니다.&lt;/p>
&lt;p>저희 서비스는 매물 목록, 실거래가 조회 같은 읽기 작업이 압도적으로 많습니다. 매물 목록 API 하나만 봐도 한 번에 수십 개의 주소를 보여줘야 하는데, 만약 주소가 정규화되어 있다면 매물을 조회할 때마다 행정구역 마스터 테이블에 JOIN을 해야 합니다. 트래픽이 많은 서비스에서 거의 모든 조회 API에 JOIN이 하나씩 추가된다면, 성능에 적지 않은 부담이 되거든요.&lt;/p>
&lt;p>저장하는 쪽도 사정이 비슷합니다. 저희 서비스는 국토교통부, 행정안전부 등 외부 API에서 데이터를 받아와서 저장하는 경우가 많은데, 이 API 응답에는 이미 완성된 주소 텍스트가 들어있습니다. &lt;code>&amp;quot;경기도 화성시 진안동 908&amp;quot;&lt;/code> 이런 식으로요. 이걸 그대로 저장하면 한 줄이지만, 정규화 구조에 맞추려면 주소를 파싱해서 시/도, 시/군/구, 동 각각의 코드를 찾고 매핑해서 저장해야 합니다. 외부 API 연동이 하나둘이 아닌 상황에서 매번 이 파싱 로직을 거치는 건 꽤 번거로운 작업이었을 겁니다.&lt;/p>
&lt;p>그리고 정규화도 과하면 그 자체로 문제가 됩니다. 이건 실제로 제가 &amp;ldquo;그럼 주소를 어디까지 정규화해야 하지?&amp;ldquo;를 고민하면서 느낀 건데, 만약 시/도, 시/군/구, 읍/면/동, 리, 번지까지 전부 별도 테이블로 분리했다고 가정해보겠습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">s&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">sg&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">d&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">r&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">bungi&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">apartment&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">JOIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dong&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">d&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">dong_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">d&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">JOIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">sigungu&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">sg&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">d&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">sigungu_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">sg&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">JOIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">sido&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">s&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">sg&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">sido_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">s&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">LEFT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">JOIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ri&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">r&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">ri_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">r&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>주소 하나를 보여주기 위해 4~5개 테이블을 JOIN해야 합니다. 저희처럼 읽기 비중이 높은 서비스에서 이런 구조는 현실적이지 않습니다. 정규화를 안 하면 이번처럼 마이그레이션 지옥을 겪게 되고, 과하게 하면 조회 성능 지옥을 겪게 됩니다. 결국 어디에서 균형을 잡을 것이냐의 문제라고 생각합니다.&lt;/p>
&lt;h2>그래서 적절한 균형은 어디인가&lt;span class="hx:absolute hx:-mt-20" id="그래서-적절한-균형은-어디인가">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%9e%98%ec%84%9c-%ec%a0%81%ec%a0%88%ed%95%9c-%ea%b7%a0%ed%98%95%ec%9d%80-%ec%96%b4%eb%94%94%ec%9d%b8%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이번 경험을 겪고 나서, 만약 처음부터 다시 설계한다면 어떻게 할까를 고민해봤습니다.&lt;/p>
&lt;p>제가 내린 결론은 &lt;strong>코드 참조를 기본으로 하되, 성능이 필요한 곳에서는 의도적으로 반정규화하는 방식&lt;/strong>이었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- 기본은 코드 참조 (정규화)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">CREATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">area_code&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">region_code&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">10&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">PRIMARY&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">KEY&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">full_address&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">100&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">-- 자주 조회되는 테이블에는 주소 텍스트도 함께 저장 (의도적 반정규화)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- 단, region_code도 함께 가지고 있어 변경 시 업데이트 가능
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">CREATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">apartment&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">BIGINT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">PRIMARY&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">KEY&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">100&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">region_code&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">10&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 코드 참조 (정규화)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">cached_address&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">200&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 성능을 위한 캐시 (반정규화)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FOREIGN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">KEY&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">region_code&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">REFERENCES&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">area_code&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">region_code&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">);&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 구조가 이전의 완전 비정규화 방식과 뭐가 다른지 의문이 드실 수 있는데, 핵심적인 차이가 하나 있습니다. &lt;code>region_code&lt;/code>라는 &lt;strong>업데이트의 기준점&lt;/strong>이 존재한다는 겁니다.&lt;/p>
&lt;p>텍스트만 저장했을 때는 &amp;ldquo;이 주소가 어느 동에 속하는지&amp;quot;를 텍스트 파싱으로 추론해야 했지만, &lt;code>region_code&lt;/code>가 있으면 코드 기준으로 정확하게 매핑할 수 있습니다. 조회 시에는 JOIN 없이 &lt;code>cached_address&lt;/code>를 바로 사용하고, 행정구역이 변경되면 &lt;code>region_code&lt;/code>를 기준으로 &lt;code>cached_address&lt;/code>를 일괄 업데이트하면 됩니다.&lt;/p>
&lt;p>실제로 일부 테이블들은 위와 같은 방식으로 설계되어 있었는데, 이번 마이그레이션 작업에서는 이 테이블들은 비교적 수월하게 처리되었습니다. &lt;code>region_code&lt;/code> 기준으로 매핑이 명확했기 때문에, 오탐 걱정 없이 단순 치환 스크립트로 바로 처리할 수 있었거든요.&lt;/p>
&lt;p>하지만 많은 테이블이 &lt;code>region_code&lt;/code> 없이 주소 텍스트만 저장하고 있었기 때문에, 이번처럼 복잡한 작업이 불가피했습니다. 모든 테이블이 위와같은 구조였다면 이번 작업이 훨씬 수월했을 거라는 생각이 듭니다.&lt;/p>
&lt;h2>정리&lt;span class="hx:absolute hx:-mt-20" id="정리">&lt;/span>
&lt;a href="#%ec%a0%95%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이번 작업을 통해 가장 크게 느낀 건, 정규화의 가치는 평소에는 잘 보이지 않는다는 점이었습니다. 텍스트로 저장하면 조회도 빠르고 저장도 편합니다. 그 편리함이 대가로 돌아오는 건, 이번처럼 데이터가 변경되는 순간이거든요. 그리고 그 대가는 75개 테이블 전수조사와 280만 건 데이터 클렌징이라는 형태로 제게 한꺼번에 찾아왔습니다.&lt;/p>
&lt;p>그렇다고 무조건 정규화가 답이라고는 생각하지 않습니다. 주소 하나 보여주려고 5개 테이블을 JOIN하는 구조도, 외부 API 응답을 매번 파싱해서 정규화하는 것도 현실적이지 않거든요. 결국 정규화와 비정규화 사이 어딘가에서 균형을 잡아야 하는 문제라고 생각합니다.&lt;/p>
&lt;p>다만 이번 경험을 겪고 나서 한 가지 확실해진 게 있습니다. 비정규화를 선택할 때, 그 이유가 &amp;ldquo;귀찮아서&amp;quot;여서는 안 된다고 생각합니다. 성능 때문에 의도적으로 텍스트를 중복 저장하더라도, &lt;code>region_code&lt;/code> 같은 업데이트의 기준점은 함께 가지고 있어야 하지 않나 싶습니다. 그래야 다음에 변경이 생겼을 때, 전수조사가 아니라 코드 기준의 일괄 업데이트로 대응할 수 있으니까요.&lt;/p>
&lt;p>다음에 비슷한 설계 결정을 내릴 때, 이번 전수조사의 기억이 꽤 오래 남아 있을 것 같습니다.&lt;/p>
&lt;h3>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;h4>화성시 분구&lt;span class="hx:absolute hx:-mt-20" id="화성시-분구">&lt;/span>
&lt;a href="#%ed%99%94%ec%84%b1%ec%8b%9c-%eb%b6%84%ea%b5%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;ul>
&lt;li>&lt;a href="https://www.mois.go.kr/frt/bbs/type001/commonSelectBoardArticle.do?bbsId=BBSMSTR_000000000052&amp;amp;nttId=122595"target="_blank" rel="noopener">행정기관(행정동) 및 관할구역(법정동) 변경내역 알림(2026.2.1. 시행) - 행정안전부&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.hankookilbo.com/News/Read/A2025082408260002063"target="_blank" rel="noopener">화성시 동탄구 등 4개 일반구 신설 확정 - 한국일보&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://namu.wiki/w/%ED%99%94%EC%84%B1%EC%8B%9C/%ED%96%89%EC%A0%95/%EB%B6%84%EA%B5%AC%20%EC%B6%94%EC%A7%84"target="_blank" rel="noopener">화성시/행정/분구 추진 - 나무위키&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;h4>데이터베이스 정규화&lt;span class="hx:absolute hx:-mt-20" id="데이터베이스-정규화">&lt;/span>
&lt;a href="#%eb%8d%b0%ec%9d%b4%ed%84%b0%eb%b2%a0%ec%9d%b4%ec%8a%a4-%ec%a0%95%ea%b7%9c%ed%99%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;ul>
&lt;li>&lt;a href="https://en.wikipedia.org/wiki/Database_normalization"target="_blank" rel="noopener">Database Normalization - Wikipedia&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>RPC 제대로 이해하기: JSON-RPC, gRPC, 그리고 흔한 오해들</title><link>https://jeongil.dev/ko/blog/backend/rpc-deep-dive/</link><pubDate>Tue, 27 Jan 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/backend/rpc-deep-dive/</guid><description>
&lt;p>얼마 전 &lt;a href="https://jeongil.dev/ko/blog/trends/mcp-deep-dive/">MCP(Model Context Protocol) 글&lt;/a>을 쓰면서 JSON-RPC를 다루게 되었습니다. 그런데 글을 쓰다 보니 스스로에게 질문이 생기더라구요.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;JSON-RPC, gRPC가 경량화됐다고 하는데, HTTP 위에서 REST랑 뭐가 다르지?&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>이 질문에 명확하게 답하려면 RPC가 뭔지부터 제대로 이해해야 할 것 같았습니다. 그래서 이번 글에서는 RPC의 개념부터 JSON-RPC, gRPC까지, 그리고 흔히 하는 오해들을 정리해보려고 합니다.&lt;/p>
&lt;h2>RPC란 무엇인가?&lt;span class="hx:absolute hx:-mt-20" id="rpc란-무엇인가">&lt;/span>
&lt;a href="#rpc%eb%9e%80-%eb%ac%b4%ec%97%87%ec%9d%b8%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>RPC는 &lt;strong>Remote Procedure Call&lt;/strong>의 약자입니다. 직역하면 &amp;ldquo;원격 프로시저 호출&amp;quot;인데, 쉽게 말해 &lt;strong>네트워크 너머에 있는 함수를 마치 로컬 함수처럼 호출하는 방식&lt;/strong>입니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant Client as 클라이언트
participant Network as 네트워크
participant Server as 서버
Client-&amp;gt;&amp;gt;Client: add(1, 2) 호출
Note over Client: 로컬 함수처럼 보이지만...
Client-&amp;gt;&amp;gt;Network: 요청 전송
Network-&amp;gt;&amp;gt;Server:
Server-&amp;gt;&amp;gt;Server: 실제 add 함수 실행
Server-&amp;gt;&amp;gt;Network: 결과: 3
Network-&amp;gt;&amp;gt;Client:
Client-&amp;gt;&amp;gt;Client: 결과 수신: 3
&lt;/pre>&lt;p>클라이언트 코드에서는 그냥 &lt;code>add(1, 2)&lt;/code>를 호출하는 것처럼 보이지만, 실제로는 네트워크를 통해 서버에서 실행되고 결과가 돌아오는 구조입니다.&lt;/p>
&lt;h3>RPC의 핵심 아이디어&lt;span class="hx:absolute hx:-mt-20" id="rpc의-핵심-아이디어">&lt;/span>
&lt;a href="#rpc%ec%9d%98-%ed%95%b5%ec%8b%ac-%ec%95%84%ec%9d%b4%eb%94%94%ec%96%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>RPC의 핵심은 &lt;strong>네트워크 통신의 복잡함을 숨기는 것&lt;/strong>이라고 생각합니다.&lt;/p>
&lt;p>개발자가 직접 소켓을 열고, 데이터를 직렬화하고, 전송하고, 응답을 파싱하는 과정을 일일이 작성하는 대신, 그냥 함수를 호출하면 라이브러리가 알아서 처리해주는 거죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;span class="lnt">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># RPC 없이 직접 구현하면...&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">socket&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">connect&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;server:8080&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">data&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">serialize&lt;/span>&lt;span class="p">({&lt;/span>&lt;span class="s2">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;add&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;params&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="mi">2&lt;/span>&lt;span class="p">]})&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">socket&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">send&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">data&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">response&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">socket&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">receive&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">result&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">deserialize&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">response&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># RPC를 사용하면...&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">result&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">server&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">add&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="mi">2&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="c1"># 이게 끝&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 아이디어는 1980년대부터 있었습니다. &lt;a href="https://datatracker.ietf.org/doc/html/rfc5531"target="_blank" rel="noopener">Sun Microsystems의 ONC RPC&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>(1988), 이후 &lt;a href="https://www.omg.org/spec/CORBA/"target="_blank" rel="noopener">CORBA&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>(1991), &lt;a href="https://docs.oracle.com/javase/8/docs/technotes/guides/rmi/"target="_blank" rel="noopener">Java RMI&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>(1997) 등 다양한 구현이 있었죠. 지금의 gRPC나 JSON-RPC도 이 오래된 아이디어의 연장선에 있습니다.&lt;/p>
&lt;h2>RPC는 프로토콜인가, 패러다임인가?&lt;span class="hx:absolute hx:-mt-20" id="rpc는-프로토콜인가-패러다임인가">&lt;/span>
&lt;a href="#rpc%eb%8a%94-%ed%94%84%eb%a1%9c%ed%86%a0%ec%bd%9c%ec%9d%b8%ea%b0%80-%ed%8c%a8%eb%9f%ac%eb%8b%a4%ec%9e%84%ec%9d%b8%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>여기서 중요한 구분이 필요합니다. &lt;strong>RPC 자체는 프로토콜이 아니라 패러다임(개념)입니다.&lt;/strong>&lt;/p>
&lt;p>더 정확히 말하면, RPC는 &lt;strong>&amp;ldquo;호출 방식&amp;rdquo;&lt;/strong> 을 의미하지 &lt;strong>&amp;ldquo;통신 방식&amp;rdquo;&lt;/strong> 을 의미하지 않습니다.&lt;/p>
&lt;h3>개념 분리: 호출 방식 vs 통신 방식 vs 데이터 포맷&lt;span class="hx:absolute hx:-mt-20" id="개념-분리-호출-방식-vs-통신-방식-vs-데이터-포맷">&lt;/span>
&lt;a href="#%ea%b0%9c%eb%85%90-%eb%b6%84%eb%a6%ac-%ed%98%b8%ec%b6%9c-%eb%b0%a9%ec%8b%9d-vs-%ed%86%b5%ec%8b%a0-%eb%b0%a9%ec%8b%9d-vs-%eb%8d%b0%ec%9d%b4%ed%84%b0-%ed%8f%ac%eb%a7%b7" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이 부분이 헷갈리기 쉬운데, 각각의 개념을 명확히 분리해보겠습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>개념&lt;/th>
&lt;th>의미&lt;/th>
&lt;th>예시&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>호출 방식 (패러다임)&lt;/strong>&lt;/td>
&lt;td>어떻게 요청을 개념화하는가&lt;/td>
&lt;td>RPC (함수 호출), REST (리소스 조작)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>전송 방법 (Transport)&lt;/strong>&lt;/td>
&lt;td>데이터가 물리적으로 어떻게 이동하는가&lt;/td>
&lt;td>HTTP, TCP, WebSocket, stdio&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>데이터 포맷&lt;/strong>&lt;/td>
&lt;td>데이터를 어떤 형식으로 인코딩하는가&lt;/td>
&lt;td>JSON, XML, Protobuf&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>프로토콜&lt;/strong>&lt;/td>
&lt;td>위 모두를 포함한 완전한 스펙&lt;/td>
&lt;td>JSON-RPC, gRPC&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>그래서 JSON-RPC와 gRPC를 분해하면 이렇게 됩니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>JSON-RPC = RPC(호출 방식) &amp;#43; JSON(데이터 포맷) &amp;#43; 정해진 메시지 구조
└─ 전송 방법은 자유 (HTTP, TCP, WebSocket, stdio 등)
gRPC = RPC(호출 방식) &amp;#43; Protobuf(데이터 포맷) &amp;#43; HTTP/2(전송 방법 고정)
└─ 전송 방법이 HTTP/2로 고정됨&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>JSON-RPC는 전송 방법이 자유롭다&lt;span class="hx:absolute hx:-mt-20" id="json-rpc는-전송-방법이-자유롭다">&lt;/span>
&lt;a href="#json-rpc%eb%8a%94-%ec%a0%84%ec%86%a1-%eb%b0%a9%eb%b2%95%ec%9d%b4-%ec%9e%90%ec%9c%a0%eb%a1%ad%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;a href="https://www.jsonrpc.org/specification"target="_blank" rel="noopener">JSON-RPC 2.0 공식 스펙&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에는 이렇게 명시되어 있습니다.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;It is transport agnostic in that the concepts can be used within the same process, over sockets, over HTTP, or in many various message passing environments.&amp;rdquo;&lt;/p>
&lt;/blockquote>
&lt;p>즉, 어떤 전송 방법을 쓰든 상관없습니다. 다만 &lt;strong>메시지 구조&lt;/strong>는 따라야 합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;getUser&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;params&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">123&lt;/span>&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 형식만 지키면, HTTP로 보내든 TCP로 보내든 stdio로 보내든 다 JSON-RPC입니다.&lt;/p>
&lt;h3>gRPC는 HTTP/2 기반이다&lt;span class="hx:absolute hx:-mt-20" id="grpc는-http2-기반이다">&lt;/span>
&lt;a href="#grpc%eb%8a%94-http2-%ea%b8%b0%eb%b0%98%ec%9d%b4%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>반면 gRPC는 다릅니다. &lt;a href="https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md"target="_blank" rel="noopener">공식 스펙&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에서 HTTP/2 기반으로 정의되어 있습니다.&lt;/p>
&lt;ul>
&lt;li>Protobuf + TCP로 통신하면? → gRPC가 &lt;strong>아닙니다&lt;/strong>. 그냥 &amp;ldquo;Protobuf 기반 RPC&amp;rdquo;&lt;/li>
&lt;li>Protobuf + HTTP/2로 통신하면? → gRPC &lt;strong>맞습니다&lt;/strong>&lt;/li>
&lt;/ul>
&lt;p>표준 gRPC가 HTTP/2를 사용하는 이유는, HTTP/2의 기능들(멀티플렉싱, 양방향 스트리밍, 헤더 압축)이 gRPC의 핵심 기능이기 때문입니다. 다만 전송 계층의 진화(HTTP/3, QUIC 등)에 따른 확장 가능성은 열려 있습니다.&lt;/p>
&lt;h3>정리&lt;span class="hx:absolute hx:-mt-20" id="정리">&lt;/span>
&lt;a href="#%ec%a0%95%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;/th>
&lt;th>JSON-RPC&lt;/th>
&lt;th>gRPC&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>호출 방식&lt;/strong>&lt;/td>
&lt;td>RPC&lt;/td>
&lt;td>RPC&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>데이터 포맷&lt;/strong>&lt;/td>
&lt;td>JSON&lt;/td>
&lt;td>Protobuf (기본)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>전송 방법&lt;/strong>&lt;/td>
&lt;td>자유 (스펙에 &amp;ldquo;transport agnostic&amp;rdquo; 명시)&lt;/td>
&lt;td>HTTP/2 (표준)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>비유하자면, &lt;strong>RPC는 &amp;ldquo;객체지향 프로그래밍&amp;quot;같은 &amp;lsquo;개념&amp;rsquo;&lt;/strong> 이고, &lt;strong>JSON-RPC나 gRPC는 &amp;ldquo;Java&amp;rdquo;, &amp;ldquo;Python&amp;quot;같은 구체적인 구현&lt;/strong>인 셈입니다.&lt;/p>
&lt;h2>RPC vs REST: 패러다임의 차이&lt;span class="hx:absolute hx:-mt-20" id="rpc-vs-rest-패러다임의-차이">&lt;/span>
&lt;a href="#rpc-vs-rest-%ed%8c%a8%eb%9f%ac%eb%8b%a4%ec%9e%84%ec%9d%98-%ec%b0%a8%ec%9d%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>RPC를 이해하려면 REST와 비교해보는 게 도움이 될 것 같습니다.&lt;/p>
&lt;h3>REST: 리소스 중심&lt;span class="hx:absolute hx:-mt-20" id="rest-리소스-중심">&lt;/span>
&lt;a href="#rest-%eb%a6%ac%ec%86%8c%ec%8a%a4-%ec%a4%91%ec%8b%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>REST는 &lt;strong>리소스(명사)&lt;/strong> 중심입니다. URL이 리소스를 나타내고, HTTP 메서드가 행위를 나타내죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>GET /users/123 → 사용자 조회
POST /users → 사용자 생성
PUT /users/123 → 사용자 수정
DELETE /users/123 → 사용자 삭제&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>RPC: 행위 중심&lt;span class="hx:absolute hx:-mt-20" id="rpc-행위-중심">&lt;/span>
&lt;a href="#rpc-%ed%96%89%ec%9c%84-%ec%a4%91%ec%8b%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>RPC는 &lt;strong>행위(동사)&lt;/strong> 중심입니다. &amp;ldquo;이 함수를 실행해줘&amp;quot;라고 요청하는 방식이죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>POST /rpc
{
&amp;#34;method&amp;#34;: &amp;#34;getUser&amp;#34;,
&amp;#34;params&amp;#34;: {&amp;#34;id&amp;#34;: 123}
}
POST /rpc
{
&amp;#34;method&amp;#34;: &amp;#34;createUser&amp;#34;,
&amp;#34;params&amp;#34;: {&amp;#34;name&amp;#34;: &amp;#34;Kim&amp;#34;, &amp;#34;email&amp;#34;: &amp;#34;kim@example.com&amp;#34;}
}&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>어떤 게 더 좋은가?&lt;span class="hx:absolute hx:-mt-20" id="어떤-게-더-좋은가">&lt;/span>
&lt;a href="#%ec%96%b4%eb%96%a4-%ea%b2%8c-%eb%8d%94-%ec%a2%8b%ec%9d%80%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>솔직히 말하면, &lt;strong>상황에 따라 다르다고 생각합니다.&lt;/strong>&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>상황&lt;/th>
&lt;th>적합한 방식&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>CRUD 중심의 리소스 관리&lt;/td>
&lt;td>REST&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>복잡한 비즈니스 로직 호출&lt;/td>
&lt;td>RPC&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>공개 API (외부 개발자용)&lt;/td>
&lt;td>REST (직관적)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>내부 마이크로서비스 통신&lt;/td>
&lt;td>RPC (효율적)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>REST가 더 직관적이고 널리 쓰이지만, 복잡한 작업을 표현할 때는 조금 어색해질 수 있습니다.&lt;/p>
&lt;p>예를 들어 &amp;ldquo;장바구니에 있는 상품들의 총 가격을 계산하고, 쿠폰을 적용하고, 배송비를 더해서 최종 금액을 반환&amp;quot;하는 API를 REST로 어떻게 표현할까요?&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>GET /carts/123/total-with-coupon-and-shipping?coupon=ABC123&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>좀 어색하지 않나요? RPC라면 다음과 같이 더 자연스럽게 표현할 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;calculateFinalPrice&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;params&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;cartId&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">123&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;couponCode&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;ABC123&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;includeShipping&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="kc">true&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이렇게 행위 중심의 복잡한 작업에는 RPC가 더 자연스러울 수 있습니다.&lt;/p>
&lt;h2>JSON-RPC: 단순함의 미학&lt;span class="hx:absolute hx:-mt-20" id="json-rpc-단순함의-미학">&lt;/span>
&lt;a href="#json-rpc-%eb%8b%a8%ec%88%9c%ed%95%a8%ec%9d%98-%eb%af%b8%ed%95%99" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>JSON-RPC는 RPC 패러다임을 JSON 메시지 포맷으로 구현한 프로토콜입니다. 스펙 문서가 몇 페이지 안 될 정도로 단순하더라구요.&lt;/p>
&lt;h3>메시지 구조&lt;span class="hx:absolute hx:-mt-20" id="메시지-구조">&lt;/span>
&lt;a href="#%eb%a9%94%ec%8b%9c%ec%a7%80-%ea%b5%ac%ec%a1%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>요청&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;subtract&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;params&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="mi">42&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="mi">23&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>응답&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;result&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">19&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>에러&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;error&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;code&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">-32601&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;message&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;Method not found&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이게 거의 전부입니다. &lt;code>jsonrpc&lt;/code> 버전, &lt;code>id&lt;/code>로 요청-응답 매칭, &lt;code>method&lt;/code>와 &lt;code>params&lt;/code>로 호출, &lt;code>result&lt;/code>나 &lt;code>error&lt;/code>로 응답.&lt;/p>
&lt;h3>JSON-RPC의 특징&lt;span class="hx:absolute hx:-mt-20" id="json-rpc의-특징">&lt;/span>
&lt;a href="#json-rpc%ec%9d%98-%ed%8a%b9%ec%a7%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>1. 전송 계층에 독립적&lt;/strong>&lt;/p>
&lt;p>JSON-RPC는 메시지 포맷만 정의합니다. HTTP, WebSocket, TCP, 심지어 stdio(표준 입출력) 위에서도 동작할 수 있습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
JSONRPC[&amp;#34;JSON-RPC 메시지&amp;#34;]
JSONRPC --&amp;gt; HTTP[&amp;#34;HTTP&amp;#34;]
JSONRPC --&amp;gt; WS[&amp;#34;WebSocket&amp;#34;]
JSONRPC --&amp;gt; TCP[&amp;#34;TCP Socket&amp;#34;]
JSONRPC --&amp;gt; STDIO[&amp;#34;stdio&amp;#34;]
&lt;/pre>&lt;p>MCP(Model Context Protocol)가 로컬에서는 stdio로, 원격에서는 HTTP로 JSON-RPC 메시지를 주고받는 것도 이런 특성 덕분입니다.&lt;/p>
&lt;p>&lt;strong>2. 배치 요청 지원&lt;/strong>&lt;/p>
&lt;p>여러 요청을 하나로 묶어서 보낼 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>&lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nt">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;getUser&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nt">&amp;#34;params&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">}},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>&lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">2&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nt">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;getUser&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nt">&amp;#34;params&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">2&lt;/span>&lt;span class="p">}},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>&lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">3&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nt">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;getUser&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nt">&amp;#34;params&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">3&lt;/span>&lt;span class="p">}}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">]&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>HTTP 오버헤드를 줄이고 싶을 때 유용합니다.&lt;/p>
&lt;p>&lt;strong>3. Notification (응답 없는 요청)&lt;/strong>&lt;/p>
&lt;p>&lt;code>id&lt;/code>가 없으면 서버는 응답을 보내지 않습니다. &amp;ldquo;알림&amp;quot;용으로 쓸 수 있죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;log&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;params&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="nt">&amp;#34;message&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;User logged in&amp;#34;&lt;/span>&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h2>gRPC: 성능을 위한 선택&lt;span class="hx:absolute hx:-mt-20" id="grpc-성능을-위한-선택">&lt;/span>
&lt;a href="#grpc-%ec%84%b1%eb%8a%a5%ec%9d%84-%ec%9c%84%ed%95%9c-%ec%84%a0%ed%83%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>gRPC는 Google이 만든 RPC 프레임워크입니다. JSON-RPC와는 다른 방향으로 발전했죠.&lt;/p>
&lt;h3>gRPC의 특징&lt;span class="hx:absolute hx:-mt-20" id="grpc의-특징">&lt;/span>
&lt;a href="#grpc%ec%9d%98-%ed%8a%b9%ec%a7%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>1. Protocol Buffers (Protobuf)&lt;/strong>&lt;/p>
&lt;p>JSON 대신 바이너리 포맷인 Protobuf를 사용합니다. 기술적으로는 다른 코덱도 가능하지만, 실무에서는 거의 대부분 Protobuf를 씁니다. (JSON transcoding을 통해 REST API와 상호운용하는 경우도 있습니다.)&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-protobuf" data-lang="protobuf">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// user.proto
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="n">syntax&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s">&amp;#34;proto3&amp;#34;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="kd">service&lt;/span> &lt;span class="n">UserService&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span> &lt;span class="k">rpc&lt;/span> &lt;span class="n">GetUser&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">GetUserRequest&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="k">returns&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">User&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span> &lt;span class="k">rpc&lt;/span> &lt;span class="n">CreateUser&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">CreateUserRequest&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="k">returns&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">User&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="kd">message&lt;/span> &lt;span class="nc">GetUserRequest&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span> &lt;span class="kt">int32&lt;/span> &lt;span class="n">id&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="kd">message&lt;/span> &lt;span class="nc">User&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span> &lt;span class="kt">int32&lt;/span> &lt;span class="n">id&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span> &lt;span class="kt">string&lt;/span> &lt;span class="n">name&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="mi">2&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span> &lt;span class="kt">string&lt;/span> &lt;span class="n">email&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="mi">3&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 &lt;code>.proto&lt;/code> 파일로 클라이언트/서버 코드를 자동 생성합니다.&lt;/p>
&lt;p>&lt;strong>2. HTTP/2 기반&lt;/strong>&lt;/p>
&lt;p>표준 gRPC는 HTTP/2를 사용합니다. 이 덕분에 하나의 연결에서 여러 요청을 동시에 처리하는 멀티플렉싱, 헤더 압축, 양방향 스트리밍 같은 기능을 활용할 수 있습니다.&lt;/p>
&lt;p>&lt;strong>3. 스트리밍 지원&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-protobuf" data-lang="protobuf">&lt;span class="line">&lt;span class="cl">&lt;span class="kd">service&lt;/span> &lt;span class="n">ChatService&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span> &lt;span class="c1">// 단방향 스트리밍: 서버가 여러 메시지를 스트림으로 보냄
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">rpc&lt;/span> &lt;span class="n">SubscribeMessages&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">SubscribeRequest&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="k">returns&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">stream&lt;/span> &lt;span class="n">Message&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span> &lt;span class="c1">// 양방향 스트리밍: 클라이언트와 서버가 동시에 스트림
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">rpc&lt;/span> &lt;span class="n">Chat&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">stream&lt;/span> &lt;span class="n">Message&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="k">returns&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">stream&lt;/span> &lt;span class="n">Message&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>JSON-RPC vs gRPC&lt;span class="hx:absolute hx:-mt-20" id="json-rpc-vs-grpc">&lt;/span>
&lt;a href="#json-rpc-vs-grpc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;/th>
&lt;th>JSON-RPC&lt;/th>
&lt;th>gRPC&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>메시지 포맷&lt;/strong>&lt;/td>
&lt;td>JSON (텍스트)&lt;/td>
&lt;td>Protobuf (바이너리)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>전송 계층&lt;/strong>&lt;/td>
&lt;td>자유 (HTTP, WS, TCP, stdio)&lt;/td>
&lt;td>HTTP/2 (표준)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>스키마&lt;/strong>&lt;/td>
&lt;td>선택적&lt;/td>
&lt;td>필수 (.proto 파일)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>코드 생성&lt;/strong>&lt;/td>
&lt;td>없음&lt;/td>
&lt;td>자동 생성&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>스트리밍&lt;/strong>&lt;/td>
&lt;td>기본 미지원&lt;/td>
&lt;td>네이티브 지원&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>브라우저 지원&lt;/strong>&lt;/td>
&lt;td>가능&lt;/td>
&lt;td>제한적 (gRPC-Web 필요)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>학습 곡선&lt;/strong>&lt;/td>
&lt;td>낮음&lt;/td>
&lt;td>높음&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2>흔한 오해들&lt;span class="hx:absolute hx:-mt-20" id="흔한-오해들">&lt;/span>
&lt;a href="#%ed%9d%94%ed%95%9c-%ec%98%a4%ed%95%b4%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>RPC에 대해 공부하면서 제가 가졌던 오해들, 그리고 자주 보이는 오해들을 정리해봤습니다.&lt;/p>
&lt;h3>오해 1: &amp;ldquo;JSON-RPC는 REST보다 가볍다&amp;rdquo;&lt;span class="hx:absolute hx:-mt-20" id="오해-1-json-rpc는-rest보다-가볍다">&lt;/span>
&lt;a href="#%ec%98%a4%ed%95%b4-1-json-rpc%eb%8a%94-rest%eb%b3%b4%eb%8b%a4-%ea%b0%80%eb%b3%8d%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>정확히 말하면, HTTP 위에서 쓸 때는 차이가 없습니다.&lt;/strong>&lt;/p>
&lt;p>JSON-RPC가 &amp;ldquo;경량&amp;quot;이라고 불리는 건 &lt;strong>SOAP/XML-RPC와 비교했을 때&lt;/strong>입니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-xml" data-lang="xml">&lt;span class="line">&lt;span class="cl">&lt;span class="c">&amp;lt;!-- SOAP 요청 예시 (장황함) --&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="cp">&amp;lt;?xml version=&amp;#34;1.0&amp;#34;?&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nt">&amp;lt;soap:Envelope&lt;/span> &lt;span class="na">xmlns:soap=&lt;/span>&lt;span class="s">&amp;#34;http://www.w3.org/2003/05/soap-envelope&amp;#34;&lt;/span>&lt;span class="nt">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;lt;soap:Header&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c">&amp;lt;!-- 헤더들... --&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;lt;/soap:Header&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;lt;soap:Body&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;lt;m:GetUser&lt;/span> &lt;span class="na">xmlns:m=&lt;/span>&lt;span class="s">&amp;#34;http://example.com/user&amp;#34;&lt;/span>&lt;span class="nt">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;lt;m:UserId&amp;gt;&lt;/span>123&lt;span class="nt">&amp;lt;/m:UserId&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;lt;/m:GetUser&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;lt;/soap:Body&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nt">&amp;lt;/soap:Envelope&amp;gt;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// JSON-RPC 요청 (단순함)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nt">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;getUser&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nt">&amp;#34;params&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">123&lt;/span>&lt;span class="p">}}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>SOAP에 비하면 확실히 가볍죠. 하지만 REST JSON API와 비교하면 HTTP 오버헤드는 동일합니다.&lt;/p>
&lt;h3>오해 2: &amp;ldquo;RPC는 특정 전송 계층에 종속된다&amp;rdquo;&lt;span class="hx:absolute hx:-mt-20" id="오해-2-rpc는-특정-전송-계층에-종속된다">&lt;/span>
&lt;a href="#%ec%98%a4%ed%95%b4-2-rpc%eb%8a%94-%ed%8a%b9%ec%a0%95-%ec%a0%84%ec%86%a1-%ea%b3%84%ec%b8%b5%ec%97%90-%ec%a2%85%ec%86%8d%eb%90%9c%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>RPC는 패러다임이지 전송 방식이 아닙니다.&lt;/p>
&lt;ul>
&lt;li>JSON-RPC: HTTP, WebSocket, TCP, stdio 등 다양하게 가능&lt;/li>
&lt;li>gRPC: HTTP/2 (이건 gRPC의 선택이지 RPC의 본질이 아님)&lt;/li>
&lt;/ul>
&lt;h3>오해 3: &amp;ldquo;REST가 항상 RPC보다 낫다&amp;rdquo; (또는 그 반대)&lt;span class="hx:absolute hx:-mt-20" id="오해-3-rest가-항상-rpc보다-낫다-또는-그-반대">&lt;/span>
&lt;a href="#%ec%98%a4%ed%95%b4-3-rest%ea%b0%80-%ed%95%ad%ec%83%81-rpc%eb%b3%b4%eb%8b%a4-%eb%82%ab%eb%8b%a4-%eb%98%90%eb%8a%94-%ea%b7%b8-%eb%b0%98%eb%8c%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>둘은 &lt;strong>다른 문제를 푸는 다른 도구&lt;/strong>라고 생각합니다.&lt;/p>
&lt;p>&lt;strong>REST가 유리한 경우&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>리소스 CRUD가 중심인 API&lt;/li>
&lt;li>캐싱이 중요한 경우 (HTTP 캐시 활용)&lt;/li>
&lt;li>브라우저에서 직접 호출&lt;/li>
&lt;li>API를 처음 보는 개발자도 이해하기 쉬워야 할 때&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>RPC가 유리한 경우&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>복잡한 비즈니스 로직 호출&lt;/li>
&lt;li>마이크로서비스 간 내부 통신&lt;/li>
&lt;li>고성능이 필요한 경우 (gRPC)&lt;/li>
&lt;li>행위 중심의 API&lt;/li>
&lt;/ul>
&lt;h3>오해 4: &amp;ldquo;gRPC는 무조건 빠르다&amp;rdquo;&lt;span class="hx:absolute hx:-mt-20" id="오해-4-grpc는-무조건-빠르다">&lt;/span>
&lt;a href="#%ec%98%a4%ed%95%b4-4-grpc%eb%8a%94-%eb%ac%b4%ec%a1%b0%ea%b1%b4-%eb%b9%a0%eb%a5%b4%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>gRPC가 JSON 기반 API보다 빠른 건 맞지만, &lt;strong>모든 상황에서 의미 있는 차이는 아닌 것 같습니다.&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>네트워크 지연이 큰 환경: 직렬화 속도보다 네트워크가 병목&lt;/li>
&lt;li>단순한 CRUD: 오버엔지니어링일 수 있음&lt;/li>
&lt;li>브라우저 클라이언트: gRPC-Web 추가 복잡성&lt;/li>
&lt;/ul>
&lt;p>gRPC의 진가는 &lt;strong>대량의 마이크로서비스 간 통신&lt;/strong>, &lt;strong>스트리밍이 필요한 경우&lt;/strong>, &lt;strong>스키마 관리가 중요한 경우&lt;/strong>에 발휘되는 것 같습니다.&lt;/p>
&lt;h2>RPC와 클라이언트 라이브러리의 관계&lt;span class="hx:absolute hx:-mt-20" id="rpc와-클라이언트-라이브러리의-관계">&lt;/span>
&lt;a href="#rpc%ec%99%80-%ed%81%b4%eb%9d%bc%ec%9d%b4%ec%96%b8%ed%8a%b8-%eb%9d%bc%ec%9d%b4%eb%b8%8c%eb%9f%ac%eb%a6%ac%ec%9d%98-%ea%b4%80%ea%b3%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>RPC에 대해 공부하다 보니 문득 이런 생각이 들었습니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;그럼 REST API를 호출하는 클라이언트 라이브러리를 만들어서 모듈화하면, 그것도 RPC 아닌가?&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>예를 들어, 코틀린에서 이런 식으로 외부 API를 감싸는 모듈을 만들었다고 해보겠습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// PaymentClient.kt
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">class&lt;/span> &lt;span class="nc">PaymentClient&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">private&lt;/span> &lt;span class="k">val&lt;/span> &lt;span class="py">baseUrl&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">String&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">fun&lt;/span> &lt;span class="nf">processPayment&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">orderId&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">String&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">amount&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">Long&lt;/span>&lt;span class="p">):&lt;/span> &lt;span class="n">PaymentResult&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 내부적으로 HTTP 요청
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">val&lt;/span> &lt;span class="py">response&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">httpClient&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">post&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="si">$baseUrl&lt;/span>&lt;span class="s2">/payments&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">body&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">mapOf&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;orderId&amp;#34;&lt;/span> &lt;span class="n">to&lt;/span> &lt;span class="n">orderId&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;amount&amp;#34;&lt;/span> &lt;span class="n">to&lt;/span> &lt;span class="n">amount&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">parseResponse&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">response&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">fun&lt;/span> &lt;span class="nf">refund&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">paymentId&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">String&lt;/span>&lt;span class="p">):&lt;/span> &lt;span class="n">RefundResult&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 내부적으로 HTTP 요청
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">val&lt;/span> &lt;span class="py">response&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">httpClient&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">post&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="si">$baseUrl&lt;/span>&lt;span class="s2">/payments/&lt;/span>&lt;span class="si">$paymentId&lt;/span>&lt;span class="s2">/refund&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">parseResponse&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">response&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 모듈을 다른 서비스에서 사용하면 이렇게 됩니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="k">val&lt;/span> &lt;span class="py">paymentClient&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">PaymentClient&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;https://payment-api.internal&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">val&lt;/span> &lt;span class="py">result&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">paymentClient&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">processPayment&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;order-123&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="m">50000L&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="c1">// 마치 로컬 함수처럼&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이거&amp;hellip; RPC의 정의인 &amp;ldquo;원격 함수를 로컬 함수처럼 호출한다&amp;quot;와 똑같지 않나요?&lt;/p>
&lt;h3>물리적으로는 같다. 하지만&amp;hellip;&lt;span class="hx:absolute hx:-mt-20" id="물리적으로는-같다-하지만">&lt;/span>
&lt;a href="#%eb%ac%bc%eb%a6%ac%ec%a0%81%ec%9c%bc%eb%a1%9c%eb%8a%94-%ea%b0%99%eb%8b%a4-%ed%95%98%ec%a7%80%eb%a7%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>솔직히 물리적으로는 같습니다. 둘 다 네트워크 통신이고, 직렬화/역직렬화가 필요하며 실패 가능성이 있죠.&lt;/p>
&lt;p>하지만 이건 &amp;ldquo;REST도 TCP 쓰고 gRPC도 TCP 쓰니까 같은 거 아님?&amp;ldquo;이라고 말하는 것과 비슷합니다.&lt;/p>
&lt;p>&lt;strong>진짜 차이는 &amp;ldquo;누가 주도권을 갖고 무엇을 표준화하느냐&amp;quot;라고 생각합니다.&lt;/strong>&lt;/p>
&lt;h3>REST 클라이언트 라이브러리: 편의성 계층&lt;span class="hx:absolute hx:-mt-20" id="rest-클라이언트-라이브러리-편의성-계층">&lt;/span>
&lt;a href="#rest-%ed%81%b4%eb%9d%bc%ec%9d%b4%ec%96%b8%ed%8a%b8-%eb%9d%bc%ec%9d%b4%eb%b8%8c%eb%9f%ac%eb%a6%ac-%ed%8e%b8%ec%9d%98%ec%84%b1-%ea%b3%84%ec%b8%b5" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>여기서 말하는 건 SDK 전체가 아니라, &lt;strong>REST API를 쓰기 쉽게 감싸는 클라이언트 라이브러리&lt;/strong>입니다. (AWS SDK, Stripe SDK 같은 것들이요.)&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="n">userClient&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">getUser&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="p">)&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 한 줄 안에 URL 조립, HTTP 메서드 선택, 인증 헤더, 재시도, 에러 파싱이 다 들어있습니다.&lt;/p>
&lt;p>하지만 이런 클라이언트 라이브러리의 본질을 생각해보면, 서버는 여전히 REST API를 제공하고 라이브러리는 클라이언트의 편의를 위한 포장지일 뿐입니다. 계약은 문서(OpenAPI 등) 수준이고, 필드 하나 바뀌면 컴파일은 OK인데 &lt;strong>런타임에 터집니다&lt;/strong>.&lt;/p>
&lt;h3>RPC: 통신 모델 + 계약&lt;span class="hx:absolute hx:-mt-20" id="rpc-통신-모델--계약">&lt;/span>
&lt;a href="#rpc-%ed%86%b5%ec%8b%a0-%eb%aa%a8%eb%8d%b8--%ea%b3%84%ec%95%bd" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>RPC는 사고방식부터 다릅니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="n">userService&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">GetUser&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">GetUserRequest&lt;/span>&lt;span class="p">)&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 순간 개발자 머릿속에는 URL도, HTTP verb도, 리소스도 없습니다. &lt;strong>그냥 함수 호출입니다.&lt;/strong>&lt;/p>
&lt;p>RPC의 본질은 통신을 함수 호출로 모델링하는 것입니다. 요청/응답이 &lt;strong>IDL(Interface Definition Language)로 강하게 정의&lt;/strong>되고, 클라이언트/서버가 &lt;strong>같은 계약을 공유&lt;/strong>합니다. 필드 하나 바뀌면? &lt;strong>컴파일 단계에서 감지&lt;/strong>됩니다.&lt;/p>
&lt;h3>진짜 차이를 표로 보면&lt;span class="hx:absolute hx:-mt-20" id="진짜-차이를-표로-보면">&lt;/span>
&lt;a href="#%ec%a7%84%ec%a7%9c-%ec%b0%a8%ec%9d%b4%eb%a5%bc-%ed%91%9c%eb%a1%9c-%eb%b3%b4%eb%a9%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>구분&lt;/th>
&lt;th>REST 클라이언트 라이브러리&lt;/th>
&lt;th>RPC&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>사고 모델&lt;/strong>&lt;/td>
&lt;td>HTTP 리소스&lt;/td>
&lt;td>함수 호출&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>계약 정의&lt;/strong>&lt;/td>
&lt;td>문서 중심 (OpenAPI 등)&lt;/td>
&lt;td>IDL 중심 (.proto 등)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>실패 감지 시점&lt;/strong>&lt;/td>
&lt;td>런타임&lt;/td>
&lt;td>컴파일 타임&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>버전 관리&lt;/strong>&lt;/td>
&lt;td>관례에 의존&lt;/td>
&lt;td>구조적으로 내장&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>다언어 지원&lt;/strong>&lt;/td>
&lt;td>언어별로 따로 구현&lt;/td>
&lt;td>IDL 하나로 자동 생성&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>네트워크 의식&lt;/strong>&lt;/td>
&lt;td>있음&lt;/td>
&lt;td>의도적으로 감춤&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3>클라이언트 라이브러리로 RPC 흉내는 낼 수 있지만&lt;span class="hx:absolute hx:-mt-20" id="클라이언트-라이브러리로-rpc-흉내는-낼-수-있지만">&lt;/span>
&lt;a href="#%ed%81%b4%eb%9d%bc%ec%9d%b4%ec%96%b8%ed%8a%b8-%eb%9d%bc%ec%9d%b4%eb%b8%8c%eb%9f%ac%eb%a6%ac%eb%a1%9c-rpc-%ed%9d%89%eb%82%b4%eb%8a%94-%eb%82%bc-%ec%88%98-%ec%9e%88%ec%a7%80%eb%a7%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>클라이언트 라이브러리로 RPC처럼 쓸 수는 있습니다. 하지만 REST 클라이언트 라이브러리에는 한계가 있습니다. 계약이 코드가 아니라 문서이고, 서버/클라이언트 릴리즈 싱크가 느슨하며, 언어별 라이브러리 품질 편차가 있습니다.&lt;/p>
&lt;p>물론 OpenAPI + 코드 생성(codegen)을 사용하면 REST에서도 컴파일 타임 검사에 가까운 강한 계약을 만들 수 있습니다. 다만 이건 프로토콜 수준에서 강제되는 게 아니라 도구로 보완하는 방식입니다.&lt;/p>
&lt;p>&lt;strong>RPC의 특징:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>계약이 &lt;strong>Single Source of Truth&lt;/strong> (IDL이 프로토콜의 일부)&lt;/li>
&lt;li>서버/클라이언트가 동시에 진화&lt;/li>
&lt;li>다국어 지원이 기본&lt;/li>
&lt;/ul>
&lt;h3>RPC 패러다임의 위험성&lt;span class="hx:absolute hx:-mt-20" id="rpc-패러다임의-위험성">&lt;/span>
&lt;a href="#rpc-%ed%8c%a8%eb%9f%ac%eb%8b%a4%ec%9e%84%ec%9d%98-%ec%9c%84%ed%97%98%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>여기까지 오면 솔직히 말해야 할 것 같은데요. RPC의 가장 큰 부작용이 있습니다.&lt;/p>
&lt;p>&lt;strong>네트워크가 없는 것처럼 착각하게 만든다는 점입니다.&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 이게 로컬 함수 호출처럼 보이지만...
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">val&lt;/span> &lt;span class="py">user&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">userService&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">getUser&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 실제로는 네트워크를 타고 있다
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// - latency가 있다
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// - 실패할 수 있다
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// - timeout이 필요하다
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// - retry 전략이 필요하다&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>RPC가 네트워크를 너무 잘 숨기면, 분산 시스템의 실패 모델을 무시한 코드가 양산될 수 있습니다. Google 내부에서 RPC 문화가 잘 작동하는 건 엄격한 SRE 규율이 함께 있기 때문이지, RPC 자체가 마법은 아니라고 생각합니다.&lt;/p>
&lt;p>&lt;strong>함수 호출처럼 보인다고 로컬 함수처럼 설계하면 안 됩니다.&lt;/strong>&lt;/p>
&lt;p>RPC는 &amp;ldquo;원격 함수를 로컬 함수처럼 호출한다&amp;quot;는 개념이지만, 그렇다고 로컬 프로그래밍처럼 상태를 가지게 설계하면 안 됩니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 로컬이라면 이렇게 해도 되지만...
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">class&lt;/span> &lt;span class="nc">Counter&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">private&lt;/span> &lt;span class="k">var&lt;/span> &lt;span class="py">count&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="m">0&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">fun&lt;/span> &lt;span class="nf">increment&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="o">++&lt;/span>&lt;span class="n">count&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 분산 시스템에서 이런 설계는 안티패턴
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// - 서버가 상태를 가지면 수평 확장이 어려움
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// - 장애 시 상태 유실
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// - 로드밸런싱 복잡해짐&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>REST는 아키텍처 정의에 &amp;ldquo;Stateless&amp;rdquo; 제약이 명시되어 있습니다. RPC는 그런 제약을 정의하지 않습니다. 하지만 &lt;strong>&amp;ldquo;정의 안 함&amp;rdquo; ≠ &amp;ldquo;해도 됨&amp;rdquo;&lt;/strong> 입니다.&lt;/p>
&lt;p>마찬가지로 멱등성(Idempotency)도 RPC에는 내장되어 있지 않습니다. REST는 HTTP 메서드에 멱등성 의미가 있지만(GET, PUT, DELETE는 멱등), RPC의 &lt;code>createUser()&lt;/code> 메서드가 멱등인지는 &lt;strong>구현하기 나름&lt;/strong>입니다. 필요하다면 직접 설계해야 합니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;/th>
&lt;th>REST&lt;/th>
&lt;th>RPC&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Stateless&lt;/strong>&lt;/td>
&lt;td>아키텍처 제약으로 정의됨&lt;/td>
&lt;td>정의 안 함 (알아서 해야 함)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>멱등성&lt;/strong>&lt;/td>
&lt;td>HTTP 메서드에 의미 내장&lt;/td>
&lt;td>정의 안 함 (알아서 해야 함)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>결국 RPC를 쓰든 REST를 쓰든, 분산 시스템의 원칙(stateless, 멱등성, 실패 처리 등)은 &lt;strong>똑같이 적용&lt;/strong>해야 합니다. RPC가 함수 호출처럼 보인다고 해서 로컬 프로그래밍처럼 설계하면 안 된다는 점을 기억해야 할 것 같습니다.&lt;/p>
&lt;h3>정리하자면&lt;span class="hx:absolute hx:-mt-20" id="정리하자면">&lt;/span>
&lt;a href="#%ec%a0%95%eb%a6%ac%ed%95%98%ec%9e%90%eb%a9%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;blockquote>
&lt;p>&lt;strong>클라이언트 라이브러리는 &amp;ldquo;편의성 계층&amp;quot;이고, RPC는 &amp;ldquo;시스템 간 계약과 사고방식&amp;quot;입니다.&lt;/strong>&lt;/p>
&lt;/blockquote>
&lt;p>클라이언트 라이브러리로 RPC처럼 쓸 수는 있지만, 계약의 강도, 진화 방식, 실패 감지 시점이 전부 다릅니다.&lt;/p>
&lt;p>그래서 &lt;strong>&amp;ldquo;직접 만든 클라이언트 라이브러리는 RPC 패러다임을 수동으로 구현한 것&amp;rdquo;&lt;/strong> 이라고 볼 수도 있지만, 엄밀히 말하면 &lt;strong>RPC의 핵심인 &amp;ldquo;강한 계약&amp;quot;이 빠진 흉내&lt;/strong>에 가깝습니다. 물론 그게 나쁘다는 건 아닙니다. 상황에 따라 REST + 클라이언트 라이브러리가 더 적합할 수 있고, 오히려 네트워크를 의식하게 해주는 게 장점일 수도 있습니다.&lt;/p>
&lt;h2>언제 무엇을 쓸까?&lt;span class="hx:absolute hx:-mt-20" id="언제-무엇을-쓸까">&lt;/span>
&lt;a href="#%ec%96%b8%ec%a0%9c-%eb%ac%b4%ec%97%87%ec%9d%84-%ec%93%b8%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>제 나름대로 정리한 선택 기준입니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TD
Start[&amp;#34;API 설계 시작&amp;#34;] --&amp;gt; Q1{&amp;#34;외부 공개 API?&amp;#34;}
Q1 --&amp;gt;|&amp;#34;예&amp;#34;| REST[&amp;#34;REST 권장&amp;lt;br/&amp;gt;(직관적, 표준적)&amp;#34;]
Q1 --&amp;gt;|&amp;#34;아니오&amp;#34;| Q2{&amp;#34;고성능/스트리밍 필요?&amp;#34;}
Q2 --&amp;gt;|&amp;#34;예&amp;#34;| gRPC[&amp;#34;gRPC 권장&amp;lt;br/&amp;gt;(성능, 스트리밍)&amp;#34;]
Q2 --&amp;gt;|&amp;#34;아니오&amp;#34;| Q3{&amp;#34;복잡한 행위 중심?&amp;#34;}
Q3 --&amp;gt;|&amp;#34;예&amp;#34;| RPC[&amp;#34;JSON-RPC 고려&amp;lt;br/&amp;gt;(단순, 행위 중심)&amp;#34;]
Q3 --&amp;gt;|&amp;#34;아니오&amp;#34;| REST2[&amp;#34;REST로 충분&amp;lt;br/&amp;gt;(범용적)&amp;#34;]
&lt;/pre>&lt;p>물론 이건 대략적인 가이드일 뿐이고, 실제로는 팀의 경험, 기존 시스템, 구체적인 요구사항에 따라 달라질 수 있습니다.&lt;/p>
&lt;h2>정리&lt;span class="hx:absolute hx:-mt-20" id="정리-1">&lt;/span>
&lt;a href="#%ec%a0%95%eb%a6%ac-1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이번 글에서 RPC에 대해 정리해봤습니다.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>RPC는 패러다임입니다.&lt;/strong> &amp;ldquo;원격 함수 호출&amp;quot;이라는 개념이지, 특정 프로토콜이 아닙니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>JSON-RPC는 단순합니다.&lt;/strong> 전송 계층에 독립적이고, 스펙이 간단합니다. 다만 HTTP 위에서 REST와 비교해 &amp;ldquo;경량&amp;quot;이라고 하기는 어렵습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>gRPC는 성능 중심입니다.&lt;/strong> Protobuf + HTTP/2로 고성능을 추구하지만, 학습 곡선이 있고 브라우저 지원이 제한적입니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>REST vs RPC는 우열의 문제가 아닙니다.&lt;/strong> 리소스 중심이냐 행위 중심이냐의 차이이고, 상황에 맞게 선택하면 됩니다.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>이 글을 쓰면서 저는 느낀 게 있는데요, 기술의 본질을 이해하면 &amp;ldquo;이게 더 좋다&amp;quot;는 식의 이분법적 사고에서 벗어날 수 있다는 점입니다. 각 기술이 어떤 문제를 풀려고 했는지, 어떤 trade-off가 있는지를 이해하면 상황에 맞는 선택을 할 수 있지 않나 싶습니다.&lt;/p>
&lt;p>긴 글 읽어주셔서 감사합니다.&lt;/p>
&lt;hr>
&lt;h2>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>공식 문서&lt;span class="hx:absolute hx:-mt-20" id="공식-문서">&lt;/span>
&lt;a href="#%ea%b3%b5%ec%8b%9d-%eb%ac%b8%ec%84%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://www.jsonrpc.org/specification"target="_blank" rel="noopener">JSON-RPC 2.0 Specification&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> - JSON-RPC 공식 스펙 (전송 계층 독립성 명시)&lt;/li>
&lt;li>&lt;a href="https://grpc.io/docs/guides/"target="_blank" rel="noopener">gRPC Official Documentation&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md"target="_blank" rel="noopener">gRPC over HTTP/2 Protocol Specification&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> - gRPC가 HTTP/2를 필수로 사용하는 이유&lt;/li>
&lt;li>&lt;a href="https://protobuf.dev/"target="_blank" rel="noopener">Protocol Buffers Documentation&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>비교 분석&lt;span class="hx:absolute hx:-mt-20" id="비교-분석">&lt;/span>
&lt;a href="#%eb%b9%84%ea%b5%90-%eb%b6%84%ec%84%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://cloud.google.com/blog/products/api-management/understanding-grpc-openapi-and-rest-and-when-to-use-them"target="_blank" rel="noopener">gRPC vs REST: Understanding gRPC, OpenAPI and REST - Google Cloud Blog&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://aws.amazon.com/compare/the-difference-between-grpc-and-rest/"target="_blank" rel="noopener">gRPC vs REST - AWS&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.ibm.com/think/topics/grpc-vs-rest"target="_blank" rel="noopener">gRPC vs. REST - IBM&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.mertech.com/blog/know-your-api-protocols"target="_blank" rel="noopener">Know your API protocols: SOAP vs. REST vs. JSON-RPC vs. gRPC vs. GraphQL vs. Thrift&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>관련 글&lt;span class="hx:absolute hx:-mt-20" id="관련-글">&lt;/span>
&lt;a href="#%ea%b4%80%eb%a0%a8-%ea%b8%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/trends/mcp-deep-dive/">MCP(Model Context Protocol) 이해하기&lt;/a> - JSON-RPC를 사용하는 실제 프로토콜 예시&lt;/li>
&lt;/ul></description></item><item><title>MCP(Model Context Protocol) 이해하기: AI와 외부 시스템을 연결하는 표준 프로토콜</title><link>https://jeongil.dev/ko/blog/trends/mcp-deep-dive/</link><pubDate>Sun, 25 Jan 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/trends/mcp-deep-dive/</guid><description>
&lt;p>요즘 AI 분야에서 MCP(Model Context Protocol)에 대한 이야기가 많이 들려옵니다. 저도 &lt;a href="https://jeongil.dev/ko/blog/trends/llms-txt-mcp-second-brain/">이전 글&lt;/a>에서 MCP 서버를 직접 만들어 활용하는 경험을 공유했었는데요.&lt;/p>
&lt;p>그런데 막상 MCP를 사용하면서도 &lt;strong>&amp;ldquo;MCP가 정확히 어떤 구조로 되어있지?&amp;rdquo;&lt;/strong>, &lt;strong>&amp;ldquo;LLM은 MCP 서버와 어떻게 통신하지?&amp;rdquo;&lt;/strong> 같은 궁금증이 있었습니다.&lt;/p>
&lt;p>이번 글에서는 MCP의 내부 구조와 동작 원리를 살펴보려 합니다. 마치 저와 함께 MCP 스펙 문서를 읽어나가는 느낌으로 정리해보겠습니다.&lt;/p>
&lt;h2>MCP란 무엇인가?&lt;span class="hx:absolute hx:-mt-20" id="mcp란-무엇인가">&lt;/span>
&lt;a href="#mcp%eb%9e%80-%eb%ac%b4%ec%97%87%ec%9d%b8%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>MCP(Model Context Protocol)는 Anthropic이 2024년 11월에 공개한 &lt;strong>Open Standard(개방형 표준)&lt;/strong> 입니다. 한 마디로 정의하자면 &lt;strong>AI 애플리케이션과 외부 시스템을 연결하기 위한 표준화된 프로토콜&lt;/strong>이라고 할 수 있습니다.&lt;/p>
&lt;p>그런데 왜 이런 프로토콜이 필요하게 되었을까요?&lt;/p>
&lt;h3>MCP가 해결하려는 문제&lt;span class="hx:absolute hx:-mt-20" id="mcp가-해결하려는-문제">&lt;/span>
&lt;a href="#mcp%ea%b0%80-%ed%95%b4%ea%b2%b0%ed%95%98%eb%a0%a4%eb%8a%94-%eb%ac%b8%ec%a0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>AI 모델은 학습 당시의 지식까지만 알고 있습니다. 그래서 최신 정보를 얻거나, 외부 데이터베이스에 접근하거나, 특정 도구를 실행하려면 &lt;strong>외부 시스템과의 연동&lt;/strong>이 필수적이죠.&lt;/p>
&lt;p>문제는 지금까지 이 연동 방식이 &lt;strong>파편화&lt;/strong>되어 있었다는 점입니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Before[&amp;#34;MCP 이전: 파편화된 통합&amp;#34;]
LLM1[&amp;#34;LLM 애플리케이션&amp;#34;]
LLM1 --&amp;gt;|&amp;#34;Custom API A&amp;#34;| DB1[&amp;#34;Database&amp;#34;]
LLM1 --&amp;gt;|&amp;#34;Custom API B&amp;#34;| GitHub1[&amp;#34;GitHub&amp;#34;]
LLM1 --&amp;gt;|&amp;#34;Custom API C&amp;#34;| Slack1[&amp;#34;Slack&amp;#34;]
LLM1 --&amp;gt;|&amp;#34;Custom API D&amp;#34;| Drive1[&amp;#34;Google Drive&amp;#34;]
end
&lt;/pre>&lt;p>각 데이터 소스마다 다른 방식으로 연동해야 했습니다. GitHub API는 GitHub 방식으로, Slack은 Slack 방식으로, 데이터베이스는 또 다른 방식으로요. 새로운 데이터 소스를 추가할 때마다 처음부터 통합 로직을 만들어야 했죠.&lt;/p>
&lt;p>마치 JSON이 등장하기 전, 각 서비스가 저마다 다른 데이터 포맷(XML, CSV 등)을 사용하던 시절과 비슷합니다. 새로운 서비스가 추가될 때마다 별도의 파서(parser)를 만들어야 했죠. (물론 지금도 XML 쓰는 곳이 있지만요&amp;hellip;)&lt;/p>
&lt;p>&lt;img src="https://assets.apidog.com/blog-next/2025/03/image-253.png" alt="" loading="lazy" />&lt;/p>
&lt;p>Anthropic은 이 문제를 &lt;strong>USB-C&lt;/strong>에 비유해서 설명합니다. 예전에는 휴대폰마다 충전 단자가 달랐습니다. 삼성은 마이크로 USB, 애플은 라이트닝, 또 다른 제조사는 또 다른 규격을 썼죠. 그러다 USB-C라는 표준이 등장하면서 하나의 케이블로 모든 기기를 연결할 수 있게 되었습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph After[&amp;#34;MCP 이후: 표준화된 통합&amp;#34;]
LLM2[&amp;#34;LLM 애플리케이션&amp;#34;]
LLM2 --&amp;gt;|&amp;#34;MCP&amp;#34;| Server1[&amp;#34;DB MCP Server&amp;#34;]
LLM2 --&amp;gt;|&amp;#34;MCP&amp;#34;| Server2[&amp;#34;GitHub MCP Server&amp;#34;]
LLM2 --&amp;gt;|&amp;#34;MCP&amp;#34;| Server3[&amp;#34;Slack MCP Server&amp;#34;]
LLM2 --&amp;gt;|&amp;#34;MCP&amp;#34;| Server4[&amp;#34;Drive MCP Server&amp;#34;]
end
&lt;/pre>&lt;p>MCP가 바로 그 &lt;strong>USB-C 역할&lt;/strong>을 합니다. 하나의 프로토콜로 다양한 외부 시스템과 연결할 수 있게 되는 거죠.&lt;/p>
&lt;h3>MCP의 탄생과 채택&lt;span class="hx:absolute hx:-mt-20" id="mcp의-탄생과-채택">&lt;/span>
&lt;a href="#mcp%ec%9d%98-%ed%83%84%ec%83%9d%ea%b3%bc-%ec%b1%84%ed%83%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>MCP는 &lt;a href="https://www.anthropic.com/news/model-context-protocol"target="_blank" rel="noopener">2024년 11월 25일 Anthropic이 오픈소스로 공개&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>했습니다. 흥미로운 점은 공개 후 빠르게 업계 표준으로 자리잡아가고 있다는 점입니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>2024년 11월&lt;/strong>: &lt;a href="https://www.anthropic.com/news/model-context-protocol"target="_blank" rel="noopener">Anthropic이 MCP 공개&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>, Python/TypeScript SDK 제공&lt;/li>
&lt;li>&lt;strong>2025년 3월&lt;/strong>: &lt;a href="https://siliconangle.com/2025/03/27/openai-adds-support-anthropics-mcp-llm-connectivity-protocol/"target="_blank" rel="noopener">OpenAI CEO Sam Altman이 MCP 지원 발표&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> - &amp;ldquo;People love MCP and we are excited to add support across our products&amp;rdquo;&lt;/li>
&lt;li>&lt;strong>2025년 4월&lt;/strong>: &lt;a href="https://techcrunch.com/2025/04/09/google-says-itll-embrace-anthropics-standard-for-connecting-ai-models-to-data/"target="_blank" rel="noopener">Google DeepMind CEO Demis Hassabis가 Gemini에 MCP 지원 예고&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> - &amp;ldquo;MCP is a good protocol and it&amp;rsquo;s rapidly becoming an open standard&amp;rdquo;&lt;/li>
&lt;li>&lt;strong>2025년 12월&lt;/strong>: &lt;a href="https://www.linuxfoundation.org/press/linux-foundation-announces-the-formation-of-the-agentic-ai-foundation"target="_blank" rel="noopener">Linux Foundation 산하 Agentic AI Foundation(AAIF)에 MCP 기부&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> - Anthropic, Block, OpenAI가 공동 설립&lt;/li>
&lt;/ul>
&lt;p>Anthropic이 만들었지만 OpenAI나 Google도 채택했다는 점이 인상적이였습니다. &lt;strong>경쟁사도 인정하는 표준&lt;/strong>이 되어가고 있는 거죠. 이는 MCP가 특정 회사의 기술이 아닌 업계 전체의 공통 과제를 해결하려 한다는 점을 보여주는 것 같습니다.&lt;/p>
&lt;p>그렇다면 MCP는 구체적으로 어떤 구조로 되어 있을까요?&lt;/p>
&lt;h2>MCP 아키텍처: 호스트, 클라이언트, 서버&lt;span class="hx:absolute hx:-mt-20" id="mcp-아키텍처-호스트-클라이언트-서버">&lt;/span>
&lt;a href="#mcp-%ec%95%84%ed%82%a4%ed%85%8d%ec%b2%98-%ed%98%b8%ec%8a%a4%ed%8a%b8-%ed%81%b4%eb%9d%bc%ec%9d%b4%ec%96%b8%ed%8a%b8-%ec%84%9c%eb%b2%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>MCP의 아키텍처를 이해하려면 세 가지 핵심 개념을 알아야 합니다. &lt;strong>Host&lt;/strong>, &lt;strong>Client&lt;/strong>, &lt;strong>Server&lt;/strong>입니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Host[&amp;#34;MCP Host (AI 애플리케이션)&amp;#34;]
direction TB
App[&amp;#34;Claude Desktop / VS Code 등&amp;#34;]
Client1[&amp;#34;MCP Client 1&amp;#34;]
Client2[&amp;#34;MCP Client 2&amp;#34;]
Client3[&amp;#34;MCP Client N&amp;#34;]
end
Server1[&amp;#34;MCP Server 1&amp;lt;br/&amp;gt;(GitHub)&amp;#34;]
Server2[&amp;#34;MCP Server 2&amp;lt;br/&amp;gt;(Database)&amp;#34;]
Server3[&amp;#34;MCP Server N&amp;lt;br/&amp;gt;(Slack)&amp;#34;]
Client1 &amp;lt;--&amp;gt;|&amp;#34;MCP Protocol&amp;#34;| Server1
Client2 &amp;lt;--&amp;gt;|&amp;#34;MCP Protocol&amp;#34;| Server2
Client3 &amp;lt;--&amp;gt;|&amp;#34;MCP Protocol&amp;#34;| Server3
&lt;/pre>&lt;h3>Host (호스트)&lt;span class="hx:absolute hx:-mt-20" id="host-호스트">&lt;/span>
&lt;a href="#host-%ed%98%b8%ec%8a%a4%ed%8a%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Host는 &lt;strong>MCP를 사용하는 AI 애플리케이션&lt;/strong>입니다. Claude Desktop, Claude Code, VS Code의 AI 확장 등이 여기에 해당합니다.&lt;/p>
&lt;p>Host의 역할은 여러 MCP 클라이언트를 관리하고, 사용자와 AI 모델 사이의 상호작용을 조율하는 것입니다.&lt;/p>
&lt;h3>Client (클라이언트)&lt;span class="hx:absolute hx:-mt-20" id="client-클라이언트">&lt;/span>
&lt;a href="#client-%ed%81%b4%eb%9d%bc%ec%9d%b4%ec%96%b8%ed%8a%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Client는 &lt;strong>Host와 Server 사이에서 MCP 프로토콜 통신을 담당하는 역할&lt;/strong>입니다. 보통 Host 내부에 구현되지만, 개념적으로는 프로토콜 통신을 담당하는 논리적 역할로 이해하면 됩니다. 각 Client는 단일 Server와 1:1 연결을 유지합니다.&lt;/p>
&lt;p>예를 들어 Claude Desktop이 GitHub, Slack, Database 세 개의 MCP 서버를 사용한다면, 내부적으로 세 개의 MCP Client가 각각의 서버와 연결되어 있는 구조입니다.&lt;/p>
&lt;h3>Server (서버)&lt;span class="hx:absolute hx:-mt-20" id="server-서버">&lt;/span>
&lt;a href="#server-%ec%84%9c%eb%b2%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Server는 &lt;strong>외부 시스템에 대한 접근을 제공하는 컴포넌트&lt;/strong>입니다. 데이터베이스, API, 파일 시스템 등 다양한 외부 리소스를 LLM이 사용할 수 있도록 노출합니다.&lt;/p>
&lt;p>이 세 컴포넌트가 어떻게 상호작용하는지 조금 더 구체적으로 살펴보겠습니다.&lt;/p>
&lt;h3>아키텍처의 핵심: 관심사의 분리&lt;span class="hx:absolute hx:-mt-20" id="아키텍처의-핵심-관심사의-분리">&lt;/span>
&lt;a href="#%ec%95%84%ed%82%a4%ed%85%8d%ec%b2%98%ec%9d%98-%ed%95%b5%ec%8b%ac-%ea%b4%80%ec%8b%ac%ec%82%ac%ec%9d%98-%eb%b6%84%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이 구조의 장점은 &lt;strong>관심사가 명확히 분리&lt;/strong>되어 있다는 점입니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>컴포넌트&lt;/th>
&lt;th>책임&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Host&lt;/strong>&lt;/td>
&lt;td>사용자 인터페이스, AI 모델 관리, 권한 제어&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Client&lt;/strong>&lt;/td>
&lt;td>프로토콜 통신, 연결 관리, 메시지 라우팅&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Server&lt;/strong>&lt;/td>
&lt;td>외부 시스템 연동, 데이터/기능 제공&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Server는 Host가 어떤 AI 모델을 쓰는지 알 필요가 없이 그냥 MCP 프로토콜에 맞게 데이터를 제공하면 됩니다. 반대로 Host도 Server가 내부적으로 어떻게 GitHub API를 호출하는지 알 필요가 없습니다.&lt;/p>
&lt;p>이런 분리 덕분에 &lt;strong>Server 하나를 만들어두면 Claude, ChatGPT, Gemini 등 어떤 Host에서든 사용할 수 있게 됩니다.&lt;/strong> 플랫폼 독립적인 구조인 거죠.&lt;/p>
&lt;p>어디서 많이 본 패턴 아닌가요? &lt;strong>인터페이스에 의존하고 구현에 의존하지 않는다&lt;/strong> — 객체지향 설계의 기본 원칙이 여기서도 적용되는 것 같습니다. MCP라는 표준 인터페이스 덕분에 Host와 Server가 서로의 구현을 몰라도 협력할 수 있는 겁니다.&lt;/p>
&lt;h2>MCP 프로토콜: JSON-RPC 기반 통신&lt;span class="hx:absolute hx:-mt-20" id="mcp-프로토콜-json-rpc-기반-통신">&lt;/span>
&lt;a href="#mcp-%ed%94%84%eb%a1%9c%ed%86%a0%ec%bd%9c-json-rpc-%ea%b8%b0%eb%b0%98-%ed%86%b5%ec%8b%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>그렇다면 Client와 Server는 구체적으로 어떻게 통신할까요? 어떤 데이터를 주고 받는지 부터 살펴보겠습니다.&lt;/p>
&lt;p>MCP는 &lt;strong>JSON-RPC 2.0&lt;/strong>을 기반으로 합니다.&lt;/p>
&lt;h3>JSON-RPC란?&lt;span class="hx:absolute hx:-mt-20" id="json-rpc란">&lt;/span>
&lt;a href="#json-rpc%eb%9e%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>JSON-RPC란 JSON(JavaScript Object Notation) 데이터 형식을 사용하여 원격 프로시저 호출(RPC)을 가능하게 하는 간단하고 경량화된 프로토콜입니다.&lt;/p>
&lt;p>저희에게 익숙한 REST API와 비교하면 다음과 같은 차이가 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// REST API 방식
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="err">GET&lt;/span> &lt;span class="err">/tools&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">POST&lt;/span> &lt;span class="err">/tools/weather/call&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;location&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;Seoul&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// JSON-RPC 방식
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;tools/call&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;params&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;name&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;weather&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;arguments&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="nt">&amp;#34;location&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;Seoul&amp;#34;&lt;/span>&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>REST는 리소스 중심(명사)이고, JSON-RPC는 행위 중심(동사)입니다. MCP에서는 &lt;strong>&amp;ldquo;도구 목록 조회&amp;rdquo;, &amp;ldquo;도구 실행&amp;rdquo;, &amp;ldquo;리소스 읽기&amp;rdquo;&lt;/strong> 같은 행위가 중심이기 때문에 JSON-RPC가 더 적합하다고 판단한 것 같습니다.&lt;/p>
&lt;p>또한 JSON-RPC는 &lt;strong>양방향 통신&lt;/strong>을 자연스럽게 지원합니다. 클라이언트가 서버에 요청할 수도 있고, 서버가 클라이언트에 알림을 보낼 수도 있죠. 이 특성이 MCP의 실시간 알림 기능에 활용됩니다.&lt;/p>
&lt;h3>메시지 타입&lt;span class="hx:absolute hx:-mt-20" id="메시지-타입">&lt;/span>
&lt;a href="#%eb%a9%94%ec%8b%9c%ec%a7%80-%ed%83%80%ec%9e%85" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>MCP에서 주고받는 메시지는 크게 세 가지 타입이 있습니다.&lt;/p>
&lt;h4>1. Request (요청)&lt;span class="hx:absolute hx:-mt-20" id="1-request-요청">&lt;/span>
&lt;a href="#1-request-%ec%9a%94%ec%b2%ad" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>응답이 필요한 메시지입니다. &lt;code>id&lt;/code> 필드가 있어서 어떤 요청에 대한 응답인지 식별할 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;tools/list&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h4>2. Response (응답)&lt;span class="hx:absolute hx:-mt-20" id="2-response-응답">&lt;/span>
&lt;a href="#2-response-%ec%9d%91%eb%8b%b5" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>요청에 대한 응답입니다. 같은 &lt;code>id&lt;/code>를 가지고 &lt;code>result&lt;/code> 또는 &lt;code>error&lt;/code>를 포함합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;result&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;tools&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;name&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;get_weather&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;description&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;Get current weather for a location&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h4>3. Notification (알림)&lt;span class="hx:absolute hx:-mt-20" id="3-notification-알림">&lt;/span>
&lt;a href="#3-notification-%ec%95%8c%eb%a6%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>응답이 필요 없는 단방향 메시지입니다. &lt;code>id&lt;/code> 필드가 없습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;notifications/tools/list_changed&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 세 가지 메시지 타입으로 MCP의 모든 통신이 이루어집니다. 단순하면서도 강력한 구조라고 생각합니다.&lt;/p>
&lt;h2>연결 수립: 초기화 과정&lt;span class="hx:absolute hx:-mt-20" id="연결-수립-초기화-과정">&lt;/span>
&lt;a href="#%ec%97%b0%ea%b2%b0-%ec%88%98%eb%a6%bd-%ec%b4%88%ea%b8%b0%ed%99%94-%ea%b3%bc%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>Client와 Server가 통신을 시작하려면 먼저 &lt;strong>초기화(Initialization)&lt;/strong> 과정을 거쳐야 합니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant Client as MCP Client
participant Server as MCP Server
Client-&amp;gt;&amp;gt;Server: Initialize Request&amp;lt;br/&amp;gt;(프로토콜 버전, 클라이언트 정보, 기능)
Server--&amp;gt;&amp;gt;Client: Initialize Response&amp;lt;br/&amp;gt;(프로토콜 버전, 서버 정보, 기능)
Client-&amp;gt;&amp;gt;Server: Initialized Notification&amp;lt;br/&amp;gt;(초기화 완료 알림)
Note over Client,Server: 이제 정상 통신 가능
&lt;/pre>&lt;h3>Initialize Request&lt;span class="hx:absolute hx:-mt-20" id="initialize-request">&lt;/span>
&lt;a href="#initialize-request" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>클라이언트가 먼저 자신의 정보와 지원하는 기능을 서버에 알립니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;initialize&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;params&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;protocolVersion&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2025-06-18&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;capabilities&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;sampling&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;clientInfo&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;name&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;claude-code&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;version&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;1.0.0&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;code>protocolVersion&lt;/code>은 클라이언트가 사용하는 MCP 버전입니다. &lt;code>capabilities&lt;/code>는 클라이언트가 지원하는 기능들을 나열합니다. 예를 들어 &lt;code>sampling&lt;/code>이 있으면 클라이언트가 LLM 호출 기능을 제공한다는 의미입니다.&lt;/p>
&lt;h3>Initialize Response&lt;span class="hx:absolute hx:-mt-20" id="initialize-response">&lt;/span>
&lt;a href="#initialize-response" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>서버도 자신의 정보와 제공하는 기능을 응답합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;result&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;protocolVersion&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2025-06-18&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;capabilities&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;tools&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="nt">&amp;#34;listChanged&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="kc">true&lt;/span>&lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;resources&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;prompts&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;serverInfo&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;name&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;github-mcp-server&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;version&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;1.2.0&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>서버의 &lt;code>capabilities&lt;/code>를 보면 이 서버가 &lt;strong>tools&lt;/strong>, &lt;strong>resources&lt;/strong>, &lt;strong>prompts&lt;/strong>를 제공한다는 것을 알 수 있습니다. &lt;code>listChanged: true&lt;/code>는 도구 목록이 변경되면 알림을 보내겠다는 의미입니다.&lt;/p>
&lt;h3>Capability Negotiation (기능 협상)&lt;span class="hx:absolute hx:-mt-20" id="capability-negotiation-기능-협상">&lt;/span>
&lt;a href="#capability-negotiation-%ea%b8%b0%eb%8a%a5-%ed%98%91%ec%83%81" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이 초기화 과정에서 중요한 것이 &lt;strong>기능 협상&lt;/strong>입니다. 클라이언트와 서버가 각자 지원하는 기능을 교환하고, 양쪽이 모두 지원하는 기능만 사용하게 됩니다.&lt;/p>
&lt;p>예를 들어&lt;/p>
&lt;ul>
&lt;li>클라이언트가 &lt;code>sampling&lt;/code>을 지원한다고 했는데 서버가 이 기능을 요청하면 사용 가능&lt;/li>
&lt;li>서버가 &lt;code>tools&lt;/code>를 제공한다고 했으니 클라이언트가 도구 목록을 요청할 수 있음&lt;/li>
&lt;/ul>
&lt;p>이 방식 덕분에 &lt;strong>하위 호환성&lt;/strong>을 유지하면서 새로운 기능을 추가할 수 있습니다. 오래된 클라이언트가 새로운 서버와 통신해도, 양쪽이 공통으로 지원하는 기능만 사용하면 되니까요.&lt;/p>
&lt;h2>MCP의 핵심 기능: Tools, Resources, Prompts&lt;span class="hx:absolute hx:-mt-20" id="mcp의-핵심-기능-tools-resources-prompts">&lt;/span>
&lt;a href="#mcp%ec%9d%98-%ed%95%b5%ec%8b%ac-%ea%b8%b0%eb%8a%a5-tools-resources-prompts" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>MCP 서버가 제공하는 기능은 크게 세 가지로 나눌 수 있습니다. &lt;strong>Tools&lt;/strong>, &lt;strong>Resources&lt;/strong>, &lt;strong>Prompts&lt;/strong>입니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
subgraph Server[&amp;#34;MCP Server가 제공하는 것들&amp;#34;]
Tools[&amp;#34;Tools&amp;lt;br/&amp;gt;(실행 가능한 함수)&amp;#34;]
Resources[&amp;#34;Resources&amp;lt;br/&amp;gt;(읽기 전용 데이터)&amp;#34;]
Prompts[&amp;#34;Prompts&amp;lt;br/&amp;gt;(메시지 템플릿)&amp;#34;]
end
LLM[&amp;#34;LLM&amp;#34;] --&amp;gt;|&amp;#34;실행&amp;#34;| Tools
LLM --&amp;gt;|&amp;#34;읽기&amp;#34;| Resources
User[&amp;#34;사용자&amp;#34;] --&amp;gt;|&amp;#34;선택&amp;#34;| Prompts
&lt;/pre>&lt;p>각각 어떤 역할을 하는지 살펴보도록 하죠.&lt;/p>
&lt;h3>Tools: LLM이 실행하는 함수&lt;span class="hx:absolute hx:-mt-20" id="tools-llm이-실행하는-함수">&lt;/span>
&lt;a href="#tools-llm%ec%9d%b4-%ec%8b%a4%ed%96%89%ed%95%98%eb%8a%94-%ed%95%a8%ec%88%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Tools는 &lt;strong>LLM이 직접 호출할 수 있는 함수&lt;/strong>입니다. 데이터베이스 쿼리, API 호출, 계산 수행 등 다양한 작업을 수행할 수 있습니다.&lt;/p>
&lt;h4>Tool 발견 (Discovery)&lt;span class="hx:absolute hx:-mt-20" id="tool-발견-discovery">&lt;/span>
&lt;a href="#tool-%eb%b0%9c%ea%b2%ac-discovery" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>먼저 클라이언트는 서버가 어떤 도구를 제공하는지 조회합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Request
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">2&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;tools/list&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Response
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">2&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;result&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;tools&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;name&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;get_weather&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;title&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;Get Current Weather&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;description&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;Retrieves current weather for a location&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;inputSchema&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;type&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;object&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;properties&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;location&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;type&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;string&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;description&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;City name&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;required&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;location&amp;#34;&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>응답을 보면 각 도구의 이름, 설명, 그리고 &lt;strong>입력 스키마&lt;/strong>가 포함되어 있습니다. &lt;code>inputSchema&lt;/code>는 JSON Schema 형식으로, 이 도구를 호출할 때 어떤 파라미터가 필요한지 정의합니다.&lt;/p>
&lt;p>LLM은 이 정보를 바탕으로 &lt;strong>어떤 도구를 언제 사용할지 스스로 결정&lt;/strong>합니다. 사용자가 &amp;ldquo;서울 날씨 알려줘&amp;quot;라고 하면 LLM이 &lt;code>get_weather&lt;/code> 도구를 선택하고, &lt;code>location: &amp;quot;Seoul&amp;quot;&lt;/code>을 파라미터로 넣어 호출하는 거죠.&lt;/p>
&lt;h4>Tool 실행&lt;span class="hx:absolute hx:-mt-20" id="tool-실행">&lt;/span>
&lt;a href="#tool-%ec%8b%a4%ed%96%89" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>도구를 실행하는 것도 간단합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Request
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">3&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;tools/call&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;params&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;name&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;get_weather&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;arguments&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;location&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;Seoul&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Response
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">3&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;result&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;content&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;type&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;text&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;text&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;Current weather in Seoul: 15°C, Partly cloudy&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;isError&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="kc">false&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>결과는 &lt;code>content&lt;/code> 배열로 반환됩니다. 텍스트뿐만 아니라 이미지, 오디오 등 다양한 형태의 결과를 반환할 수 있습니다.&lt;/p>
&lt;h4>Model-Controlled의 의미&lt;span class="hx:absolute hx:-mt-20" id="model-controlled의-의미">&lt;/span>
&lt;a href="#model-controlled%ec%9d%98-%ec%9d%98%eb%af%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>Tools의 가장 중요한 특징은 &lt;strong>Model-Controlled&lt;/strong>라는 점입니다. 사람이 &amp;ldquo;이 도구를 써&amp;quot;라고 명시적으로 지시하는 게 아니라, &lt;strong>LLM이 상황을 추론해서 알아서 도구를 선택하고 호출&lt;/strong>합니다.&lt;/p>
&lt;p>물론 이게 가능하려면 LLM이 도구를 잘 이해해야 합니다. 그래서 &lt;code>description&lt;/code>을 명확하게 작성하는 것이 중요합니다. &amp;ldquo;날씨를 가져옵니다&amp;rdquo; 보다는 &amp;ldquo;지정된 도시의 현재 날씨 정보(온도, 상태)를 조회합니다&amp;quot;처럼 구체적으로 작성하는 게 추론 정확도를 높입니다.&lt;/p>
&lt;h4>LLM은 어떻게 MCP 도구를 알고 호출하는가?&lt;span class="hx:absolute hx:-mt-20" id="llm은-어떻게-mcp-도구를-알고-호출하는가">&lt;/span>
&lt;a href="#llm%ec%9d%80-%ec%96%b4%eb%96%bb%ea%b2%8c-mcp-%eb%8f%84%ea%b5%ac%eb%a5%bc-%ec%95%8c%ea%b3%a0-%ed%98%b8%ec%b6%9c%ed%95%98%eb%8a%94%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>여기서 한 가지 중요한 오해를 짚고 넘어가야 할 것 같습니다. &lt;strong>MCP 자체는 추론을 수행하지 않습니다&lt;/strong>. MCP는 데이터를 주고받는 프로토콜일 뿐이고, 판단과 선택은 전적으로 Host의 LLM이 담당합니다.&lt;/p>
&lt;p>그렇다면 LLM은 어떻게 MCP 도구를 &amp;ldquo;알아서&amp;rdquo; 선택하고 호출할까요? 전체 흐름을 살펴보겠습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant User as 사용자
participant Host as Host (Claude Desktop 등)
participant MCP as MCP Server
participant LLM as LLM API (Claude)
Note over Host,MCP: 1단계: 초기화 - 도구 정보 수집
Host-&amp;gt;&amp;gt;MCP: tools/list 요청
MCP--&amp;gt;&amp;gt;Host: 도구 목록 반환 (이름, 설명, 파라미터)
Note over User,LLM: 2단계: 사용자 요청 + 도구 정보를 LLM에 전달
User-&amp;gt;&amp;gt;Host: &amp;#34;서울 날씨 알려줘&amp;#34;
Host-&amp;gt;&amp;gt;LLM: 사용자 메시지 + tools 파라미터로 도구 정의 전달
Note over LLM: 3단계: LLM의 추론 (Tool Use)
LLM-&amp;gt;&amp;gt;LLM: &amp;#34;날씨 질문이네? get_weather 도구가 적합하겠다&amp;#34;
Note over Host,MCP: 4단계: Host가 실제 MCP 호출 수행
LLM--&amp;gt;&amp;gt;Host: tool_use 블록 반환 (도구명, 파라미터)
Host-&amp;gt;&amp;gt;MCP: tools/call 실행
MCP--&amp;gt;&amp;gt;Host: 결과 반환
Note over User,LLM: 5단계: 결과를 LLM에 전달하여 최종 응답 생성
Host-&amp;gt;&amp;gt;LLM: tool_result로 결과 전달
LLM--&amp;gt;&amp;gt;Host: 자연어 응답 생성
Host--&amp;gt;&amp;gt;User: &amp;#34;서울의 현재 날씨는 15°C이며...&amp;#34;
&lt;/pre>&lt;p>흐름을 풀어서 설명하면 다음과 같습니다.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Host가 도구 정보를 수집합니다&lt;/strong>: Host(예: Claude Desktop)가 MCP Server에 &lt;code>tools/list&lt;/code>를 호출해서 사용 가능한 도구 목록을 가져옵니다. 이 정보에는 도구 이름, 설명, 필요한 파라미터가 포함됩니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Host가 LLM API에 도구 정의를 전달합니다&lt;/strong>: 사용자가 메시지를 보내면, Host는 LLM API를 호출할 때 &lt;code>tools&lt;/code> 파라미터에 수집한 도구 정의를 함께 전달합니다. Claude API를 예로 들면 이런 형태입니다:&lt;/p>
&lt;/li>
&lt;/ol>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="n">response&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">client&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">messages&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">create&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">model&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;claude-sonnet-4-20250514&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">messages&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="p">[{&lt;/span>&lt;span class="s2">&amp;#34;role&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;user&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;content&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;서울 날씨 알려줘&amp;#34;&lt;/span>&lt;span class="p">}],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">tools&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="p">[&lt;/span> &lt;span class="c1"># MCP Server에서 수집한 도구 정보&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;name&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;get_weather&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;description&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;지정된 도시의 현재 날씨 정보를 조회합니다&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;input_schema&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;type&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;object&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;properties&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;city&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="s2">&amp;#34;type&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;string&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;description&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;도시 이름&amp;#34;&lt;/span>&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;required&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;city&amp;#34;&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">)&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;ol start="3">
&lt;li>
&lt;p>&lt;strong>LLM이 스스로 판단합니다&lt;/strong>: LLM은 **Tool Use(또는 Function Calling)**라는 능력을 학습하고 있습니다. 사용자의 질문과 주어진 도구 목록을 보고, &amp;ldquo;이 상황에서 어떤 도구를 어떤 파라미터로 호출해야 하는가&amp;quot;를 추론합니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>LLM은 구조화된 형태로 도구 호출을 요청합니다&lt;/strong>: 도구를 사용하기로 결정하면, LLM은 다음과 같은 구조화된 응답을 반환합니다:&lt;/p>
&lt;/li>
&lt;/ol>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;type&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;tool_use&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;name&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;get_weather&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;input&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;city&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;Seoul&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;ol start="5">
&lt;li>&lt;strong>Host가 실제 MCP 호출을 수행합니다&lt;/strong>: LLM은 직접 MCP Server를 호출하지 않습니다. Host가 이 &lt;code>tool_use&lt;/code> 응답을 받아서, 실제로 MCP Server에 &lt;code>tools/call&lt;/code> 요청을 보내고, 결과를 다시 LLM에게 전달합니다.&lt;/li>
&lt;/ol>
&lt;p>정리하면, &lt;strong>MCP는 도구를 제공하는 표준화된 파이프라인&lt;/strong>이고, &lt;strong>도구 선택은 100% LLM의 추론 능력&lt;/strong>입니다. Host는 이 둘을 연결하는 오케스트레이터 역할을 합니다.&lt;/p>
&lt;p>이것이 바로 앞서 언급한 &lt;code>description&lt;/code>이 중요한 이유입니다. LLM은 도구의 실제 구현 코드를 볼 수 없고, 오직 이름과 설명만으로 판단하기 때문입니다. 좋은 설명은 LLM이 올바른 도구를 올바른 상황에 선택하도록 도와줍니다.&lt;/p>
&lt;p>익숙하지 않으신가요? 결국 추상화입니다. 우리가 프로그래밍할 때도 함수의 내부 구현을 몰라도 함수 이름과 설명만 보고 사용할 수 있잖아요? MCP 도구도 마찬가지입니다. LLM은 함수의 내부 코드를 볼 수 없고, 오직 메타데이터(이름, 설명, 입력 스키마)만으로 판단하는 거죠.&lt;/p>
&lt;h3>Resources: 읽기 전용 데이터&lt;span class="hx:absolute hx:-mt-20" id="resources-읽기-전용-데이터">&lt;/span>
&lt;a href="#resources-%ec%9d%bd%ea%b8%b0-%ec%a0%84%ec%9a%a9-%eb%8d%b0%ec%9d%b4%ed%84%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Resources는 &lt;strong>서버가 제공하는 읽기 전용 데이터&lt;/strong>입니다. 파일 내용, 데이터베이스 스키마, 설정 정보 등이 여기에 해당합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 리소스 목록 조회
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">4&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;resources/list&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 응답
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">4&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;result&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;resources&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;uri&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;file:///project/src/main.rs&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;name&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;main.rs&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;description&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;Primary application entry point&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;mimeType&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;text/x-rust&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>각 리소스는 &lt;strong>URI&lt;/strong>로 식별됩니다. &lt;code>file://&lt;/code>, &lt;code>https://&lt;/code>, &lt;code>git://&lt;/code> 등 다양한 스킴을 사용할 수 있습니다.&lt;/p>
&lt;h4>Tools vs Resources: 뭐가 다른가?&lt;span class="hx:absolute hx:-mt-20" id="tools-vs-resources-뭐가-다른가">&lt;/span>
&lt;a href="#tools-vs-resources-%eb%ad%90%ea%b0%80-%eb%8b%a4%eb%a5%b8%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>처음에는 &amp;ldquo;데이터베이스에서 데이터 읽는 것도 Tool로 하면 되지 않나?&amp;ldquo;라는 의문이 들 수 있습니다. 실제로 가능합니다. 그렇다면 왜 Resources가 따로 있을까요?&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;/th>
&lt;th>Tools&lt;/th>
&lt;th>Resources&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>목적&lt;/strong>&lt;/td>
&lt;td>동작 수행 (side effect 가능)&lt;/td>
&lt;td>데이터 읽기 (read-only)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>제어&lt;/strong>&lt;/td>
&lt;td>LLM이 자동 선택&lt;/td>
&lt;td>애플리케이션/사용자가 선택&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>변경&lt;/strong>&lt;/td>
&lt;td>데이터를 변경할 수 있음&lt;/td>
&lt;td>변경 불가, 읽기만&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Tools는 LLM이 스스로 판단해서 호출하지만, Resources는 보통 &lt;strong>애플리케이션이나 사용자가 명시적으로 선택&lt;/strong>합니다. 예를 들어 IDE에서 &amp;ldquo;이 파일을 컨텍스트에 추가&amp;quot;하는 식으로요.&lt;/p>
&lt;p>또한 Resources는 &lt;strong>구독(Subscription)&lt;/strong> 기능을 지원합니다. 특정 리소스가 변경되면 알림을 받을 수 있죠. 파일이 수정되었을 때 자동으로 컨텍스트를 업데이트하는 데 유용합니다.&lt;/p>
&lt;h3>Prompts: 재사용 가능한 템플릿&lt;span class="hx:absolute hx:-mt-20" id="prompts-재사용-가능한-템플릿">&lt;/span>
&lt;a href="#prompts-%ec%9e%ac%ec%82%ac%ec%9a%a9-%ea%b0%80%eb%8a%a5%ed%95%9c-%ed%85%9c%ed%94%8c%eb%a6%bf" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Prompts는 &lt;strong>사용자가 선택할 수 있는 메시지 템플릿&lt;/strong>입니다. 자주 쓰는 프롬프트 패턴을 미리 정의해두고 재사용할 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 프롬프트 조회
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">5&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;prompts/get&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;params&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;name&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;code_review&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;arguments&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;code&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;def hello():\n print(&amp;#39;world&amp;#39;)&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 응답
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">5&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;result&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;description&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;Code review prompt&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;messages&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;role&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;user&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;content&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;type&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;text&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;text&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;Please review this Python code:\ndef hello():\n print(&amp;#39;world&amp;#39;)&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>Prompts는 Tools나 Resources와 달리 &lt;strong>사용자 제어(User-Controlled)&lt;/strong> 방식입니다. LLM이 알아서 선택하는 게 아니라, 사용자가 UI에서 명시적으로 선택합니다. 보통 &lt;code>/&lt;/code> 명령어(슬래시 커맨드) 형태로 노출되죠.&lt;/p>
&lt;h3>세 기능의 상호작용&lt;span class="hx:absolute hx:-mt-20" id="세-기능의-상호작용">&lt;/span>
&lt;a href="#%ec%84%b8-%ea%b8%b0%eb%8a%a5%ec%9d%98-%ec%83%81%ed%98%b8%ec%9e%91%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>실제 사용 시나리오에서는 이 세 기능이 함께 동작합니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant User as 사용자
participant Host as MCP Host
participant Server as MCP Server
User-&amp;gt;&amp;gt;Host: &amp;#34;/code_review 실행&amp;#34;
Host-&amp;gt;&amp;gt;Server: prompts/get (code_review)
Server--&amp;gt;&amp;gt;Host: 프롬프트 템플릿
Host-&amp;gt;&amp;gt;Host: LLM에게 전달
Note over Host: LLM이 코드 분석에&amp;lt;br/&amp;gt;도구가 필요하다고 판단
Host-&amp;gt;&amp;gt;Server: tools/call (analyze_code)
Server--&amp;gt;&amp;gt;Host: 분석 결과
Host-&amp;gt;&amp;gt;Server: resources/read (style_guide)
Server--&amp;gt;&amp;gt;Host: 코딩 스타일 가이드
Host--&amp;gt;&amp;gt;User: 종합된 코드 리뷰 결과
&lt;/pre>&lt;ol>
&lt;li>사용자가 &lt;code>code_review&lt;/code> 프롬프트를 선택&lt;/li>
&lt;li>LLM이 코드 분석 도구를 호출&lt;/li>
&lt;li>스타일 가이드 리소스를 참조&lt;/li>
&lt;li>모든 정보를 종합해서 코드 리뷰 결과 생성&lt;/li>
&lt;/ol>
&lt;p>이렇게 세 기능이 유기적으로 연결되어 풍부한 AI 경험을 만들어냅니다.&lt;/p>
&lt;h3>FastMCP로 직접 구현해보기&lt;span class="hx:absolute hx:-mt-20" id="fastmcp로-직접-구현해보기">&lt;/span>
&lt;a href="#fastmcp%eb%a1%9c-%ec%a7%81%ec%a0%91-%ea%b5%ac%ed%98%84%ed%95%b4%eb%b3%b4%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>지금까지 Tools, Resources, Prompts의 개념을 살펴봤는데요. 실제로 어떻게 구현하는지 궁금하지 않으신가요? &lt;a href="https://github.com/jlowin/fastmcp"target="_blank" rel="noopener">FastMCP&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>를 사용하면 Python 데코레이터로 간단하게 MCP 서버를 만들 수 있더라구요.&lt;/p>
&lt;p>FastMCP는 MCP 서버 구현을 위한 Pythonic한 프레임워크입니다. 복잡한 프로토콜 처리를 추상화해서 비즈니스 로직에만 집중할 수 있게 해줍니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt"> 10
&lt;/span>&lt;span class="lnt"> 11
&lt;/span>&lt;span class="lnt"> 12
&lt;/span>&lt;span class="lnt"> 13
&lt;/span>&lt;span class="lnt"> 14
&lt;/span>&lt;span class="lnt"> 15
&lt;/span>&lt;span class="lnt"> 16
&lt;/span>&lt;span class="lnt"> 17
&lt;/span>&lt;span class="lnt"> 18
&lt;/span>&lt;span class="lnt"> 19
&lt;/span>&lt;span class="lnt"> 20
&lt;/span>&lt;span class="lnt"> 21
&lt;/span>&lt;span class="lnt"> 22
&lt;/span>&lt;span class="lnt"> 23
&lt;/span>&lt;span class="lnt"> 24
&lt;/span>&lt;span class="lnt"> 25
&lt;/span>&lt;span class="lnt"> 26
&lt;/span>&lt;span class="lnt"> 27
&lt;/span>&lt;span class="lnt"> 28
&lt;/span>&lt;span class="lnt"> 29
&lt;/span>&lt;span class="lnt"> 30
&lt;/span>&lt;span class="lnt"> 31
&lt;/span>&lt;span class="lnt"> 32
&lt;/span>&lt;span class="lnt"> 33
&lt;/span>&lt;span class="lnt"> 34
&lt;/span>&lt;span class="lnt"> 35
&lt;/span>&lt;span class="lnt"> 36
&lt;/span>&lt;span class="lnt"> 37
&lt;/span>&lt;span class="lnt"> 38
&lt;/span>&lt;span class="lnt"> 39
&lt;/span>&lt;span class="lnt"> 40
&lt;/span>&lt;span class="lnt"> 41
&lt;/span>&lt;span class="lnt"> 42
&lt;/span>&lt;span class="lnt"> 43
&lt;/span>&lt;span class="lnt"> 44
&lt;/span>&lt;span class="lnt"> 45
&lt;/span>&lt;span class="lnt"> 46
&lt;/span>&lt;span class="lnt"> 47
&lt;/span>&lt;span class="lnt"> 48
&lt;/span>&lt;span class="lnt"> 49
&lt;/span>&lt;span class="lnt"> 50
&lt;/span>&lt;span class="lnt"> 51
&lt;/span>&lt;span class="lnt"> 52
&lt;/span>&lt;span class="lnt"> 53
&lt;/span>&lt;span class="lnt"> 54
&lt;/span>&lt;span class="lnt"> 55
&lt;/span>&lt;span class="lnt"> 56
&lt;/span>&lt;span class="lnt"> 57
&lt;/span>&lt;span class="lnt"> 58
&lt;/span>&lt;span class="lnt"> 59
&lt;/span>&lt;span class="lnt"> 60
&lt;/span>&lt;span class="lnt"> 61
&lt;/span>&lt;span class="lnt"> 62
&lt;/span>&lt;span class="lnt"> 63
&lt;/span>&lt;span class="lnt"> 64
&lt;/span>&lt;span class="lnt"> 65
&lt;/span>&lt;span class="lnt"> 66
&lt;/span>&lt;span class="lnt"> 67
&lt;/span>&lt;span class="lnt"> 68
&lt;/span>&lt;span class="lnt"> 69
&lt;/span>&lt;span class="lnt"> 70
&lt;/span>&lt;span class="lnt"> 71
&lt;/span>&lt;span class="lnt"> 72
&lt;/span>&lt;span class="lnt"> 73
&lt;/span>&lt;span class="lnt"> 74
&lt;/span>&lt;span class="lnt"> 75
&lt;/span>&lt;span class="lnt"> 76
&lt;/span>&lt;span class="lnt"> 77
&lt;/span>&lt;span class="lnt"> 78
&lt;/span>&lt;span class="lnt"> 79
&lt;/span>&lt;span class="lnt"> 80
&lt;/span>&lt;span class="lnt"> 81
&lt;/span>&lt;span class="lnt"> 82
&lt;/span>&lt;span class="lnt"> 83
&lt;/span>&lt;span class="lnt"> 84
&lt;/span>&lt;span class="lnt"> 85
&lt;/span>&lt;span class="lnt"> 86
&lt;/span>&lt;span class="lnt"> 87
&lt;/span>&lt;span class="lnt"> 88
&lt;/span>&lt;span class="lnt"> 89
&lt;/span>&lt;span class="lnt"> 90
&lt;/span>&lt;span class="lnt"> 91
&lt;/span>&lt;span class="lnt"> 92
&lt;/span>&lt;span class="lnt"> 93
&lt;/span>&lt;span class="lnt"> 94
&lt;/span>&lt;span class="lnt"> 95
&lt;/span>&lt;span class="lnt"> 96
&lt;/span>&lt;span class="lnt"> 97
&lt;/span>&lt;span class="lnt"> 98
&lt;/span>&lt;span class="lnt"> 99
&lt;/span>&lt;span class="lnt">100
&lt;/span>&lt;span class="lnt">101
&lt;/span>&lt;span class="lnt">102
&lt;/span>&lt;span class="lnt">103
&lt;/span>&lt;span class="lnt">104
&lt;/span>&lt;span class="lnt">105
&lt;/span>&lt;span class="lnt">106
&lt;/span>&lt;span class="lnt">107
&lt;/span>&lt;span class="lnt">108
&lt;/span>&lt;span class="lnt">109
&lt;/span>&lt;span class="lnt">110
&lt;/span>&lt;span class="lnt">111
&lt;/span>&lt;span class="lnt">112
&lt;/span>&lt;span class="lnt">113
&lt;/span>&lt;span class="lnt">114
&lt;/span>&lt;span class="lnt">115
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">fastmcp&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">FastMCP&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">datetime&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">datetime&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># MCP 서버 인스턴스 생성&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 이 서버가 바로 &amp;#34;Server&amp;#34; 컴포넌트가 됩니다&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">mcp&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">FastMCP&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;날씨 서비스&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># ===== Tools: LLM이 호출하는 함수 =====&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># @mcp.tool() 데코레이터로 정의&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># LLM이 &amp;#34;Model-Controlled&amp;#34; 방식으로 알아서 호출합니다&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@mcp.tool&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">get_weather&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">city&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> 지정된 도시의 현재 날씨 정보를 조회합니다.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> 이 docstring이 앞서 설명한 &amp;#39;description&amp;#39;이 됩니다.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> LLM은 이 설명을 보고 언제 이 도구를 사용할지 판단합니다.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> Args:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> city: 날씨를 조회할 도시 이름 (예: &amp;#34;서울&amp;#34;, &amp;#34;부산&amp;#34;)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> 이 부분이 inputSchema의 properties가 됩니다.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> &amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1"># 실제로는 외부 날씨 API를 호출하겠지만, 예시로 하드코딩&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">weather_data&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;서울&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="s2">&amp;#34;temp&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">15&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;condition&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;맑음&amp;#34;&lt;/span>&lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;부산&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="s2">&amp;#34;temp&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">18&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;condition&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;흐림&amp;#34;&lt;/span>&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="n">city&lt;/span> &lt;span class="ow">in&lt;/span> &lt;span class="n">weather_data&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">data&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">weather_data&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">city&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">city&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">의 현재 날씨: &lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">data&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;temp&amp;#39;&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">°C, &lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">data&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;condition&amp;#39;&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">city&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">의 날씨 정보를 찾을 수 없습니다.&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># ===== Resources: 읽기 전용 데이터 =====&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># @mcp.resource()로 정의, URI 형식으로 식별&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Tools와 달리 &amp;#34;Application/User-Controlled&amp;#34; 방식입니다&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@mcp.resource&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;config://weather/settings&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">get_weather_settings&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> 날씨 서비스 설정 정보를 제공합니다.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> Resource는 LLM이 자동으로 선택하는 게 아니라,
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> 애플리케이션이나 사용자가 명시적으로 컨텍스트에 추가합니다.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> &amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> 지원 도시: 서울, 부산, 대구, 인천, 광주, 대전, 울산
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> 업데이트 주기: 10분
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> 데이터 출처: 기상청 API
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> &amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 동적 리소스 - URI 템플릿 사용&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># {city} 부분이 파라미터로 전달됩니다&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@mcp.resource&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;weather://forecast/&lt;/span>&lt;span class="si">{city}&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">get_forecast&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">city&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;특정 도시의 주간 예보를 리소스로 제공합니다.&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> &lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">city&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2"> 주간 예보:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> - 월요일: 맑음, 15°C
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> - 화요일: 흐림, 13°C
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> - 수요일: 비, 10°C
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> &amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># ===== Prompts: 재사용 가능한 메시지 템플릿 =====&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># @mcp.prompt()로 정의&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 사용자가 &amp;#34;/날씨_리포트&amp;#34; 같은 슬래시 커맨드로 선택합니다&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@mcp.prompt&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">weather_report&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">city&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> 종합 날씨 리포트를 생성하는 프롬프트입니다.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> Prompt는 &amp;#34;User-Controlled&amp;#34; 방식으로,
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> 사용자가 UI에서 명시적으로 선택해서 사용합니다.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> &amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> &lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">city&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">의 종합 날씨 리포트를 작성해주세요.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> 다음 정보를 포함해주세요:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> 1. 현재 날씨 상태
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> 2. 오늘의 최고/최저 기온
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> 3. 주간 날씨 전망
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> 4. 외출 시 주의사항
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> 친근하고 이해하기 쉬운 어조로 작성해주세요.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> &amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># ===== Context: 요청 컨텍스트 활용 =====&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Context를 통해 로깅, 진행 상황 보고 등이 가능합니다&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">fastmcp&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">Context&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@mcp.tool&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">async&lt;/span> &lt;span class="k">def&lt;/span> &lt;span class="nf">analyze_weather_trend&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">city&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">ctx&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">Context&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> 도시의 날씨 트렌드를 분석합니다.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> Context를 활용하면 장기 실행 작업의 진행 상황을
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> 클라이언트에 보고할 수 있습니다.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> &amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">await&lt;/span> &lt;span class="n">ctx&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">info&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">city&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2"> 날씨 데이터 수집 중...&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1"># 실제로는 여기서 데이터 수집 로직&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">await&lt;/span> &lt;span class="n">ctx&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">report_progress&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">progress&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="mi">50&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">total&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="mi">100&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">await&lt;/span> &lt;span class="n">ctx&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">info&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;트렌드 분석 중...&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1"># 실제로는 여기서 분석 로직&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">await&lt;/span> &lt;span class="n">ctx&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">report_progress&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">progress&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="mi">100&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">total&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="mi">100&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">city&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">의 최근 날씨 트렌드: 평년보다 2°C 높은 기온 유지 중&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 서버 실행 (stdio 전송)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">if&lt;/span> &lt;span class="vm">__name__&lt;/span> &lt;span class="o">==&lt;/span> &lt;span class="s2">&amp;#34;__main__&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">mcp&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">run&lt;/span>&lt;span class="p">()&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>코드를 보시면 각 데코레이터가 앞서 설명한 개념과 정확히 대응되는 것을 알 수 있습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>데코레이터&lt;/th>
&lt;th>MCP 개념&lt;/th>
&lt;th>제어 방식&lt;/th>
&lt;th>용도&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>@mcp.tool()&lt;/code>&lt;/td>
&lt;td>Tools&lt;/td>
&lt;td>Model-Controlled&lt;/td>
&lt;td>LLM이 판단해서 호출하는 함수&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>@mcp.resource()&lt;/code>&lt;/td>
&lt;td>Resources&lt;/td>
&lt;td>App/User-Controlled&lt;/td>
&lt;td>읽기 전용 컨텍스트 데이터&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>@mcp.prompt()&lt;/code>&lt;/td>
&lt;td>Prompts&lt;/td>
&lt;td>User-Controlled&lt;/td>
&lt;td>재사용 가능한 메시지 템플릿&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>특히 주목할 점은 &lt;strong>docstring이 그대로 &lt;code>description&lt;/code>이 된다&lt;/strong>는 점입니다. LLM은 이 설명을 보고 도구를 선택하기 때문에, docstring을 명확하게 작성하는 게 중요하다고 생각합니다.&lt;/p>
&lt;p>함수의 타입 힌트(&lt;code>city: str&lt;/code>)는 자동으로 &lt;code>inputSchema&lt;/code>로 변환됩니다. FastMCP가 Python의 타입 시스템을 활용해서 JSON Schema를 생성해주는 거죠.&lt;/p>
&lt;p>이렇게 만든 서버를 Claude Desktop에서 사용하려면 설정 파일에 추가하면 됩니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;mcpServers&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;weather&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;command&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;python&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;args&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;/path/to/weather_server.py&amp;#34;&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>FastMCP 외에도 TypeScript, Java, Kotlin, C#, Rust 등 다양한 언어로 MCP 서버를 만들 수 있습니다. 공식 문서의 &lt;a href="https://modelcontextprotocol.io/docs/develop/build-server"target="_blank" rel="noopener">Build an MCP Server&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> 가이드에서 각 언어별 구현 방법을 상세히 설명하고 있으니 참고하시면 좋을 것 같습니다.&lt;/p>
&lt;blockquote>
&lt;p>⚠️ &lt;strong>stdio 기반 서버 개발 시 주의사항&lt;/strong>: &lt;code>print()&lt;/code> (Python), &lt;code>console.log()&lt;/code> (JavaScript) 같은 stdout 출력은 JSON-RPC 메시지를 오염시켜 서버가 깨질 수 있습니다. 로깅은 반드시 stderr나 파일로 출력하도록 설정해야 합니다.&lt;/p>
&lt;/blockquote>
&lt;h2>전송 계층: stdio와 Streamable HTTP&lt;span class="hx:absolute hx:-mt-20" id="전송-계층-stdio와-streamable-http">&lt;/span>
&lt;a href="#%ec%a0%84%ec%86%a1-%ea%b3%84%ec%b8%b5-stdio%ec%99%80-streamable-http" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>지금까지 &lt;strong>무엇&lt;/strong>을 주고받는지 살펴봤다면, 이제 &lt;strong>어떻게&lt;/strong> 주고받는지 알아볼 차례입니다. MCP는 두 가지 표준 전송 방식을 정의합니다.&lt;/p>
&lt;h3>stdio: 로컬 프로세스 통신&lt;span class="hx:absolute hx:-mt-20" id="stdio-로컬-프로세스-통신">&lt;/span>
&lt;a href="#stdio-%eb%a1%9c%ec%bb%ac-%ed%94%84%eb%a1%9c%ec%84%b8%ec%8a%a4-%ed%86%b5%ec%8b%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>가장 간단한 방식입니다. Host가 MCP 서버를 &lt;strong>서브 프로세스로 실행&lt;/strong>하고, 표준 입출력(stdin/stdout)으로 통신합니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
subgraph Host[&amp;#34;MCP Host&amp;#34;]
Client[&amp;#34;MCP Client&amp;#34;]
end
subgraph Server[&amp;#34;MCP Server Process&amp;#34;]
ServerApp[&amp;#34;Server Logic&amp;#34;]
end
Client --&amp;gt;|&amp;#34;stdin&amp;#34;| ServerApp
ServerApp --&amp;gt;|&amp;#34;stdout&amp;#34;| Client
&lt;/pre>&lt;p>&lt;strong>특징:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>네트워크 오버헤드 없음 (같은 머신에서 실행)&lt;/li>
&lt;li>설정이 간단함 (서버 프로그램 경로만 지정)&lt;/li>
&lt;li>보안 설정 불필요 (로컬 통신)&lt;/li>
&lt;/ul>
&lt;p>Claude Desktop이나 Claude Code에서 로컬 MCP 서버를 사용할 때 이 방식을 씁니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;span class="lnt">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Claude Desktop 설정 예시
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;mcpServers&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;my-blog&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;command&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;python&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;args&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;/path/to/server.py&amp;#34;&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>메시지는 줄바꿈(&lt;code>\n&lt;/code>)으로 구분합니다. 한 줄에 하나의 JSON-RPC 메시지가 들어가는 구조입니다.&lt;/p>
&lt;h3>Streamable HTTP: 원격 서버 통신&lt;span class="hx:absolute hx:-mt-20" id="streamable-http-원격-서버-통신">&lt;/span>
&lt;a href="#streamable-http-%ec%9b%90%ea%b2%a9-%ec%84%9c%eb%b2%84-%ed%86%b5%ec%8b%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>원격 서버와 통신할 때는 &lt;strong>HTTP&lt;/strong>를 사용합니다. 클라이언트가 HTTP POST로 메시지를 보내고, 서버는 응답을 &lt;strong>Server-Sent Events(SSE)&lt;/strong> 스트림으로 반환합니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant Client as MCP Client
participant Server as Remote MCP Server
Client-&amp;gt;&amp;gt;Server: POST /mcp&amp;lt;br/&amp;gt;(JSON-RPC 메시지)
Server--&amp;gt;&amp;gt;Client: SSE Stream 시작
Server--&amp;gt;&amp;gt;Client: 이벤트: JSON-RPC 응답
Server--&amp;gt;&amp;gt;Client: 이벤트: 추가 알림 (있다면)
Server--&amp;gt;&amp;gt;Client: 스트림 종료
&lt;/pre>&lt;p>&lt;strong>왜 SSE를 쓰는가?&lt;/strong>&lt;/p>
&lt;p>단순 HTTP 요청/응답으로도 통신은 가능합니다. 하지만 MCP에서는 &lt;strong>서버가 클라이언트에게 먼저 메시지를 보내야 하는 경우&lt;/strong>가 있습니다. 다음과 같은 상황들입니다.&lt;/p>
&lt;ul>
&lt;li>도구 목록이 변경되었을 때 알림&lt;/li>
&lt;li>긴 작업의 진행 상황 업데이트&lt;/li>
&lt;/ul>
&lt;p>SSE를 사용하면 서버가 클라이언트에게 &lt;strong>여러 메시지를 스트리밍&lt;/strong>으로 보낼 수 있습니다.&lt;/p>
&lt;h4>세션 관리&lt;span class="hx:absolute hx:-mt-20" id="세션-관리">&lt;/span>
&lt;a href="#%ec%84%b8%ec%85%98-%ea%b4%80%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>Streamable HTTP에서는 &lt;strong>세션&lt;/strong> 개념이 있습니다. 초기화 시 서버가 세션 ID를 발급하고, 이후 모든 요청에 이 ID를 포함합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>// 초기화 응답 헤더
Mcp-Session-Id: abc123xyz
// 이후 요청 헤더
Mcp-Session-Id: abc123xyz&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>세션이 만료되면 서버는 HTTP 404를 반환하고, 클라이언트는 새로운 초기화를 시작해야 합니다.&lt;/p>
&lt;h4>보안 고려사항&lt;span class="hx:absolute hx:-mt-20" id="보안-고려사항">&lt;/span>
&lt;a href="#%eb%b3%b4%ec%95%88-%ea%b3%a0%eb%a0%a4%ec%82%ac%ed%95%ad" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>Streamable HTTP를 사용할 때는 &lt;strong>보안에 주의&lt;/strong>해야 합니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Origin 헤더 검증&lt;/strong>: DNS rebinding 공격 방지&lt;/li>
&lt;li>&lt;strong>인증 구현&lt;/strong>: Bearer Token, API Key, OAuth 등&lt;/li>
&lt;li>&lt;strong>localhost 바인딩&lt;/strong>: 로컬에서 실행할 때는 127.0.0.1에만 바인딩&lt;/li>
&lt;/ul>
&lt;p>특히 MCP 서버가 민감한 데이터(데이터베이스, 파일 시스템 등)에 접근할 수 있다면 인증은 필수죠.&lt;/p>
&lt;h3>어떤 전송 방식을 선택해야 할까?&lt;span class="hx:absolute hx:-mt-20" id="어떤-전송-방식을-선택해야-할까">&lt;/span>
&lt;a href="#%ec%96%b4%eb%96%a4-%ec%a0%84%ec%86%a1-%eb%b0%a9%ec%8b%9d%ec%9d%84-%ec%84%a0%ed%83%9d%ed%95%b4%ec%95%bc-%ed%95%a0%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;/th>
&lt;th>stdio&lt;/th>
&lt;th>Streamable HTTP&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>사용 사례&lt;/strong>&lt;/td>
&lt;td>로컬 도구, 개인 개발&lt;/td>
&lt;td>공유 서비스, 팀 도구&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>장점&lt;/strong>&lt;/td>
&lt;td>설정 간단, 빠름&lt;/td>
&lt;td>원격 접근, 중앙 관리&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>단점&lt;/strong>&lt;/td>
&lt;td>로컬만 가능&lt;/td>
&lt;td>네트워크 오버헤드, 보안 설정 필요&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>개인적으로 사용하는 MCP 서버라면 &lt;strong>stdio&lt;/strong>로 충분하다고 생각합니다. 팀에서 공유하거나 여러 환경에서 접근해야 한다면 &lt;strong>Streamable HTTP&lt;/strong>를 고려해볼 수 있겠죠.&lt;/p>
&lt;h2>Sampling: 서버가 LLM을 호출하는 방법&lt;span class="hx:absolute hx:-mt-20" id="sampling-서버가-llm을-호출하는-방법">&lt;/span>
&lt;a href="#sampling-%ec%84%9c%eb%b2%84%ea%b0%80-llm%ec%9d%84-%ed%98%b8%ec%b6%9c%ed%95%98%eb%8a%94-%eb%b0%a9%eb%b2%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>지금까지는 Host(클라이언트) → Server 방향의 통신을 살펴봤습니다. 그런데 MCP에서는 &lt;strong>반대 방향&lt;/strong>도 가능합니다. Server가 Host에게 LLM 호출을 요청하는 거죠.&lt;/p>
&lt;p>이 기능을 &lt;strong>Sampling&lt;/strong>이라고 합니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant Server as MCP Server
participant Client as MCP Client
participant LLM as LLM Provider
Note over Server: 서버 로직 실행 중&amp;lt;br/&amp;gt;LLM 도움이 필요함
Server-&amp;gt;&amp;gt;Client: sampling/createMessage
Note over Client: 사용자에게&amp;lt;br/&amp;gt;승인 요청 (선택적)
Client-&amp;gt;&amp;gt;LLM: LLM API 호출
LLM--&amp;gt;&amp;gt;Client: 응답
Client--&amp;gt;&amp;gt;Server: 결과 반환
&lt;/pre>&lt;h3>왜 이런 기능이 필요할까?&lt;span class="hx:absolute hx:-mt-20" id="왜-이런-기능이-필요할까">&lt;/span>
&lt;a href="#%ec%99%9c-%ec%9d%b4%eb%9f%b0-%ea%b8%b0%eb%8a%a5%ec%9d%b4-%ed%95%84%ec%9a%94%ed%95%a0%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>MCP 서버를 만들다 보면 &lt;strong>서버 내부에서도 LLM의 도움이 필요한 경우&lt;/strong>가 있습니다.&lt;/p>
&lt;p>예를 들면 다음과 같은 상황들입니다.&lt;/p>
&lt;ul>
&lt;li>검색 결과를 요약해서 반환하고 싶을 때&lt;/li>
&lt;li>복잡한 데이터를 자연어로 설명해야 할 때&lt;/li>
&lt;li>서버 측에서 AI 에이전트 로직을 실행할 때&lt;/li>
&lt;/ul>
&lt;p>Sampling을 사용하면 서버가 직접 LLM API 키를 가질 필요가 없습니다. 서버가 직접 모델을 실행하는 것이 아니라, Host에게 모델 실행을 요청하고 결과를 받는 구조입니다.&lt;/p>
&lt;h3>Sampling 요청 예시&lt;span class="hx:absolute hx:-mt-20" id="sampling-요청-예시">&lt;/span>
&lt;a href="#sampling-%ec%9a%94%ec%b2%ad-%ec%98%88%ec%8b%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">10&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;sampling/createMessage&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;params&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;messages&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;role&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;user&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;content&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;type&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;text&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;text&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;Summarize this data: ...&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;modelPreferences&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;hints&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[{&lt;/span>&lt;span class="nt">&amp;#34;name&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;claude-sonnet-4&amp;#34;&lt;/span>&lt;span class="p">}],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;speedPriority&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mf">0.8&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;maxTokens&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">500&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;code>modelPreferences&lt;/code>에서 원하는 모델의 힌트를 줄 수 있지만, &lt;strong>최종 모델 선택은 클라이언트가&lt;/strong> 합니다. 서버는 &amp;ldquo;빠른 모델이 좋겠다&amp;rdquo; 정도의 힌트만 줄 수 있습니다.&lt;/p>
&lt;h3>인간 개입의 중요성&lt;span class="hx:absolute hx:-mt-20" id="인간-개입의-중요성">&lt;/span>
&lt;a href="#%ec%9d%b8%ea%b0%84-%ea%b0%9c%ec%9e%85%ec%9d%98-%ec%a4%91%ec%9a%94%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>MCP 스펙에서 Sampling과 관련해 &lt;strong>인간 개입(Human-in-the-loop)&lt;/strong> 을 강조합니다.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;Implementations must always include human oversight capabilities for sampling requests.&amp;rdquo;&lt;/p>
&lt;/blockquote>
&lt;p>클라이언트는 Sampling 요청을 사용자에게 보여주고 승인을 받을 수 있어야 합니다. 이는 MCP 서버가 악의적으로 LLM을 남용하는 것을 방지하기 위함입니다.&lt;/p>
&lt;p>실제로 Claude Desktop에서는 MCP 서버가 도구를 호출하거나 Sampling을 요청하면 사용자에게 확인을 받는 UI가 표시됩니다.&lt;/p>
&lt;h2>실시간 업데이트: Notification 시스템&lt;span class="hx:absolute hx:-mt-20" id="실시간-업데이트-notification-시스템">&lt;/span>
&lt;a href="#%ec%8b%a4%ec%8b%9c%ea%b0%84-%ec%97%85%eb%8d%b0%ec%9d%b4%ed%8a%b8-notification-%ec%8b%9c%ec%8a%a4%ed%85%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>MCP에서 또 하나 흥미로운 기능은 &lt;strong>Notification&lt;/strong>입니다. 서버가 클라이언트에게 변경 사항을 실시간으로 알려줄 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;jsonrpc&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;2.0&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;method&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;notifications/tools/list_changed&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 알림을 받은 클라이언트는 &lt;code>tools/list&lt;/code>를 다시 호출해서 최신 도구 목록을 가져옵니다.&lt;/p>
&lt;h3>어떤 알림이 있나?&lt;span class="hx:absolute hx:-mt-20" id="어떤-알림이-있나">&lt;/span>
&lt;a href="#%ec%96%b4%eb%96%a4-%ec%95%8c%eb%a6%bc%ec%9d%b4-%ec%9e%88%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>알림&lt;/th>
&lt;th>설명&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>notifications/tools/list_changed&lt;/code>&lt;/td>
&lt;td>도구 목록이 변경됨&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>notifications/resources/list_changed&lt;/code>&lt;/td>
&lt;td>리소스 목록이 변경됨&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>notifications/resources/updated&lt;/code>&lt;/td>
&lt;td>특정 리소스 내용이 변경됨&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>notifications/prompts/list_changed&lt;/code>&lt;/td>
&lt;td>프롬프트 목록이 변경됨&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>이 기능 덕분에 &lt;strong>동적인 MCP 서버&lt;/strong>를 만들 수 있습니다. 새로운 플러그인이 설치되면 도구 목록을 업데이트하거나, 설정 파일이 변경되면 리소스를 업데이트하거나, 데이터베이스 스키마가 변경되면 알림을 보내는 식이죠.&lt;/p>
&lt;p>실시간 알림이 필요 없다면 이 기능을 구현하지 않아도 됩니다. 서버가 &lt;code>capabilities&lt;/code>에서 &lt;code>listChanged: true&lt;/code>를 선언한 경우에만 클라이언트가 알림을 기대합니다.&lt;/p>
&lt;h2>실제 서비스에서의 MCP 활용&lt;span class="hx:absolute hx:-mt-20" id="실제-서비스에서의-mcp-활용">&lt;/span>
&lt;a href="#%ec%8b%a4%ec%a0%9c-%ec%84%9c%eb%b9%84%ec%8a%a4%ec%97%90%ec%84%9c%ec%9d%98-mcp-%ed%99%9c%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>지금까지 살펴본 예시들은 대부분 &lt;strong>로컬 환경&lt;/strong>을 기준으로 했습니다. Claude Desktop에서 로컬 MCP 서버를 실행하고, stdio로 통신하는 구조였죠. 하지만 실제 프로덕션 서비스를 구축할 때는 어떨까요?&lt;/p>
&lt;h3>로컬이 아닌 서버에서의 MCP&lt;span class="hx:absolute hx:-mt-20" id="로컬이-아닌-서버에서의-mcp">&lt;/span>
&lt;a href="#%eb%a1%9c%ec%bb%ac%ec%9d%b4-%ec%95%84%eb%8b%8c-%ec%84%9c%eb%b2%84%ec%97%90%ec%84%9c%ec%9d%98-mcp" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이커머스 회사에서 AI 챗봇을 구축한다고 가정해봅시다. 챗봇이 주문 조회, 상품 검색, 재고 확인 등의 기능을 제공해야 합니다.&lt;/p>
&lt;h4>방법 1: 커스텀 REST API 방식&lt;span class="hx:absolute hx:-mt-20" id="방법-1-커스텀-rest-api-방식">&lt;/span>
&lt;a href="#%eb%b0%a9%eb%b2%95-1-%ec%bb%a4%ec%8a%a4%ed%85%80-rest-api-%eb%b0%a9%ec%8b%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>MCP 없이 직접 구현하는 방식입니다. 많은 분들이 AI 챗봇 백엔드를 구축할 때 이런 식으로 하셨을 것 같습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Client[&amp;#34;사용자 브라우저&amp;#34;]
UI[&amp;#34;채팅 UI&amp;#34;]
end
subgraph Backend[&amp;#34;AI 챗봇 백엔드 서버&amp;#34;]
API[&amp;#34;API 서버&amp;#34;]
Router[&amp;#34;요청 분석 로직&amp;#34;]
end
subgraph Services[&amp;#34;내부 서비스&amp;#34;]
Order[&amp;#34;주문 서비스&amp;#34;]
Product[&amp;#34;상품 서비스&amp;#34;]
DocSearch[&amp;#34;문서 검색 서비스&amp;#34;]
end
subgraph External[&amp;#34;외부&amp;#34;]
LLM[&amp;#34;LLM API or LLM Model&amp;#34;]
end
UI --&amp;gt;|&amp;#34;질문&amp;#34;| API
API --&amp;gt; Router
Router --&amp;gt;|&amp;#34;REST&amp;#34;| Order
Router --&amp;gt;|&amp;#34;REST&amp;#34;| Product
Router --&amp;gt;|&amp;#34;REST&amp;#34;| DocSearch
API &amp;lt;--&amp;gt;|&amp;#34;프롬프트&amp;#34;| LLM
&lt;/pre>&lt;p>이 방식은 백엔드가 사용자 질문을 분석해서 어떤 서비스를 호출할지 결정하고 각 서비스마다 다른 REST API 인터페이스를 호출하며 새로운 서비스를 추가할 때마다 백엔드 라우팅 로직 수정이 필요해 집니다.&lt;/p>
&lt;p>이처럼 작동은 합니다. 하지만 서비스가 늘어날수록 몇 가지 문제가 생길 수 있죠.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>인터페이스 불일치&lt;/strong>: 주문 서비스는 &lt;code>/orders/{id}&lt;/code>, 상품 서비스는 &lt;code>/api/products/search&lt;/code>&amp;hellip; 서비스마다 API 설계가 다름&lt;/li>
&lt;li>&lt;strong>문서화 부담&lt;/strong>: 각 서비스의 API 문서를 별도로 관리&lt;/li>
&lt;li>&lt;strong>LLM 통합 복잡성&lt;/strong>: 각 서비스를 LLM이 이해할 수 있도록 프롬프트에 설명을 직접 작성&lt;/li>
&lt;li>&lt;strong>유지보수 비용&lt;/strong>: 서비스 API가 변경되면 백엔드 라우터와 LLM 프롬프트 모두 수정 필요&lt;/li>
&lt;/ul>
&lt;h4>방법 2: MCP 표준화 방식&lt;span class="hx:absolute hx:-mt-20" id="방법-2-mcp-표준화-방식">&lt;/span>
&lt;a href="#%eb%b0%a9%eb%b2%95-2-mcp-%ed%91%9c%ec%a4%80%ed%99%94-%eb%b0%a9%ec%8b%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>이제 MCP를 도입한 구조를 살펴보겠습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Client[&amp;#34;사용자 브라우저&amp;#34;]
UI[&amp;#34;채팅 UI&amp;#34;]
end
subgraph Backend[&amp;#34;AI 챗봇 백엔드 서버 (MCP Host)&amp;#34;]
API[&amp;#34;API 서버&amp;#34;]
MCPClient[&amp;#34;MCP Client&amp;#34;]
end
subgraph MCPServers[&amp;#34;MCP 서버들 (HTTP)&amp;#34;]
OrderMCP[&amp;#34;주문 MCP Server&amp;#34;]
ProductMCP[&amp;#34;상품 MCP Server&amp;#34;]
DocMCP[&amp;#34;문서 검색 MCP Server&amp;#34;]
end
subgraph External[&amp;#34;외부&amp;#34;]
LLM[&amp;#34;LLM API or LLM Model&amp;#34;]
end
UI --&amp;gt;|&amp;#34;질문&amp;#34;| API
API --&amp;gt; MCPClient
MCPClient &amp;lt;--&amp;gt;|&amp;#34;MCP (HTTP)&amp;#34;| OrderMCP
MCPClient &amp;lt;--&amp;gt;|&amp;#34;MCP (HTTP)&amp;#34;| ProductMCP
MCPClient &amp;lt;--&amp;gt;|&amp;#34;MCP (HTTP)&amp;#34;| DocMCP
API &amp;lt;--&amp;gt;|&amp;#34;tools 파라미터&amp;#34;| LLM
&lt;/pre>&lt;p>여기서 두 방법의 핵심적인 차이점은 다음과 같습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>백엔드가 MCP Host 역할&lt;/strong>: 사용자 요청을 받아 LLM API와 MCP 서버들을 오케스트레이션&lt;/li>
&lt;li>&lt;strong>MCP 서버들은 별도 서비스로 배포&lt;/strong>: 컨테이너, 마이크로서비스, 서버리스 등&lt;/li>
&lt;li>&lt;strong>Streamable HTTP로 통신&lt;/strong>: 로컬 stdio가 아닌 HTTP 기반 통신&lt;/li>
&lt;li>&lt;strong>도구 정보 자동 수집&lt;/strong>: 백엔드가 시작할 때 각 MCP 서버에서 &lt;code>tools/list&lt;/code>로 도구 목록 수집&lt;/li>
&lt;/ol>
&lt;h3>서비스 구조 예시&lt;span class="hx:absolute hx:-mt-20" id="서비스-구조-예시">&lt;/span>
&lt;a href="#%ec%84%9c%eb%b9%84%ec%8a%a4-%ea%b5%ac%ec%a1%b0-%ec%98%88%ec%8b%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>실제 코드로 어떻게 구성되는지 살펴보겠습니다.&lt;/p>
&lt;h4>MCP 서버: 주문 조회 서비스&lt;span class="hx:absolute hx:-mt-20" id="mcp-서버-주문-조회-서비스">&lt;/span>
&lt;a href="#mcp-%ec%84%9c%eb%b2%84-%ec%a3%bc%eb%ac%b8-%ec%a1%b0%ed%9a%8c-%ec%84%9c%eb%b9%84%ec%8a%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># order-mcp-server/server.py&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">mcp.server&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">Server&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">mcp.server.stdio&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">stdio_server&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">mcp.types&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">Tool&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">TextContent&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">server&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">Server&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;order-service&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@server.list_tools&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">async&lt;/span> &lt;span class="k">def&lt;/span> &lt;span class="nf">list_tools&lt;/span>&lt;span class="p">():&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">Tool&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">name&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;get_order&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">description&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;주문 ID로 주문 상세 정보를 조회합니다. 주문 상태, 상품 목록, 배송 정보를 반환합니다.&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">inputSchema&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;type&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;object&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;properties&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;order_id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="s2">&amp;#34;type&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;string&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;description&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;주문 ID (예: ORD-12345)&amp;#34;&lt;/span>&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;required&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;order_id&amp;#34;&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">Tool&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">name&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;cancel_order&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">description&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;주문을 취소합니다. 배송 전 상태의 주문만 취소 가능합니다.&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">inputSchema&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;type&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;object&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;properties&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;order_id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="s2">&amp;#34;type&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;string&amp;#34;&lt;/span>&lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;reason&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="s2">&amp;#34;type&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;string&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;description&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;취소 사유&amp;#34;&lt;/span>&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;required&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;order_id&amp;#34;&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@server.call_tool&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">async&lt;/span> &lt;span class="k">def&lt;/span> &lt;span class="nf">call_tool&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">arguments&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="nb">dict&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="n">name&lt;/span> &lt;span class="o">==&lt;/span> &lt;span class="s2">&amp;#34;get_order&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">order&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">await&lt;/span> &lt;span class="n">db&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">get_order&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">arguments&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;order_id&amp;#34;&lt;/span>&lt;span class="p">])&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="n">TextContent&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nb">type&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;text&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">text&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="n">json&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">dumps&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">order&lt;/span>&lt;span class="p">))]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">elif&lt;/span> &lt;span class="n">name&lt;/span> &lt;span class="o">==&lt;/span> &lt;span class="s2">&amp;#34;cancel_order&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">result&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">await&lt;/span> &lt;span class="n">db&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">cancel_order&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">arguments&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;order_id&amp;#34;&lt;/span>&lt;span class="p">],&lt;/span> &lt;span class="n">arguments&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">get&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;reason&amp;#34;&lt;/span>&lt;span class="p">))&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="n">TextContent&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nb">type&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;text&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">text&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;주문이 취소되었습니다: &lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">result&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="p">)]&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h4>백엔드 서버: MCP Host 역할&lt;span class="hx:absolute hx:-mt-20" id="백엔드-서버-mcp-host-역할">&lt;/span>
&lt;a href="#%eb%b0%b1%ec%97%94%eb%93%9c-%ec%84%9c%eb%b2%84-mcp-host-%ec%97%ad%ed%95%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;span class="lnt">45
&lt;/span>&lt;span class="lnt">46
&lt;/span>&lt;span class="lnt">47
&lt;/span>&lt;span class="lnt">48
&lt;/span>&lt;span class="lnt">49
&lt;/span>&lt;span class="lnt">50
&lt;/span>&lt;span class="lnt">51
&lt;/span>&lt;span class="lnt">52
&lt;/span>&lt;span class="lnt">53
&lt;/span>&lt;span class="lnt">54
&lt;/span>&lt;span class="lnt">55
&lt;/span>&lt;span class="lnt">56
&lt;/span>&lt;span class="lnt">57
&lt;/span>&lt;span class="lnt">58
&lt;/span>&lt;span class="lnt">59
&lt;/span>&lt;span class="lnt">60
&lt;/span>&lt;span class="lnt">61
&lt;/span>&lt;span class="lnt">62
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># backend/main.py&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">mcp&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">ClientSession&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">anthropic&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">Anthropic&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">ChatbotBackend&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="fm">__init__&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">anthropic&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">Anthropic&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">mcp_servers&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;order&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;https://order-mcp.internal:8080/mcp&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;product&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;https://product-mcp.internal:8080/mcp&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;docs&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;https://docs-mcp.internal:8080/mcp&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">tools&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">[]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">async&lt;/span> &lt;span class="k">def&lt;/span> &lt;span class="nf">initialize&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;시작 시 모든 MCP 서버에서 도구 정보 수집&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">for&lt;/span> &lt;span class="n">name&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">url&lt;/span> &lt;span class="ow">in&lt;/span> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">mcp_servers&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">items&lt;/span>&lt;span class="p">():&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">async&lt;/span> &lt;span class="k">with&lt;/span> &lt;span class="n">ClientSession&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">url&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="k">as&lt;/span> &lt;span class="n">session&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">await&lt;/span> &lt;span class="n">session&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">initialize&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">tools&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">await&lt;/span> &lt;span class="n">session&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">list_tools&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">tools&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">extend&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">tools&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">async&lt;/span> &lt;span class="k">def&lt;/span> &lt;span class="nf">handle_message&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">user_message&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1"># 1. LLM API 호출 (수집한 도구 정보와 함께)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">response&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">anthropic&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">messages&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">create&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">model&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;claude-sonnet-4-20250514&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">messages&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="p">[{&lt;/span>&lt;span class="s2">&amp;#34;role&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;user&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;content&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">user_message&lt;/span>&lt;span class="p">}],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">tools&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">_convert_to_anthropic_tools&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">tools&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1"># 2. LLM이 도구 사용을 요청하면 해당 MCP 서버에 호출&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">while&lt;/span> &lt;span class="n">response&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">stop_reason&lt;/span> &lt;span class="o">==&lt;/span> &lt;span class="s2">&amp;#34;tool_use&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">tool_results&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">[]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">for&lt;/span> &lt;span class="n">block&lt;/span> &lt;span class="ow">in&lt;/span> &lt;span class="n">response&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">content&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="n">block&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">type&lt;/span> &lt;span class="o">==&lt;/span> &lt;span class="s2">&amp;#34;tool_use&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">result&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">await&lt;/span> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">_call_mcp_tool&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">block&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">block&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">input&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">tool_results&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">append&lt;/span>&lt;span class="p">({&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;type&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;tool_result&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;tool_use_id&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">block&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;content&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">result&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">})&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1"># 3. 결과를 다시 LLM에 전달&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">response&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">anthropic&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">messages&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">create&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">model&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;claude-sonnet-4-20250514&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">messages&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>&lt;span class="s2">&amp;#34;role&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;user&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;content&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">user_message&lt;/span>&lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>&lt;span class="s2">&amp;#34;role&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;assistant&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;content&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">response&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">content&lt;/span>&lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>&lt;span class="s2">&amp;#34;role&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;user&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;content&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">tool_results&lt;/span>&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">tools&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">_convert_to_anthropic_tools&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">tools&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">response&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">content&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="mi">0&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">text&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">async&lt;/span> &lt;span class="k">def&lt;/span> &lt;span class="nf">_call_mcp_tool&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">tool_name&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">arguments&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="nb">dict&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;도구 이름으로 해당 MCP 서버를 찾아 호출&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">server_url&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">_find_server_for_tool&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">tool_name&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">async&lt;/span> &lt;span class="k">with&lt;/span> &lt;span class="n">ClientSession&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">server_url&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="k">as&lt;/span> &lt;span class="n">session&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">await&lt;/span> &lt;span class="n">session&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">initialize&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">result&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">await&lt;/span> &lt;span class="n">session&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">call_tool&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">tool_name&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">arguments&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">result&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>MCP 표준화의 이점&lt;span class="hx:absolute hx:-mt-20" id="mcp-표준화의-이점">&lt;/span>
&lt;a href="#mcp-%ed%91%9c%ec%a4%80%ed%99%94%ec%9d%98-%ec%9d%b4%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이렇게 MCP를 도입하면 어떤 이점이 있을까요?&lt;/p>
&lt;p>&lt;strong>1. 일관된 인터페이스&lt;/strong>&lt;/p>
&lt;p>모든 서비스가 동일한 MCP 프로토콜을 따릅니다. &lt;code>tools/list&lt;/code>로 도구 목록을 조회하고, &lt;code>tools/call&lt;/code>로 호출합니다. 서비스마다 다른 REST API 설계를 고민할 필요가 없습니다.&lt;/p>
&lt;p>&lt;strong>2. 자기 설명적 (Self-describing)&lt;/strong>&lt;/p>
&lt;p>각 MCP 서버가 자신의 기능을 &lt;code>description&lt;/code>과 &lt;code>inputSchema&lt;/code>로 설명합니다. 백엔드에서 별도로 &amp;ldquo;주문 서비스는 이런 기능이 있고&amp;hellip;&amp;ldquo;라고 프롬프트에 작성할 필요가 없습니다. LLM API 호출 시 도구 정보를 그대로 전달하면 됩니다.&lt;/p>
&lt;p>&lt;strong>3. 독립적인 배포&lt;/strong>&lt;/p>
&lt;p>각 MCP 서버는 독립적으로 배포하고 업데이트할 수 있습니다. 주문 서비스에 새로운 기능을 추가해도, 백엔드는 &lt;code>tools/list&lt;/code>를 다시 호출하면 자동으로 새 도구를 인식합니다.&lt;/p>
&lt;p>&lt;strong>4. 생태계 호환성&lt;/strong>&lt;/p>
&lt;p>MCP는 오픈 표준입니다. 사내에서 만든 MCP 서버를 Claude Desktop에서도 그대로 사용할 수 있고, 다른 MCP 호환 클라이언트에서도 사용할 수 있습니다.&lt;/p>
&lt;p>&lt;strong>5. 관심사의 분리&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>MCP 서버: 비즈니스 로직에 집중 (주문 조회, 취소 등)&lt;/li>
&lt;li>백엔드: 오케스트레이션에 집중 (사용자 인증, MCP 연결, LLM 호출)&lt;/li>
&lt;li>LLM: 추론에 집중 (사용자 의도 파악, 도구 선택)&lt;/li>
&lt;/ul>
&lt;h3>구체적으로 뭐가 달라지는데?&lt;span class="hx:absolute hx:-mt-20" id="구체적으로-뭐가-달라지는데">&lt;/span>
&lt;a href="#%ea%b5%ac%ec%b2%b4%ec%a0%81%ec%9c%bc%eb%a1%9c-%eb%ad%90%ea%b0%80-%eb%8b%ac%eb%9d%bc%ec%a7%80%eb%8a%94%eb%8d%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>솔직히 위의 장점들만 보면 &amp;ldquo;그래서 뭐?&amp;rdquo; 싶을 수 있습니다. 구체적인 시나리오로 비교해보겠습니다.&lt;/p>
&lt;p>&lt;strong>시나리오: &amp;ldquo;환불 조회&amp;rdquo; 기능 추가&lt;/strong>&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>단계&lt;/th>
&lt;th>REST 방식&lt;/th>
&lt;th>MCP 방식&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>1&lt;/td>
&lt;td>환불 API 개발&lt;/td>
&lt;td>환불 MCP 도구 개발&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>2&lt;/td>
&lt;td>API 문서 작성 (Swagger 등)&lt;/td>
&lt;td>&lt;em>(도구 정의가 곧 문서)&lt;/em>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>3&lt;/td>
&lt;td>백엔드 라우터에 새 경로 추가&lt;/td>
&lt;td>&lt;em>(불필요)&lt;/em>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>4&lt;/td>
&lt;td>LLM 프롬프트에 도구 설명 추가&lt;/td>
&lt;td>&lt;em>(tools/list가 자동 수집)&lt;/em>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>수정 포인트&lt;/strong>&lt;/td>
&lt;td>&lt;strong>4곳&lt;/strong>&lt;/td>
&lt;td>&lt;strong>1곳&lt;/strong>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>차이가 보이시나요? MCP에서는 &lt;strong>도구 정의 하나가 문서이자 인터페이스이자 LLM 프롬프트&lt;/strong>입니다. 이것이 바로 &lt;strong>Single Source of Truth&lt;/strong>입니다.&lt;/p>
&lt;p>도구가 3개일 때는 별 차이 없어 보여도, 도구가 30개가 되면 이야기가 달라집니다. REST 방식에서는 30개 × 4곳 = 120곳을 관리해야 하지만, MCP에서는 30곳만 관리하면 됩니다.&lt;/p>
&lt;h4>소프트웨어 설계 원칙과의 연결&lt;span class="hx:absolute hx:-mt-20" id="소프트웨어-설계-원칙과의-연결">&lt;/span>
&lt;a href="#%ec%86%8c%ed%94%84%ed%8a%b8%ec%9b%a8%ec%96%b4-%ec%84%a4%ea%b3%84-%ec%9b%90%ec%b9%99%ea%b3%bc%ec%9d%98-%ec%97%b0%ea%b2%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>이 글을 쓰면서 저는 느낀 게 있는데요, MCP의 설계 철학이 우리가 알고 있는 좋은 소프트웨어 설계 원칙과 맞닿아 있다는 점입니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>추상화&lt;/strong>: LLM은 구현을 모르고 인터페이스(이름, 설명, 스키마)만 봄&lt;/li>
&lt;li>&lt;strong>단일 책임 원칙(SRP)&lt;/strong>: 각 MCP 서버는 하나의 도메인만 담당&lt;/li>
&lt;li>&lt;strong>개방-폐쇄 원칙(OCP)&lt;/strong>: 새 도구 추가 시 기존 코드 수정 없이 확장&lt;/li>
&lt;li>&lt;strong>의존성 역전(DIP)&lt;/strong>: 구현이 아닌 프로토콜(인터페이스)에 의존&lt;/li>
&lt;/ul>
&lt;p>결국 MCP가 해결하려는 문제는 새로운 게 아닌 것 같습니다. &lt;strong>&amp;ldquo;변경에 유연하고 유지보수하기 쉬운 시스템&amp;rdquo;&lt;/strong>, 우리가 늘 추구하던 그 목표를 AI 도구 통합 영역에 적용한 것이 아닌가 싶습니다.&lt;/p>
&lt;h3>배포 아키텍처 예시&lt;span class="hx:absolute hx:-mt-20" id="배포-아키텍처-예시">&lt;/span>
&lt;a href="#%eb%b0%b0%ed%8f%ac-%ec%95%84%ed%82%a4%ed%85%8d%ec%b2%98-%ec%98%88%ec%8b%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>한번 MCP를 이용하는 MCP 서버 구성도를 그려봤습니다. 아키텍처로 보면 아무래도 이해가 더 쉬울 것 같아서요.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph K8s[&amp;#34;Kubernetes Cluster&amp;#34;]
subgraph Backend[&amp;#34;Backend Pods&amp;#34;]
API1[&amp;#34;API Pod 1&amp;#34;]
API2[&amp;#34;API Pod 2&amp;#34;]
end
subgraph MCP[&amp;#34;MCP Server Pods&amp;#34;]
Order[&amp;#34;order-mcp&amp;#34;]
Product[&amp;#34;product-mcp&amp;#34;]
Docs[&amp;#34;docs-mcp&amp;#34;]
end
Ingress[&amp;#34;Ingress&amp;#34;]
end
subgraph External[&amp;#34;External&amp;#34;]
User[&amp;#34;사용자&amp;#34;]
LLM[&amp;#34;Claude API&amp;#34;]
end
User --&amp;gt; Ingress
Ingress --&amp;gt; API1
Ingress --&amp;gt; API2
API1 &amp;amp; API2 &amp;lt;--&amp;gt; Order &amp;amp; Product &amp;amp; Docs
API1 &amp;amp; API2 &amp;lt;--&amp;gt; LLM
&lt;/pre>&lt;ul>
&lt;li>Kubernetes Pod로 배포&lt;/li>
&lt;li>내부 서비스로 노출 (외부에서 직접 접근 불가)&lt;/li>
&lt;li>Streamable HTTP로 통신&lt;/li>
&lt;li>각각 독립적으로 스케일링 가능&lt;/li>
&lt;/ul>
&lt;h3>언제 MCP를 도입해야 할까?&lt;span class="hx:absolute hx:-mt-20" id="언제-mcp를-도입해야-할까">&lt;/span>
&lt;a href="#%ec%96%b8%ec%a0%9c-mcp%eb%a5%bc-%eb%8f%84%ec%9e%85%ed%95%b4%ec%95%bc-%ed%95%a0%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>물론 모든 서비스에 MCP가 필요한 건 아니라고 생각합니다.&lt;/p>
&lt;p>&lt;strong>MCP가 유용한 경우&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>여러 AI 기능(챗봇, 검색, 추천 등)에서 같은 백엔드 서비스를 사용할 때&lt;/li>
&lt;li>새로운 기능이 자주 추가되고 LLM이 자동으로 인식해야 할 때&lt;/li>
&lt;li>팀 간에 AI 도구를 표준화하고 공유하고 싶을 때&lt;/li>
&lt;li>로컬 개발(stdio)과 프로덕션(HTTP)에서 같은 서버 코드를 사용하고 싶을 때&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>MCP가 과할 수 있는 경우&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>단일 AI 기능만 있고, 도구가 1-2개뿐일 때&lt;/li>
&lt;li>빠르게 MVP를 만들어야 할 때 (직접 REST API 호출이 더 간단)&lt;/li>
&lt;li>팀에 MCP 학습 비용을 투자할 여유가 없을 때&lt;/li>
&lt;/ul>
&lt;p>결국 &lt;strong>표준화의 이점이 도입 비용을 상쇄하는지&lt;/strong>가 핵심인 것 같습니다. 서비스가 성장하고 AI 기능이 늘어날수록 MCP의 가치는 커지지만, 처음부터 과도하게 설계할 필요는 없지 않나 싶네요.&lt;/p>
&lt;p>다만 이제까지 이야기한건 우리 서비스에 MCP를 도입해 사용자에게 제공할때의 이야기 였습니다. 하지만 현재 보통의 경우에는 로컬 환경에서 개인이 MCP 서버를 설치해 실행하는 경우가 많죠. 그렇기 때문에 설계에 대한 부분은 단순히 로컬에서 MCP 서버를 실행하는 경우와는 다른 문제입니다.&lt;/p>
&lt;h2>MCP의 한계와 보안 고려사항&lt;span class="hx:absolute hx:-mt-20" id="mcp의-한계와-보안-고려사항">&lt;/span>
&lt;a href="#mcp%ec%9d%98-%ed%95%9c%ea%b3%84%ec%99%80-%eb%b3%b4%ec%95%88-%ea%b3%a0%eb%a0%a4%ec%82%ac%ed%95%ad" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>지금까지 MCP의 구조와 기능을 살펴봤습니다. 하지만 모든 기술이 그렇듯 MCP도 완벽하지는 않습니다.&lt;/p>
&lt;h3>보안 취약점&lt;span class="hx:absolute hx:-mt-20" id="보안-취약점">&lt;/span>
&lt;a href="#%eb%b3%b4%ec%95%88-%ec%b7%a8%ec%95%bd%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>2025년에 여러 보안 연구자들이 MCP 관련 보안 이슈를 발표했습니다.&lt;/p>
&lt;p>&lt;strong>주요 취약점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Prompt Injection&lt;/strong>: &lt;a href="https://simonwillison.net/2025/Apr/9/mcp-prompt-injection/"target="_blank" rel="noopener">Simon Willison의 분석&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에 따르면, MCP 서버가 반환하는 데이터에 악의적인 지시가 포함될 경우 LLM의 동작을 조작할 수 있습니다. OWASP에서도 Prompt Injection을 LLM 보안 위험 1위로 선정했습니다.&lt;/li>
&lt;li>&lt;strong>Tool Poisoning&lt;/strong>: &lt;a href="https://unit42.paloaltonetworks.com/model-context-protocol-attack-vectors/"target="_blank" rel="noopener">Palo Alto Unit42 연구&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에서 도구의 메타데이터(description)에 악성 지시를 숨겨 LLM이 의도치 않은 도구를 호출하게 만드는 공격 벡터를 발표했습니다. 사용자에게는 보이지 않지만 AI 모델은 해석할 수 있는 악성 지시가 문제입니다.&lt;/li>
&lt;li>&lt;strong>Critical RCE 취약점&lt;/strong>: &lt;a href="https://jfrog.com/blog/2025-6514-critical-mcp-remote-rce-vulnerability/"target="_blank" rel="noopener">JFrog Security Research가 발견한 CVE-2025-6514&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>(CVSS 9.6)는 mcp-remote 패키지(v0.0.5~0.1.15)에서 발견된 원격 코드 실행 취약점입니다. 악성 MCP 서버에 연결 시 클라이언트 OS에서 임의 명령이 실행될 수 있으며, 해당 패키지는 &lt;a href="https://thehackernews.com/2025/07/critical-mcp-remote-vulnerability.html"target="_blank" rel="noopener">43만 7천 회 이상 다운로드&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>되었습니다.&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>노출된 MCP 서버:&lt;/strong>&lt;/p>
&lt;p>&lt;a href="https://www.trendmicro.com/vinfo/us/security/news/cybercrime-and-digital-threats/mcp-security-network-exposed-servers-are-backdoors-to-your-private-data"target="_blank" rel="noopener">Trend Micro 연구&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에서는 인터넷에 노출된 MCP 서버 492개를 발견했는데, &lt;strong>인증이나 암호화 없이&lt;/strong> 운영되고 있었습니다. 이 서버들은 총 1,402개의 도구에 접근할 수 있었고, 90% 이상이 데이터 소스에 직접 읽기 권한을 제공하고 있었습니다. &lt;a href="https://www.bitsight.com/blog/exposed-mcp-servers-reveal-new-ai-vulnerabilities"target="_blank" rel="noopener">Bitsight 보고서&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에서도 약 1,000개의 MCP 서버가 인증 없이 공개 인터넷에 노출되어 있다고 경고했습니다.&lt;/p>
&lt;p>또한 &lt;a href="https://astrix.security/learn/blog/state-of-mcp-server-security-2025/"target="_blank" rel="noopener">Astrix의 MCP 보안 현황 보고서&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에 따르면, MCP 서버의 88%가 자격 증명을 요구하지만, 그중 53%는 장기간 유효한 정적 API 키나 PAT(Personal Access Token)에 의존하고 있었습니다.&lt;/p>
&lt;p>이런 연구 결과들을 보면, MCP를 사용할 때는 보안에 특히 신경 써야 한다는 생각이 들었습니다.&lt;/p>
&lt;h3>권장 보안 사례&lt;span class="hx:absolute hx:-mt-20" id="권장-보안-사례">&lt;/span>
&lt;a href="#%ea%b6%8c%ec%9e%a5-%eb%b3%b4%ec%95%88-%ec%82%ac%eb%a1%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>서버 측&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>모든 입력 값 검증&lt;/li>
&lt;li>적절한 접근 제어 구현&lt;/li>
&lt;li>Rate Limiting 적용&lt;/li>
&lt;li>민감한 데이터 필터링&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>클라이언트 측&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>민감한 작업에 사용자 확인 요청&lt;/li>
&lt;li>도구 호출 전 입력 값 표시&lt;/li>
&lt;li>도구 실행 로깅&lt;/li>
&lt;li>타임아웃 설정&lt;/li>
&lt;/ul>
&lt;p>특히 MCP 서버가 파일 시스템이나 데이터베이스에 접근한다면, &lt;strong>최소 권한 원칙&lt;/strong>을 적용하는 것이 중요하다고 생각합니다.&lt;/p>
&lt;h2>정리&lt;span class="hx:absolute hx:-mt-20" id="정리">&lt;/span>
&lt;a href="#%ec%a0%95%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이번 글에서 MCP의 구조와 동작 원리를 살펴보았습니다. 정리하자면&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>MCP는 AI와 외부 시스템을 연결하는 표준 프로토콜&lt;/strong>입니다. USB-C처럼 하나의 표준으로 다양한 연결을 가능하게 합니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Host-Client-Server 아키텍처&lt;/strong>로 관심사가 분리되어 있습니다. 덕분에 서버 하나를 만들면 여러 AI 애플리케이션에서 재사용할 수 있습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>JSON-RPC 2.0 기반&lt;/strong>으로 통신합니다. Request, Response, Notification 세 가지 메시지 타입으로 모든 상호작용이 이루어집니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Tools, Resources, Prompts&lt;/strong> 세 가지 핵심 기능을 제공합니다. 각각 실행 가능한 함수, 읽기 전용 데이터, 재사용 가능한 템플릿 역할을 합니다. MCP 자체는 지능이 없으며, &lt;strong>도구 선택은 LLM의 Tool Use 능력&lt;/strong>에 의해 이루어집니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>stdio와 Streamable HTTP&lt;/strong> 두 가지 전송 방식을 지원합니다. 로컬 개발에는 stdio, 원격 서비스에는 HTTP를 사용합니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>프로덕션 서비스에서도 활용 가능&lt;/strong>합니다. 백엔드가 MCP Host 역할을 하고, MCP 서버들을 별도 서비스로 배포하면 됩니다. 커스텀 REST API 대비 표준화, 자기 설명적 인터페이스, 독립 배포 등의 이점이 있습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Sampling&lt;/strong>을 통해 서버도 LLM을 호출할 수 있습니다. 단, 인간 개입이 가능해야 합니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>보안에 주의&lt;/strong>해야 합니다. 인증, 입력 검증, 권한 관리가 중요합니다.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>MCP는 아직 발전 중인 프로토콜입니다. 스펙도 계속 업데이트되고 있고, 생태계도 성장하고 있습니다.&lt;/p>
&lt;p>이 글을 정리하면서 느낀 점이 있습니다. MCP가 해결하려는 문제는 사실 새로운 게 아니었던 것 같습니다. &lt;strong>추상화, 관심사의 분리, 인터페이스 기반 설계&lt;/strong>. 저희가 좋은 소프트웨어를 만들기 위해 오랫동안 고민해온 원칙들이 AI 도구 통합이라는 새로운 영역에 적용된 것뿐이라는 생각이 듭니다.&lt;/p>
&lt;p>결국 좋은 설계란 시대가 바뀌어도 본질은 같은 것 같습니다. MCP를 공부하면서 오히려 기본기의 중요성을 다시 느꼈습니다.&lt;/p>
&lt;p>긴 글 읽어주셔서 감사합니다. 이 글이 MCP를 이해하는 데 조금이나마 도움이 되었길 바랍니다.&lt;/p>
&lt;hr>
&lt;h2>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>공식 문서&lt;span class="hx:absolute hx:-mt-20" id="공식-문서">&lt;/span>
&lt;a href="#%ea%b3%b5%ec%8b%9d-%eb%ac%b8%ec%84%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://modelcontextprotocol.io/introduction"target="_blank" rel="noopener">Model Context Protocol - Introduction&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://spec.modelcontextprotocol.io/specification/"target="_blank" rel="noopener">MCP Specification&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://modelcontextprotocol.io/docs/concepts/architecture"target="_blank" rel="noopener">MCP Architecture&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://modelcontextprotocol.io/docs/concepts/transports"target="_blank" rel="noopener">MCP Transports&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://modelcontextprotocol.io/docs/develop/build-server"target="_blank" rel="noopener">Build an MCP Server&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> - 다양한 언어로 MCP 서버 구현하기 (Python, TypeScript, Java, Kotlin, C#, Rust)&lt;/li>
&lt;/ul>
&lt;h3>Anthropic 발표&lt;span class="hx:absolute hx:-mt-20" id="anthropic-발표">&lt;/span>
&lt;a href="#anthropic-%eb%b0%9c%ed%91%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://www.anthropic.com/news/model-context-protocol"target="_blank" rel="noopener">Introducing the Model Context Protocol - Anthropic&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>관련 글&lt;span class="hx:absolute hx:-mt-20" id="관련-글">&lt;/span>
&lt;a href="#%ea%b4%80%eb%a0%a8-%ea%b8%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/trends/llms-txt-mcp-second-brain/">LLM을 내 두 번째 뇌로 만들기: MCP 서버로 개인 블로그를 RAG로 활용하는 방법&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/backend/rpc-deep-dive/">RPC 제대로 이해하기: JSON-RPC, gRPC, 그리고 흔한 오해들&lt;/a> - MCP가 사용하는 JSON-RPC에 대한 상세 설명&lt;/li>
&lt;/ul>
&lt;h3>추가 자료&lt;span class="hx:absolute hx:-mt-20" id="추가-자료">&lt;/span>
&lt;a href="#%ec%b6%94%ea%b0%80-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://en.wikipedia.org/wiki/Model_Context_Protocol"target="_blank" rel="noopener">Model Context Protocol - Wikipedia&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.jsonrpc.org/specification"target="_blank" rel="noopener">JSON-RPC 2.0 Specification&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>[MSA에 관한 고찰 7/7편] 우리는 정말 MSA가 필요한가?</title><link>https://jeongil.dev/ko/blog/architecture/msa-series-7-conclusion/</link><pubDate>Thu, 22 Jan 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/architecture/msa-series-7-conclusion/</guid><description>
&lt;p>전편: &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-6-event-consistency/">[MSA에 관한 고찰 6/7편] 이벤트 기반 데이터 정합성&lt;/a>&lt;/p>
&lt;hr>
&lt;p>지금까지 6편에 걸쳐 MSA의 여러 측면을 살펴봤습니다. 서비스를 어떻게 나눌지, 어떻게 통신할지, 장애에 어떻게 대응할지, 데이터를 어떻게 분리하고 정합성을 맞출지까지요.&lt;/p>
&lt;p>정말 여러분과 제가 실제로 한 팀에서 MSA를 선택하게 되면서 함께 문제를 맞이하고 고민하는 것처럼 느끼실 수 있게 이야기를 풀어보려 노력해 봤습니다. 그래서 정말 쉽지 않은 여정처럼 느껴지셨을 수 있을 것 같습니다. 다만 맛보기 만이라도 MSA를 도입하는 과정을 몸소 체감해보시길 바랬습니다.&lt;/p>
&lt;p>이제는 MSA가 문제를 해결하기위해 시스템의 복잡성을 이끌어 오게 되는 트레이드오프 임을 충분히 이해하시고 공감하시지 않으실까 싶습니다.&lt;/p>
&lt;p>이제 저희는 &lt;strong>&amp;ldquo;이 트레이드오프가 정말 필요한가?&amp;rdquo;&lt;/strong> 라는 질문에 대해 생각해볼 시간입니다.&lt;/p>
&lt;p>이번 편에서는 이 질문에 대한 제 생각을 적어보려 합니다.&lt;/p>
&lt;blockquote>
&lt;p>다만 이번 글에는 제 개인적인 의견이 많이 담겨있음을 미리 양해 부탁드립니다. 부족한 3년차 개발자의 개인적인 생각일 뿐임을 염두해주시고 넓은 아량으로 이해해주시며 읽어주시면 감사하겠습니다.&lt;/p>
&lt;/blockquote>
&lt;h2>MSA의 진짜 비용&lt;span class="hx:absolute hx:-mt-20" id="msa의-진짜-비용">&lt;/span>
&lt;a href="#msa%ec%9d%98-%ec%a7%84%ec%a7%9c-%eb%b9%84%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>MSA를 도입하기 위해 해야할 고민들과 문제들을 살펴보셨을때 어떤 생각이 드셨나요? 예상보다 훨씬 복잡하고 어려운 문제들이 끝없이 쏟아져 나온다는 생각이 들지 않으셨나요?&lt;/p>
&lt;p>서비스를 어떻게 나눌지 정했더니 서비스 간 통신이 필요해졌고, 통신이 생기니 장애가 발생할 수 밖에 없었고, 장애가 생기니 이를 대비한 설계가 필요해졌고, 서비스를 나누다보니 데이터 정합성 문제가 발생했고, 데이터 정합성을 맞추려다보니 결국 또 다른 복잡한 설계가 필요해졌습니다. &lt;strong>이 모든 과정은 오로지 MSA를 도입하겠다는 결정 하나만으로 시작된 문제들&lt;/strong>이었습니다.&lt;/p>
&lt;p>MSA가 러닝커브가 높다는 말을 직접 체감하시게 되신거죠.&lt;/p>
&lt;p>그렇지만 MSA를 도입하기 위해 마주했던 수많은 문제들보다 더 크게 우선시 되어야하는 현실적인 문제가 있지 않나 싶습니다.&lt;/p>
&lt;p>저를 포함한 많은 개발자들이 흔히 개발, 운영과정에서의 문제만을 고려하는 경향이 있는 것 같습니다. 하지만 정말 문제는 기술적인 문제가 아닌 바로 &lt;strong>비용&lt;/strong>입니다.&lt;/p>
&lt;h3>운영 비용의 현실&lt;span class="hx:absolute hx:-mt-20" id="운영-비용의-현실">&lt;/span>
&lt;a href="#%ec%9a%b4%ec%98%81-%eb%b9%84%ec%9a%a9%ec%9d%98-%ed%98%84%ec%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>저희가 비용을 이야기할때 여러가지 의미에서 &amp;lsquo;비용&amp;rsquo;이라는 단어를 사용하곤 합니다. 개발자의 시간, 서버 리소스, 관리의 복잡성 등등 말이죠. 물론 MSA를 도입하기로 결정하게되면 이 모든 비용이 증가하게 됩니다만 제가 이야기하고 싶은 &amp;lsquo;비용&amp;rsquo;은 정말 말 그대로 &amp;lsquo;돈&amp;rsquo;입니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;MSA는 돈이 많이 들어갑니다.&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>물론 잘 만들고 잘 운영하는 MSA는 모놀리식보다도 운영비용이 적을 수도 있습니다. 하지만 대부분의 경우에는 그렇지 않더라고요.&lt;/p>
&lt;p>MSA는 서비스가 나뉘어지면서 각각의 서비스가 독립적으로 운영되어야 합니다. 즉, 각각의 서비스는 별도의 서버, 별도의 데이터베이스, 별도의 모니터링 시스템, 별도의 배포 파이프라인 등을 필요로 하게 됩니다.&lt;/p>
&lt;p>기존에는 RDS 1대, EC2 인스턴스 2대, 모니터링 시스템 1개로 운영되던 서비스가 MSA로 전환되면 RDS 5대, EC2 인스턴스 10대, LB 2대 등으로 늘어날 수 있다는 거죠.&lt;/p>
&lt;p>단순 무식하게 계산해봐도 더 비용이 많이 나올 가능성이 높습니다. 물론 모놀리식이라고 해서 꼭 저렴한건 아닙니다. 하지만 MSA가 더 비싸질 가능성이 훨씬 높다는 점은 명확하지 않나 싶습니다.&lt;/p>
&lt;p>실제로 2023년에 Amazon Prime Video 팀이 MSA를 모놀리식으로 전환하면서 &lt;strong>비용을 90% 절감&lt;/strong>했다는 사례가 있습니다. AWS Step Functions와 Lambda를 활용한 &amp;ldquo;교과서적인&amp;rdquo; 분산 시스템이었는데, 실제 운영에서는 오히려 비효율적이었다고 하더라고요. 재밌는건 AWS가 MSA 인프라를 판매해서 수익을 내는 회사인데도 &amp;ldquo;때로는 모놀리식이 낫다&amp;quot;고 인정한 점이지 않나 싶습니다. (&lt;a href="https://www.docker.com/blog/do-you-really-need-microservices/"target="_blank" rel="noopener">Docker 블로그 - You Want Microservices, But Do You Really Need Them?&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>)&lt;/p>
&lt;p>회사 입장에서는 당연히 지출비용을 줄이고 싶어할 수 밖에 없습니다. 회사는 영리를 추구하는 조직이니까요. 그렇기 때문에 &lt;strong>&amp;quot;&amp;lsquo;돈&amp;rsquo;이 더 많이 들어감에도 불구하고 MSA가 필요한 이유&amp;rdquo;&lt;/strong> 가 분명해야 합니다.&lt;/p>
&lt;p>&amp;ldquo;MSA가 훨씬 좋은 것 같으니까&amp;quot;와 같은 불명확하고 근거도 빈약한 주장으로 앞으로 회사가 감수해야할 큰 비용을 정당화할 수는 없다는 거죠.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;어째서 MSA가 아니면 안되는가&amp;quot;를 설득할 수 있어야 한다고 생각합니다.&lt;/strong>&lt;/p>
&lt;h3>기술적 복잡성의 대가&lt;span class="hx:absolute hx:-mt-20" id="기술적-복잡성의-대가">&lt;/span>
&lt;a href="#%ea%b8%b0%ec%88%a0%ec%a0%81-%eb%b3%b5%ec%9e%a1%ec%84%b1%ec%9d%98-%eb%8c%80%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>또 &amp;ldquo;유지보수&amp;rdquo;, &amp;ldquo;고가용성&amp;rdquo;, &amp;ldquo;확장성&amp;quot;을 얻기 위해 MSA를 선택하는 경우들도 많은 것 같습니다.&lt;/p>
&lt;p>다만 &amp;ldquo;유지보수&amp;rdquo;, &amp;ldquo;고가용성&amp;rdquo;, &amp;ldquo;확장성&amp;quot;을 확보하는 다른 대안들도 많이 존재하기 때문에 &amp;ldquo;유지보수&amp;quot;가 더 쉽다거나 &amp;ldquo;고가용성&amp;rdquo;, &amp;ldquo;확장성&amp;quot;이 더 좋다는 이유만으로는 부족하지 않나 싶습니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;기술적 복잡성&amp;quot;은 결국 개발자와 운영자가 감당해야할 부담으로 돌아옵니다.&lt;/strong> 복잡한 시스템을 이해하고 관리하는데 더 많은 시간과 노력이 필요하게 되죠. 모니터링 툴이 빈약하면 거의 재앙수준으로 다가올 수 있습니다.&lt;/p>
&lt;p>경험상 APM을 거의 필수적으로 도입해야 했습니다. 처음 팀에 합류했을때 Cloud Watch로만 MSA 모니터링한적이 있는데 상상 이상으로 운영이 힘들었습니다. 서비스 간 호출 관계를 파악하는 것도 힘들었고 요청A가 어떤 서비스를 거쳐서 응답이 돌아오는지 추적하는 것도 힘들었죠. 같은 요청이라고 추측할 수 있는 단서는 같은 시간(ms 단위까지)이라는 것과 호출하는 흐름을 직접 코드로 확인하는 것 밖에 없었습니다.&lt;/p>
&lt;p>Grafana LGTM Stack &lt;a href="https://jeongil.dev/ko/blog/infrastructure/building-a-monitoring-system/">&lt;strong>모니터링 시스템 설계 및 구축&lt;/strong>&lt;/a>를 도입하면서 비로소 좀 쾌적한 운영이 가능해졌습니다. 다시 생각해도 정말 운영이 힘들었던 기억이 납니다.&lt;/p>
&lt;p>이처럼 &lt;strong>잘못 만든 MSA는 개발자와 운영자의 부담만 가중시키고, &amp;ldquo;유지보수&amp;quot;마저 어렵게 만들 수 있다&lt;/strong>고 생각합니다. 새롭게 팀에 합류하는 개발자들의 온보딩 난이도도 덩달아 높아지게 되죠.&lt;/p>
&lt;p>결국 &amp;ldquo;유지보수&amp;quot;를 향상시킨다는 건 MSA를 잘 설계하고 도입했을 때의 이야기가 아닐까 싶습니다.&lt;/p>
&lt;h3>조직이 준비되어야 한다&lt;span class="hx:absolute hx:-mt-20" id="조직이-준비되어야-한다">&lt;/span>
&lt;a href="#%ec%a1%b0%ec%a7%81%ec%9d%b4-%ec%a4%80%eb%b9%84%eb%90%98%ec%96%b4%ec%95%bc-%ed%95%9c%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>또 MSA를 도입하기 전에 반드시 고려해야할 점이 하나 더 있다고 생각합니다. 바로 &lt;strong>조직의 준비 상태&lt;/strong>입니다.&lt;/p>
&lt;p>이게 결국 MSA의 러닝커브 와도 연결되는 문제인데요. MSA는 단순히 기술적인 문제만이 아니라 조직적인 문제도 함께 고려해야하는 복잡한 문제입니다.&lt;/p>
&lt;p>단순히 팀원중 한명이 MSA를 해봤다 거나 할줄 안다 정도로는 부족하다고 생각합니다. &lt;strong>팀 전체가 MSA의 복잡성을 이해하고, 그에 맞는 개발 및 운영 문화를 갖추고 있어야 한다&lt;/strong>고 생각합니다.&lt;/p>
&lt;p>혹시 갖추어져 있지 않다면 충분한 학습과 준비 기간을 갖는 것이 중요하다고 생각합니다. MSA를 도입하는 과정에서 발생할 수 있는 문제들을 미리 예측하고 대비할 수 있어야 하기 때문이죠.&lt;/p>
&lt;p>팀원들끼리 캡스톤 프로젝트를 진행해본다거나, 사이드 프로젝트로 MSA를 경험해본다거나 하는 방법들이 있을 수 있겠죠.&lt;/p>
&lt;p>그리고 6편까지의 과정에서 언급했던 수많은 문제들과 이를 해결하기 위한 방법들중 어떤 것들을 선택할지 충분한 논의와 합의가 필요하다고 생각합니다.&lt;/p>
&lt;h3>욕심은 아닌지 돌아봐야 한다&lt;span class="hx:absolute hx:-mt-20" id="욕심은-아닌지-돌아봐야-한다">&lt;/span>
&lt;a href="#%ec%9a%95%ec%8b%ac%ec%9d%80-%ec%95%84%eb%8b%8c%ec%a7%80-%eb%8f%8c%ec%95%84%eb%b4%90%ec%95%bc-%ed%95%9c%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>개발자들은 성장에 대한 욕구가 강한 편이라고 생각합니다. 새로운 기술을 배우고, 새로운 도전을 해보고 싶어하죠. MSA도 기술적인 챌린지를 할 수 있고 성장 욕구를 충족해줄거라 기대하게 되는 매력적인 주제 중 하나인 것 같습니다.&lt;/p>
&lt;p>내가 트렌드에 뒤쳐지진 않았는지, 내 커리어에 도움이 될지, 기술적인 도전에 대한 갈망 등등.&lt;/p>
&lt;p>이런 욕구들이 내 안에서 MSA 도입에 대한 고려를 긍정적인 방향에서만 바라보게 하는 순간들이 있는 것 같습니다. 저 또한 그랬구요.&lt;/p>
&lt;p>물론 개발자가 성장에 대한 욕구를 가지고 새로운 기술을 학습하고 싶어하는 그리고 도전하고 싶어하는 마음은 아주 긍정적인 부분이라고 생각합니다.&lt;/p>
&lt;p>다만 이 마음이 욕심이 되어 &lt;strong>정말 필요한지 여부를 객관적인 사실 기반 데이터와 근거로 판단하지 못하게&lt;/strong> 판단력을 흐리게 하는 역할을 할 수 있다는 거죠.&lt;/p>
&lt;p>&amp;ldquo;에이 그래도 그건 너무 갔다. 연구를 해본것도 아니면서 어떻게 알아?&amp;rdquo; 라고 하신다면 &amp;ldquo;제가 그랬습니다&amp;rdquo;&lt;/p>
&lt;p>저는 모순적인 사람인지라 마음 한켠에선 &amp;ldquo;MSA 그래도 해보고 싶다&amp;hellip;&amp;rdquo; 라는 마음과 &amp;ldquo;정말 필요한가?&amp;rdquo; 라는 마음이 계속해서 싸우고 있었습니다. &amp;ldquo;우리 서비스에는 MSA가 굳이 필요하지않다&amp;rdquo; 라는 결론을 스스로 내렸음에도 불구하고 말이죠.&lt;/p>
&lt;p>이런 욕심은 결국 팀원들과 회사에 부담으로 돌아올 수 밖에 없습니다. 그렇기 때문에 &lt;strong>욕심이 생긴다면 사이드 프로젝트로 푸는게 낫다&lt;/strong>고 생각합니다. (저 또한 운영 환경에서 경험하기 전에는 사이드 프로젝트로 구성해서 욕심을 채웠습니다)&lt;/p>
&lt;p>물론 실제 운영환경에서만 겪을 수 있는 문제들도 많기 때문에 사이드 프로젝트로는 한계가 있을 수 있습니다. 그렇지만 팀 전체에 해를 끼칠 수 있는 결정을 욕심으로 밀어붙이는 것보다는 낫다고 생각합니다.&lt;/p>
&lt;p>그렇다면 이렇게 말하실 수 있습니다. &amp;ldquo;우리 서비스에 필요 없다면서 MSA는 어떻게 경험하셨나요?&amp;rdquo;.&lt;/p>
&lt;p>음 어떻게 보면 굉장히 운이 좋다고도 할 수 있을 것 같습니다. 이직한 회사가 이미 MSA 도입을 결정하고 진행중이었던 케이스였거든요. 그래서 저는 MSA 도입에 조심스러운 입장이면서도 운좋게도 MSA를 경험할 수 있었습니다.&lt;/p>
&lt;p>다만 겪으면서 &lt;strong>“명확한 필요에 의해 선택된 것이 아니라면, MSA는 불필요할 가능성이 높다”&lt;/strong> 라는 생각이 더욱 확고해졌습니다.&lt;/p>
&lt;p>그렇다면 MSA가 아닌 뭘 선택해야 할까요?&lt;/p>
&lt;h2>모놀리식은 정말 나쁜가?&lt;span class="hx:absolute hx:-mt-20" id="모놀리식은-정말-나쁜가">&lt;/span>
&lt;a href="#%eb%aa%a8%eb%86%80%eb%a6%ac%ec%8b%9d%ec%9d%80-%ec%a0%95%eb%a7%90-%eb%82%98%ec%81%9c%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>여기서 처음으로 돌아가 보겠습니다.&lt;/p>
&lt;p>MSA는 모놀리식의 한계점들을 극복하기 위해 등장한 아키텍처라고 &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-1-introduction/">1편&lt;/a>에서 말씀드렸습니다. 그렇다면 모놀리식은 정말 나쁜 아키텍처일까요?&lt;/p>
&lt;p>저는 그렇지 않다고 생각합니다.&lt;/p>
&lt;h3>모놀리식에 대한 오해&lt;span class="hx:absolute hx:-mt-20" id="모놀리식에-대한-오해">&lt;/span>
&lt;a href="#%eb%aa%a8%eb%86%80%eb%a6%ac%ec%8b%9d%ec%97%90-%eb%8c%80%ed%95%9c-%ec%98%a4%ed%95%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>모놀리식 하면 어떤 이미지가 떠오르시나요? &amp;ldquo;레거시&amp;rdquo;, &amp;ldquo;기술 부채&amp;rdquo;, &amp;ldquo;확장 불가&amp;rdquo;, &amp;ldquo;구식&amp;rdquo;&amp;hellip; 이런 부정적인 단어들이 연상되시지 않나요?&lt;/p>
&lt;p>저도 한때 그랬습니다. 그러면 안되지만 MSA가 모던하고 트렌디한 아키텍처이고, 모놀리식은 과거의 유산 정도로 생각했던 순간들이 있었습니다. MSA를 직접 경험하고 나니 생각이 많이 바뀌었지만 말입니다.&lt;/p>
&lt;p>제가 느낀건 &lt;strong>모놀리식이 나쁜 게 아니라, 잘못 설계된 모놀리식이 나쁜 거라는 것 입니다.&lt;/strong>&lt;/p>
&lt;p>모놀리식이라고 해서 반드시 스파게티 코드가 되는 건 아니죠. 모듈 간 경계가 명확하고, 의존성이 잘 관리되고, 테스트가 잘 작성된 모놀리식은 충분히 유지보수하기 좋은 시스템이 될 수 있다고 생각합니다.&lt;/p>
&lt;p>오히려 문제는 &lt;strong>&amp;ldquo;모놀리식이어서 문제&amp;rdquo;&lt;/strong> 가 아니라 &lt;strong>&amp;ldquo;설계를 안 해서 문제&amp;rdquo;&lt;/strong> 인 경우가 많았습니다. 모듈 간 경계 없이 아무 데서나 아무 클래스를 참조하고, 순환 의존성이 생기고, 변경의 영향 범위를 예측할 수 없는 상태가 되는 거죠. 그래서 아무 관계없는 것 같던 기능에서 버그가 발생하는 상황도 생기고요.&lt;/p>
&lt;p>이건 모놀리식의 문제가 아니라 설계의 문제라고 생각합니다. 이런 문제는 MSA에서도 똑같이 발생할 수 있습니다. 저희가 &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-2-boundary/">2편&lt;/a>에서 다뤘던 Distributed Monolith가 바로 그 예시죠. 서비스는 나눴는데 서비스 간 경계가 잘못 설정되어 결국 &amp;ldquo;나눠진 스파게티&amp;quot;가 되는 상황 말입니다.&lt;/p>
&lt;p>결국 &lt;strong>아키텍처가 문제를 해결해주는 게 아니라, 좋은 설계가 문제를 해결해주는 것&lt;/strong>이라고 생각합니다.&lt;/p>
&lt;h3>잘 설계된 모놀리식의 힘&lt;span class="hx:absolute hx:-mt-20" id="잘-설계된-모놀리식의-힘">&lt;/span>
&lt;a href="#%ec%9e%98-%ec%84%a4%ea%b3%84%eb%90%9c-%eb%aa%a8%eb%86%80%eb%a6%ac%ec%8b%9d%ec%9d%98-%ed%9e%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그렇다면 잘 설계된 모놀리식은 어떤 모습일까요?&lt;/p>
&lt;p>제가 생각하는 잘 설계된 모놀리식의 특징은 다음과 같습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>모듈 간 경계가 명확하다&lt;/strong>: 각 모듈이 자신의 책임을 명확히 가지고, 다른 모듈의 내부 구현에 의존하지 않습니다.&lt;/li>
&lt;li>&lt;strong>공개 인터페이스를 통해서만 통신한다&lt;/strong>: 모듈 간에는 정의된 API를 통해서만 소통하고, 내부 클래스를 직접 참조하지 않습니다.&lt;/li>
&lt;li>&lt;strong>변경의 영향 범위가 예측 가능하다&lt;/strong>: 특정 모듈을 수정해도 다른 모듈에 미치는 영향을 쉽게 파악할 수 있습니다.&lt;/li>
&lt;li>&lt;strong>테스트가 용이하다&lt;/strong>: 모듈 단위로 테스트할 수 있고, 다른 모듈을 Mock으로 대체할 수 있습니다.&lt;/li>
&lt;/ol>
&lt;p>이런 특징들을 보면, 사실 &lt;strong>좋은 코드의 원칙들과 다를 게 없는 것 같습니다.&lt;/strong> 단일 책임 원칙, 인터페이스 분리, 의존성 역전&amp;hellip; SOLID 원칙들도 결국 이런 방향성을 지향하고 있으니까요.&lt;/p>
&lt;p>이런 원칙들을 잘 지키면 모놀리식이든 MSA든 좋은 구조가 나올 수 있다고 생각합니다.&lt;/p>
&lt;p>그리고 잘 설계된 모놀리식은 &lt;strong>생각보다 많은 문제를 해결할 수 있다고 생각합니다.&lt;/strong> 모놀리식의 장점이였던 배포가 간단하고, 트랜잭션이 보장되며, 운영이 단순한 점들이 큰 강점이 될 수 있죠.&lt;/p>
&lt;p>물론 모놀리식의 한계도 분명히 존재합니다. &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-1-introduction/">1편&lt;/a>에서 이야기했듯이 스케일링의 어려움, 배포의 어려움, 기술 스택의 제약 등이 있죠. 하지만 제가 중요하게 생각하는건 이런 한계들이 &lt;strong>실제로 우리 회사와 팀에 문제가 되는지&lt;/strong>입니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;그저 미래에 그럴지도 모른다.&amp;rdquo;&lt;/strong> 라는 막연한 두려움 때문에 MSA를 선택하는 건 옳지 않다고 생각합니다.&lt;/p>
&lt;p>트래픽이 아직 많지 않은데 스케일링 걱정을 하는 게 의미가 있을까요? 팀이 5명인데 배포 충돌을 걱정해야 할까요? 대부분의 스타트업이나 초기 서비스에서는 이런 문제들을 겪을 가능성은 현저히 낮다고 생각합니다.&lt;/p>
&lt;h3>모듈러 모놀리식: 중간 지점&lt;span class="hx:absolute hx:-mt-20" id="모듈러-모놀리식-중간-지점">&lt;/span>
&lt;a href="#%eb%aa%a8%eb%93%88%eb%9f%ac-%eb%aa%a8%eb%86%80%eb%a6%ac%ec%8b%9d-%ec%a4%91%ea%b0%84-%ec%a7%80%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그리고 &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-1-introduction/">1편&lt;/a>에서 잠깐 언급했던 &lt;strong>모듈러 모놀리식(Modular Monolith)&lt;/strong> 에 대해 조금 더 이야기해보려 합니다.&lt;/p>
&lt;p>모듈러 모놀리식은 &lt;strong>모놀리식의 단순함을 유지하면서도, MSA로의 전환을 염두에 둔 구조&lt;/strong>입니다. 하나의 배포 단위이지만, 내부적으로는 명확한 모듈 경계를 가지는 거죠.&lt;/p>
&lt;p>저는 개인적으로 이 모듈러 모놀리식 접근 방식을 꽤 좋아합니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph ModularMonolith[&amp;#34;모듈러 모놀리식&amp;#34;]
direction TB
subgraph OrderModule[&amp;#34;주문 모듈&amp;#34;]
OA[&amp;#34;API&amp;#34;]
OD[&amp;#34;Domain&amp;#34;]
OR[&amp;#34;Repository&amp;#34;]
end
subgraph PaymentModule[&amp;#34;결제 모듈&amp;#34;]
PA[&amp;#34;API&amp;#34;]
PD[&amp;#34;Domain&amp;#34;]
PR[&amp;#34;Repository&amp;#34;]
end
subgraph UserModule[&amp;#34;회원 모듈&amp;#34;]
UA[&amp;#34;API&amp;#34;]
UD[&amp;#34;Domain&amp;#34;]
UR[&amp;#34;Repository&amp;#34;]
end
end
OrderModule -.-&amp;gt;|&amp;#34;공개 API만&amp;lt;br/&amp;gt;호출 가능&amp;#34;| PaymentModule
OrderModule -.-&amp;gt;|&amp;#34;공개 API만&amp;lt;br/&amp;gt;호출 가능&amp;#34;| UserModule
ModularMonolith --&amp;gt; DB[(Database)]
&lt;/pre>&lt;p>모듈러 모놀리식의 핵심은 &lt;strong>&amp;ldquo;지금은 모놀리식이지만, 나중에 필요하면 MSA로 전환할 수 있는 구조&amp;rdquo;&lt;/strong> 라는 점이지 않나 싶습니다. 모듈 간 통신을 인터페이스를 통해 하도록 강제하면, 나중에 해당 모듈을 별도 서비스로 분리할 때 인터페이스 구현체만 HTTP 클라이언트로 바꾸면 됩니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 모듈러 모놀리식에서의 호출&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">interface&lt;/span> &lt;span class="nc">PaymentService&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">PaymentResult&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">processPayment&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">PaymentRequest&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">request&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">// 지금은 같은 프로세스 내에서 직접 호출&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Service&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">PaymentServiceImpl&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">implements&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">PaymentService&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">PaymentResult&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">processPayment&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">PaymentRequest&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">request&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 직접 처리&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">// 나중에 MSA로 전환하면 HTTP 클라이언트로 교체&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Service&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">PaymentServiceClient&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">implements&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">PaymentService&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">PaymentResult&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">processPayment&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">PaymentRequest&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">request&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">restTemplate&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">post&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;/payments&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">request&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">PaymentResult&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">class&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이렇게 하면 &lt;strong>점진적인 전환&lt;/strong>이 가능해질 가능성이 높습니다. 모든 걸 한 번에 MSA로 바꾸는 게 아니라, 필요한 모듈부터 하나씩 분리해나갈 수 있는 거죠. 이렇게 되면 &lt;strong>지금 당장 MSA의 복잡성을 감수할 필요 없이&lt;/strong>, 나중에 필요할 때 전환할 수 있는 옵션을 열어두니까요.&lt;/p>
&lt;p>물론 모듈러 모놀리식도 쉬운 건 아닌 것 같습니다. 모듈 간 경계를 나눠야하고 컨벤션으로 지정하고, 또 강제하려면 빌드 시스템에서 의존성을 제한하거나, 아키텍처 테스트 도구(ArchUnit 같은)를 활용해야 합니다. 그리고 팀원 모두가 이 규칙을 이해하고 지켜야 하죠.&lt;/p>
&lt;p>그래도 저는 &lt;strong>&amp;ldquo;처음부터 MSA&amp;rdquo;&lt;/strong> 보다는 &lt;strong>&amp;ldquo;모듈러 모놀리식에서 시작해서 필요할 때 MSA로&amp;rdquo;&lt;/strong> 가 좀 더 현명한 선택이지 않나 싶습니다.&lt;/p>
&lt;h2>그렇다면 언제 MSA인가?&lt;span class="hx:absolute hx:-mt-20" id="그렇다면-언제-msa인가">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%a0%87%eb%8b%a4%eb%a9%b4-%ec%96%b8%ec%a0%9c-msa%ec%9d%b8%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>그렇다면 MSA를 하지 말라는게 제 의견이냐? 그건 아닙니다.&lt;/p>
&lt;p>&amp;ldquo;어째서 MSA가 아니면 안되는가&amp;quot;를 답할 수 있는 순간들이 분명히 존재한다고 생각합니다.&lt;/p>
&lt;p>그렇다면 언제가 제가 생각하는 그 순간일까요?&lt;/p>
&lt;h3>MSA를 고려해야 하는 신호&lt;span class="hx:absolute hx:-mt-20" id="msa를-고려해야-하는-신호">&lt;/span>
&lt;a href="#msa%eb%a5%bc-%ea%b3%a0%eb%a0%a4%ed%95%b4%ec%95%bc-%ed%95%98%eb%8a%94-%ec%8b%a0%ed%98%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;h4>스케일 업의 한계에 도달&lt;span class="hx:absolute hx:-mt-20" id="스케일-업의-한계에-도달">&lt;/span>
&lt;a href="#%ec%8a%a4%ec%bc%80%ec%9d%bc-%ec%97%85%ec%9d%98-%ed%95%9c%ea%b3%84%ec%97%90-%eb%8f%84%eb%8b%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>서비스가 성장하면서 인스턴스 혹은 DB의 한계에 도달하는 순간이 올 수 있습니다. CPU, 메모리, 네트워크 I/O 등 자원 사용량이 너무 높아져서 더 이상 성능 향상이 어려운 경우가 있죠.&lt;/p>
&lt;p>물론 이 경우에도 수평적 확장(스케일 아웃)을 먼저 고려해볼 수 있습니다. 로드 밸런서를 도입하고, 여러 인스턴스를 띄우거나 Replication, Sharding과 같이 부하를 분산시키는 방법이죠.&lt;/p>
&lt;p>하지만 특정 기능이나 모듈이 지나치게 많은 자원을 소비하는 경우, 해당 부분만 별도의 서비스로 분리하고 DB도 독립시키는 게 효율적일 수 있습니다.&lt;/p>
&lt;p>이런 경우 특정 기능을 분리해야하는 상황이라고 생각합니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;단일 서버나 데이터베이스의 한계에 도달할 정도로&amp;rdquo;&lt;/strong> 서비스가 성장했을 때 말이죠.&lt;/p>
&lt;h4>장애 격리가 중요하다&lt;span class="hx:absolute hx:-mt-20" id="장애-격리가-중요하다">&lt;/span>
&lt;a href="#%ec%9e%a5%ec%95%a0-%ea%b2%a9%eb%a6%ac%ea%b0%80-%ec%a4%91%ec%9a%94%ed%95%98%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>위와 이어지는 문제입니다만 특정 기능에만 지나치게 많은 자원을 소비하며 전체 서비스에 영향을 주기 시작하는 순간이 올 수 있습니다.&lt;/p>
&lt;p>특정 기능에 트래픽이 몰려서 서비스 전체가 죽는 경우가 발생한다거나 말입니다.&lt;/p>
&lt;p>이런 경우 전체 서비스에 영향을 주지 않도록 조치를 취해야 하는데 이런 경우에 가능한 빨리 특정 기능만 별도의 서비스로 분리하는 것을 고려해야한다고 생각합니다.&lt;/p>
&lt;p>전체 서비스로의 장애 전파가 사용자 경험에 절대 좋을리는 없으니까요.&lt;/p>
&lt;h4>조직이 크다&lt;span class="hx:absolute hx:-mt-20" id="조직이-크다">&lt;/span>
&lt;a href="#%ec%a1%b0%ec%a7%81%ec%9d%b4-%ed%81%ac%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>팀 규모가 거대하면 모놀리식의 한계가 빨리 찾아올 수 있다고 생각합니다.&lt;/p>
&lt;p>개발팀 인원만 300~400명 되는데 한 코드베이스에서 모두가 협업하라고 하는건 오히려 팀 생산성에 해가 될 수 있다고 생각합니다. 그 시점이 &lt;strong>하나의 코드베이스에서 협업하기 어려워지는 시점&lt;/strong>인거죠.&lt;/p>
&lt;p>매일 Git 충돌이 발생하고, 배포 일정을 조율하느라 시간을 많이 쓰고, 다른 팀의 변경 사항 때문에 내 기능이 배포가 밀리는 상황이 발생 할 수 있으니까요.&lt;/p>
&lt;p>이런 경우에는 팀의 역할별로 기능을 분리하는 것이 충분히 고려되어야 한다고 생각합니다.&lt;/p>
&lt;p>다만 &lt;strong>팀이 크다고 무조건 필요하다고 생각하는 건 아닙니다.&lt;/strong> 제가 중요하게 생각하는 건 &lt;strong>협업의 병목이 실제로 발생하고 있는가&lt;/strong>입니다.&lt;/p>
&lt;h4>이렇게 하다보면 MSA다&lt;span class="hx:absolute hx:-mt-20" id="이렇게-하다보면-msa다">&lt;/span>
&lt;a href="#%ec%9d%b4%eb%a0%87%ea%b2%8c-%ed%95%98%eb%8b%a4%eb%b3%b4%eb%a9%b4-msa%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>눈치 채신분들도 있겠지만 제가 위에 &amp;ldquo;MSA를 고려해야한다&amp;quot;고 언급하지 않았습니다. &lt;strong>&amp;ldquo;특정 기능을 분리해야하는 상황&amp;rdquo;&lt;/strong> 이라고 표현했습니다.&lt;/p>
&lt;p>위 문제들은 공통적으로 &lt;strong>필요에 의해 기능을 분리해야 하는 상황&lt;/strong>들입니다. 원해서 하는 게 아닌 필요해서 자연스레 특정 기능을 분리해야 하는 상황들인거죠.&lt;/p>
&lt;p>저런 경우에 하나씩 분리해 내다보면 결국 종착지가 MSA가 될 수도 있다고 생각합니다.&lt;/p>
&lt;p>&lt;strong>MSA를 바라보고 달리는게 아니라 달리다 보니 종착지가 MSA가 된다는 거죠.&lt;/strong> 이런 상황들이 제가 생각하는 MSA가 필요한 순간들입니다.&lt;/p>
&lt;p>물론 &amp;ldquo;달리다보니 MSA&amp;quot;는 약간 비약이 있을 수 있습니다. 특정 기능을 몇개 분리하다보면 &amp;ldquo;MSA 해야겠다&amp;quot;라고 필요에 의해서 생각하실 테니까요.&lt;/p>
&lt;h3>MSA를 피해야 하는 신호&lt;span class="hx:absolute hx:-mt-20" id="msa를-피해야-하는-신호">&lt;/span>
&lt;a href="#msa%eb%a5%bc-%ed%94%bc%ed%95%b4%ec%95%bc-%ed%95%98%eb%8a%94-%ec%8b%a0%ed%98%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>반대로, MSA를 피해야 할 신호들도 있다고 생각합니다.&lt;/p>
&lt;h4>팀이 작다&lt;span class="hx:absolute hx:-mt-20" id="팀이-작다">&lt;/span>
&lt;a href="#%ed%8c%80%ec%9d%b4-%ec%9e%91%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>팀이 5명 이하인 상황에서 MSA를 도입하는 건 대부분의 경우 &lt;strong>오버엔지니어링&lt;/strong>이라고 생각합니다.&lt;/p>
&lt;p>MSA의 운영 복잡성을 감당하려면 충분한 인력이 필요합니다. 인프라 관리, 모니터링, 장애 대응, 서비스 간 통신 관리&amp;hellip; 이 모든 걸 소수의 인원이 감당하면서 동시에 기능 개발까지 하기는 정말 어렵다고 생각합니다.&lt;/p>
&lt;p>MSA의 장점이 분명히 존재하지만, 저는 작은 팀에서는 그 장점들이 복잡성을 감당하는 비용보다 크지 않다고 봅니다.&lt;/p>
&lt;p>저희 팀이 이 경우에 속합니다. 지금 팀은 총 4명이고, 그 중 백엔드 개발자는 2명 뿐입니다. 저는 DevOps까지 병행하며 K8s를 포함한 인프라도 관리하고 있는데 이런 상황에서 MSA를 운영하고 있으니 정말 쉽지 않습니다.&lt;/p>
&lt;p>물론 쉽지 않지만 못할건 아닙니다. 팀이 작다는건 그만큼 서비스가 크지 않다는 뜻이기도 하기때문에 어떻게 어떻게 다 잘 굴러는 가더라구요.&lt;/p>
&lt;p>결론은 충분한 인력이 필요하다고 생각합니다. 최소한 &lt;strong>&amp;ldquo;여러 팀으로 나뉘어 독립적으로 개발 및 운영이 가능한 규모&amp;rdquo;&lt;/strong> 가 되어야 한다고 생각합니다.&lt;/p>
&lt;h4>도메인을 충분히 이해하지 못했다&lt;span class="hx:absolute hx:-mt-20" id="도메인을-충분히-이해하지-못했다">&lt;/span>
&lt;a href="#%eb%8f%84%eb%a9%94%ec%9d%b8%ec%9d%84-%ec%b6%a9%eb%b6%84%ed%9e%88-%ec%9d%b4%ed%95%b4%ed%95%98%ec%a7%80-%eb%aa%bb%ed%96%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>또 서비스 경계를 제대로 설정하려면 도메인에 대한 깊은 이해가 필요합니다. &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-2-boundary/">2편&lt;/a>에서 이야기했듯이, 잘못 나눈 서비스 경계는 나중에 수정하기가 정말 어렵습니다.&lt;/p>
&lt;p>프로젝트 초기에는 도메인 이해가 부족한 경우가 많습니다. 이 상태에서 MSA를 시작하면 높은 확률로 경계를 잘못 설정하게 될 가능성이 높다고 생각합니다.&lt;/p>
&lt;p>&lt;strong>모놀리식으로 시작해서 도메인 이해가 깊어진 후에 필요한 부분만 분리&lt;/strong>하는 게 더 안전한 접근이라고 생각합니다.&lt;/p>
&lt;h4>빠른 개발이 최우선이다&lt;span class="hx:absolute hx:-mt-20" id="빠른-개발이-최우선이다">&lt;/span>
&lt;a href="#%eb%b9%a0%eb%a5%b8-%ea%b0%9c%eb%b0%9c%ec%9d%b4-%ec%b5%9c%ec%9a%b0%ec%84%a0%ec%9d%b4%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>스타트업 초기나 MVP 단계에서는 &lt;strong>빠른 출시와 피드백&lt;/strong>이 가장 중요하다고 생각합니다. 스타트업에서 애자일 애자일 하는 이유가 있죠.&lt;/p>
&lt;p>MSA의 복잡성은 개발 속도를 늦추기 마련입니다. 그렇기 때문에 속도가 생명인 환경에서는 모놀리식으로 빠르게 시장에 진입하고, 서비스가 성공해서 필요해졌을때 MSA를 고려해도 늦지 않다고 생각합니다.&lt;/p>
&lt;h4>인프라 역량이 부족하다&lt;span class="hx:absolute hx:-mt-20" id="인프라-역량이-부족하다">&lt;/span>
&lt;a href="#%ec%9d%b8%ed%94%84%eb%9d%bc-%ec%97%ad%eb%9f%89%ec%9d%b4-%eb%b6%80%ec%a1%b1%ed%95%98%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>MSA를 제대로 운영하려면 컨테이너 오케스트레이션, 분산 시스템 모니터링, CI/CD 파이프라인 등 인프라 역량이 필요하다고 생각합니다.&lt;/p>
&lt;p>MSA의 목적중 하나인 고가용성을 확보하기 위해선 자동화된 배포와 모니터링 시스템이 필수적이라고 보기 때문입니다.&lt;/p>
&lt;p>만약 이런 역량 없이 MSA를 도입하면 &lt;strong>&amp;ldquo;서비스가 많아졌는데 관리는 못 하는&amp;rdquo;&lt;/strong> 상황이 될 수 있지 않나 싶습니다. APM 없이 MSA 환경에서 로그를 확인해야했던 제 경험처럼요. 정말 쉽지 않았습니다.&lt;/p>
&lt;h2>정리&lt;span class="hx:absolute hx:-mt-20" id="정리">&lt;/span>
&lt;a href="#%ec%a0%95%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이번 편에서 하고 싶었던 이야기를 정리하면 다음과 같습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>MSA는 복잡성을 끌어들이는 선택입니다.&lt;/strong> 그 복잡성을 감당할 만큼의 명확한 이유가 있어야 한다고 생각합니다.&lt;/li>
&lt;li>&lt;strong>비용을 절대 무시할 수 없습니다.&lt;/strong> 인프라 비용, 운영 비용, 개발자의 인지 부하&amp;hellip; 이 모든 게 증가합니다.&lt;/li>
&lt;li>&lt;strong>모놀리식이 나쁜 게 아닙니다.&lt;/strong> 잘 설계된 모놀리식은 충분히 훌륭한 선택이 될 수 있다고 생각합니다.&lt;/li>
&lt;li>&lt;strong>모듈러 모놀리식이라는 중간 지점도 있습니다.&lt;/strong> 지금은 모놀리식의 이점을 누리면서, 나중에 필요할 때 MSA로 전환할 수 있는 구조지 않나 싶습니다.&lt;/li>
&lt;li>&lt;strong>MSA가 필요한 시점은 생각보다 늦게 옵니다.&lt;/strong> 대부분의 서비스는 모놀리식으로도 충분히 잘 운영될 수 있다고 생각합니다.&lt;/li>
&lt;/ol>
&lt;p>결국 제가 전달드리고 싶은 핵심 메시지는 이겁니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;우리 서비스에 MSA가 정말 필요한가?&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>이 질문에 &lt;strong>&amp;ldquo;팀이 커서&amp;rdquo;&lt;/strong>, &lt;strong>&amp;ldquo;트래픽이 많아서&amp;rdquo;&lt;/strong>, &lt;strong>&amp;ldquo;장애 격리가 필요해서&amp;rdquo;&lt;/strong> 같은 구체적이고 데이터에 기반한 답변을 할 수 있다면 MSA를 고려해볼 만하다고 생각합니다.&lt;/p>
&lt;p>하지만 저와 한 팀에서 &lt;strong>&amp;ldquo;요즘 트렌드니까&amp;rdquo;&lt;/strong>, &lt;strong>&amp;ldquo;나중에 필요할 것 같아서&amp;rdquo;&lt;/strong>, &lt;strong>&amp;ldquo;MSA가 더 좋아 보여서&amp;rdquo;&lt;/strong> 같은 막연한 이유들로 MSA 도입 논의 회의를 개최하셨다면 아마 저는 &amp;ldquo;도입 반대&amp;quot;의 입장에서 협의를 진행하게 될 것 같습니다.&lt;/p>
&lt;h2>시리즈를 마치며&lt;span class="hx:absolute hx:-mt-20" id="시리즈를-마치며">&lt;/span>
&lt;a href="#%ec%8b%9c%eb%a6%ac%ec%a6%88%eb%a5%bc-%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>7편에 걸쳐 MSA에 대한 여러 문제들과 고민들을 풀어봤습니다.&lt;/p>
&lt;p>1편에서 MSA가 무엇인지, 왜 등장했는지부터 시작해서, 서비스를 어떻게 나눌지, 어떻게 통신할지, 장애에 어떻게 대응할지, 데이터를 어떻게 분리하고 정합성을 맞출지까지요.&lt;/p>
&lt;p>제가 MSA를 경험하면서 했던 고민들과 겪었던 문제들 그리고 겪을 수 있는 문제들까지 제 머리에서부터 정리하고 읽으시는 분 또한 머리속에 그려지도록 노력했습니다.&lt;/p>
&lt;p>글에 있는 문제들을 함께 맞이해가는 과정들을 돌아보면 정말 쉽지 않은 여정이었습니다. 하나 문제를 해결하면 또 다른 문제가 2개 튀어나오고, 그 문제를 해결하면 또 다른 복잡성이 따라오고&amp;hellip; MSA는 &lt;strong>&amp;ldquo;문제 해결의 끝없는 연속&amp;rdquo;&lt;/strong> 이라는 생각이 들 정도였습니다.&lt;/p>
&lt;p>그래서 저는 마지막 편에서 &lt;strong>&amp;ldquo;정말 MSA가 필요한가?&amp;rdquo;&lt;/strong> 라는 질문을 던지고 싶었습니다. MSA의 여러 패턴들과 해결책들을 알아가는 것도 중요하지만, 애초에 그런 복잡성을 감당해야 하는 상황인지를 먼저 판단하는 게 더 중요하다고 생각하기 때문입니다.&lt;/p>
&lt;p>이 시리즈를 읽으시면서 &lt;strong>&amp;ldquo;MSA 생각보다 별거 아니네&amp;rdquo;&lt;/strong> 보다는 &lt;strong>&amp;ldquo;MSA 생각보다 쉽지 않네&amp;rdquo;&lt;/strong> 라는 느낌을 받으셨다면, 저는 어느 정도 성공했다고 생각합니다. 그 &amp;ldquo;어려움&amp;quot;과 &amp;ldquo;문제&amp;quot;들을 인지하는 게 올바른 판단의 시작이라고 믿으니까요.&lt;/p>
&lt;p>물론 MSA가 무조건 피해야 할 선택이라고 생각하는 건 아닙니다. 조직이 크고, 도메인이 복잡하고, 트래픽이 많고, 독립적인 배포와 스케일링이 필요한 상황이라면 MSA는 분명 너무나 효과적인 선택이 될 수 있다고 생각합니다. 넷플릭스, 아마존, 쿠팡, 배민 같은 회사들이 MSA를 선택한 데는 그만한 이유가 있으니까요.&lt;/p>
&lt;p>다만 저는 &lt;strong>&amp;ldquo;필요에 의한 선택&amp;rdquo;&lt;/strong> 이어야 한다고 생각합니다. 트렌드나 막연한 기대, 성장욕구가 아니라, 실제로 겪고 있는 문제를 해결하기 위한 &lt;strong>&amp;ldquo;생존을 위한 선택&amp;rdquo;&lt;/strong> 이어야 한다는 거죠.&lt;/p>
&lt;p>&lt;strong>기술 선택은 언제나 트레이드오프의 연속입니다.&lt;/strong> MSA를 선택하면 독립성과 확장성을 얻지만, 복잡성과 운영 부담을 감수해야 합니다. 모놀리식을 선택하면 단순함을 얻지만, 규모가 커지면 한계에 부딪힐 수 있습니다.&lt;/p>
&lt;p>&lt;strong>정답은 없다고 생각합니다. 우리 서비스, 우리 팀, 우리 상황에 맞는 선택들이 있다고 믿을 뿐입니다.&lt;/strong>&lt;/p>
&lt;p>이 시리즈가 그 선택을 하는 데 조금이나마 도움이 되었기를 바랍니다.&lt;/p>
&lt;p>긴 글 읽어주셔서 감사합니다.&lt;/p>
&lt;hr>
&lt;h2>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>관련 경험 글&lt;span class="hx:absolute hx:-mt-20" id="관련-경험-글">&lt;/span>
&lt;a href="#%ea%b4%80%eb%a0%a8-%ea%b2%bd%ed%97%98-%ea%b8%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/architecture/msa-to-multi-module/">16개 레포지토리를 하나로 - MSA 멀티모듈 전환기&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/architecture/is-gradual-msa-transition-an-illusion/">점진적 MSA 전환은 환상일까?&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/infrastructure/docker-compose-to-k8s/">Docker-compose에서 Kubernetes로&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>참고 문헌&lt;span class="hx:absolute hx:-mt-20" id="참고-문헌">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%eb%ac%b8%ed%97%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>Martin Fowler - &lt;a href="https://martinfowler.com/articles/microservices.html"target="_blank" rel="noopener">Microservices&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>Martin Fowler - &lt;a href="https://martinfowler.com/bliki/MonolithFirst.html"target="_blank" rel="noopener">Monolith First&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>Sam Newman - &lt;em>Building Microservices&lt;/em> (O&amp;rsquo;Reilly, 2021)&lt;/li>
&lt;li>Chris Richardson - &lt;em>Microservices Patterns&lt;/em> (Manning, 2018)&lt;/li>
&lt;/ul>
&lt;h3>시리즈&lt;span class="hx:absolute hx:-mt-20" id="시리즈">&lt;/span>
&lt;a href="#%ec%8b%9c%eb%a6%ac%ec%a6%88" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>1편: &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-1-introduction/">[MSA에 관한 고찰 1/7편] MSA(Microservices Architecture)란 무엇인가?&lt;/a>&lt;/li>
&lt;li>2편: &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-2-boundary/">[MSA에 관한 고찰 2/7편] MSA에서 서비스는 어떻게 나눌 것인가&lt;/a>&lt;/li>
&lt;li>3편: &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-3-communication/">[MSA에 관한 고찰 3/7편] MSA에서의 서비스간 통신&lt;/a>&lt;/li>
&lt;li>4편: &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-4-resilience/">[MSA에 관한 고찰 4/7편] 장애는 어떻게 전파되고, 우리는 어디서 끊어야 하는가&lt;/a>&lt;/li>
&lt;li>5편: &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-5-data-separation/">[MSA에 관한 고찰 5/7편] 데이터는 어떻게 분리해야 하는가&lt;/a>&lt;/li>
&lt;li>6편: &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-6-event-consistency/">[MSA에 관한 고찰 6/7편] 이벤트 기반 데이터 정합성&lt;/a>&lt;/li>
&lt;li>7편: &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-7-conclusion/">[MSA에 관한 고찰 7/7편] 우리는 정말 MSA가 필요한가?&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>[MSA에 관한 고찰 6/7편] MSA에서의 이벤트 기반 데이터 정합성 문제 및 해결방법</title><link>https://jeongil.dev/ko/blog/architecture/msa-series-6-event-consistency/</link><pubDate>Wed, 21 Jan 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/architecture/msa-series-6-event-consistency/</guid><description>
&lt;p>전편: &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-5-data-separation/">[MSA에 관한 고찰 5/7편] 데이터는 어떻게 분리해야 하는가&lt;/a>&lt;/p>
&lt;hr>
&lt;p>저번 편에서 저희는 MSA 환경에서 DB를 왜 분리해야 하는지, 그리고 분리했을 때 JOIN이 안 되는 문제를 어떻게 해결하는지 살펴봤습니다. API Composition과 데이터 복제라는 두 가지 방법이 있었죠.&lt;/p>
&lt;p>그런데 &lt;strong>&amp;ldquo;데이터 복제 방법을 선택했다&amp;rdquo;&lt;/strong> 고 해서 끝이 아닙니다. 여기서부터 또 다른 어려운 문제들이 시작됩니다.&lt;/p>
&lt;p>이번 편에서는 이벤트 기반 데이터 동기화에서 발생하는 정합성 문제들을 다뤄보겠습니다. DB 저장과 이벤트 발행을 어떻게 원자적으로 처리할지, 이벤트 순서가 꼬이면 어떻게 되는지, 메시지가 유실되거나 중복되면 어떻게 해야 하는지, 그리고 분산 트랜잭션의 대안인 Saga 패턴까지 이야기 해보겠습니다.&lt;/p>
&lt;h2>데이터 복제: 이벤트로 동기화하기&lt;span class="hx:absolute hx:-mt-20" id="데이터-복제-이벤트로-동기화하기">&lt;/span>
&lt;a href="#%eb%8d%b0%ec%9d%b4%ed%84%b0-%eb%b3%b5%ec%a0%9c-%ec%9d%b4%eb%b2%a4%ed%8a%b8%eb%a1%9c-%eb%8f%99%ea%b8%b0%ed%99%94%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>자 그렇다면 데이터 복제를 선택했다고 가정해보겠습니다. 이제 &lt;strong>어떻게 동기화할지&lt;/strong>를 생각해야할 차례입니다. 앞서 설명드렸듯이 보통은 이벤트 기반으로 동기화를 구현하게 됩니다.&lt;/p>
&lt;h3>DB 저장과 이벤트 발행, 둘 다 성공해야 한다&lt;span class="hx:absolute hx:-mt-20" id="db-저장과-이벤트-발행-둘-다-성공해야-한다">&lt;/span>
&lt;a href="#db-%ec%a0%80%ec%9e%a5%ea%b3%bc-%ec%9d%b4%eb%b2%a4%ed%8a%b8-%eb%b0%9c%ed%96%89-%eb%91%98-%eb%8b%a4-%ec%84%b1%ea%b3%b5%ed%95%b4%ec%95%bc-%ed%95%9c%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>가장 먼저 떠오르는 방법은 이거 아닐까요? &amp;ldquo;DB에 저장하고, 이벤트도 발행하면 끝&amp;rdquo;&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Transactional&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">updateUser&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">UserUpdateRequest&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">request&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 1. DB에 저장&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">userRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">save&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 2. 이벤트 발행&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">eventPublisher&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">publish&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">UserUpdatedEvent&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>직관적이고 간단해 보입니다. 하지만 여기에 &lt;strong>한가지 큰 문제&lt;/strong>가 숨어 있습니다. 어떤 문제일까요? 다음과 같은 상황을 상상해보겠습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant App as 애플리케이션
participant DB as 데이터베이스
participant MQ as 메시지 브로커
App-&amp;gt;&amp;gt;DB: 1. DB 저장 ✓
App-&amp;gt;&amp;gt;MQ: 2. 이벤트 발행 시도
MQ--xApp: 3. 네트워크 오류!
Note over App,MQ: 결과: DB는 변경됐는데&amp;lt;br/&amp;gt;이벤트는 안 나감 → 불일치!
&lt;/pre>&lt;p>DB 저장은 성공했는데 이벤트 발행이 실패하면 어떻게 될까요? 데이터는 변경됐는데 다른 서비스는 모르는 상태가 됩니다. 회원 이름이 바뀌었는데 주문 서비스의 복제 테이블에는 옛날 이름이 그대로 남아있는 거죠.&lt;/p>
&lt;p>반대 상황은 조금 더 심각합니다. 이벤트는 발행됐는데 DB 트랜잭션이 롤백되면? 다른 서비스는 &lt;strong>존재하지 않는 데이터&lt;/strong>를 참조하게 됩니다.&lt;/p>
&lt;p>&amp;ldquo;그럼 트랜잭션 안에서 같이 처리하면 되지 않나?&amp;ldquo;라고 생각하실 수도 있는데, DB 트랜잭션과 메시지 브로커 발행은 서로 다른 시스템이라 &lt;strong>하나의 트랜잭션으로 묶을 수가 없습니다.&lt;/strong> 이게 DB 저장과 이벤트 발행을 따로 처리할 때 발생하는 근본적인 문제입니다.&lt;/p>
&lt;h3>Transactional Outbox 패턴&lt;span class="hx:absolute hx:-mt-20" id="transactional-outbox-패턴">&lt;/span>
&lt;a href="#transactional-outbox-%ed%8c%a8%ed%84%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그렇다면 이 문제를 어떻게 해결할 수 있을까요? 검증된 방법이 있습니다. 바로 &lt;strong>Transactional Outbox 패턴&lt;/strong>입니다. 아이디어는 의외로 간단합니다. &lt;strong>이벤트를 DB에 먼저 저장하고, 나중에 발행한다.&lt;/strong>&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
subgraph Transaction[&amp;#34;하나의 트랜잭션&amp;#34;]
App[&amp;#34;애플리케이션&amp;#34;]
Users[(users 테이블)]
Outbox[(outbox 테이블)]
end
subgraph Async[&amp;#34;비동기 처리&amp;#34;]
Relay[&amp;#34;Message Relay&amp;#34;]
MQ[[&amp;#34;메시지 브로커&amp;#34;]]
end
App --&amp;gt;|&amp;#34;1. UPDATE&amp;#34;| Users
App --&amp;gt;|&amp;#34;2. INSERT&amp;#34;| Outbox
Relay --&amp;gt;|&amp;#34;3. 폴링&amp;#34;| Outbox
Relay --&amp;gt;|&amp;#34;4. 발행&amp;#34;| MQ
style Users fill:#4ecdc4
style Outbox fill:#4ecdc4
&lt;/pre>&lt;p>코드로 보면 이렇습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Transactional&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">updateUser&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">UserUpdateRequest&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">request&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 같은 DB 트랜잭션에서 둘 다 처리!&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">userRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">save&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">outboxRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">save&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">OutboxEvent&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;UserUpdated&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">toJson&lt;/span>&lt;span class="p">()));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>유저 정보를 저장하는 것과 함께, outbox라는 별도의 테이블에 이벤트 정보를 저장합니다. 이 두 작업은 같은 DB 트랜잭션 안에서 처리되기 때문에 &lt;strong>원자성이 보장&lt;/strong>됩니다.&lt;/p>
&lt;p>만약 해당 트랜잭션에서 실패하면 둘 다 롤백되고, 성공하면 둘 다 커밋됩니다. 그래서 DB 저장과 이벤트 발행이 불일치하는 상황이 발생하지 않습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;span class="lnt">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 별도 스케줄러가 주기적으로 실행&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Scheduled&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">fixedDelay&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">1000&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">publishPendingEvents&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">List&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">OutboxEvent&lt;/span>&lt;span class="o">&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">events&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">outboxRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">findPending&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">OutboxEvent&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">events&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">messagePublisher&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">publish&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">outboxRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">markAsPublished&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이벤트 발행은 별도의 스케줄러가 담당하게 합니다. outbox 테이블을 폴링해서 아직 발행 안 된 이벤트를 찾아서 발행하는 거죠. Flag를 사용해 발행 여부를 관리하면 발행이 실패해도 outbox에 남아있으니 다음 폴링 때 다시 시도할 수 있습니다.&lt;/p>
&lt;p>단점도 있습니다. 폴링 주기만큼 지연이 발생하고, outbox 테이블을 관리해야 한다는 점이죠. 특히 발행 완료된 레코드를 주기적으로 삭제하거나 아카이빙하는 작업도 필요합니다. 안 그러면 outbox 테이블이 계속 커지거든요. 하지만 이런 관리 부담을 감안하더라도 데이터 일관성을 보장한다는 점에서 개별적으로 DB 저장과 이벤트 발행을 처리하는 것보다 훨씬 낫다고 생각합니다.&lt;/p>
&lt;h3>Change Data Capture (CDC)&lt;span class="hx:absolute hx:-mt-20" id="change-data-capture-cdc">&lt;/span>
&lt;a href="#change-data-capture-cdc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>비슷하지만 다른 방법도 있습니다. 바로 &lt;strong>Change Data Capture (CDC)&lt;/strong> 를 사용하는 방법인데&lt;/p>
&lt;p>CDC란 데이터베이스의 변경 사항을 캡처해서 다른 시스템으로 전달하는 기술입니다. 보통 CDC는 DB의 변경 로그를 직접 읽어서 이벤트를 발행하거나 다른 시스템에 동기화하는 데 사용됩니다.&lt;/p>
&lt;p>이번 경우에는 이벤트를 발행하는 데 사용할 수도 있고, 직접 다른 서비스의 복제 테이블로 동기화하는 데 사용할 수도 있습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
MySQL[(MySQL)] --&amp;gt;|&amp;#34;WAL/Binlog&amp;#34;| CDC[&amp;#34;CDC 도구&amp;lt;br/&amp;gt;(Debezium, DMS 등)&amp;#34;]
CDC --&amp;gt;|&amp;#34;이벤트 발행&amp;#34;| Kafka[[&amp;#34;메시지 브로커&amp;#34;]]
CDC --&amp;gt;|&amp;#34;직접 동기화&amp;#34;| TargetDB[(복제 DB)]
style MySQL fill:#4ecdc4
style Kafka fill:#ff6b6b
style TargetDB fill:#ff6b6b
&lt;/pre>&lt;p>MySQL의 Binlog나 PostgreSQL의 WAL을 Debezium이나 AWS DMS 같은 도구가 읽어서, 변경 사항을 메시지 브로커로 발행하거나 다른 DB에 직접 동기화할 수 있습니다.&lt;/p>
&lt;p>이렇게 구성하게 되면 장점은 &lt;strong>애플리케이션 코드에서는 아무것도 안 해도 됩니다.&lt;/strong> 폴링 지연도 줄어들게 되고 모든 DB 변경을 캡처할 수 있습니다. &lt;strong>그냥 DB에 저장만 하면 알아서 변경이 전파되는 거죠.&lt;/strong>&lt;/p>
&lt;p>문제는 여기서 발생합니다. 이로 인해 인프라 복잡도가 증가한다는 점입니다. CDC를 운영해야 하고, DB마다 설정을 다르게 해줘야하며, 문제가 생기면 디버깅이 어렵습니다.&lt;/p>
&lt;p>그리고 더 골치 아픈 건 &lt;strong>원본 테이블 스키마가 변경될 때&lt;/strong> CDC 파이프라인도 함께 수정해야 한다는 점이라고 생각합니다. Debezium 같은 도구도 스키마 변경에 민감해서, DDL 변경 시 이벤트 포맷이 바뀌거나 파이프라인이 깨지는 경우가 있거든요. 관리 포인트가 하나 더 늘어나는 셈이죠.&lt;/p>
&lt;p>결국은 Transactional Outbox와 CDC 모두 트레이드 오프가 존재하니 팀의 상황에 맞게 선택하는 게 중요하다고 생각합니다.&lt;/p>
&lt;p>다만 제 경험상으로는 복잡도가 높을수록 운영하는 인력이 더 중요해지더라구요. 작은 팀에서는 Transactional Outbox가 더 적합할 수 있고, 인프라 운영팀이 잘 갖춰진 큰 조직에서는 CDC가 더 나을 수도 있다고 생각합니다.&lt;/p>
&lt;p>물론 작은 팀이 MSA를 선택한 것 자체가 모순일 수도 있지만요.&lt;/p>
&lt;h2>이벤트 기반 데이터 정합성 문제&lt;span class="hx:absolute hx:-mt-20" id="이벤트-기반-데이터-정합성-문제">&lt;/span>
&lt;a href="#%ec%9d%b4%eb%b2%a4%ed%8a%b8-%ea%b8%b0%eb%b0%98-%eb%8d%b0%ec%9d%b4%ed%84%b0-%ec%a0%95%ed%95%a9%ec%84%b1-%eb%ac%b8%ec%a0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이제 저희가 MSA 환경에서 서로 다른 서비스간의 데이터 조회 문제를 이벤트를 기반으로 동기화하기로 결정했고 이벤트 발행의 원자성 문제도 인지하고 있어 여러분과 제가 어떻게 어떻게 잘 협의하여 Outbox나 CDC로 이벤트 발행의 원자성은 보장했다고 가정하겠습니다.&lt;/p>
&lt;p>&amp;ldquo;그렇다면 아무 문제 없이 이제 개발만 하고 서비스를 운영하면 될까요?&amp;rdquo; &lt;strong>정말 아쉽게도 그렇지 않습니다.&lt;/strong> 다른 문제가 발생할 수 있거든요. 바로 또 다른 이벤트 기반 데이터 정합성 문제입니다.&lt;/p>
&lt;p>&lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-3-communication/">3편&lt;/a>에서 &amp;ldquo;비동기라고 문제가 없는 건 아니다&amp;quot;라고 했었는데요. 이벤트 기반 데이터 정합성 문제가 대표적으로 그렇습니다.&lt;/p>
&lt;p>어떤 문제가 발생할 수 있을까요?&lt;/p>
&lt;h3>순서 역전&lt;span class="hx:absolute hx:-mt-20" id="순서-역전">&lt;/span>
&lt;a href="#%ec%88%9c%ec%84%9c-%ec%97%ad%ec%a0%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Outbox나 CDC를 잘 구성하면 DB 커밋 순서대로 이벤트 &lt;strong>발행&lt;/strong> 순서를 보장할 수 있습니다. 하지만 여기서 끝이 아닙니다. &lt;strong>Consumer가 소비하는 순서까지 보장되는 건 아니거든요.&lt;/strong>&lt;/p>
&lt;p>여러 Consumer가 병렬로 이벤트를 처리하거나, 메시지 브로커에서 여러 파티션에 분산되거나, 네트워크 지연이나 재시도가 발생하면 &lt;strong>소비 순서&lt;/strong>가 뒤바뀔 수 있습니다.&lt;/p>
&lt;p>예를 들어보겠습니다. 결제 흐름에서 이런 이벤트들이 순서대로 발행됐다고 가정해보죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>발행 순서: 결제시도 → 결제승인 → 결제완료&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>그런데 Consumer들이 병렬로 처리하다 보니 이런 일이 생길 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>Consumer A: &amp;#34;결제완료&amp;#34; 이벤트를 먼저 처리
Consumer B: &amp;#34;결제시도&amp;#34; 이벤트를 나중에 처리
→ 결제완료 처리 시점에 결제시도 기록이 없어서 실패!&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>더 단순한 예시로, 같은 엔티티의 상태 변경도 마찬가지입니다.&lt;/p>
&lt;ol>
&lt;li>회원 이름을 &amp;ldquo;정정일&amp;quot;로 변경 (이벤트 A)&lt;/li>
&lt;li>회원 이름을 &amp;ldquo;정정이&amp;quot;로 변경 (이벤트 B)&lt;/li>
&lt;li>Consumer가 이벤트 B를 먼저 처리, 이벤트 A를 나중에 처리&lt;/li>
&lt;li>최종 결과: &amp;ldquo;정정일&amp;rdquo; (잘못됨!)&lt;/li>
&lt;/ol>
&lt;p>원래는 &amp;ldquo;정정이&amp;quot;가 최신인데, &lt;strong>소비 순서&lt;/strong>가 뒤바뀌어서 오래된 &amp;ldquo;정정일&amp;quot;이 최종 값이 되어버렸습니다. 발행은 순서대로 됐는데 소비에서 꼬인 거죠. 비동기 시스템에서는 의외로 자주 발생하는 문제입니다.&lt;/p>
&lt;h4>해결 방법 1: 파티션 키 활용&lt;span class="hx:absolute hx:-mt-20" id="해결-방법-1-파티션-키-활용">&lt;/span>
&lt;a href="#%ed%95%b4%ea%b2%b0-%eb%b0%a9%eb%b2%95-1-%ed%8c%8c%ed%8b%b0%ec%85%98-%ed%82%a4-%ed%99%9c%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>이런 이벤트 순서 문제를 해결하는 방법 중 하나는 메시지 브로커의 &lt;strong>파티션 키&lt;/strong>를 활용하는 것입니다.&lt;/p>
&lt;p>Kafka를 쓴다면, 같은 회원의 이벤트는 같은 파티션으로 보내서 순서를 보장할 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">kafkaTemplate&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">send&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;user-events&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getId&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">toString&lt;/span>&lt;span class="p">(),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="o">//&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getId&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="n">가&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">파티션&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">키&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="err">→&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">같은&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">유저의&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">이벤트는&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">같은&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">파티션&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>Kafka에서 파티션은 데이터를 분산 저장하는 단위입니다. 한 토픽에 여러 파티션이 있을 수 있는데, 각 파티션은 독립적으로 데이터를 저장하고 처리합니다.&lt;/p>
&lt;p>파티션 키는 &lt;strong>해시를 통해 어느 파티션에 들어갈지&lt;/strong>를 결정합니다. &lt;code>hash(userId) % 파티션수&lt;/code>로 계산되기 때문에 유저가 5만 명이어도 파티션이 10개라면 10개의 파티션에 분산되는 거죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>토픽 생성: user-events (파티션 10개)
userId=123 → hash(123) % 10 = 3번 파티션
userId=456 → hash(456) % 10 = 7번 파티션
userId=789 → hash(789) % 10 = 3번 파티션
userId=999 → hash(999) % 10 = 3번 파티션&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>핵심은 &lt;strong>같은 userId는 항상 같은 파티션에 들어간다&lt;/strong>는 점입니다. 그래서 같은 파티션 내에서는 순서가 보장되니까, 같은 회원에 대한 이벤트는 발생 순서대로 처리됩니다.&lt;/p>
&lt;h4>해결 방법 2: 버전 기반 낙관적 처리&lt;span class="hx:absolute hx:-mt-20" id="해결-방법-2-버전-기반-낙관적-처리">&lt;/span>
&lt;a href="#%ed%95%b4%ea%b2%b0-%eb%b0%a9%eb%b2%95-2-%eb%b2%84%ec%a0%84-%ea%b8%b0%eb%b0%98-%eb%82%99%ea%b4%80%ec%a0%81-%ec%b2%98%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>또 다른 방법으로는 낙관적 처리 방식을 사용하는 것입니다. JPA의 낙관적 락과 비슷한 개념인데요. 이벤트에 버전이나 타임스탬프를 포함시키고, 오래된 이벤트는 무시하는 방식이 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@EventListener&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">onUserUpdated&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">UserUpdatedEvent&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">UserReplica&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">existing&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">userReplicaRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">findById&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getUserId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 기존 데이터가 더 최신이면 무시&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">existing&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">!=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">&amp;amp;&amp;amp;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">existing&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getVersion&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">&amp;gt;=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getVersion&lt;/span>&lt;span class="p">())&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">log&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">info&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;오래된 이벤트 무시: {}&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">userReplicaRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">save&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">UserReplica&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">from&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 방식은 Kafka가 아닌 다른 메시지 브로커를 쓸 때도 적용할 수 있다는 장점이 있습니다.&lt;/p>
&lt;h3>이벤트에는 어떤 내용을 담아야 할까?&lt;span class="hx:absolute hx:-mt-20" id="이벤트에는-어떤-내용을-담아야-할까">&lt;/span>
&lt;a href="#%ec%9d%b4%eb%b2%a4%ed%8a%b8%ec%97%90%eb%8a%94-%ec%96%b4%eb%96%a4-%eb%82%b4%ec%9a%a9%ec%9d%84-%eb%8b%b4%ec%95%84%ec%95%bc-%ed%95%a0%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그런데 여기서 한 가지 의문이 생깁니다. 버전 기반으로 순서 역전을 해결하려면 &lt;strong>이벤트 내용에 버전 정보에 대한 데이터가 있어야&lt;/strong>합니다. 그렇다면 이벤트에는 어떤 내용까지 담아야 할까요?&lt;/p>
&lt;p>이벤트에 데이터를 담는 방식에는 크게 두 가지 방식이 있습니다.&lt;/p>
&lt;h4>Fat Event&lt;span class="hx:absolute hx:-mt-20" id="fat-event">&lt;/span>
&lt;a href="#fat-event" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>필요한 모든 정보를 이벤트에 담아 발행하는 방식을 Fat Event라고 합니다. 예를 들어 회원 정보 변경 이벤트라면, 변경된 회원의 이름, 이메일, 전화번호, 주소 등 모든 정보를 이벤트에 담는 거죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;span class="lnt">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;eventType&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;UserUpdated&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;userId&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;example&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;version&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">5&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;name&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;정정일&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;email&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;jeong@example.com&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;phone&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;010-1234-5678&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;address&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;서울시 강남구...&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>Consumer가 API 호출 없이 바로 처리할 수 있다는 장점이 있습니다. 버전 정보도 포함되어 있으니 순서 역전 문제도 해결할 수 있고요. 다만 이벤트 크기가 커지고, 스키마가 변경되면 모든 Consumer가 영향을 받는다는 단점이 있습니다.&lt;/p>
&lt;p>기존에 정합성 문제의 예시들은 이 Fat Event 방식을 쓴다는 가정하에 설명드린 것입니다.&lt;/p>
&lt;h4>Thin Event와 Zero Payload 패턴&lt;span class="hx:absolute hx:-mt-20" id="thin-event와-zero-payload-패턴">&lt;/span>
&lt;a href="#thin-event%ec%99%80-zero-payload-%ed%8c%a8%ed%84%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>반대로 이벤트에는 최소한의 정보만 담는 방식도 있습니다. ID와 이벤트 타입 정도만 담아서 발행하는 거죠. 이런 방식을 &lt;strong>Thin Event&lt;/strong>라고 합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;eventType&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;UserUpdated&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;userId&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="mi">123&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이렇게 되면 이벤트 크기가 작고 스키마 변경에 유연하게 됩니다. 그런데 여기서 의문이 생깁니다. &lt;strong>&amp;ldquo;이렇게 최소한의 정보만 받으면, Consumer는 나머지 데이터를 어떻게 가져오지?&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>답은 생각보다 간단합니다. 해당 원본 데이터를 가지고있는 서비스의 &lt;strong>API를 호출해서 가져오면 됩니다.&lt;/strong> 이렇게 Thin Event를 받고 API를 통해 데이터를 조회하는 방식을 &lt;strong>Zero Payload 패턴&lt;/strong>이라고 합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@EventListener&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">onUserUpdated&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">UserUpdatedEvent&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 이벤트에는 userId만 있음 → API로 최신 데이터 조회&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">UserDto&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">latest&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">userServiceClient&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getUser&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getUserId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">userReplicaRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">save&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">UserReplica&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">from&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">latest&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 방식의 장점은 &lt;strong>순서 역전 문제가 자연스럽게 해결됩니다.&lt;/strong>&lt;/p>
&lt;p>이벤트가 어떤 순서로 오든 상관 없어 어차피 마지막에 처리되는 이벤트가 API를 호출하면 그 시점의 &lt;strong>최신 데이터&lt;/strong>를 조회해오기 때문에 이벤트 A, B가 순서가 바뀌어서 B, A 순으로 처리되더라도, 결국 A를 처리할 때 API를 호출하면 최신 상태를 가져오게 됩니다. 이 덕분에 자연스레 이벤트 순서로 인한 데이터 정합성 문제가 해결되는 거죠.&lt;/p>
&lt;p>이게 바로 &lt;strong>최종적 일관성(Eventual Consistency)&lt;/strong> 의 핵심이라고 볼 수 있다고 생각합니다.&lt;/p>
&lt;p>저희에게 유명한 배달의 민족을 서비스하는 우아한 형제들 역시 Zero Payload 패턴을 활용하고 있다고 합니다. 저 역시 해당 영상을 보고 Zero Payload 방식을 접하게 됐습니다. 궁금하신 분들은 &lt;a href="https://youtu.be/BnS6343GTkY?si=C03UBL_Sxll71g3J"target="_blank" rel="noopener">[우아콘2020] 배달의민족 마이크로서비스 여행기&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>과 &lt;a href="https://techblog.woowahan.com/7835/"target="_blank" rel="noopener">회원시스템 이벤트기반 아키텍처 구축하기&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>을 참고해주세요.&lt;/p>
&lt;h3>최종적 일관성(Eventual Consistency)&lt;span class="hx:absolute hx:-mt-20" id="최종적-일관성eventual-consistency">&lt;/span>
&lt;a href="#%ec%b5%9c%ec%a2%85%ec%a0%81-%ec%9d%bc%ea%b4%80%ec%84%b1eventual-consistency" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그렇다면 최종적 일관성은 뭘까요?&lt;/p>
&lt;p>최종적 일관성이란 말 그대로 &amp;ldquo;결국에는 일관성이 맞아진다&amp;quot;는 뜻입니다. MSA에서 정말 중요한 개념이라 조금 더 자세히 다뤄보겠습니다.&lt;/p>
&lt;h4>Strong Consistency vs Eventual Consistency&lt;span class="hx:absolute hx:-mt-20" id="strong-consistency-vs-eventual-consistency">&lt;/span>
&lt;a href="#strong-consistency-vs-eventual-consistency" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>전통적인 단일 DB 시스템에서는 보통 &lt;strong>Strong Consistency(강한 일관성)&lt;/strong> 를 보장합니다. A가 데이터를 바꾸면, 그 직후 B가 조회했을 때 바뀐 값을 봐야 하죠. 트랜잭션이 커밋되면 모든 조회자가 즉시 같은 데이터를 보는 겁니다.&lt;/p>
&lt;p>반면 &lt;strong>Eventual Consistency&lt;/strong>는 다릅니다. &amp;ldquo;지금 당장은 다를 수 있지만, &lt;strong>결국에는&lt;/strong> 모두 같아진다&amp;quot;는 개념이에요. 일시적인 불일치를 허용하는 대신, 시스템 전체의 확장성과 가용성을 얻는 선택입니다.&lt;/p>
&lt;p>개발자 입장에서 데이터 정합성이 틀어지는 걸 허용하는 게 불안할 수 있지만, 생각보다 일상에서 흔히 접하는 개념입니다.&lt;/p>
&lt;p>SNS의 &amp;lsquo;좋아요&amp;rsquo; 수를 생각해보면 제가 좋아요를 눌렀는데, 친구 화면에서는 아직 반영이 안 됐을 수 있습니다. 하지만 잠시 후 새로고침하면 반영되어 있죠. 사용자 입장에서는 대부분 인지하지도 못합니다. YouTube 조회수가 실시간으로 정확하지 않은 것도 같은 이유입니다.&lt;/p>
&lt;h4>왜 MSA에서는 Eventual Consistency를 선택할까?&lt;span class="hx:absolute hx:-mt-20" id="왜-msa에서는-eventual-consistency를-선택할까">&lt;/span>
&lt;a href="#%ec%99%9c-msa%ec%97%90%ec%84%9c%eb%8a%94-eventual-consistency%eb%a5%bc-%ec%84%a0%ed%83%9d%ed%95%a0%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>분산 시스템에서는 &lt;strong>일관성(Consistency)&lt;/strong> 과 &lt;strong>가용성(Availability)&lt;/strong> 사이에서 선택을 해야 하는 상황이 생깁니다.&lt;/p>
&lt;p>Strong Consistency를 고집하면, 네트워크 문제가 생겼을 때 서비스가 멈추게 됩니다. &amp;ldquo;일관성이 깨질 바에야 차라리 응답을 안 하겠다&amp;quot;는 거죠. 반면 Eventual Consistency를 선택하면, 일시적으로 데이터가 다를 수 있지만 서비스는 계속 동작합니다.&lt;/p>
&lt;p>대부분의 비즈니스에서 &amp;ldquo;잠깐 데이터가 다른 것&amp;quot;보다 &amp;ldquo;서비스가 멈추는 것&amp;quot;이 더 큰 문제일 가능성이 높습니다. 그래서 MSA에서는 Eventual Consistency가 자연스러운 선택이 되는 거죠.&lt;/p>
&lt;p>이 처럼 최종적 일관성은 개발자가 별다른 작업을 하지 않아도 알아서 되는 개념은 아닙니다. 개발자가 의도적으로 설계하고 구현해야 하는 개념이죠. 이벤트 기반 아키텍처에서는 특히 더 그렇습니다.&lt;/p>
&lt;p>Zero Payload 패턴은 이 Eventual Consistency를 구현한 케이스입니다. &amp;ldquo;이벤트 순서가 꼬여도 괜찮아, 어차피 최신 데이터를 가져올 거니까&amp;quot;라는 발상의 전환이죠.&lt;/p>
&lt;p>다만 trade-off가 있습니다. 이벤트마다 API를 호출하기 때문에 API 호출 부하가 발생할 수 있고, 네트워크 의존성이 생기며, 동기 API 호출로 인해 지연 시간이 늘어날 수 있습니다.&lt;/p>
&lt;p>그래서 이벤트 발생량이 많거나 API 서비스 안정성이 불안하다면 부담이 될 수 있습니다.&lt;/p>
&lt;h3>그래서 어떻게 해야 할까?&lt;span class="hx:absolute hx:-mt-20" id="그래서-어떻게-해야-할까">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%9e%98%ec%84%9c-%ec%96%b4%eb%96%bb%ea%b2%8c-%ed%95%b4%ec%95%bc-%ed%95%a0%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>결국 순서 역전 문제를 해결하는 방법과 이벤트 방식을 정리하면 이렇습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>방식&lt;/th>
&lt;th>장점&lt;/th>
&lt;th>단점&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>파티션 키&lt;/td>
&lt;td>순서 보장 확실&lt;/td>
&lt;td>Kafka 의존, 파티션 단위 처리&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>버전 기반 (Fat Event)&lt;/td>
&lt;td>순서 무관하게 처리 가능, API 호출 불필요&lt;/td>
&lt;td>이벤트 크기 큼, 스키마 결합&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Zero Payload (Thin Event + API)&lt;/td>
&lt;td>항상 최신 데이터, 스키마 유연, 순서 역전 자동 해결&lt;/td>
&lt;td>API 부하, 네트워크 의존&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;ul>
&lt;li>&lt;strong>데이터 복제가 목적이고 이벤트 많으면&lt;/strong> → Fat Event + 버전 기반&lt;/li>
&lt;li>&lt;strong>알림 성격이고 최신 상태만 중요하면&lt;/strong> → Zero Payload&lt;/li>
&lt;li>&lt;strong>Kafka 쓰고 파티션 설계가 잘 되어 있으면&lt;/strong> → 파티션 키로 순서 보장&lt;/li>
&lt;/ul>
&lt;p>일반적인 가이드라인은 위와 같지만, 결국에는 서비스 특성에 맞게 선택하는 게 중요하다고 생각합니다.&lt;/p>
&lt;p>다만 제 개인적인 생각을 덧붙이자면, 저는 어느쪽이건 일관성이 중요하다고 생각합니다. 우리 서비스는 Zero Payload 방식으로 하기로 했다면 전체 서비스가 해당 방식으로 데이터를 동기화하는게 낫지 않나 싶습니다. 일종의 컨벤션 같은 거죠.&lt;/p>
&lt;p>&lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-3-communication/">3편&lt;/a>에서도 언급했지만 동기 통신에서도 저는 서비스간 통신에서 어떤 방식이 됐건 팀과 합의된 일관된 방식을 따르는 게 중요하다고 생각한다고 적었습니다.&lt;/p>
&lt;p>이 이벤트를 통한 데이터 동기화에서도 마찬가지라고 생각합니다. 어디는 Fat Event, 어디는 Zero Payload, 어디는 파티션 키로 순서 보장 이렇게 제각각이면 서비스 파악도 어려워지고 이벤트 추적도 케이스마다 달리해야하니 너무 복잡하고 어려워 지는 것 같습니다.&lt;/p>
&lt;p>물론 제 생각이 정답도 아니고, 회사가 너무 커 서비스가 엄청난데 무조건 일관성을 강제하기도 어려울 수 있습니다. 하지만 가능하다면 일관된 방식을 채택하는게 장기적으로 유지보수에 훨씬 도움이 된다고 생각합니다. 결론은 서비스 특성에 맞게 선택하되 &lt;strong>&amp;ldquo;일정 기준을 정하고 일관되게 적용하는게 좋을 것 같다&amp;rdquo;&lt;/strong> 가 제 의견입니다.&lt;/p>
&lt;p>어쩌다 보니 이벤트 순서 역전 문제에 대해 길게 설명드렸는데, 이게 끝이 아닙니다. 이벤트 기반 데이터 정합성 문제는 여기서 그치지 않습니다.&lt;/p>
&lt;h3>메시지 유실&lt;span class="hx:absolute hx:-mt-20" id="메시지-유실">&lt;/span>
&lt;a href="#%eb%a9%94%ec%8b%9c%ec%a7%80-%ec%9c%a0%ec%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이벤트 순서 문제 외에도 &lt;strong>메시지가 유실되는 경우&lt;/strong>도 고려해야 합니다.&lt;/p>
&lt;p>메시지 전달 보장 수준에는 세 가지가 있습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>전달 보장 수준&lt;/th>
&lt;th>설명&lt;/th>
&lt;th>특징&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>At-most-once&lt;/td>
&lt;td>최대 한 번&lt;/td>
&lt;td>유실 가능, 중복 없음&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>At-least-once&lt;/td>
&lt;td>최소 한 번&lt;/td>
&lt;td>유실 없음, 중복 가능&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Exactly-once&lt;/td>
&lt;td>정확히 한 번&lt;/td>
&lt;td>유실 없음, 중복 없음&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Exactly-once가 이상적으로 보이지만, 분산 시스템에서 이걸 보장하기는 &lt;strong>매우 어렵다고 생각합니다.&lt;/strong> Kafka 0.11부터 트랜잭션 기능을 통해 Kafka 내부에서는 Exactly-once semantics(EOS)를 지원하지만, 외부 시스템(DB, 다른 메시지 브로커 등)까지 포함한 end-to-end Exactly-once는 여전히 어렵습니다. 네트워크 오류, 서버 재시작 등 다양한 상황에서 &amp;ldquo;정확히 한 번&amp;quot;을 완벽히 보장하려면 상당한 복잡도가 필요합니다.&lt;/p>
&lt;p>그래서 대부분의 시스템은 &lt;strong>At-least-once&lt;/strong>가 적합하다고 봅니다. &lt;strong>유실보다 중복이 낫기 때문&lt;/strong>이죠. 중복은 어플리케이션 레벨에서 처리할 수 있지만, 유실은 복구하기 어렵습니다. 잃어버린 이벤트가 뭔지도 모르니까요.&lt;/p>
&lt;h3>중복 처리: 멱등성이 필수&lt;span class="hx:absolute hx:-mt-20" id="중복-처리-멱등성이-필수">&lt;/span>
&lt;a href="#%ec%a4%91%eb%b3%b5-%ec%b2%98%eb%a6%ac-%eb%a9%b1%eb%93%b1%ec%84%b1%ec%9d%b4-%ed%95%84%ec%88%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>At-least-once면 중복이 발생할 수 있습니다. 그래서 Consumer 측에서 &lt;strong>멱등성&lt;/strong>을 보장해야 합니다.&lt;/p>
&lt;p>&lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-4-resilience/">4편&lt;/a>에서 Retry를 다룰 때 멱등성 이야기를 했었는데, 이벤트 처리에서도 동일한 개념입니다. 같은 이벤트가 여러 번 와도 결과가 같아야 하죠. 해결방법 역시 비슷합니다. 어플리케이션 레벨에서 중복 처리를 구현해야 합니다.&lt;/p>
&lt;h4>방법 1: 처리 완료 기록&lt;span class="hx:absolute hx:-mt-20" id="방법-1-처리-완료-기록">&lt;/span>
&lt;a href="#%eb%b0%a9%eb%b2%95-1-%ec%b2%98%eb%a6%ac-%ec%99%84%eb%a3%8c-%ea%b8%b0%eb%a1%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@EventListener&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">onUserUpdated&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">UserUpdatedEvent&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 이미 처리한 이벤트인지 확인&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">processedEventRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">existsByEventId&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getId&lt;/span>&lt;span class="p">()))&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">log&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">info&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;이미 처리된 이벤트: {}&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 실제 처리&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">userReplicaRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">save&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">UserReplica&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">from&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 처리 완료 기록&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">processedEventRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">save&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ProcessedEvent&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getId&lt;/span>&lt;span class="p">()));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h4>방법 2: Upsert 활용&lt;span class="hx:absolute hx:-mt-20" id="방법-2-upsert-활용">&lt;/span>
&lt;a href="#%eb%b0%a9%eb%b2%95-2-upsert-%ed%99%9c%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@EventListener&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">onUserUpdated&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">UserUpdatedEvent&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// INSERT or UPDATE - 여러 번 실행해도 결과가 같음&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">userReplicaRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">upsert&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">UserReplica&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">from&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>Upsert가 가능한 상황이라면 이 방식이 더 간단합니다. 별도의 처리 기록 테이블 없이도 멱등성이 보장되니까요.&lt;/p>
&lt;h3>처리 실패 시: Dead Letter Queue (DLQ)&lt;span class="hx:absolute hx:-mt-20" id="처리-실패-시-dead-letter-queue-dlq">&lt;/span>
&lt;a href="#%ec%b2%98%eb%a6%ac-%ec%8b%a4%ed%8c%a8-%ec%8b%9c-dead-letter-queue-dlq" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그런데 멱등성을 보장해도 &lt;strong>처리 자체가 계속 실패하는 경우&lt;/strong>는 어떻게 할까요? 네트워크 문제가 아니라 데이터 자체가 잘못됐거나, 비즈니스 로직상 처리할 수 없는 이벤트일 수 있습니다.&lt;/p>
&lt;p>이런 경우를 위해 &lt;strong>Dead Letter Queue (DLQ)&lt;/strong> 패턴을 사용합니다. 일정 횟수 이상 재시도해도 실패하는 메시지는 별도의 DLQ로 보내서 나중에 수동으로 처리하거나 분석하는 거죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@KafkaListener&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">topics&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;user-events&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">consume&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">UserUpdatedEvent&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">try&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">processEvent&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">catch&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Exception&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getRetryCount&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">&amp;gt;=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">MAX_RETRY&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// DLQ로 이동&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">dlqProducer&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">send&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;user-events-dlq&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">log&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">error&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;DLQ로 이동: {}&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">else&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 재시도 큐로&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">throw&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// Kafka가 자동 재시도&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>DLQ에 쌓인 메시지는 모니터링 알림을 설정해두고, 원인을 파악한 후 수동으로 재처리하거나 폐기합니다. 이렇게 하면 문제 있는 메시지가 계속 재시도되면서 전체 처리를 막는 상황을 방지할 수 있습니다.&lt;/p>
&lt;h2>분산 트랜잭션: ACID가 깨진다&lt;span class="hx:absolute hx:-mt-20" id="분산-트랜잭션-acid가-깨진다">&lt;/span>
&lt;a href="#%eb%b6%84%ec%82%b0-%ed%8a%b8%eb%9e%9c%ec%9e%ad%ec%85%98-acid%ea%b0%80-%ea%b9%a8%ec%a7%84%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>아직 끝나지 않았습니다. 더욱 어려운 문제가 남아있죠. 바로 &lt;strong>분산 트랜잭션&lt;/strong>입니다.&lt;/p>
&lt;p>앞서 &amp;ldquo;트랜잭션이 안 된다&amp;quot;고 했는데, 이게 왜 그렇게 문제인지 살펴보겠습니다.&lt;/p>
&lt;h3>공유 DB에서의 트랜잭션&lt;span class="hx:absolute hx:-mt-20" id="공유-db에서의-트랜잭션">&lt;/span>
&lt;a href="#%ea%b3%b5%ec%9c%a0-db%ec%97%90%ec%84%9c%ec%9d%98-%ed%8a%b8%eb%9e%9c%ec%9e%ad%ec%85%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>콘서트 예매를 다시 생각해 보겠습니다. 공유 DB 환경에서는 이렇게 할 수 있었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Transactional&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">bookConcert&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">BookingRequest&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">request&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 1. 좌석 예약&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">seatRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">reserve&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">request&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getSeatId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 2. 결제 처리&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">paymentRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">process&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">request&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getPayment&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 3. 티켓 발급&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ticketRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">issue&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">request&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getUserId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 하나라도 실패하면 전체 롤백!&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>ACID가 보장됩니다. 결제에서 오류가 나면 좌석 예약도 자동으로 롤백됩니다. 개발자가 따로 신경 쓸 필요가 없죠. 얼마나 편한 세상이었는지 모릅니다.&lt;/p>
&lt;h3>MSA에서의 현실&lt;span class="hx:absolute hx:-mt-20" id="msa에서의-현실">&lt;/span>
&lt;a href="#msa%ec%97%90%ec%84%9c%ec%9d%98-%ed%98%84%ec%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>하지만 좌석 서비스, 결제 서비스, 티켓 서비스가 각자 DB를 가지면 어떻게 될까요?&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
subgraph SeatService[&amp;#34;좌석 서비스&amp;#34;]
SeatDB[(좌석 DB&amp;lt;br/&amp;gt;예약 ✓)]
end
subgraph PaymentService[&amp;#34;결제 서비스&amp;#34;]
PaymentDB[(결제 DB&amp;lt;br/&amp;gt;결제 ✓)]
end
subgraph TicketService[&amp;#34;티켓 서비스&amp;#34;]
TicketDB[(티켓 DB&amp;lt;br/&amp;gt;발급 ✗)]
end
SeatService --&amp;gt; PaymentService --&amp;gt; TicketService
style SeatDB fill:#90EE90
style PaymentDB fill:#90EE90
style TicketDB fill:#ff6b6b
&lt;/pre>&lt;p>좌석은 예약됐고, 결제도 됐는데, 티켓이 안 나왔습니다. 어떻게 롤백해야 할까요?&lt;/p>
&lt;p>결제는 이미 카드사에 청구됐습니다. 좌석 예약은 좌석 서비스 DB에 커밋됐습니다. 각 서비스가 자기 DB에 커밋하고 나면, 다른 서비스의 실패를 알아도 &lt;strong>롤백이 안 됩니다&lt;/strong>.&lt;/p>
&lt;p>이게 바로 분산 시스템에서 트랜잭션이 어려운 이유입니다.&lt;/p>
&lt;h3>2PC (Two-Phase Commit)의 한계&lt;span class="hx:absolute hx:-mt-20" id="2pc-two-phase-commit의-한계">&lt;/span>
&lt;a href="#2pc-two-phase-commit%ec%9d%98-%ed%95%9c%ea%b3%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&amp;ldquo;그럼 분산 트랜잭션을 쓰면 되지 않나?&amp;ldquo;라고 생각하실 수 있습니다. 전통적인 해결책으로 &lt;strong>2PC (Two-Phase Commit)&lt;/strong> 이 있습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant C as Coordinator
participant S as 좌석 서비스
participant P as 결제 서비스
participant T as 티켓 서비스
Note over C,T: Phase 1: Prepare
C-&amp;gt;&amp;gt;S: 커밋할 준비 됐어?
C-&amp;gt;&amp;gt;P: 커밋할 준비 됐어?
C-&amp;gt;&amp;gt;T: 커밋할 준비 됐어?
S--&amp;gt;&amp;gt;C: Yes!
P--&amp;gt;&amp;gt;C: Yes!
T--&amp;gt;&amp;gt;C: Yes!
Note over C,T: Phase 2: Commit
C-&amp;gt;&amp;gt;S: 커밋해
C-&amp;gt;&amp;gt;P: 커밋해
C-&amp;gt;&amp;gt;T: 커밋해
&lt;/pre>&lt;p>Coordinator가 모든 참여자에게 &amp;ldquo;준비됐어?&amp;ldquo;라고 물어보고, 다 &amp;ldquo;Yes&amp;quot;라고 하면 그때 커밋을 지시하는 방식입니다. 이론적으로는 ACID를 보장할 수 있습니다.&lt;/p>
&lt;p>하지만 &lt;strong>MSA에서는 거의 사용하지 않는 것으로 알고있습니다.&lt;/strong> 왜일까요?&lt;/p>
&lt;p>Coordinator가 SPOF가 되어 Coordinator가 죽으면 전체 트랜잭션이 멈춰버립니다. 또 모든 서비스가 Lock을 잡고 대기해야 해서 성능도 안 좋습니다. 그리고 모든 DB가 2PC를 지원해야 하는데, MSA의 장점중 하나인 &lt;strong>독립적인 DB 선택&lt;/strong>을 어렵게 합니다.&lt;/p>
&lt;p>결국 2PC는 MSA의 핵심 가치인 &lt;strong>독립성과 확장성&lt;/strong>을 훼손하게 됩니다. 그래서 다른 방법이 필요합니다.&lt;/p>
&lt;h3>CAP 이론&lt;span class="hx:absolute hx:-mt-20" id="cap-이론">&lt;/span>
&lt;a href="#cap-%ec%9d%b4%eb%a1%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>앞서 &lt;strong>최종적 일관성(Eventual Consistency)&lt;/strong> 이 무엇인지, 그리고 왜 MSA에서 일관성보다 가용성을 선택하는지 설명했습니다. 여기서 그 이론적 배경인 &lt;strong>CAP 정리&lt;/strong>를 짚고 넘어가겠습니다.&lt;/p>
&lt;p>분산 시스템에는 CAP 이론이 있습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>C (Consistency)&lt;/strong>: 모든 노드가 같은 시점에 같은 데이터를 본다&lt;/li>
&lt;li>&lt;strong>A (Availability)&lt;/strong>: 장애가 발생해도 항상 응답을 반환한다&lt;/li>
&lt;li>&lt;strong>P (Partition Tolerance)&lt;/strong>: 네트워크가 분리되어도 시스템이 동작한다&lt;/li>
&lt;/ul>
&lt;p>CAP 이론의 핵심은 분산 시스템에서는 위 3가지를 &lt;strong>동시에 만족시킬 수 없다&lt;/strong>는 겁니다.&lt;/p>
&lt;p>그런데 여기서 P(Partition Tolerance)는 사실상 포기할 수 없습니다. 네트워크는 언제든 끊길 수 있고, 이건 우리가 통제할 수 없는 영역이거든요. 그러면 결국 &lt;strong>C와 A 중 하나를 선택&lt;/strong>해야 합니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>CP 선택&lt;/strong>: 일관성을 지키되, 네트워크 문제 시 일부 요청은 거부한다&lt;/li>
&lt;li>&lt;strong>AP 선택&lt;/strong>: 가용성을 지키되, 일시적으로 데이터가 다를 수 있다&lt;/li>
&lt;/ul>
&lt;p>대부분의 MSA 시스템은 &lt;strong>AP를 선택&lt;/strong>합니다. 앞서 설명했듯이 대부분의 비즈니스에서 &amp;ldquo;서비스가 멈추는 것&amp;quot;이 &amp;ldquo;데이터가 잠깐 다른 것&amp;quot;보다 더 치명적이기 때문이죠. AP를 선택하면 자연스럽게 Eventual Consistency를 받아들이게 됩니다.&lt;/p>
&lt;p>그렇다면 MSA에서 Eventual Consistency를 어떻게 체계적으로 구현할까요? 바로 &lt;strong>Saga 패턴&lt;/strong>입니다.&lt;/p>
&lt;h2>Saga 패턴: 분산 트랜잭션의 대안&lt;span class="hx:absolute hx:-mt-20" id="saga-패턴-분산-트랜잭션의-대안">&lt;/span>
&lt;a href="#saga-%ed%8c%a8%ed%84%b4-%eb%b6%84%ec%82%b0-%ed%8a%b8%eb%9e%9c%ec%9e%ad%ec%85%98%ec%9d%98-%eb%8c%80%ec%95%88" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>Saga의 기본 개념&lt;span class="hx:absolute hx:-mt-20" id="saga의-기본-개념">&lt;/span>
&lt;a href="#saga%ec%9d%98-%ea%b8%b0%eb%b3%b8-%ea%b0%9c%eb%85%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Saga는 1987년 Hector Garcia-Molina와 Kenneth Salem의 논문에서 나온 개념입니다. 핵심 아이디어는 다음과 같습니다.&lt;/p>
&lt;blockquote>
&lt;p>하나의 긴 트랜잭션을 여러 개의 로컬 트랜잭션으로 분리하고,
실패 시 &lt;strong>보상 트랜잭션&lt;/strong>으로 되돌린다.&lt;/p>
&lt;/blockquote>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Success[&amp;#34;성공 시&amp;#34;]
T1[&amp;#34;T1&amp;lt;br/&amp;gt;좌석예약&amp;#34;] --&amp;gt; T2[&amp;#34;T2&amp;lt;br/&amp;gt;결제&amp;#34;] --&amp;gt; T3[&amp;#34;T3&amp;lt;br/&amp;gt;티켓발급&amp;#34;] --&amp;gt; Done[&amp;#34;완료&amp;#34;]
end
subgraph Failure[&amp;#34;실패 시 (T3 실패)&amp;#34;]
F1[&amp;#34;T1&amp;lt;br/&amp;gt;좌석예약&amp;#34;] --&amp;gt; F2[&amp;#34;T2&amp;lt;br/&amp;gt;결제&amp;#34;] --&amp;gt; F3[&amp;#34;T3&amp;lt;br/&amp;gt;실패&amp;#34;]
F3 --&amp;gt; C2[&amp;#34;C2&amp;lt;br/&amp;gt;결제취소&amp;#34;]
C2 --&amp;gt; C1[&amp;#34;C1&amp;lt;br/&amp;gt;좌석취소&amp;#34;]
end
style T3 fill:#90EE90
style F3 fill:#ff6b6b
style C2 fill:#ffa94d
style C1 fill:#ffa94d
&lt;/pre>&lt;p>각 단계(T1, T2, T3)는 독립적인 로컬 트랜잭션입니다. 각 서비스가 자기 DB에 커밋하죠. T3가 실패하면, C2(결제 취소)와 C1(좌석 취소)이라는 &lt;strong>보상 트랜잭션&lt;/strong>을 실행해서 되돌립니다.&lt;/p>
&lt;p>DB 롤백처럼 &amp;ldquo;없던 일&amp;quot;로 만드는 게 아니라, &lt;strong>&amp;ldquo;되돌리는 새로운 작업&amp;rdquo;&lt;/strong> 을 하는 겁니다. 생긴 데이터를 그 전상태로 롤백하는 게 아니라, 생긴 데이터를 없애는 새로운 작업을 수행하는 거죠.&lt;/p>
&lt;p>Saga를 구현하는 방식에는 두 가지가 있습니다. &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-3-communication/">3편&lt;/a>에서 다뤘던 Choreography와 Orchestration이죠.&lt;/p>
&lt;h3>Choreography Saga&lt;span class="hx:absolute hx:-mt-20" id="choreography-saga">&lt;/span>
&lt;a href="#choreography-saga" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-3-communication/">3편&lt;/a>에서 본 구조와 같이 중앙 조정자 없이 &lt;strong>이벤트로 연결&lt;/strong>하는 방식입니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
Seat[&amp;#34;좌석 서비스&amp;#34;] --&amp;gt;|&amp;#34;SeatReserved&amp;#34;| Payment[&amp;#34;결제 서비스&amp;#34;]
Payment --&amp;gt;|&amp;#34;PaymentCompleted&amp;#34;| Ticket[&amp;#34;티켓 서비스&amp;#34;]
Ticket --&amp;gt;|&amp;#34;TicketIssueFailed&amp;#34;| Payment
Payment --&amp;gt;|&amp;#34;PaymentRefunded&amp;#34;| Seat
style Seat fill:#4ecdc4
style Payment fill:#4ecdc4
style Ticket fill:#ff6b6b
&lt;/pre>&lt;p>각 서비스가 이벤트를 발행하고, 다른 서비스가 개별적으로 그 이벤트에 반응하게 구성하는겁니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 좌석 서비스&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@EventListener&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">onBookingRequested&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">BookingRequestedEvent&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">seatRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">reserve&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getSeatId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">eventPublisher&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">publish&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">SeatReservedEvent&lt;/span>&lt;span class="p">(...));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@EventListener&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">onPaymentRefunded&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">PaymentRefundedEvent&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 보상 트랜잭션: 좌석 예약 취소&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">seatRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">release&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getSeatId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>장점&lt;/strong>은 느슨한 결합입니다. 각 서비스가 독립적이고, 새로운 서비스를 추가하기 쉽게 됩니다. 다만 &lt;strong>단점&lt;/strong>은 전체 흐름 파악이 어렵다는 점입니다.&lt;/p>
&lt;p>이벤트가 여기저기서 발생하니까, &amp;ldquo;지금 어디까지 진행됐지?&amp;ldquo;를 알기 어렵고 디버깅도 복잡합니다. 서비스가 많아지면 이벤트 간의 관계가 꼬이기도 하죠. 문서화가 잘 되어 있지 않으면 어디서 어떤 보상 트랜잭션이 발생하는지 알기 어려워집니다.&lt;/p>
&lt;p>이게 정말 큰 문제 입니다. Choreography 방식은 서비스가 적고 흐름이 단순할 때는 괜찮지만, 서비스가 많아지고 비즈니스 로직이 복잡해지면 흐름을 파악하기도 관리하기도 어려워집니다.&lt;/p>
&lt;h3>Orchestration Saga&lt;span class="hx:absolute hx:-mt-20" id="orchestration-saga">&lt;/span>
&lt;a href="#orchestration-saga" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>중앙 &lt;strong>Orchestrator가 흐름을 관리&lt;/strong>하는 방식입니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
Orch[&amp;#34;Booking Orchestrator&amp;#34;]
Orch --&amp;gt; Seat[&amp;#34;좌석 서비스&amp;#34;]
Orch --&amp;gt; Payment[&amp;#34;결제 서비스&amp;#34;]
Orch --&amp;gt; Ticket[&amp;#34;티켓 서비스&amp;#34;]
style Orch fill:#ffe066
style Seat fill:#4ecdc4
style Payment fill:#4ecdc4
style Ticket fill:#4ecdc4
&lt;/pre>&lt;p>Orchestrator가 순서대로 각 서비스를 호출하고, 실패하면 보상 로직을 실행합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Service&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">BookingOrchestrator&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">processBooking&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">BookingRequest&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">request&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">try&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 1. 좌석 예약&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">SeatReservation&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">seat&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">seatService&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">reserve&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">request&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getSeatId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">try&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 2. 결제&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">Payment&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">payment&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">paymentService&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">process&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">request&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getPayment&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">try&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 3. 티켓 발급&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ticketService&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">issue&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">request&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getUserId&lt;/span>&lt;span class="p">(),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">seat&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">catch&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Exception&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 티켓 실패 → 결제 취소&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">paymentService&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">refund&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">payment&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">throw&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">catch&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Exception&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 결제 실패 → 좌석 취소&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">seatService&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">release&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">seat&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">throw&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">catch&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Exception&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">throw&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">BookingFailedException&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>장점&lt;/strong>은 흐름이 명확하다는 점입니다. 비즈니스 로직이 한 곳에 모여있어서 이해하기 쉽고, 에러 처리도 비교적 용이하죠. &lt;strong>단점&lt;/strong>은 Orchestrator가 SPOF가 될 수 있다는 점입니다. 또한 로직이 한 곳에 집중되면서 Orchestrator가 점점 커질 수 있습니다.&lt;/p>
&lt;h3>보상 트랜잭션: 완벽한 롤백은 없다&lt;span class="hx:absolute hx:-mt-20" id="보상-트랜잭션-완벽한-롤백은-없다">&lt;/span>
&lt;a href="#%eb%b3%b4%ec%83%81-%ed%8a%b8%eb%9e%9c%ec%9e%ad%ec%85%98-%ec%99%84%eb%b2%bd%ed%95%9c-%eb%a1%a4%eb%b0%b1%ec%9d%80-%ec%97%86%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>여기서 중요한 걸 짚고 넘어가야 할것 같습니다. &lt;strong>보상 트랜잭션은 완벽한 롤백이 아니라는 겁니다.&lt;/strong>&lt;/p>
&lt;p>DB 롤백은 &amp;ldquo;없던 일&amp;quot;로 만들지만, 보상 트랜잭션은 &lt;strong>&amp;ldquo;이미 일어난 일을 되돌리는 새로운 작업&amp;rdquo;&lt;/strong> 입니다. 차이가 느껴지실거라 생각합니다.&lt;/p>
&lt;p>예를 들어보겠습니다. 사용자께서 결제를 시도했고 결제 안에는 좌석이 예약되고 예약이 완료되면 티켓이 발급되는 시나리오에서 티켓 발급이 실패했다고 가정해보죠.&lt;/p>
&lt;p>결제가 완료했을때 이미 이메일을 발송하고난 이후에 티켓 발급에 실패했다면 어떻게 될까요? 결제나 좌석은 보상 트랜잭션으로 되돌릴 수 있지만, 이메일은 이미 발송됐기 때문에 되돌릴 수 없습니다.&lt;/p>
&lt;p>그래서 Saga를 설계할 때는 다음 사항들을 고려해야 합니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>보상이 가능한 작업인지 확인&lt;/strong>: 모든 작업이 되돌릴 수 있는 건 아닙니다&lt;/li>
&lt;li>&lt;strong>보상 로직을 비즈니스 레벨에서 정의&lt;/strong>: 기술적 롤백이 아닌 비즈니스적 취소 로직이 필요합니다&lt;/li>
&lt;li>&lt;strong>되돌릴 수 없는 작업은 마지막에 배치&lt;/strong>: 이메일 발송 같은 건 맨 마지막에 하는 게 좋다고 생각합니다.&lt;/li>
&lt;/ol>
&lt;p>또 모니터링이 중요합니다. 어디까지 진행됐는지, 어떤 보상 트랜잭션이 실행됐는지 추적할 수 있어야 합니다. 그래야 장애 상황에서 빠르게 대응할 수 있거든요.&lt;/p>
&lt;h3>Saga 상태 관리&lt;span class="hx:absolute hx:-mt-20" id="saga-상태-관리">&lt;/span>
&lt;a href="#saga-%ec%83%81%ed%83%9c-%ea%b4%80%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Orchestration Saga를 구현할 때 놓치기 쉬운 부분이 &lt;strong>Saga 상태 저장&lt;/strong>입니다. Orchestrator가 &amp;ldquo;지금 어디까지 진행됐는지&amp;quot;를 알아야 장애 복구가 가능합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Entity&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">BookingSaga&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nd">@Id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">sagaId&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">SagaStatus&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">status&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// STARTED, SEAT_RESERVED, PAYMENT_COMPLETED, COMPLETED, COMPENSATING, FAILED&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">seatReservationId&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">paymentId&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">LocalDateTime&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">startedAt&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">LocalDateTime&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">completedAt&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>Saga의 각 단계가 완료될 때마다 상태를 저장해두면 Orchestrator가 재시작되더라도 중단된 지점부터 다시 시작하거나 보상 트랜잭션을 실행할 수 있습니다. 이렇게 저장된 상태는 장애 분석이나 모니터링에도 활용됩니다.&lt;/p>
&lt;p>여기서 하나 더 주의할 점이 있는데요. Orchestrator가 재시작 후 같은 단계를 다시 실행할 때, &lt;strong>각 서비스 호출도 멱등해야&lt;/strong> 합니다. 예를 들어 결제 서비스를 두 번 호출해도 중복 결제가 안 되도록 &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-3-communication/">3편&lt;/a>에서도 이야기했던 멱등성 키(idempotency key)를 전달하는 방식 등으로 말이죠. 그래야 Orchestrator가 재시도하더라도 안전하게 처리할 수 있거든요.&lt;/p>
&lt;h3>언제 무엇을 선택할까요?&lt;span class="hx:absolute hx:-mt-20" id="언제-무엇을-선택할까요">&lt;/span>
&lt;a href="#%ec%96%b8%ec%a0%9c-%eb%ac%b4%ec%97%87%ec%9d%84-%ec%84%a0%ed%83%9d%ed%95%a0%ea%b9%8c%ec%9a%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>상황&lt;/th>
&lt;th>권장 방식&lt;/th>
&lt;th>이유&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>서비스 수가 적고 흐름이 단순&lt;/td>
&lt;td>Choreography&lt;/td>
&lt;td>오버헤드 없이 간단하게 구현&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>서비스 수가 많고 흐름이 복잡&lt;/td>
&lt;td>Orchestration&lt;/td>
&lt;td>전체 흐름을 한눈에 파악 가능&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>비즈니스 로직 중심&lt;/td>
&lt;td>Orchestration&lt;/td>
&lt;td>로직이 한 곳에 모여있어 관리 용이&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>느슨한 결합 중시&lt;/td>
&lt;td>Choreography&lt;/td>
&lt;td>서비스 간 의존성 최소화&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>개인적으로는 3개 이상의 서비스가 관여하는 복잡한 비즈니스 흐름에서는 &lt;strong>Orchestration이 관리하기 훨씬 편했습니다.&lt;/strong> Choreography는 처음엔 깔끔해 보이지만, 서비스가 늘어나면 &amp;ldquo;지금 전체 흐름이 어디까지 진행됐지?&amp;ldquo;를 파악하기 어려워지는 경우가 많았거든요.&lt;/p>
&lt;p>물론 둘을 혼합해서 사용할 수도 있습니다. 핵심 비즈니스 흐름은 Orchestration으로, 부가적인 이벤트 처리는 Choreography로 가져가는 식이죠.&lt;/p>
&lt;p>다만 제 개인적으로는 &amp;ldquo;복잡한 분산 트랜잭션은 Orchestration으로 관리하는 게 낫다&amp;rdquo; 생각하는 쪽입니다. 그래야 장애 상황에서 빠르게 대응할 수 있고, 전체 흐름을 이해하기도 쉽다고 생각합니다.&lt;/p>
&lt;h3>Saga를 피해야 할 때&lt;span class="hx:absolute hx:-mt-20" id="saga를-피해야-할-때">&lt;/span>
&lt;a href="#saga%eb%a5%bc-%ed%94%bc%ed%95%b4%ec%95%bc-%ed%95%a0-%eb%95%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그런데 여기서 중요한 걸 짚고 넘어가야 할 것 같습니다. &lt;strong>Saga가 만능은 아니라고 생각합니다.&lt;/strong> 오히려 Saga를 도입하면 안 되는 경우도 많은 것 같습니다.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>실시간 일관성이 반드시 필요한 경우&lt;/strong>: 은행 이체처럼 &amp;ldquo;잔액이 맞지 않으면 큰일 나는&amp;rdquo; 시나리오에서는 Eventual Consistency가 적합하지 않을 수 있습니다. 이런 경우에는 서비스 경계를 재검토하거나, 동기방식으로 처리하는 게 낫다고 생각합니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>보상이 불가능한 작업이 많은 경우&lt;/strong>: 앞서 말했듯이 이메일 발송, 외부 API 호출 같은 건 되돌릴 수 없습니다. 이런 작업이 흐름 중간에 많다면 Saga로 풀기 어렵다고 생각합니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>단순한 CRUD인데 억지로 분산시킨 경우&lt;/strong>: 솔직히 말하면, Saga가 필요한 상황 자체가 &amp;ldquo;서비스를 잘못 나눈 건 아닌가?&amp;rdquo; 하는 신호일 수도 있습니다. 트랜잭션이 함께 필요한 데이터라면 애초에 같은 서비스에 있어야 할 수도 있거든요.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>팀이 분산 시스템 경험이 부족한 경우&lt;/strong>: Saga 패턴은 디버깅이 어렵고, 장애 상황에서 데이터 정합성을 맞추는 게 쉽지 않다고 생각합니다. 팀의 역량이 준비되지 않은 상태에서 도입하면 오히려 장애가 늘어날 수 있지 않나 싶네요.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h2>정리&lt;span class="hx:absolute hx:-mt-20" id="정리">&lt;/span>
&lt;a href="#%ec%a0%95%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이번 편에서 다룬 내용을 정리하면 다음과 같습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>이벤트 발행의 원자성&lt;/strong>을 보장하기 위해 Transactional Outbox나 CDC 패턴을 사용합니다.&lt;/li>
&lt;li>&lt;strong>이벤트 동기화&lt;/strong>에서는 순서 역전, 메시지 유실, 중복 처리를 고려해야 합니다.&lt;/li>
&lt;li>&lt;strong>순서 역전&lt;/strong>은 파티션 키, 버전 기반, Zero Payload 패턴으로 해결할 수 있습니다.&lt;/li>
&lt;li>&lt;strong>Eventual Consistency&lt;/strong>를 받아들이는 것이 MSA에서는 자연스러운 선택입니다.&lt;/li>
&lt;li>&lt;strong>분산 트랜잭션 대신&lt;/strong> Saga 패턴으로 보상 트랜잭션을 구현합니다.&lt;/li>
&lt;li>&lt;strong>Saga는 만능이 아닙니다.&lt;/strong> 실시간 일관성이 필요하거나 보상이 어려운 경우에는 서비스 경계를 재검토해야 합니다.&lt;/li>
&lt;/ol>
&lt;p>생각보다 정말 많은 문제들이 있었고, 이걸 정리하느라 많은 내용을 담게 됐습니다. 참 쉽지 않았네요. 이걸 읽는 여러분도 쉽지 않으셨을 거라 생각합니다.&lt;/p>
&lt;p>결국 &lt;strong>이벤트 기반 데이터 정합성은 공짜가 아니라는 것 입니다.&lt;/strong> 모놀리식에서 당연하게 쓰던 트랜잭션이 얼마나 강력한 도구였는지 MSA를 하게 되면 점점 더 깨달을 수 있는 것 같습니다.&lt;/p>
&lt;p>RDB가 수십 년간 발전시켜온 ACID 보장을 포기하고, 그걸 애플리케이션 레벨에서 다시 구현하려니 어려울 수 밖에 없겠죠.&lt;/p>
&lt;h2>다음 편에서&lt;span class="hx:absolute hx:-mt-20" id="다음-편에서">&lt;/span>
&lt;a href="#%eb%8b%a4%ec%9d%8c-%ed%8e%b8%ec%97%90%ec%84%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>지금까지 6편에 걸쳐 MSA의 여러 측면을 살펴봤습니다. 서비스를 어떻게 나눌지, 어떻게 통신할지, 장애에 어떻게 대응할지, 데이터를 어떻게 분리하고 정합성을 맞출지까지요. 이 글을 읽으신분들도 느끼시겠지만 정말 쉽지 않은 여정이였습니다.&lt;/p>
&lt;p>그런데 이쯤 되면 한 가지 의문이 들 수 있습니다. &amp;ldquo;이 모든 복잡성을 감당할 만큼 우리 서비스가 큰가?&amp;rdquo; 라는 질문 말입니다. MSA를 선두한 기업들은 엄청난 트래픽과 복잡한 비즈니스를 다루기 위해 필요에 의해 MSA를 선택하게 됐습니다. 하지만 저희가 운영하는 서비스도 그럴까요?&lt;/p>
&lt;p>마지막 편에서는 이 질문에 대한 저의 생각을 적어보려 합니다.&lt;/p>
&lt;hr>
&lt;h2>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>이벤트 동기화&lt;span class="hx:absolute hx:-mt-20" id="이벤트-동기화">&lt;/span>
&lt;a href="#%ec%9d%b4%eb%b2%a4%ed%8a%b8-%eb%8f%99%ea%b8%b0%ed%99%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://microservices.io/patterns/data/transactional-outbox.html"target="_blank" rel="noopener">Transactional Outbox Pattern&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://debezium.io/"target="_blank" rel="noopener">Debezium - Change Data Capture&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>Saga 패턴&lt;span class="hx:absolute hx:-mt-20" id="saga-패턴">&lt;/span>
&lt;a href="#saga-%ed%8c%a8%ed%84%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://microservices.io/patterns/data/saga.html"target="_blank" rel="noopener">Microservices.io - Saga&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>Hector Garcia-Molina, Kenneth Salem - &lt;em>Sagas&lt;/em> (1987)&lt;/li>
&lt;/ul>
&lt;h3>CAP 정리와 분산 시스템&lt;span class="hx:absolute hx:-mt-20" id="cap-정리와-분산-시스템">&lt;/span>
&lt;a href="#cap-%ec%a0%95%eb%a6%ac%ec%99%80-%eb%b6%84%ec%82%b0-%ec%8b%9c%ec%8a%a4%ed%85%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>Eric Brewer - &lt;em>CAP Twelve Years Later&lt;/em> (2012)&lt;/li>
&lt;li>Martin Kleppmann - &lt;em>Designing Data-Intensive Applications&lt;/em> (O&amp;rsquo;Reilly, 2017)&lt;/li>
&lt;/ul>
&lt;h3>참고 영상 및 글&lt;span class="hx:absolute hx:-mt-20" id="참고-영상-및-글">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%98%81%ec%83%81-%eb%b0%8f-%ea%b8%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://youtu.be/BnS6343GTkY?si=C03UBL_Sxll71g3J"target="_blank" rel="noopener">[우아콘2020] 배달의민족 마이크로서비스 여행기&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://techblog.woowahan.com/7835/"target="_blank" rel="noopener">회원시스템 이벤트기반 아키텍처 구축하기&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>[MSA에 관한 고찰 5/7편] MSA에서 데이터는 어떻게 분리해야 하는가</title><link>https://jeongil.dev/ko/blog/architecture/msa-series-5-data-separation/</link><pubDate>Tue, 20 Jan 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/architecture/msa-series-5-data-separation/</guid><description>
&lt;p>전편: &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-4-resilience/">[MSA에 관한 고찰 4/7편] 장애는 어떻게 전파되고, 우리는 어디서 끊어야 하는가&lt;/a>&lt;/p>
&lt;hr>
&lt;p>저번 편에서 저희는 MSA 환경에서 장애가 어떻게 전파되는지, 그리고 이를 막기 위한 여러 패턴들에 대해 살펴보았습니다. Timeout, Retry, Circuit Breaker까지 다양한 방법들이 있었죠.&lt;/p>
&lt;p>하지만 아직 해야 할 고민이 훨씬 많이 남아있습니다. &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-2-boundary/">2편&lt;/a>에서 서비스를 어떻게 나눌지 고민했고, &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-3-communication/">3편&lt;/a>과 &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-4-resilience/">4편&lt;/a>에서 나눠진 서비스들이 어떻게 통신하고 장애에 대응하는지 살펴봤습니다. 이제는 MSA 환경에서 가장 골치 아픈 문제 중 하나인 &lt;strong>데이터 분리 문제&lt;/strong>에 대해 이야기해보려 합니다. 실제로 제가 MSA를 도입하면서 가장 많이 고민하게 됐던 부분입니다.&lt;/p>
&lt;p>모놀리식에서는 JOIN 한 방이면 끝났던 일이, MSA에서는 생각보다 복잡한 의사결정을 해야합니다. 이번 편에서는 제가 어떤 고민들을 하게 됐는지, MSA 환경에서 데이터를 어떻게 분리해야 하는지, 그리고 분리하면 무엇이 어려워지는지에 대해 알아보는 시간을 가져보려 합니다.&lt;/p>
&lt;h2>꼭 DB를 분리해야 하는가&lt;span class="hx:absolute hx:-mt-20" id="꼭-db를-분리해야-하는가">&lt;/span>
&lt;a href="#%ea%bc%ad-db%eb%a5%bc-%eb%b6%84%eb%a6%ac%ed%95%b4%ec%95%bc-%ed%95%98%eb%8a%94%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>먼저 근본적인 질문부터 던져보겠습니다. MSA에서라고 해서 꼭 DB를 분리해야 할까요? 한번 생각해보면 좋을 것 같습니다.&lt;/p>
&lt;p>&lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-1-introduction/">1편&lt;/a>에서도 이야기 했듯이 모든 기술은 보통 &lt;strong>특정한 문제&lt;/strong>를 해결하기 위해 도입됩니다. 그렇다면 MSA에서 DB를 분리하지 않았을 때 어떤 &lt;strong>특정한 문제&lt;/strong>들이 발생할 수 있는지 살펴보면 꼭 분리해야하는 지 여부를 쉽게 판단할 수 있을 것 같습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Services[&amp;#34;서비스들&amp;#34;]
Order[&amp;#34;주문 서비스&amp;#34;]
User[&amp;#34;회원 서비스&amp;#34;]
Product[&amp;#34;상품 서비스&amp;#34;]
end
Order --&amp;gt; DB[(공유 DB&amp;lt;br/&amp;gt;MySQL)]
User --&amp;gt; DB
Product --&amp;gt; DB
style DB fill:#4ecdc4
&lt;/pre>&lt;p>위와같은 구조를 생각해봅시다. MSA환경에서 주문 서비스, 회원 서비스, 상품 서비스가 모두 하나의 MySQL DB를 공유하는 구조입니다. 단일 DB이기 때문에 JOIN도 자유롭고, 트랜잭션도 보장되고, 기존에 하던 대로 개발하면 됩니다. 뭐가 문제일까요?&lt;/p>
&lt;h3>MSA 환경에서 공유 DB: 편리함의 대가&lt;span class="hx:absolute hx:-mt-20" id="msa-환경에서-공유-db-편리함의-대가">&lt;/span>
&lt;a href="#msa-%ed%99%98%ea%b2%bd%ec%97%90%ec%84%9c-%ea%b3%b5%ec%9c%a0-db-%ed%8e%b8%eb%a6%ac%ed%95%a8%ec%9d%98-%eb%8c%80%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>개발하는 초기에는 편하다고 생각합니다. 복잡성이 줄어들고 러닝커브 역시 분산 DB보다는 훨씬 낮아지니까요. 이 점이 공유 DB의 장점입니다.&lt;/p>
&lt;p>DB와 데이터의 분리에 대해서 고민할 필요가 없고 다른 서비스의 데이터가 필요하면 일반 모놀리식 아키텍처에서 했던 것 처럼 JOIN 한 방이면 됩니다.&lt;/p>
&lt;p>트랜잭션도 보장되니까 개발도 익숙한 방식으로 하면 되고요. 하지만 문제는 시간이 지나면서 드러나게 됩니다.&lt;/p>
&lt;h4>스키마 변경의 공포&lt;span class="hx:absolute hx:-mt-20" id="스키마-변경의-공포">&lt;/span>
&lt;a href="#%ec%8a%a4%ed%82%a4%eb%a7%88-%eb%b3%80%ea%b2%bd%ec%9d%98-%ea%b3%b5%ed%8f%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>만약 회원 서비스에서 &lt;code>users&lt;/code> 테이블의 컬럼 하나를 변경하고 싶다고 가정하겠습니다.&lt;/p>
&lt;p>그런데 회원 테이블을 주문 서비스, 상품 서비스, 정산 서비스&amp;hellip; 전부 해당 테이블을 참조하고 있다면 &lt;code>users&lt;/code> 테이블의 영향도가 굉장히 커집니다. &amp;ldquo;이 컬럼 변경하면 어느 서비스까지 확인해야하지?&amp;rdquo;&lt;/p>
&lt;p>공유 DB에서는 스키마 변경이 모든 서비스에 영향을 줄 수 있기 때문에 결국 모든 서비스를 전수조사 하며 영향도를 파악 해야하고 관련있는 모든 팀이 모여서 협의를 해야 할 수도 있습니다.&lt;/p>
&lt;p>결국 모놀리식에서 하던 것과 다를 게 없어집니다. 무늬만 MSA인 셈이죠.&lt;/p>
&lt;h4>배포 의존성&lt;span class="hx:absolute hx:-mt-20" id="배포-의존성">&lt;/span>
&lt;a href="#%eb%b0%b0%ed%8f%ac-%ec%9d%98%ec%a1%b4%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>또 다른 문제도 있습니다. 마찬가지로 &lt;code>users&lt;/code> 테이블에 컬럼이 삭제 됐다고 가정해봅시다.&lt;/p>
&lt;p>관련있는 모든 팀이 모여서 어떻게 어떻게 협의까지 끝냈고, 각 서비스들이 해당 컬럼을 사용하고 있는지 전수조사를 통해 힘겹지만 결국 확인했다고 해보겠습니다.&lt;/p>
&lt;p>그런데 조사해보니 모든 서비스가 이 컬럼을 참조하고 있었을 수도 있겠죠? 그렇다면 해당 컬럼을 삭제하기 위해서는 모든 서비스들이 이 변경사항을 반영하도록 코드를 수정하고 배포해야 합니다. 즉, 서비스 간 배포 의존성이 생깁니다.&lt;/p>
&lt;p>서비스는 분리되어 있는데 배포는 함께 해야하는 일이 발생합니다. 이 역시 무늬만 MSA가 되는 셈이죠.&lt;/p>
&lt;h4>장애 전파&lt;span class="hx:absolute hx:-mt-20" id="장애-전파">&lt;/span>
&lt;a href="#%ec%9e%a5%ec%95%a0-%ec%a0%84%ed%8c%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>&lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-3-communication/">3편&lt;/a>에서 장애 전파에 대해 이야기했는데, DB를 공유하면 여기서도 문제가 생깁니다. 하나의 서비스에서 무거운 쿼리를 날리거나 Lock을 오래 잡으면, 다른 서비스들도 영향을 받습니다.&lt;/p>
&lt;p>서비스는 분리되어 있는데 장애는 전파되는 일이 발생합니다. Noisy Neighbor 문제라고도 하죠. 결국 장애 격리가 안되고 이는 위 두 문제들과 마찬가지로 &lt;strong>MSA의 이점을 버리는 셈&lt;/strong>에 가깝다고 생각합니다.&lt;/p>
&lt;p>이런 MSA의 이점을 버리는 선택을 한다면 왜 굳이 MSA를 선택했는지 의문이 들 수밖에 없지 않나 싶습니다.&lt;/p>
&lt;h3>그래서 결국&lt;span class="hx:absolute hx:-mt-20" id="그래서-결국">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%9e%98%ec%84%9c-%ea%b2%b0%ea%b5%ad" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그래서 결국 저는 MSA 환경에서의 공유 DB는 MSA를 통해 얻고자 하는 많은 이점들을 희생시키고 &lt;strong>MSA의 핵심 가치인 독립성을 훼손&lt;/strong>시킨다고 생각합니다. 서비스 레벨만 분리되고 데이터 레벨은 여전히 결합되어버려 겉보기에만 MSA가 되는 셈이니까요.&lt;/p>
&lt;p>그렇기 때문에 &amp;ldquo;MSA를 제대로 하려면 결국 DB도 분리해야 한다&amp;quot;는 결론에 도달할 수 밖에 없지 않나 싶습니다.&lt;/p>
&lt;p>물론 위 문제들을 해결하기 위한 방법들도 있긴 합니다. 예를 들어 스키마 변경의 공포는 &lt;strong>Schema Versioning&lt;/strong>으로, 배포 의존성은 &lt;strong>Backward Compatibility&lt;/strong>로, 장애 전파는 &lt;strong>Connection Pool 분리&lt;/strong>나 &lt;strong>쿼리 타임아웃&lt;/strong>으로 어느정도 완화할 수 있겠죠. 하지만 이런 방법들은 결국 공유 DB의 근본적인 문제를 해결하지는 못한다고 생각합니다.&lt;/p>
&lt;h2>Database per Service&lt;span class="hx:absolute hx:-mt-20" id="database-per-service">&lt;/span>
&lt;a href="#database-per-service" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>그렇다면 이제 DB의 분리가 필요하다는 부분에 대해 팀 모두가 동의했다고 가정하고, 다음 질문으로 넘어가 보겠습니다. MSA에서 저희는 DB를 어떤 기준으로 나눠야 할까요?&lt;/p>
&lt;p>MSA에 대해 조금이라도 공부해보신 분들은 &amp;ldquo;Database per Service&amp;quot;라는 말을 한 번쯤은 들어보셨을 겁니다. 말 그대로 &lt;strong>서비스마다 자기만의 DB를 가지는&lt;/strong> 아키텍처 패턴이죠.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Services[&amp;#34;서비스들&amp;#34;]
Order[&amp;#34;주문 서비스&amp;#34;]
User[&amp;#34;회원 서비스&amp;#34;]
Product[&amp;#34;상품 서비스&amp;#34;]
end
Order --&amp;gt; OrderDB[(주문 DB)]
User --&amp;gt; UserDB[(회원 DB)]
Product --&amp;gt; ProductDB[(상품 DB)]
style OrderDB fill:#4ecdc4
style UserDB fill:#4ecdc4
style ProductDB fill:#4ecdc4
&lt;/pre>&lt;p>제가 생각하는 &amp;ldquo;Database per Service&amp;quot;의 가장 큰 장점은 &lt;strong>기준이 명확하다&lt;/strong>는 점입니다. &amp;ldquo;DB를 어디서 어떻게 나눠야 하지?&amp;ldquo;라는 고민 없이, 서비스 단위로 나누면 되니까요.&lt;/p>
&lt;p>또 다른 장점으로는 &lt;strong>Polyglot Persistence&lt;/strong>가 가능해진다는 점입니다. 서비스마다 자기만의 DB를 가지니까, 각 서비스의 특성에 맞는 DB 기술을 선택할 수 있습니다. 주문 서비스는 트랜잭션이 중요하니 RDB를, 검색 서비스는 전문 검색이 필요하니 Elasticsearch를, 세션 저장소는 빠른 읽기/쓰기가 필요하니 Redis를 사용하는 식이죠. 공유 DB에서는 모든 서비스가 하나의 DB 기술에 종속되지만, DB를 분리하면 이런 유연성을 얻을 수 있게 됩니다.&lt;/p>
&lt;h3>다른 분리 전략들&lt;span class="hx:absolute hx:-mt-20" id="다른-분리-전략들">&lt;/span>
&lt;a href="#%eb%8b%a4%eb%a5%b8-%eb%b6%84%eb%a6%ac-%ec%a0%84%eb%9e%b5%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>물론 &amp;ldquo;Database per Service&amp;quot;만이 유일한 방법은 아닙니다. 몇 가지 대안도 있습니다.&lt;/p>
&lt;h4>Schema per Service&lt;span class="hx:absolute hx:-mt-20" id="schema-per-service">&lt;/span>
&lt;a href="#schema-per-service" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>Schema per Service는 물리적으로는 하나의 DB 인스턴스를 사용하지만, 서비스마다 별도의 스키마로 논리적 분리를 하는 방식입니다. 운영 비용을 줄일 수 있고 초기 단계에서 부담이 적습니다. 같은 DB 인스턴스이기 때문에 Cross-schema JOIN이 가능하고 트랜잭션도 원하면 묶을 수 있습니다. MySQL이든 PostgreSQL이든 동일한 인스턴스 내 스키마 간에는 별도 설정 없이 Cross-schema JOIN과 트랜잭션이 가능합니다.&lt;/p>
&lt;p>참고로 PostgreSQL에서 &lt;code>dblink&lt;/code>나 &lt;code>postgres_fdw&lt;/code>가 필요한 건 스키마가 아닌 &lt;strong>다른 데이터베이스&lt;/strong>에 접근할 때입니다. PostgreSQL에서 &amp;ldquo;스키마&amp;quot;와 &amp;ldquo;데이터베이스&amp;quot;는 다른 개념이거든요.&lt;/p>
&lt;p>다만 문제는 결국은 공유 DB이기 때문에 Noisy Neighbor 문제는 여전히 남아있고, 결국 앞서 언급한 공유 DB의 문제들(스키마 변경의 공포, 배포 의존성)에서 완전히 자유롭지는 못합니다.&lt;/p>
&lt;h4>Database per Bounded Context&lt;span class="hx:absolute hx:-mt-20" id="database-per-bounded-context">&lt;/span>
&lt;a href="#database-per-bounded-context" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>Database per Bounded Context는 서비스 단위가 아닌 도메인(Bounded Context) 단위로 DB를 나누는 방식입니다. 같은 도메인에 속한 여러 서비스가 하나의 DB를 공유할 수 있어서 트랜잭션 경계를 더 유연하게 가져갈 수 있습니다.&lt;/p>
&lt;p>다만 도메인 간에는 여전히 분산 DB의 문제가 발생합니다.&lt;/p>
&lt;p>정리하자면, Schema per Service는 공유 DB의 문제를 일부 안고 가는 대신 분산 DB의 복잡성을 피하는 방식이고, Database per Service나 Database per Bounded Context는 완전한 격리를 얻는 대신 분산 DB의 문제를 감수하는 방식입니다.&lt;/p>
&lt;h3>결국 중요한 건&lt;span class="hx:absolute hx:-mt-20" id="결국-중요한-건">&lt;/span>
&lt;a href="#%ea%b2%b0%ea%b5%ad-%ec%a4%91%ec%9a%94%ed%95%9c-%ea%b1%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>어떤 방식을 선택하든 결국 트레이드오프가 있고, &lt;strong>DB가 물리적으로 분리되는 순간 분산 DB가 가지게 되는 문제들은 발생하게 됩니다.&lt;/strong> 분리의 &amp;ldquo;기준&amp;quot;보다는 분리로 인해 발생하는 &amp;ldquo;문제&amp;quot;를 어떻게 다룰 것인가가 더 중요한 문제라고 볼 수 있습니다.&lt;/p>
&lt;p>그래서 이 글에서는 가장 보편적으로 사용되는 &amp;ldquo;Database per Service&amp;quot;를 기준으로 설명을 이어가겠습니다. 어떤 방식을 선택하든 아래에서 다룰 문제들과 해결책은 동일하게 적용되니까요.&lt;/p>
&lt;p>자, 그럼 DB를 분리하면 어떤 문제들이 생기는지 살펴보겠습니다. 이 문제들이 꽤나 골치아픕니다.&lt;/p>
&lt;h3>JOIN이 안 됩니다&lt;span class="hx:absolute hx:-mt-20" id="join이-안-됩니다">&lt;/span>
&lt;a href="#join%ec%9d%b4-%ec%95%88-%eb%90%a9%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>먼저 첫번째는 쉽게 예상하실수 있겠지만 생각보다 까다로운 &lt;strong>JOIN이 안된다&lt;/strong>는 문제입니다.&lt;/p>
&lt;p>공유 DB에서는 주문 상세 정보를 조회할 때 회원 이름이랑 상품 정보까지 한 번에 가져오고 싶다면 당연하게도 이런 쿼리가 가능했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">o&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">u&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">u&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">email&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">p&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">title&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">orders&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">o&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">JOIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">users&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">u&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">o&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">user_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">u&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">JOIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">products&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">p&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">o&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">product_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">p&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">o&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;example&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>한 번의 쿼리로 주문, 회원, 상품 정보를 다 가져올 수 있었죠. 아마 개발을 하시면서 수도 없이 작성해보셨을 쿼리이지 않을까 싶습니다.&lt;/p>
&lt;p>하지만 DB가 분리되면 각 DB가 개별적으로 존재하기 때문에 이런 쿼리는 불가능해집니다. 주문 DB에는 회원 테이블이 없고, 회원 DB에는 주문 테이블이 없습니다.&lt;/p>
&lt;p>그렇기 때문에 &lt;strong>하나의 DB 엔진이 연산해주는 SQL JOIN은 사용할 수 없게 됩니다.&lt;/strong> 그래서 각 DB에 따로 쿼리해서 애플리케이션에서 조합하거나 다른 방법을 사용 해야 합니다.&lt;/p>
&lt;p>벌써부터 이건 어떻게 해결해야하나 복잡해지는 느낌이 드시나요? 해결 가능한 방법들은 뒤에서 더 자세히 다루겠습니다.&lt;/p>
&lt;h3>트랜잭션이 안 됩니다&lt;span class="hx:absolute hx:-mt-20" id="트랜잭션이-안-됩니다">&lt;/span>
&lt;a href="#%ed%8a%b8%eb%9e%9c%ec%9e%ad%ec%85%98%ec%9d%b4-%ec%95%88-%eb%90%a9%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>두번째 문제는 JOIN과 마찬가지로 하나의 DB 엔진이 처리해주던 &lt;strong>트랜잭션이 안 된다&lt;/strong>는 점입니다.&lt;/p>
&lt;p>이번에는 콘서트 예매를 생각해 보겠습니다. 콘서트 티켓을 예매하려면 다음 세 가지 작업이 필요합니다.&lt;/p>
&lt;ol>
&lt;li>좌석 예약 (좌석 서비스)&lt;/li>
&lt;li>결제 처리 (결제 서비스)&lt;/li>
&lt;li>티켓 발급 (티켓 서비스)&lt;/li>
&lt;/ol>
&lt;p>공유 DB 환경에서는 이 세 작업을 하나의 트랜잭션으로 묶을 수 있었습니다. 결제가 실패하면 좌석 예약도 자동으로 롤백되죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">BEGIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TRANSACTION&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">-- 1. 좌석 예약
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">UPDATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">seats&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">SET&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">status&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;RESERVED&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">123&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">seat_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;A-15&amp;#39;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AND&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">status&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;AVAILABLE&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">-- 2. 결제 처리
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">INSERT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">INTO&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">payments&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">user_id&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">amount&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">status&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">VALUES&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">123&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">150000&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;COMPLETED&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">-- 3. 티켓 발급
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">INSERT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">INTO&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">tickets&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">user_id&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">seat_id&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">concert_id&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">VALUES&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">123&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;A-15&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;concert-2024&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">COMMIT&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">-- 하나라도 실패하면 전체 ROLLBACK!&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>하지만 DB가 분리되면 어떻게 될까요? 좌석 테이블은 좌석 DB에, 결제 테이블은 결제 DB에, 티켓 테이블은 티켓 DB에 있습니다.&lt;/p>
&lt;p>개별적인 DB로 운영되기때문에 &lt;strong>하나의 트랜잭션으로 묶을 수가 없습니다.&lt;/strong> 분산 트랜잭션이 필요해지는데, 이게 생각보다 훨씬 복잡합니다. 이 부분도 뒤에서 자세히 다루겠습니다.&lt;/p>
&lt;h3>데이터 일관성이 깨집니다&lt;span class="hx:absolute hx:-mt-20" id="데이터-일관성이-깨집니다">&lt;/span>
&lt;a href="#%eb%8d%b0%ec%9d%b4%ed%84%b0-%ec%9d%bc%ea%b4%80%ec%84%b1%ec%9d%b4-%ea%b9%a8%ec%a7%91%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>위 예시를 이어서 생각해보겠습니다. 좌석 예약은 성공했고, 결제도 성공했는데, 티켓 발급에서 실패하면 어떻게 될까요?&lt;/p>
&lt;p>공유 DB에서는 트랜잭션만 잘 사용했다면 전체가 롤백되니까 크게 문제가 없습니다. 하지만 DB가 분리된 MSA에서는 &lt;strong>결제는 완료됐는데 티켓은 없는&lt;/strong> 상태가 될 수 있습니다. 사용자 입장에서는 돈은 빠져나갔는데 티켓은 없는 황당한 상황이 되는 거죠.&lt;/p>
&lt;p>이게 바로 &lt;strong>분산 환경에서의 데이터 정합성 문제&lt;/strong>입니다. 각 서비스가 독립적으로 커밋하기 때문에, 중간에 실패가 발생하면 일부는 성공하고 일부는 실패한 상태로 남게 됩니다. 이 문제를 어떻게 해결할지가 MSA의 큰 숙제라고 볼 수 있습니다.&lt;/p>
&lt;p>지금까지 설명드린 문제들은 모두 &lt;strong>DB 분리로 인해 발생하는 문제들&lt;/strong>입니다. 정리하자면 다음과 같습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>JOIN이 안 된다&lt;/strong> → 다른 서비스의 데이터를 어떻게 가져올 것인가?&lt;/li>
&lt;li>&lt;strong>트랜잭션이 안 된다&lt;/strong> → 여러 서비스에 걸친 작업을 어떻게 원자적으로 처리할 것인가?&lt;/li>
&lt;li>&lt;strong>일관성이 깨진다&lt;/strong> → 분산된 데이터의 정합성을 어떻게 맞출 것인가?&lt;/li>
&lt;/ol>
&lt;p>이제부터는 이 문제들을 어떻게 해결할 수 있는지 하나씩 살펴보겠습니다.&lt;/p>
&lt;h2>다른 서비스의 데이터가 필요할 때&lt;span class="hx:absolute hx:-mt-20" id="다른-서비스의-데이터가-필요할-때">&lt;/span>
&lt;a href="#%eb%8b%a4%eb%a5%b8-%ec%84%9c%eb%b9%84%ec%8a%a4%ec%9d%98-%eb%8d%b0%ec%9d%b4%ed%84%b0%ea%b0%80-%ed%95%84%ec%9a%94%ed%95%a0-%eb%95%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>먼저 JOIN이 안 되는 문제부터 살펴보겠습니다. 구체적인 상황을 가정하고 진행해보겠습니다.&lt;/p>
&lt;p>저희는 MSA 환경에서 주문 서비스에 &amp;ldquo;주문 상세 조회&amp;quot;를 만들어야 하는 Task를 받게 됐습니다. 화면에 보여줄 정보는&lt;/p>
&lt;ul>
&lt;li>주문 정보 (주문 서비스 DB)&lt;/li>
&lt;li>주문한 회원의 이름, 연락처 (회원 서비스 DB)&lt;/li>
&lt;li>주문한 상품의 이름, 가격 (상품 서비스 DB)&lt;/li>
&lt;/ul>
&lt;p>이렇게 세 가지입니다. 공유 DB를 사용하고 있었다면 주문 서비스에서 JOIN해 한 번에 가져올 수 있었겠지만, 이제는 DB가 분리되어 있으니 불가능합니다.&lt;/p>
&lt;h3>프론트에서 각각 호출하면 안 되나요?&lt;span class="hx:absolute hx:-mt-20" id="프론트에서-각각-호출하면-안-되나요">&lt;/span>
&lt;a href="#%ed%94%84%eb%a1%a0%ed%8a%b8%ec%97%90%ec%84%9c-%ea%b0%81%ea%b0%81-%ed%98%b8%ec%b6%9c%ed%95%98%eb%a9%b4-%ec%95%88-%eb%90%98%eb%82%98%ec%9a%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&amp;ldquo;그냥 프론트에서 3개 API 각각 호출하면 되는 거 아니에요?&amp;ldquo;라고 생각하실 수도 있습니다. 물론 가능합니다. 하지만 몇 가지 문제가 있습니다.&lt;/p>
&lt;p>첫째, &lt;strong>네트워크 요청이 늘어납니다.&lt;/strong> 모바일 환경이나 네트워크가 불안정한 상황에서는 3번의 API 호출이 부담이 될 수 있습니다. 특히 하나의 화면을 그리기 위해 여러 번 왔다갔다하면 사용자 경험이 나빠지게 되겠죠.&lt;/p>
&lt;p>둘째, &lt;strong>프론트엔드가 백엔드 구조를 알아야 합니다.&lt;/strong> &amp;ldquo;주문 상세를 보려면 주문 API, 회원 API, 상품 API를 각각 호출해야 해&amp;quot;라는 지식이 프론트에 스며들게 됩니다. 나중에 백엔드 구조가 바뀌면 프론트도 함께 수정해야 하고요.&lt;/p>
&lt;p>셋째, &lt;strong>권한 처리가 복잡해집니다.&lt;/strong> 주문 상세를 볼 권한이 있으면 해당 주문에 연관된 회원 정보나 상품 정보도 볼 수 있어야 하는데, 각 API가 분리되어 있으면 이런 권한 체계를 일관되게 관리하기가 어려워질 수 있습니다.&lt;/p>
&lt;p>그래서 보통은 백엔드에서 이 문제를 해결하는 선택을 하게 되는 것 같습니다. 그렇다면 백엔드에서는 어떻게 여러 서비스의 데이터를 조합할 수 있을까요?&lt;/p>
&lt;h3>해결책 1: API Composition&lt;span class="hx:absolute hx:-mt-20" id="해결책-1-api-composition">&lt;/span>
&lt;a href="#%ed%95%b4%ea%b2%b0%ec%b1%85-1-api-composition" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>먼저 생각해볼 수 있는 방법은 가장 직관적인 방법인 것 같습니다. &lt;strong>필요할 때마다 다른 서비스의 API를 호출&lt;/strong>해서 데이터를 가져오는 거죠.&lt;/p>
&lt;p>기존에 모놀리식에서도 외부 협력사의 API를 호출해서 데이터를 조회하는 경우들도 있었으니, 이와 같은거라 생각하시면 됩니다.&lt;/p>
&lt;p>REST API 혹은 gRPC 같은 통신 방식을 사용해 주문 서비스에서 회원 서비스와 상품 서비스의 API를 호출해서 데이터를 가져오면 됩니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">OrderDetailResponse&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">getOrderDetail&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Long&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">orderId&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 먼저 내 DB에서 주문 정보 조회&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">Order&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">order&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">orderRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">findById&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">orderId&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 다른 서비스 API 호출해서 필요한 데이터 가져오기&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">UserResponse&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">userClient&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getUser&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">order&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getUserId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ProductResponse&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">product&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">productClient&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getProduct&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">order&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getProductId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 조합해서 반환&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">OrderDetailResponse&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">builder&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">order&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">order&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">userName&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getName&lt;/span>&lt;span class="p">())&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">productTitle&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">product&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getTitle&lt;/span>&lt;span class="p">())&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">build&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>구현이 단순하고 직관적입니다. 그리고 &lt;strong>항상 최신 데이터&lt;/strong>를 가져온다는 장점도 있죠. 회원 서비스에서 회원분 이름이 바뀌면 바로 반영됩니다.&lt;/p>
&lt;p>하지만 잠깐 생각해봐도 이 방법에는 단점들이 존재합니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>지연 시간 증가&lt;/strong>: 하나의 요청을 처리하기 위해 여러 API를 호출하니 당연히 느려집니다. 네트워크 왕복이 추가되니까요.&lt;/li>
&lt;li>&lt;strong>장애 전파&lt;/strong>: &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-3-communication/">3편&lt;/a>에서 다뤘던 문제죠. 회원 서비스가 죽으면 주문 조회도 안 됩니다. 회원 이름 하나 때문에 전체가 실패하는 거죠. 물론 장애 격리 패턴을 적용할 수는 있지만, 의존성이 있다는 사실 자체는 변하지 않습니다.&lt;/li>
&lt;li>&lt;strong>N+1 문제&lt;/strong>: 주문 목록 조회를 생각해보세요. 주문 10개를 조회하면 회원 API 10번, 상품 API 10번&amp;hellip; 성능에 영향을 미치게 될 가능성이 높습니다. 물론 Batch API(예: &lt;code>GET /users?ids=1,2,3,4,5&lt;/code>)를 만들어서 한 번에 여러 건을 조회하는 방식으로 완화할 수 있지만 이렇게 되면 API 설계가 복잡해지고, 모든 상황에 적용 가능한 것도 아니라서 근본적인 해결책이라고 보기는 어려운 것 같습니다.&lt;/li>
&lt;/ul>
&lt;h3>해결책 2: 데이터 복제&lt;span class="hx:absolute hx:-mt-20" id="해결책-2-데이터-복제">&lt;/span>
&lt;a href="#%ed%95%b4%ea%b2%b0%ec%b1%85-2-%eb%8d%b0%ec%9d%b4%ed%84%b0-%eb%b3%b5%ec%a0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>두 번째 방법은 &lt;strong>필요한 데이터를 미리 내 DB에 복사해두는 것&lt;/strong>입니다.&lt;/p>
&lt;p>주문 서비스에도 회원 정보에 대한 복제 테이블을 만들어두고, 회원 서비스에서 회원 정보가 생성되거나 변경될 때마다 이벤트를 발행해서 주문 서비스가 이를 구독하도록 하는 방식입니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
subgraph UserService[&amp;#34;회원 서비스&amp;#34;]
UserDB[(회원 DB)]
end
subgraph OrderService[&amp;#34;주문 서비스&amp;#34;]
OrderDB[(주문 DB&amp;lt;br/&amp;gt;+ 회원 복제 테이블)]
end
UserDB --&amp;gt;|&amp;#34;회원 정보 변경 시&amp;lt;br/&amp;gt;이벤트 발행&amp;#34;| OrderDB
style UserDB fill:#4ecdc4
style OrderDB fill:#4ecdc4
&lt;/pre>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 회원 정보 변경 이벤트를 받아서 복제 테이블 업데이트&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@EventListener&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">onUserUpdated&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">UserUpdatedEvent&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">userReplicaRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">save&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">UserReplica&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">from&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">// 조회할 때는 내 DB에서 바로 가져옴&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">OrderDetailResponse&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">getOrderDetail&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Long&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">orderId&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">Order&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">order&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">orderRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">findById&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">orderId&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 내 DB에서 조회 - 빠르고 안정적!&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">UserReplica&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">userReplicaRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">findById&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">order&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getUserId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">OrderDetailResponse&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">builder&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">order&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">order&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">userName&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getName&lt;/span>&lt;span class="p">())&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">build&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>같은 DB 엔진에서 조회해오기 때문에 원한다면 JOIN을 사용할 수도 있고, 트랜잭션도 보장할 수 있습니다. 그리고 &lt;strong>장애 격리&lt;/strong>도 됩니다. 회원 서비스가 죽어도 주문 조회는 가능하죠.&lt;/p>
&lt;p>물론 이 방식도 단점이 있습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>데이터 불일치 가능성&lt;/strong>: 이벤트가 지연되면 잠시 동안 오래된 데이터가 보일 수 있습니다. 이벤트 유실로 인해 데이터 정합성 문제가 발생할 수도 있고요. (이 문제는 Transactional Outbox 패턴이나 Kafka 같은 신뢰성 있는 메시지 브로커를 사용해서 해결할 수 있는데, 자세한 내용은 &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-6-event-consistency/">6편&lt;/a>에서 다루겠습니다.)&lt;/li>
&lt;li>&lt;strong>저장 공간 증가&lt;/strong>: 같은 데이터를 여러 곳에 저장하기 때문에 저장 공간이 더 필요합니다.&lt;/li>
&lt;li>&lt;strong>동기화 로직 관리&lt;/strong>: 이벤트 처리 로직을 만들고 유지보수해야 합니다.&lt;/li>
&lt;/ul>
&lt;h4>복제 테이블은 조회 전용이다&lt;span class="hx:absolute hx:-mt-20" id="복제-테이블은-조회-전용이다">&lt;/span>
&lt;a href="#%eb%b3%b5%ec%a0%9c-%ed%85%8c%ec%9d%b4%eb%b8%94%ec%9d%80-%ec%a1%b0%ed%9a%8c-%ec%a0%84%ec%9a%a9%ec%9d%b4%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>여기서 중요한 점이 있습니다. 이렇게 만든 복제 테이블은 &lt;strong>조회 전용&lt;/strong>입니다. 주문 서비스에서 회원 복제 테이블에 직접 INSERT나 UPDATE를 하면 안 됩니다. 왜냐하면 회원 데이터의 원본은 회원 서비스에 있으니까요.&lt;/p>
&lt;p>복제 테이블의 데이터는 &lt;strong>오직 이벤트를 통해서만&lt;/strong> 변경되어야 합니다. 그래야 원본과 복제본의 일관성이 유지됩니다.&lt;/p>
&lt;p>이렇게 쓰기(원본 서비스)와 읽기(복제 테이블)를 분리하는 패턴을 &lt;strong>CQRS(Command Query Responsibility Segregation)&lt;/strong> 라고 부릅니다.&lt;/p>
&lt;h4>CQRS, 왜 이런 패턴이 생겼을까&lt;span class="hx:absolute hx:-mt-20" id="cqrs-왜-이런-패턴이-생겼을까">&lt;/span>
&lt;a href="#cqrs-%ec%99%9c-%ec%9d%b4%eb%9f%b0-%ed%8c%a8%ed%84%b4%ec%9d%b4-%ec%83%9d%ea%b2%bc%ec%9d%84%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>CQRS는 이름 그대로 &lt;strong>Command(쓰기)&lt;/strong> 와 &lt;strong>Query(읽기)&lt;/strong> 의 책임을 분리하는 패턴입니다. 처음 들으면 &amp;ldquo;왜 굳이 분리하지?&amp;ldquo;라는 생각이 들 수 있는데, MSA에서 데이터 복제를 하다 보면 자연스럽게 이 패턴을 적용하게 됩니다.&lt;/p>
&lt;p>생각해보면 전통적인 CRUD 아키텍처에서는 하나의 모델로 읽기와 쓰기를 모두 처리합니다. &lt;code>User&lt;/code> 엔티티로 사용자를 생성하고, 수정하고, 조회하죠. 간단한 애플리케이션에서는 이게 충분합니다.&lt;/p>
&lt;p>하지만 시스템이 복잡해지면 읽기와 쓰기의 요구사항이 달라지기 시작합니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>쓰기&lt;/strong>: 비즈니스 규칙 검증, 정합성 보장, 트랜잭션 처리가 중요&lt;/li>
&lt;li>&lt;strong>읽기&lt;/strong>: 빠른 응답 속도, 다양한 조회 조건, 여러 데이터의 조합이 중요&lt;/li>
&lt;/ul>
&lt;p>하나의 모델로 이 두 가지를 다 만족시키려다 보면 어느 쪽도 제대로 못하게 되는 경우가 생깁니다. 조회 성능을 위해 비정규화를 하면 쓰기가 복잡해지고, 쓰기를 위해 정규화를 하면 조회할 때 JOIN이 늘어나고요.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Traditional[&amp;#34;전통적인 CRUD&amp;#34;]
Client1[클라이언트] --&amp;gt; Model[User 모델]
Model --&amp;gt; DB1[(DB)]
end
&lt;/pre>&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph CQRS[&amp;#34;CQRS 패턴&amp;#34;]
Client2[클라이언트] --&amp;gt;|Command| WriteModel[쓰기 모델]
Client2 --&amp;gt;|Query| ReadModel[읽기 모델]
WriteModel --&amp;gt; WriteDB[(쓰기 DB)]
WriteDB --&amp;gt;|이벤트/동기화| ReadDB[(읽기 DB)]
ReadModel --&amp;gt; ReadDB
end
&lt;/pre>&lt;p>CQRS는 이 문제를 &lt;strong>&amp;ldquo;그냥 분리하자&amp;rdquo;&lt;/strong> 라는 단순한 아이디어로 해결합니다. 쓰기는 쓰기에 최적화된 모델로, 읽기는 읽기에 최적화된 모델로 각각 처리하는 거죠.&lt;/p>
&lt;h4>MSA에서 CQRS가 자연스러운 이유&lt;span class="hx:absolute hx:-mt-20" id="msa에서-cqrs가-자연스러운-이유">&lt;/span>
&lt;a href="#msa%ec%97%90%ec%84%9c-cqrs%ea%b0%80-%ec%9e%90%ec%97%b0%ec%8a%a4%eb%9f%ac%ec%9a%b4-%ec%9d%b4%ec%9c%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>그런데 저희가 앞에서 다룬 &lt;strong>데이터 복제&lt;/strong> 방식을 다시 보면, 이미 CQRS를 적용하고 있다는 걸 알 수 있습니다.&lt;/p>
&lt;ul>
&lt;li>회원 정보의 &lt;strong>원본(쓰기)&lt;/strong> 은 회원 서비스에 있고 주문 서비스의 &lt;strong>복제 테이블(읽기)&lt;/strong> 은 조회 전용 테이블이 됩니다. 두 저장소는 &lt;strong>이벤트를 통해&lt;/strong> 동기화되죠.&lt;/li>
&lt;/ul>
&lt;p>MSA에서 데이터 복제를 하면 자연스럽게 CQRS 구조가 되는 겁니다. 원본 서비스가 Command를 담당하고, 복제 테이블이 Query를 담당하는 거죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 회원 서비스 (Command 담당 - 원본)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Service&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">UserService&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">updateUserName&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Long&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">newName&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">User&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">userRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">findById&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">changeName&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">newName&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 비즈니스 규칙 검증&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">userRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">save&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">eventPublisher&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">publish&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">UserNameChangedEvent&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">newName&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">// 주문 서비스 (Query 담당 - 복제본)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Service&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">OrderQueryService&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">OrderDetailResponse&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">getOrderDetail&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Long&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">orderId&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 복제 테이블에서 빠르게 조회&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">orderDetailViewRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">findByOrderId&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">orderId&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>혹시 놓치실 수 있는 부분이 한가지 있다면 복제 DB의 스키마 구조는 꼭 원본 DB와 동일할 필요가 없다는 점입니다. 읽기 모델은 조회에 최적화된 구조로 마음껏 설계할 수 있습니다. 불필요한건 덜어내고 필요한건 더 추가해서요.&lt;/p>
&lt;p>예를 들어 유저 서비스의 &lt;code>User&lt;/code> 테이블의 스키마는 아래와 같다면&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">CREATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Users&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">BIGINT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">PRIMARY&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">KEY&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">100&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">email&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">100&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">password_hash&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">255&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">created_at&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TIMESTAMP&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">updated_at&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TIMESTAMP&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">);&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>주문 서비스에서 회원 정보를 조회할 때는 이름과 이메일만 필요하다고 가정해보겠습니다. 그럼 주문 서비스의 복제 테이블은 이렇게 설계할 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">CREATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">UserReplica&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">BIGINT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">PRIMARY&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">KEY&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">100&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">email&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">100&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">);&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h4>CQRS의 진짜 장점&lt;span class="hx:absolute hx:-mt-20" id="cqrs의-진짜-장점">&lt;/span>
&lt;a href="#cqrs%ec%9d%98-%ec%a7%84%ec%a7%9c-%ec%9e%a5%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>CQRS를 적용하면 읽기와 쓰기를 &lt;strong>독립적으로 최적화&lt;/strong>할 수 있습니다.&lt;/p>
&lt;p>정규화에 얽매일 필요 없이, 화면에 필요한 데이터를 미리 JOIN해서 저장해두면 됩니다. JOIN 없이 한 번의 쿼리로 필요한 데이터를 다 가져올 수 있죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 주문 상세 화면에 딱 맞는 구조로 저장&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Entity&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">OrderDetailView&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Long&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">orderId&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">orderStatus&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">LocalDateTime&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">orderDate&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 회원 정보 (복제)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">userName&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">userEmail&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 상품 정보 (복제)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">productName&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Integer&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">productPrice&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// JOIN 없이 한 방 쿼리로 조회 가능!&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>원본 서비스는 조회 성능을 신경 쓸 필요 없이 비즈니스 로직과 데이터 정합성에만 집중할 수 있습니다. 정규화된 구조를 유지하면서 도메인 규칙을 깔끔하게 구현할 수 있죠. 읽기 트래픽이 많으면 읽기 DB만 스케일 아웃하면 됩니다. 쓰기와 읽기의 부하가 서로 영향을 주지 않게 됩니다.&lt;/p>
&lt;h4>CQRS의 대가&lt;span class="hx:absolute hx:-mt-20" id="cqrs의-대가">&lt;/span>
&lt;a href="#cqrs%ec%9d%98-%eb%8c%80%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>물론 CQRS에도 대가가 있습니다. 모델이 두 개가 되니 관리할 코드가 늘어나게 됩니다. 자연스럽게 복잡도가 증가하죠.&lt;/p>
&lt;p>그리고 쓰기 후 읽기 모델에 반영되기까지 시간차가 있습니다. &amp;ldquo;방금 수정했는데 왜 안 바뀌어 있지?&amp;ldquo;라는 상황이 발생할 수 있죠. 이벤트 처리, 실패 시 재처리 등도 고려해야 합니다. 이 부분은 &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-6-event-consistency/">6편&lt;/a>에서 좀더 자세히 다루도록 하겠습니다.&lt;/p>
&lt;p>그래서 CQRS는 &lt;strong>복잡한 도메인&lt;/strong>이나 &lt;strong>읽기/쓰기 패턴이 다른 경우&lt;/strong>에 효과적이라고 생각합니다. 단순한 CRUD 앱에는 과한 선택일 수 있고요. 다만 MSA에서 데이터 복제를 선택했다면, 이미 CQRS의 구조를 따르게 되니 자연스럽게 적용되는 셈이라고 저는 생각합니다.&lt;/p>
&lt;p>참고로 CQRS는 &lt;strong>Event Sourcing&lt;/strong>과 함께 언급되는 경우가 많은것 같습니다. 다만 저는 둘은 독립적인 패턴이라고 생각합니다. Event Sourcing은 상태 변경을 이벤트의 연속으로 저장하는 패턴인데, CQRS와 궁합이 좋아서 같이 사용되는 경우가 많은 것 같습니다. 하지만 CQRS는 Event Sourcing 없이도 충분히 적용할 수 있고, 이 글에서 Event Sourcing은 별도로 다루지 않으려고 합니다. &amp;ldquo;CQRS 하면 Event Sourcing도 해야 하는 거 아니야?&amp;ldquo;라고 오해하실 수 있어서 한번 짚고 넘어가는 가고 싶었습니다. 기회가 있다면 Event Sourcing도 따로 다른 글에서 다뤄보도록 하겠습니다.&lt;/p>
&lt;h3>언제 무엇을 선택해야할까요?&lt;span class="hx:absolute hx:-mt-20" id="언제-무엇을-선택해야할까요">&lt;/span>
&lt;a href="#%ec%96%b8%ec%a0%9c-%eb%ac%b4%ec%97%87%ec%9d%84-%ec%84%a0%ed%83%9d%ed%95%b4%ec%95%bc%ed%95%a0%ea%b9%8c%ec%9a%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>상황&lt;/th>
&lt;th>권장 방식&lt;/th>
&lt;th>이유&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>실시간성이 중요한 경우&lt;/td>
&lt;td>API Composition&lt;/td>
&lt;td>항상 최신 데이터 보장&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>조회 성능이 중요한 경우&lt;/td>
&lt;td>데이터 복제&lt;/td>
&lt;td>네트워크 호출 없이 빠른 조회&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>데이터 변경이 자주 없는 경우&lt;/td>
&lt;td>데이터 복제&lt;/td>
&lt;td>동기화 부담이 적음&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>장애 격리가 중요한 경우&lt;/td>
&lt;td>데이터 복제&lt;/td>
&lt;td>다른 서비스 장애에 영향 없음&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>구현 복잡도를 낮추고 싶은 경우&lt;/td>
&lt;td>API Composition&lt;/td>
&lt;td>이벤트 처리 로직 불필요&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>개인적으로 저는 조회가 많은 서비스에서는 &lt;strong>데이터 복제를 더 선호&lt;/strong>하는 편입니다. API Composition은 처음엔 간단해 보이지만, 트래픽이 늘어나면 성능 문제가 심각해지는 경우가 꽤 있었습니다.&lt;/p>
&lt;p>데이터 복제를 해둔 상태라면 100-200ms 수준으로 응답할 API가 API Composition으론 네트워크 호출이 여러 번 겹치면서 1초가 넘게 걸리는 경우도 있었고, N+1 문제도 생각보다 자주 마주치게 됐습니다.&lt;/p>
&lt;p>물론 &amp;ldquo;무조건 데이터 복제가 좋다&amp;quot;는 얘기는 아닙니다. API Composition은 직관적이여서 초기 개발 속도도 빠르고 개발자가 더 빠르게 서비스를 이해할 수 있게 만듭니다. 실시간성이 중요한 경우에도 API Composition이 더 적합할 수 있습니다.&lt;/p>
&lt;p>결국 중요한건 상황에 따라 적절한 방식을 선택하는 거라고 생각합니다. 다만 어떤 상황에서 뭘 사용해야하는지를 명확히 알고 선택하는 게 중요하겠죠.&lt;/p>
&lt;h2>정리&lt;span class="hx:absolute hx:-mt-20" id="정리">&lt;/span>
&lt;a href="#%ec%a0%95%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이번 편에서 다룬 내용을 정리하면 다음과 같습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>공유 DB는 편하지만&lt;/strong>, MSA의 핵심 가치인 독립성을 훼손합니다. 스키마 변경의 공포, 배포 의존성, 장애 전파 문제가 발생합니다.&lt;/li>
&lt;li>&lt;strong>DB를 분리하면&lt;/strong> JOIN이 안 되고, 트랜잭션이 안 되고, 일관성이 깨집니다. 이건 피할 수 없는 트레이드오프입니다.&lt;/li>
&lt;li>&lt;strong>JOIN 대신&lt;/strong> API Composition 또는 데이터 복제를 사용할 수 있습니다.&lt;/li>
&lt;li>&lt;strong>API Composition&lt;/strong>은 직관적이지만 지연 시간 증가, 장애 전파, N+1 문제가 있습니다.&lt;/li>
&lt;li>&lt;strong>데이터 복제&lt;/strong>는 성능과 장애 격리가 좋지만, 이벤트 동기화의 복잡성을 감수해야 합니다.&lt;/li>
&lt;/ol>
&lt;p>결국 &lt;strong>데이터 분리에는 분명한 대가가 따릅니다.&lt;/strong> 오히려 MSA에서 가장 많은 고민이 필요한 부분이라고 생각합니다.&lt;/p>
&lt;p>그래서 저는 데이터 분리를 고민할 때마다 이 질문을 먼저 던져야 한다고 생각합니다. &lt;strong>&amp;ldquo;정말 이 데이터가 분리되어야 하는가?&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>기술적으로 분리할 수 있다고 해서 분리해야 하는 건 아니니까요. 함께 변경되고, 함께 조회되고, 함께 트랜잭션이 필요한 데이터라면 애초에 같은 곳에 있어야 하는 게 아닌지 고민해볼 필요가 있다고 생각합니다.&lt;/p>
&lt;h2>다음 편에서&lt;span class="hx:absolute hx:-mt-20" id="다음-편에서">&lt;/span>
&lt;a href="#%eb%8b%a4%ec%9d%8c-%ed%8e%b8%ec%97%90%ec%84%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이번 편에서는 DB를 왜 분리해야 하는지, 그리고 분리했을 때 JOIN이 안 되는 문제를 API Composition과 데이터 복제로 어떻게 해결하는지 살펴봤습니다.&lt;/p>
&lt;p>그런데 &lt;strong>&amp;ldquo;데이터 복제를 선택했다&amp;rdquo;&lt;/strong> 고 해서 끝이 아닙니다. 오히려 여기서부터 더 어려운 문제들이 시작됩니다.&lt;/p>
&lt;p>말하고 보니 어려운 문제들 뿐이네요 ㅎㅎ..&lt;/p>
&lt;p>다음 6편에서는 이벤트 기반 데이터 동기화에서 발생하는 정합성 문제들을 다루려 합니다. DB 저장과 이벤트 발행을 어떻게 원자적으로 처리할지, 이벤트 순서가 꼬이면 어떻게 되는지, 메시지가 유실되거나 중복되면 어떻게 해야 하는지, 그리고 분산 트랜잭션의 대안인 Saga 패턴까지 이야기 해보도록 하겠습니다.&lt;/p>
&lt;p>후편: &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-6-event-consistency/">[MSA에 관한 고찰 6/7편] 이벤트 기반 데이터 정합성&lt;/a>&lt;/p>
&lt;hr>
&lt;h2>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>데이터 관리 패턴&lt;span class="hx:absolute hx:-mt-20" id="데이터-관리-패턴">&lt;/span>
&lt;a href="#%eb%8d%b0%ec%9d%b4%ed%84%b0-%ea%b4%80%eb%a6%ac-%ed%8c%a8%ed%84%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>Chris Richardson - &lt;em>Microservices Patterns&lt;/em> (Manning, 2018)&lt;/li>
&lt;li>&lt;a href="https://microservices.io/patterns/data/database-per-service.html"target="_blank" rel="noopener">Microservices.io - Database per Service&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>CQRS&lt;span class="hx:absolute hx:-mt-20" id="cqrs">&lt;/span>
&lt;a href="#cqrs" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>Martin Fowler - &lt;a href="https://martinfowler.com/bliki/CQRS.html"target="_blank" rel="noopener">CQRS&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>Greg Young - &lt;em>CQRS Documents&lt;/em> (2010)&lt;/li>
&lt;/ul></description></item><item><title>[MSA에 관한 고찰 4/7편] 장애는 어떻게 전파되고, 우리는 어디서 끊어야 하는가</title><link>https://jeongil.dev/ko/blog/architecture/msa-series-4-resilience/</link><pubDate>Mon, 19 Jan 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/architecture/msa-series-4-resilience/</guid><description>
&lt;p>전편: &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-3-communication/">[MSA에 관한 고찰 3/7편] MSA에서의 서비스간 통신&lt;/a>&lt;/p>
&lt;hr>
&lt;p>저번 편에서 저희는 MSA 환경에서 서비스 간 통신 방식에 대해 살펴보았습니다. REST, gRPC, 메시지 큐까지 다양한 선택지가 있었죠.&lt;/p>
&lt;p>그런데 어떤 통신 방식을 선택하든, 분산 시스템에서 반드시 마주하게 되는 현실이 있는 것 같습니다. 바로 &lt;strong>장애는 피할 수 없다&lt;/strong>는 점입니다.&lt;/p>
&lt;p>저번 편에서 분산 컴퓨팅의 8가지 오류를 언급했습니다. 그중 첫 번째가 &amp;ldquo;네트워크는 신뢰할 수 있다&amp;quot;는 오류였죠. MSA 환경에서 서비스 간 통신은 네트워크를 통해 이루어지기 때문에, 네트워크가 불안정하면 장애로 이어질 수밖에 없습니다. 물론 모놀리식 환경에서도 장애는 발생할 수 있지만, MSA 환경에서는 네트워크 통신이 추가되면서 장애의 원인과 전파 방식이 훨씬 더 복잡해집니다.&lt;/p>
&lt;p>그렇다면 MSA 환경에서 장애는 어떻게 전파되고, 우리는 이를 어디서 어떻게 끊어야 할까요?&lt;/p>
&lt;p>이번 편에서는 MSA 환경에서의 장애 전파 메커니즘과 이를 막기 위한 패턴들에 대해 이야기해보려 합니다.&lt;/p>
&lt;h2>장애는 어떻게 전파되는가&lt;span class="hx:absolute hx:-mt-20" id="장애는-어떻게-전파되는가">&lt;/span>
&lt;a href="#%ec%9e%a5%ec%95%a0%eb%8a%94-%ec%96%b4%eb%96%bb%ea%b2%8c-%ec%a0%84%ed%8c%8c%eb%90%98%eb%8a%94%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>우선 장애는 어떻게 전파 될까요? 모놀리식 환경에서는 모든 기능이 하나의 프로세스 안에서 실행되기 때문에, 한 모듈의 장애가 전체 애플리케이션에 영향을 줄 수 있다고 &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-1-introduction/">1편&lt;/a>에서 이야기했습니다. 그렇다면 MSA에서는 서비스가 분리되어 있으니 장애 격리가 자연스럽게 될까요?&lt;/p>
&lt;p>안타깝게도 &lt;strong>꼭 그렇지만은 않습니다.&lt;/strong>&lt;/p>
&lt;p>콘서트 예매 서비스를 다시 예로 들어보겠습니다. 주문 서비스가 결제 서비스를 동기로 호출한다고 가정해보겠습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant User as 사용자
participant Order as 주문 서비스
participant Payment as 결제 서비스
User-&amp;gt;&amp;gt;Order: 주문 요청
Order-&amp;gt;&amp;gt;Payment: 결제 요청
Note right of Payment: 💥 응답 지연 (DB 과부하)
Note right of Order: 응답 대기 중...&amp;lt;br/&amp;gt;스레드 점유
Note right of Order: 응답 대기 중...&amp;lt;br/&amp;gt;스레드 점유
Note right of Order: 응답 대기 중...&amp;lt;br/&amp;gt;스레드 점유
Order--xUser: 결국 Timeout 또는 에러
&lt;/pre>&lt;p>결제 서비스에 문제가 생겨 응답이 느려지면 어떻게 될까요? 주문 서비스는 결제 응답을 기다리며 스레드를 점유하게 됩니다. 이런 요청이 계속 쌓이면 주문 서비스의 스레드 풀이 고갈되고, 결국 주문 서비스 자체가 응답 불가 상태가 될 수 있습니다.&lt;/p>
&lt;p>결제 서비스만 문제였는데, 주문 서비스까지 장애가 전파된 겁니다. 만약 주문 서비스를 호출하는 또 다른 서비스가 있다면 거기까지 장애가 퍼지게 되죠.&lt;/p>
&lt;p>이처럼 MSA에서도 &lt;strong>동기 호출 체인이 있다면 장애는 연쇄적으로 전파될 수 있습니다.&lt;/strong> 서비스가 물리적으로 분리되어 있더라도 논리적으로 강하게 결합되어 있다면 장애 격리의 이점을 제대로 누리지 못하는 것이죠.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
Client[&amp;#34;👤 클라이언트&amp;lt;br/&amp;gt;④ 서비스 이용 불가&amp;#34;] --&amp;gt; Gateway[&amp;#34;API Gateway&amp;lt;br/&amp;gt;③ 응답 지연&amp;#34;]
Gateway --&amp;gt; Order[&amp;#34;주문 서비스&amp;lt;br/&amp;gt;② 스레드 고갈&amp;#34;]
Gateway --&amp;gt; User[&amp;#34;사용자 서비스&amp;#34;]
Order --&amp;gt; Payment[&amp;#34;💥 결제 서비스&amp;lt;br/&amp;gt;① 장애 발생&amp;#34;]
Order --&amp;gt; Inventory[&amp;#34;재고 서비스&amp;#34;]
Order --&amp;gt; User
style Payment fill:#ff6b6b,color:#fff
style Order fill:#ffa94d
style Gateway fill:#ffe066
style Client fill:#ffe066
&lt;/pre>&lt;p>결제 서비스 하나에 장애가 발생했을 뿐인데, 주문 서비스가 스레드 고갈로 죽고, Gateway까지 응답 지연이 발생하고, 결국 클라이언트는 서비스를 이용할 수 없게 됩니다. 재고 서비스와 사용자 서비스는 살아있지만, 주문 흐름 전체가 마비되어 의미가 없죠.&lt;/p>
&lt;p>지금은 단순한 시나리오지만, 실제 MSA 환경에서는 수십, 수백 개의 서비스가 얽히고설켜 있습니다. 하나의 서비스 장애가 어떻게 전파될지 예측하기 어려운 상황이 벌어질 수 있죠.&lt;/p>
&lt;p>이런 장애 전파는 실제로도 자주 발생합니다. 2017년 AWS S3 장애 때 S3에 의존하던 수많은 서비스들이 연쇄적으로 다운된 사례가 있었습니다. S3 자체의 문제였지만, S3 상태를 확인하는 대시보드마저 S3에 의존하고 있어서 장애 상황을 파악하기도 어려웠다고 하죠. 의존성이 어디까지 퍼져있는지 파악하지 못하면 이런 일이 생길 수 있다는 걸 보여주는 사례인 것 같습니다.&lt;/p>
&lt;p>그렇다면 이 장애 전파를 어떻게 막을 수 있을까요?&lt;/p>
&lt;h2>장애 전파를 끊는 방법들&lt;span class="hx:absolute hx:-mt-20" id="장애-전파를-끊는-방법들">&lt;/span>
&lt;a href="#%ec%9e%a5%ec%95%a0-%ec%a0%84%ed%8c%8c%eb%a5%bc-%eb%81%8a%eb%8a%94-%eb%b0%a9%eb%b2%95%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>장애 전파를 막기 위한 여러 패턴들이 있습니다. 크게 보면 &lt;strong>빠르게 실패하기&lt;/strong>, &lt;strong>재시도하기&lt;/strong>, &lt;strong>차단하기&lt;/strong>, &lt;strong>대체하기&lt;/strong>, &lt;strong>격리하기&lt;/strong>로 나눌 수 있는 것 같습니다.&lt;/p>
&lt;p>각각의 패턴이 어떤 문제를 해결하는지 살펴보겠습니다.&lt;/p>
&lt;h3>1. Timeout: 빠르게 실패하기&lt;span class="hx:absolute hx:-mt-20" id="1-timeout-빠르게-실패하기">&lt;/span>
&lt;a href="#1-timeout-%eb%b9%a0%eb%a5%b4%ea%b2%8c-%ec%8b%a4%ed%8c%a8%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>가장 기본적이면서도 중요한 패턴입니다. &lt;strong>응답을 무한정 기다리지 않고, 일정 시간이 지나면 실패로 처리&lt;/strong>하는 방식이죠.&lt;/p>
&lt;p>앞서 본 장애 전파 시나리오에서, 주문 서비스가 결제 서비스를 30초 동안 기다린다면 그 30초 동안 스레드가 점유됩니다. 하지만 Timeout을 3초로 설정하면 3초 후에 스레드가 해제되어 다른 요청을 처리할 수 있게 됩니다. 물론 다른 요청도 실패할 수 있지만, 시스템 전체가 멈추는 것보다는 낫겠죠.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant Order as 주문 서비스
participant Payment as 결제 서비스
rect rgb(255, 240, 240)
Note over Order,Payment: Timeout 없는 경우
Order-&amp;gt;&amp;gt;Payment: 결제 요청
Note right of Order: 무한 대기...&amp;lt;br/&amp;gt;스레드 점유
end
rect rgb(240, 255, 240)
Note over Order,Payment: Timeout 3초 설정
Order-&amp;gt;&amp;gt;Payment: 결제 요청
Note right of Order: 3초 대기
Order--&amp;gt;&amp;gt;Order: Timeout!&amp;lt;br/&amp;gt;스레드 해제
end
&lt;/pre>&lt;p>Timeout 설정에서 고민되는 부분은 &lt;strong>적절한 값을 어떻게 정할 것인가&lt;/strong>입니다.&lt;/p>
&lt;p>너무 짧으면 정상적인 요청도 실패로 처리될 수 있고, 너무 길면 장애 전파를 막는 효과가 떨어집니다. 평균 응답 시간보다는 &lt;strong>P99(99번째 백분위수) 응답 시간&lt;/strong>을 기준으로 설정하는 것이 실무적으로 효과적입니다.&lt;/p>
&lt;p>예를 들어, 결제 서비스의 응답 시간이 다음과 같다고 가정해보겠습니다.&lt;/p>
&lt;ul>
&lt;li>평균: 200ms&lt;/li>
&lt;li>P95: 400ms&lt;/li>
&lt;li>P99: 800ms&lt;/li>
&lt;/ul>
&lt;p>평균(200ms)의 &lt;code>2~3배&lt;/code>인 &lt;code>400~600ms&lt;/code>로 Timeout을 설정하면, 정상 요청의 약 5%가 Timeout으로 실패할 수 있습니다. 반면 P99(800ms)를 기준으로 여유를 두어 1~1.5초로 설정하면, 정상 요청의 99% 이상이 성공하면서도 장애 상황에서는 빠르게 실패할 수 있습니다.&lt;/p>
&lt;p>물론 이 값도 서비스 특성에 따라 달라집니다. 결제처럼 중요한 호출은 여유를 더 두고, 추천처럼 실패해도 괜찮은 호출은 더 공격적으로 설정할 수 있죠. 중요한 건 &lt;strong>근거 있는 수치로 시작해서 모니터링하며 조정&lt;/strong>하는 것입니다.&lt;/p>
&lt;p>한 가지 더 고려할 점은 &lt;strong>Connection Timeout과 Read Timeout을 구분&lt;/strong>해서 설정해야 한다는 것입니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Connection Timeout&lt;/strong>: 연결 수립까지 대기하는 시간입니다. TCP 핸드셰이크가 완료될 때까지의 시간이죠. 보통 1~3초 정도로 짧게 설정합니다. 연결조차 못 맺는다면 서버가 아예 죽었거나 네트워크 문제일 가능성이 높으니까요.&lt;/li>
&lt;li>&lt;strong>Read Timeout (Socket Timeout)&lt;/strong>: 연결은 됐지만 응답 데이터를 기다리는 시간입니다. 앞서 P99 기준으로 설정한다고 한 건 주로 이 값입니다.&lt;/li>
&lt;/ul>
&lt;p>둘을 구분하지 않고 하나의 Timeout만 설정하면, 연결 실패와 응답 지연을 구분해서 대응하기 어려워집니다. 대부분의 HTTP 클라이언트 라이브러리에서 이 두 값을 별도로 설정할 수 있으니 확인해보시는 걸 권장합니다.&lt;/p>
&lt;p>중요한 것은 &lt;strong>Timeout을 설정했다면 Timeout 발생 시 어떻게 처리할지도 함께 정해야 한다&lt;/strong>는 점입니다. 그냥 에러를 반환할지, 재시도를 할지, 대체 로직을 실행할지 말이죠.&lt;/p>
&lt;h3>2. Retry: 재시도하기&lt;span class="hx:absolute hx:-mt-20" id="2-retry-재시도하기">&lt;/span>
&lt;a href="#2-retry-%ec%9e%ac%ec%8b%9c%eb%8f%84%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>네트워크는 종종 순간적으로 불안정해집니다. 간헐적으로 요청이 실패하거나 응답이 지연될 수 있죠. 이런 상황에서는 &lt;strong>재시도(Retry)&lt;/strong> 가 효과적일 수 있습니다.&lt;/p>
&lt;p>패킷이 유실되거나 서버가 잠깐 과부하 상태였을 수 있죠. 이런 &lt;strong>일시적인 장애(Transient Failure)&lt;/strong> 는 다시 시도하면 성공하는 경우가 많습니다.&lt;/p>
&lt;p>하지만 무작정 재시도하면 문제가 생깁니다. 이미 과부하 상태인 서비스에 더 많은 요청을 보내면 상황이 더 악화될 수 있으니까요.&lt;/p>
&lt;p>그래서 &lt;strong>Exponential Backoff(지수 백오프)&lt;/strong> 방식을 많은 서비스에서 사용합니다. 재시도 간격을 지수적으로 늘려가는 거죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>1차 시도: 즉시
2차 시도: 1초 후
3차 시도: 2초 후
4차 시도: 4초 후
5차 시도: 8초 후
... (최대 재시도 횟수 도달 시 종료)&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>여기에 &lt;strong>Jitter(무작위 지연)&lt;/strong> 를 추가하면 조금 더 효과적입니다. 여러 클라이언트가 동시에 재시도하면 특정 시점에 요청이 몰릴 수 있는데, 무작위 지연을 추가하면 재시도 시점이 분산됩니다. 캐싱쪽에는 이와 비슷한 문제로 Cache Stampede(캐시 폭주 현상) 문제가 있는데, 이를 완화하는 데도 Jitter가 효과적입니다.&lt;/p>
&lt;h4>주의: 멱등성(Idempotency)&lt;span class="hx:absolute hx:-mt-20" id="주의-멱등성idempotency">&lt;/span>
&lt;a href="#%ec%a3%bc%ec%9d%98-%eb%a9%b1%eb%93%b1%ec%84%b1idempotency" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>문제는 Retry를 적용할 때 반드시 고려해야 할 부분이 있습니다. 바로 &lt;strong>멱등성&lt;/strong>입니다.&lt;/p>
&lt;p>결제 요청을 보냈는데 Timeout이 발생했다고 가정해보겠습니다. 클라이언트 입장에서는 요청이 실패한 것처럼 보이지만, 실제로는 서버에서 결제가 성공적으로 처리되었고 응답만 늦게 온 상황이라면 재시도를 했을 때 결제가 두 번 처리될 수 있죠. 듣기만해도 서늘한 큰 문제로 이어질 수 있는 심각한 문제입니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant Order as 주문 서비스
participant Payment as 결제 서비스
Order-&amp;gt;&amp;gt;Payment: 결제 요청 (10,000원)
Note right of Payment: 결제 처리 성공!
Note right of Order: 응답 지연 → Timeout
Order-&amp;gt;&amp;gt;Payment: 재시도 (10,000원)
Note right of Payment: 또 결제 처리 성공!
Note over Payment: 💀 20,000원 결제됨
&lt;/pre>&lt;p>이 문제를 방지하려면 &lt;strong>서버 측에서 멱등성을 보장&lt;/strong>해야 합니다. 같은 요청이 여러 번 와도 한 번만 처리되도록 하는 거죠. 보통 멱등성 키(Idempotency Key)를 사용해서 이미 처리된 요청인지 확인하는 방식으로 구현하곤 합니다.&lt;/p>
&lt;p>HTTP 메서드별로 보면 GET, PUT, DELETE는 스펙상 멱등해야 하고, POST는 기본적으로 멱등하지 않습니다. 하지만 스펙이 멱등을 요구해도 실제 구현이 멱등하지 않을 수 있기 때문에, Retry가 필요한 API는 명시적으로 멱등성을 검증해야 합니다. Retry를 적용하기 전에 꼭 멱등성을 검토해봐야하는 이유입니다.&lt;/p>
&lt;p>그리고 재시도 횟수도 적절히 제한해야 합니다. 무한정 재시도하면 장애가 장기화될 수 있으니까요.&lt;/p>
&lt;p>재시도 횟수를 정할 때는 &lt;strong>총 대기 시간&lt;/strong>을 함께 고려해야 합니다. Exponential Backoff를 적용하면 재시도 횟수에 따라 총 대기 시간이 급격히 늘어나기 때문입니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>3회 재시도 (1초 &amp;#43; 2초 &amp;#43; 4초) = 최대 7초
5회 재시도 (1초 &amp;#43; 2초 &amp;#43; 4초 &amp;#43; 8초 &amp;#43; 16초) = 최대 31초
7회 재시도 = 최대 127초 (2분 이상)&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>사용자가 2분 넘게 기다리는 건 현실적이지 않죠. 그래서 대부분의 경우 &lt;strong>3~5회&lt;/strong>가 적당합니다. 일시적인 네트워크 문제는 보통 몇 초 내에 해결되고, 그 이상 실패한다면 재시도보다는 Circuit Breaker가 개입해야 할 상황일 가능성이 높습니다.&lt;/p>
&lt;h3>3. Circuit Breaker: 차단하기&lt;span class="hx:absolute hx:-mt-20" id="3-circuit-breaker-차단하기">&lt;/span>
&lt;a href="#3-circuit-breaker-%ec%b0%a8%eb%8b%a8%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Timeout과 Retry로도 해결되지 않는 상황이 있습니다. 결제 서비스가 완전히 죽어서 모든 요청이 실패하는 경우죠.&lt;/p>
&lt;p>이 상황에서 계속 요청을 보내면 어떻게 될까요? 매번 Timeout까지 기다리고, Retry까지 하면 하나의 요청을 처리하는 데 상당한 시간이 걸립니다. 죽은 서비스에 계속 요청을 보내면서 자원만 낭비하는 거죠.&lt;/p>
&lt;p>&lt;strong>Circuit Breaker&lt;/strong>는 이런 상황을 방지합니다. 연속된 실패가 감지되면 &lt;strong>아예 요청을 보내지 않고 즉시 실패&lt;/strong>를 반환하는 방식입니다.&lt;/p>
&lt;p>이름이 &amp;ldquo;회로 차단기&amp;quot;인 이유는 집의 전기 차단기와 동작 방식이 비슷하기 때문입니다. 전기가 과부하되면 차단기가 내려가서 화재를 방지하죠? 마찬가지로 서비스 호출이 계속 실패하면 회로 차단기가 열려서 더 이상 요청을 보내지 않습니다.&lt;/p>
&lt;p>주문 서비스에서 결제 서비스를 호출하는 상황으로 예를 들어보겠습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
stateDiagram-v2
[*] --&amp;gt; Closed
Closed: Closed(결제 서비스 정상 호출)
Open: Open(결제 서비스 호출 차단)
HalfOpen: Half-Open(복구 테스트 중)
Closed --&amp;gt; Open: 실패율 50% 초과
Open --&amp;gt; HalfOpen: 30초 경과
HalfOpen --&amp;gt; Closed: 결제 성공
HalfOpen --&amp;gt; Open: 결제 실패
&lt;/pre>&lt;ul>
&lt;li>
&lt;p>&lt;strong>Closed&lt;/strong>: 회로가 연결된 상태입니다. 요청이 정상적으로 결제 서비스에 전달됩니다. 실패율을 모니터링하다가 임계치를 넘으면 Open으로 전환합니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Open&lt;/strong>: 회로가 차단된 상태입니다. 결제 서비스에 요청을 보내지 않고 즉시 실패를 반환합니다. 일정 시간이 지나면 Half-Open으로 전환합니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Half-Open&lt;/strong>: 결제 서비스가 복구되었는지 확인하는 상태입니다. 일부 요청만 보내보고, 성공하면 Closed로, 실패하면 다시 Open으로 전환합니다.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>Circuit Breaker의 핵심은 &lt;strong>실패가 예상되면 시도 자체를 하지 않는 것&lt;/strong>입니다. Timeout은 요청을 보내고 빨리 포기하는 거라면, Circuit Breaker는 요청 자체를 보내지 않습니다. 실패할 요청에 자원을 낭비하지 않고, 장애 서비스가 복구할 시간도 벌어줄 수 있죠.&lt;/p>
&lt;h3>4. Fallback: 대체하기&lt;span class="hx:absolute hx:-mt-20" id="4-fallback-대체하기">&lt;/span>
&lt;a href="#4-fallback-%eb%8c%80%ec%b2%b4%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>지금까지 살펴본 패턴들은 모두 실패를 감지하고 대응하는 방법이었습니다. 그런데 실패가 감지되면 그 다음은 뭘 해야 할까요?&lt;/p>
&lt;p>경우에 따라 &lt;strong>대체 로직을 실행&lt;/strong>하는 것이 더 나을 수 있습니다. 이를 &lt;strong>Fallback&lt;/strong>이라고 합니다.&lt;/p>
&lt;p>콘서트 예매 서비스에서 &amp;ldquo;이 공연을 본 사람들이 좋아한 다른 공연&amp;rdquo; 추천 기능이 있다고 가정해보겠습니다. 추천 서비스가 다운되었다고 해서 전체 페이지가 에러가 되면 안 되겠죠.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
Request[&amp;#34;추천 요청&amp;#34;]
Service[&amp;#34;추천 서비스&amp;#34;]
Cache[&amp;#34;캐시된 추천&amp;#34;]
Popular[&amp;#34;인기 공연&amp;#34;]
Response[&amp;#34;응답&amp;#34;]
Request --&amp;gt; Service
Service --&amp;gt;|&amp;#34;성공&amp;#34;| Response
Service --&amp;gt;|&amp;#34;실패&amp;#34;| Cache
Cache --&amp;gt;|&amp;#34;캐시 있음&amp;#34;| Response
Cache --&amp;gt;|&amp;#34;캐시 없음&amp;#34;| Popular
Popular --&amp;gt; Response
&lt;/pre>&lt;p>추천 서비스가 실패하면 캐시된 추천 목록을 보여주거나, 그마저 없으면 인기 공연 목록을 보여주는 거죠. 사용자 입장에서는 &amp;ldquo;추천이 좀 별로네&amp;rdquo; 정도지, &amp;ldquo;페이지가 안 열려&amp;quot;는 아닙니다.&lt;/p>
&lt;p>다만 &lt;strong>핵심 기능에는 Fallback을 신중하게 적용해야 합니다.&lt;/strong> 결제가 실패했는데 &amp;ldquo;일단 성공으로 처리&amp;quot;하는 Fallback은 비즈니스적으로 큰 문제가 될 수 있으니까요.&lt;/p>
&lt;h3>5. Bulkhead: 격리하기&lt;span class="hx:absolute hx:-mt-20" id="5-bulkhead-격리하기">&lt;/span>
&lt;a href="#5-bulkhead-%ea%b2%a9%eb%a6%ac%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>마지막으로 &lt;strong>Bulkhead(격벽)&lt;/strong> 패턴입니다. 선박에서 한 구역에 물이 들어와도 격벽 덕분에 다른 구역으로 퍼지지 않는 것처럼, &lt;strong>시스템의 한 부분에서 발생한 장애가 다른 부분으로 전파되지 않도록 격리&lt;/strong>하는 방식입니다. 구체적으로는 &lt;strong>서비스별로 독립적인 리소스 풀(스레드 풀, 커넥션 풀 등)을 할당&lt;/strong>합니다.&lt;/p>
&lt;p>말로만 들으면 잘 와닿지 않을 수 있으니 예시를 통해 이해해보죠.&lt;/p>
&lt;p>주문 서비스가 결제, 재고, 알림 서비스를 호출하는데 하나의 스레드 풀(20개)을 공유한다고 가정해보겠습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Order[&amp;#34;주문 서비스&amp;#34;]
API[&amp;#34;API&amp;#34;]
SharedPool[&amp;#34;공유 스레드 풀 (20)&amp;#34;]
end
SharedPool --&amp;gt; Payment[&amp;#34;결제 서비스&amp;#34;]
SharedPool --&amp;gt; Inventory[&amp;#34;재고 서비스&amp;#34;]
SharedPool --&amp;gt; Notification[&amp;#34;💥 알림 서비스&amp;lt;br/&amp;gt;(응답 지연)&amp;#34;]
style Notification fill:#ff6b6b,color:#fff
style SharedPool fill:#ffa94d
&lt;/pre>&lt;p>알림 서비스가 느려지면 알림 호출이 스레드를 계속 점유합니다. 알림은 부가 기능일 뿐인데, 스레드 풀이 고갈되면서 정작 중요한 결제와 재고 호출까지 영향을 받게 되죠. 모놀리식 환경에서 한 모듈의 장애가 전체 애플리케이션에 영향을 주는 것과 비슷한 상황이 발생하는 겁니다.&lt;/p>
&lt;p>Bulkhead를 적용하면 이 문제를 해결할 수 있습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Order[&amp;#34;주문 서비스&amp;#34;]
API[&amp;#34;API&amp;#34;]
subgraph Pools[&amp;#34;격리된 스레드 풀&amp;#34;]
PaymentPool[&amp;#34;결제용 (10)&amp;#34;]
InventoryPool[&amp;#34;재고용 (10)&amp;#34;]
NotificationPool[&amp;#34;알림용 (5)&amp;#34;]
end
end
PaymentPool --&amp;gt; Payment[&amp;#34;결제 서비스&amp;#34;]
InventoryPool --&amp;gt; Inventory[&amp;#34;재고 서비스&amp;#34;]
NotificationPool --&amp;gt; Notification[&amp;#34;💥 알림 서비스&amp;lt;br/&amp;gt;(응답 지연)&amp;#34;]
style Notification fill:#ff6b6b,color:#fff
style NotificationPool fill:#ffa94d
&lt;/pre>&lt;p>이렇게 되면 알림 서비스가 느려져서 알림용 스레드 풀(5개)이 전부 점유되어도, 결제용(10개), 재고용(10개) 스레드 풀은 영향을 받지 않습니다. 핵심 기능인 결제와 재고는 정상 동작하는 거죠.&lt;/p>
&lt;p>스레드 풀 크기를 정하는 것도 고민이 필요합니다. 너무 작으면 정상 상황에서도 요청이 거부될 수 있고, 너무 크면 격리 효과가 떨어집니다. 이 역시 해당 서비스의 평균 처리량과 응답 시간을 기준으로 산정하되, 모니터링하면서 조정하는 것이 좋다고 생각합니다.&lt;/p>
&lt;h2>패턴 조합하기&lt;span class="hx:absolute hx:-mt-20" id="패턴-조합하기">&lt;/span>
&lt;a href="#%ed%8c%a8%ed%84%b4-%ec%a1%b0%ed%95%a9%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>실제로는 이 패턴들을 개별적으로 사용하기보다 &lt;strong>조합해서 사용&lt;/strong>하는 것이 일반적입니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
Request[&amp;#34;요청&amp;#34;] --&amp;gt; Bulkhead[&amp;#34;🚧 Bulkhead&amp;#34;]
Bulkhead --&amp;gt; Timeout[&amp;#34;⏱️ Timeout&amp;#34;]
Timeout --&amp;gt; Retry[&amp;#34;🔄 Retry&amp;#34;]
Retry --&amp;gt; CB{&amp;#34;🔌 Circuit Breaker&amp;#34;}
CB --&amp;gt;|&amp;#34;Closed&amp;#34;| Service[&amp;#34;외부 서비스&amp;#34;]
CB --&amp;gt;|&amp;#34;Open&amp;#34;| Fallback[&amp;#34;🔀 Fallback&amp;#34;]
Service --&amp;gt;|&amp;#34;성공&amp;#34;| Response[&amp;#34;응답&amp;#34;]
Service --&amp;gt;|&amp;#34;실패&amp;#34;| Retry
Retry --&amp;gt;|&amp;#34;재시도 초과&amp;#34;| Fallback
Fallback --&amp;gt; Response
&lt;/pre>&lt;p>외부 서비스를 호출할 때&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Bulkhead&lt;/strong>로 이 호출이 다른 호출에 영향을 주지 않도록 격리하고&lt;/li>
&lt;li>&lt;strong>Timeout&lt;/strong>으로 최대 대기 시간을 설정하고&lt;/li>
&lt;li>실패하면 &lt;strong>Retry&lt;/strong>(Exponential Backoff)로 재시도하고&lt;/li>
&lt;li>연속 실패하면 &lt;strong>Circuit Breaker&lt;/strong>가 열려서 즉시 실패를 반환하고&lt;/li>
&lt;li>최종적으로 &lt;strong>Fallback&lt;/strong>으로 대체 로직을 실행합니다&lt;/li>
&lt;/ol>
&lt;p>물론 모든 호출에 이 모든 패턴을 적용할 필요는 없습니다. 호출의 중요도와 특성에 따라 적절히 선택해야 한다고 생각합니다.&lt;/p>
&lt;h3>언제 이 패턴들을 쓰면 안 되는가&lt;span class="hx:absolute hx:-mt-20" id="언제-이-패턴들을-쓰면-안-되는가">&lt;/span>
&lt;a href="#%ec%96%b8%ec%a0%9c-%ec%9d%b4-%ed%8c%a8%ed%84%b4%eb%93%a4%ec%9d%84-%ec%93%b0%eb%a9%b4-%ec%95%88-%eb%90%98%eb%8a%94%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-2-boundary/">2편&lt;/a>에서도 &amp;ldquo;언제 쓰면 안 되는가&amp;quot;를 강조했듯이, 장애 대응 패턴도 마찬가지로 피해야 할 상황이 있습니다.&lt;/p>
&lt;h4>Retry를 쓰면 안 될 때&lt;span class="hx:absolute hx:-mt-20" id="retry를-쓰면-안-될-때">&lt;/span>
&lt;a href="#retry%eb%a5%bc-%ec%93%b0%eb%a9%b4-%ec%95%88-%eb%90%a0-%eb%95%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;ul>
&lt;li>멱등성이 보장되지 않는 API (중복 처리 위험)&lt;/li>
&lt;li>비즈니스 로직 에러 (400 Bad Request는 재시도해도 성공하지 않음)&lt;/li>
&lt;li>이미 과부하인 서비스에 Jitter 없이 재시도&lt;/li>
&lt;/ul>
&lt;h4>Circuit Breaker를 쓰면 안 될 때&lt;span class="hx:absolute hx:-mt-20" id="circuit-breaker를-쓰면-안-될-때">&lt;/span>
&lt;a href="#circuit-breaker%eb%a5%bc-%ec%93%b0%eb%a9%b4-%ec%95%88-%eb%90%a0-%eb%95%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;ul>
&lt;li>호출 빈도가 낮은 경우 (연속 실패 추적이 무의미)&lt;/li>
&lt;li>실패해도 괜찮은 호출 (로깅, 통계 수집 등)&lt;/li>
&lt;li>이미 비동기로 처리하는 경우&lt;/li>
&lt;/ul>
&lt;h4>Fallback을 쓰면 안 될 때&lt;span class="hx:absolute hx:-mt-20" id="fallback을-쓰면-안-될-때">&lt;/span>
&lt;a href="#fallback%ec%9d%84-%ec%93%b0%eb%a9%b4-%ec%95%88-%eb%90%a0-%eb%95%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;ul>
&lt;li>핵심 비즈니스 로직 (결제 실패를 성공으로 처리하면 안 됨)&lt;/li>
&lt;li>데이터 정합성이 중요한 경우&lt;/li>
&lt;/ul>
&lt;h4>일반적인 안티패턴&lt;span class="hx:absolute hx:-mt-20" id="일반적인-안티패턴">&lt;/span>
&lt;a href="#%ec%9d%bc%eb%b0%98%ec%a0%81%ec%9d%b8-%ec%95%88%ed%8b%b0%ed%8c%a8%ed%84%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;ul>
&lt;li>모든 호출에 모든 패턴 적용 (복잡도만 증가)&lt;/li>
&lt;li>기본값 그대로 사용 (서비스 특성에 맞게 조정 필요)&lt;/li>
&lt;li>모니터링 없이 도입 (Circuit이 Open됐는지 알 수 없으면 의미 없음)&lt;/li>
&lt;/ul>
&lt;p>이제 어떨때 이 패턴들을 적용하고, 어떨때 피해야 하는지 감이 오시나요? 만약 이제 저희가 구현해야한다면 어떻게 할 수 있을지 살펴보겠습니다.&lt;/p>
&lt;h2>구현하기&lt;span class="hx:absolute hx:-mt-20" id="구현하기">&lt;/span>
&lt;a href="#%ea%b5%ac%ed%98%84%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>어플리케이션 레벨에서 해결하기: Resilience4j&lt;span class="hx:absolute hx:-mt-20" id="어플리케이션-레벨에서-해결하기-resilience4j">&lt;/span>
&lt;a href="#%ec%96%b4%ed%94%8c%eb%a6%ac%ec%bc%80%ec%9d%b4%ec%85%98-%eb%a0%88%eb%b2%a8%ec%97%90%ec%84%9c-%ed%95%b4%ea%b2%b0%ed%95%98%ea%b8%b0-resilience4j" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이러한 패턴들을 직접 구현할 수도 있지만, 검증된 라이브러리를 사용하는 것이 일반적입니다. Java/Kotlin 생태계에서는 &lt;strong>Resilience4j&lt;/strong>가 가장 많이 사용되는 것 같습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Service&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">PaymentService&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">private&lt;/span> &lt;span class="k">val&lt;/span> &lt;span class="py">paymentClient&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">PaymentClient&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nd">@CircuitBreaker&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">name&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;payment&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">fallbackMethod&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;paymentFallback&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nd">@Retry&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">name&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;payment&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nd">@TimeLimiter&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">name&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;payment&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">fun&lt;/span> &lt;span class="nf">processPayment&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">orderId&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">String&lt;/span>&lt;span class="p">):&lt;/span> &lt;span class="n">CompletableFuture&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">PaymentResult&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="nc">CompletableFuture&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">supplyAsync&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">paymentClient&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">pay&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">orderId&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">private&lt;/span> &lt;span class="k">fun&lt;/span> &lt;span class="nf">paymentFallback&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">orderId&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">String&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">ex&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">Exception&lt;/span>&lt;span class="p">):&lt;/span> &lt;span class="n">CompletableFuture&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">PaymentResult&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="nc">CompletableFuture&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">completedFuture&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nc">PaymentResult&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">pending&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">orderId&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;결제 서비스 일시 장애&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># application.yml&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">resilience4j&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">circuitbreaker&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">instances&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">payment&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">failure-rate-threshold&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">50&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">wait-duration-in-open-state&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">30s&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">sliding-window-size&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">10&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">retry&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">instances&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">payment&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">max-attempts&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">3&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">wait-duration&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">500ms&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">enable-exponential-backoff&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">timelimiter&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">instances&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">payment&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">timeout-duration&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">3s&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>Spring Boot에서는 어노테이션으로 간단하게 적용할 수 있습니다. 설정은 YAML 파일에서 관리할 수 있어서 코드와 설정을 분리할 수 있다는 장점이 있습니다. 사용하시는 프로그래밍 언어에 맞는 라이브러리를 찾아보시면 비슷한 기능을 제공하는 경우가 많을 겁니다.&lt;/p>
&lt;p>그런데 이걸 서비스마다 일일이 적용하는 게 번거롭지 않을까요? 서비스가 많아지면 관리 포인트가 늘어나고, 동일한 설정을 여러 서비스에 반복해서 넣어야 하니까요. 혹여 설정이 바뀌면 일일이 다 수정해야 하고요.&lt;/p>
&lt;p>이런 경우에는 인프라 레벨에서 해결하는 방법도 고려해볼 수 있습니다.&lt;/p>
&lt;h3>인프라 레벨에서 해결하기: Service Mesh&lt;span class="hx:absolute hx:-mt-20" id="인프라-레벨에서-해결하기-service-mesh">&lt;/span>
&lt;a href="#%ec%9d%b8%ed%94%84%eb%9d%bc-%eb%a0%88%eb%b2%a8%ec%97%90%ec%84%9c-%ed%95%b4%ea%b2%b0%ed%95%98%ea%b8%b0-service-mesh" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>Service Mesh&lt;/strong>는 이런 횡단 관심사를 인프라 레벨로 내리는 접근입니다. Spring에서 AOP로 횡단 관심사를 분리하는 것과 비슷한 개념이죠.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
subgraph PodA[&amp;#34;Pod A&amp;#34;]
AppA[&amp;#34;주문 서비스&amp;#34;] --&amp;gt; ProxyA[&amp;#34;Sidecar Proxy&amp;#34;]
end
subgraph PodB[&amp;#34;Pod B&amp;#34;]
ProxyB[&amp;#34;Sidecar Proxy&amp;#34;] --&amp;gt; AppB[&amp;#34;결제 서비스&amp;#34;]
end
ProxyA --&amp;gt;|&amp;#34;자동 Retry, Timeout,&amp;lt;br/&amp;gt;Circuit Breaker&amp;#34;| ProxyB
&lt;/pre>&lt;p>쿠버네티스에서 Istio, Linkerd 같은 Service Mesh는 각 Pod 옆에 Sidecar Proxy를 붙여서 모든 네트워크 트래픽을 가로챕니다. 이 Proxy에서 Retry, Timeout, Circuit Breaker를 처리하기 때문에 &lt;strong>애플리케이션 코드 변경 없이&lt;/strong> 장애 대응 패턴을 적용할 수 있습니다.&lt;/p>
&lt;p>다만 Service Mesh와 애플리케이션 레벨 구현은 역할이 다르다고 생각합니다. Service Mesh는 기본적인 Retry, Timeout, Circuit Breaker를 처리하기에 좋지만, &lt;strong>비즈니스 로직이 필요한 Fallback은 애플리케이션에서 구현&lt;/strong>해야 합니다.&lt;/p>
&lt;p>서비스가 10개 미만이고 단일 언어라면 Resilience4j로 충분하지만, 폴리글랏 환경에서 수십 개 서비스를 운영한다면 Service Mesh 도입을 검토해볼 만하다고 생각합니다.&lt;/p>
&lt;h2>모니터링하기&lt;span class="hx:absolute hx:-mt-20" id="모니터링하기">&lt;/span>
&lt;a href="#%eb%aa%a8%eb%8b%88%ed%84%b0%eb%a7%81%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>앞서 안티패턴에서 &amp;ldquo;모니터링 없이 도입&amp;quot;을 언급했습니다. 장애 대응 패턴을 도입했다면, &lt;strong>이 패턴들이 실제로 어떻게 동작하고 있는지 관찰할 수 있어야 합니다.&lt;/strong>&lt;/p>
&lt;p>Circuit Breaker가 Open 상태가 됐는데 아무도 모른다면, 장애 대응이 아니라 장애 은폐가 되어버리죠. 다음은 모니터링해야 할 핵심 메트릭들입니다.&lt;/p>
&lt;h3>핵심 메트릭&lt;span class="hx:absolute hx:-mt-20" id="핵심-메트릭">&lt;/span>
&lt;a href="#%ed%95%b5%ec%8b%ac-%eb%a9%94%ed%8a%b8%eb%a6%ad" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>메트릭&lt;/th>
&lt;th>의미&lt;/th>
&lt;th>알람 기준 예시&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Circuit Breaker 상태&lt;/strong>&lt;/td>
&lt;td>Closed/Open/Half-Open&lt;/td>
&lt;td>Open 전환 시 즉시 알람&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>실패율 (Failure Rate)&lt;/strong>&lt;/td>
&lt;td>최근 N개 요청 중 실패 비율&lt;/td>
&lt;td>30% 초과 시 경고, 50% 초과 시 위험&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>응답 시간 분포&lt;/strong>&lt;/td>
&lt;td>P50, P95, P99&lt;/td>
&lt;td>P99가 Timeout의 80% 도달 시 경고&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Retry 발생 횟수&lt;/strong>&lt;/td>
&lt;td>재시도가 얼마나 자주 발생하는지&lt;/td>
&lt;td>급증 시 경고&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Fallback 호출 빈도&lt;/strong>&lt;/td>
&lt;td>대체 로직이 얼마나 사용되는지&lt;/td>
&lt;td>평소 대비 급증 시 경고&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3>Resilience4j + Micrometer 연동&lt;span class="hx:absolute hx:-mt-20" id="resilience4j--micrometer-연동">&lt;/span>
&lt;a href="#resilience4j--micrometer-%ec%97%b0%eb%8f%99" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Resilience4j는 Micrometer와 통합되어 있어서, 이 메트릭들을 자동으로 수집할 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># application.yml&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">resilience4j&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">circuitbreaker&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">instances&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">payment&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">register-health-indicator&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># Actuator health에 노출&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">management&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">metrics&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">tags&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">application&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">order-service&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">endpoints&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">web&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">exposure&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">include&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">health, metrics, prometheus&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이렇게 설정하면 &lt;code>/actuator/prometheus&lt;/code> 엔드포인트에서 다음과 같은 메트릭을 확인할 수 있습니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code># Circuit Breaker 상태
resilience4j_circuitbreaker_state{name=&amp;#34;payment&amp;#34;} 0 # 0=closed, 1=open, 2=half-open
# 실패율
resilience4j_circuitbreaker_failure_rate{name=&amp;#34;payment&amp;#34;} 12.5
# 호출 결과별 카운트
resilience4j_circuitbreaker_calls_seconds_count{kind=&amp;#34;successful&amp;#34;, name=&amp;#34;payment&amp;#34;} 1000
resilience4j_circuitbreaker_calls_seconds_count{kind=&amp;#34;failed&amp;#34;, name=&amp;#34;payment&amp;#34;} 50&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 메트릭들을 Prometheus로 수집하고 Grafana로 시각화하면, 장애 대응 패턴의 동작을 실시간으로 관찰할 수 있습니다.&lt;/p>
&lt;h3>알람 설정 예시&lt;span class="hx:absolute hx:-mt-20" id="알람-설정-예시">&lt;/span>
&lt;a href="#%ec%95%8c%eb%9e%8c-%ec%84%a4%ec%a0%95-%ec%98%88%ec%8b%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>단순히 메트릭을 수집하는 것만으로는 부족하다고 생각합니다. &lt;strong>이상 징후가 감지되면 가능한 빨리 알 수 있어야 합니다.&lt;/strong> Prometheus AlertManager나 Grafana Alerting 등에서 다음과 같은 알람 규칙을 설정할 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># 알람 규칙 예시 (PromQL 기반)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">groups&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">resilience&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">rules&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">alert&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">CircuitBreakerOpen&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">expr&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">resilience4j_circuitbreaker_state == 1&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">for&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">0m&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">labels&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">severity&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">critical&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">annotations&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">summary&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;Circuit Breaker가 Open 상태입니다&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">alert&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">HighFailureRate&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">expr&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">resilience4j_circuitbreaker_failure_rate &amp;gt; 30&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">for&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">1m&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">labels&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">severity&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">warning&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">annotations&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">summary&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;실패율이 30%를 초과했습니다&amp;#34;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>Circuit Breaker가 Open으로 전환되면 알람이 오고, 실패율이 30%를 넘으면 경고가 발생합니다. 이렇게 해야 &amp;ldquo;패턴이 동작은 하는데 우리가 모르고 있었다&amp;quot;는 상황을 방지할 수 있습니다.&lt;/p>
&lt;h2>검증하기: Chaos Engineering&lt;span class="hx:absolute hx:-mt-20" id="검증하기-chaos-engineering">&lt;/span>
&lt;a href="#%ea%b2%80%ec%a6%9d%ed%95%98%ea%b8%b0-chaos-engineering" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>지금까지 여러 장애 대응 패턴과 구현 방법을 살펴봤습니다. 그런데 한 가지 질문이 남습니다.&lt;/p>
&lt;p>&lt;strong>이 패턴들이 정말 잘 동작하는지 어떻게 알 수 있을까요?&lt;/strong>&lt;/p>
&lt;p>장애는 예고 없이 찾아옵니다. Circuit Breaker를 설정해뒀는데 막상 장애가 터지니까 설정값이 잘못되어 있었다든지, Fallback 로직에 버그가 있었다든지 하는 일이 생길 수 있습니다. 프로덕션에서 장애가 터지고 나서야 &amp;ldquo;아, 이게 안 되네&amp;quot;를 깨닫는 건 너무 늦은 거죠.&lt;/p>
&lt;p>Netflix는 이 문제를 해결하기 위해 &lt;strong>Chaos Monkey&lt;/strong>라는 도구를 만들었습니다. 프로덕션 환경에서 &lt;strong>무작위로 서비스 인스턴스를 종료시켜&lt;/strong>서 시스템의 복원력을 검증하는 도구입니다.&lt;/p>
&lt;p>처음 이 이야기를 들었을 때 꽤나 많이 놀라웠습니다. 저는 Chaos Engineering이라는 개념 자체를 처음 접했거든요. 자기 서비스를 스스로 죽인다니, 저로서는 상상하기도 어려운 개념이었습니다.&lt;/p>
&lt;p>하지만 생각해보면 꽤 합리적이었습니다. 장애가 언제 올지 모르니까, 일부러 장애를 일으켜서 &amp;ldquo;정말로 대비가 되어 있는가&amp;quot;를 검증하는 거죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>&amp;#34;장애는 예방하는 것이 아니라 대비하는 것이다&amp;#34;&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>Chaos Engineering의 핵심 철학이라고 생각합니다. 모든 외부 호출에 &amp;ldquo;이 서비스가 죽으면 어떻게 되지?&amp;ldquo;라는 질문을 던져보고, 그 답이 명확하지 않다면 그 부분에 장애 대응 패턴이 필요한 겁니다.&lt;/p>
&lt;p>물론 처음부터 프로덕션에서 Chaos Monkey를 돌릴 필요는 없다고 생각합니다. 스테이징 환경에서 특정 서비스를 죽여보고 시스템이 어떻게 반응하는지 관찰하는 것만으로도 많은 것을 파악할 수 있지 않나 싶습니다.&lt;/p>
&lt;h2>정리&lt;span class="hx:absolute hx:-mt-20" id="정리">&lt;/span>
&lt;a href="#%ec%a0%95%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이번 편에서는 MSA 환경에서 장애가 어떻게 전파되는지, 그리고 이를 막기 위한 여러 장애 대응 패턴에 대해 살펴보았습니다.&lt;/p>
&lt;p>결국 &lt;strong>장애 대응은 &amp;ldquo;장애가 발생하지 않게 하는 것&amp;quot;이 아니라 &amp;ldquo;장애가 발생해도 시스템이 버틸 수 있게 하는 것&amp;rdquo;&lt;/strong> 이라고 생각합니다.&lt;/p>
&lt;p>MSA 환경에서 일하면서 가장 많이 했던 고민 중 하나 역시 &amp;ldquo;이 서비스가 죽으면 우리 시스템은 어떻게 되지?&amp;ldquo;였습니다. 그 질문에 명확한 답을 가지고 있어야 장애가 왔을 때 당황하지 않고 대응할 수 있다고 생각합니다.&lt;/p>
&lt;h2>다음 편에서&lt;span class="hx:absolute hx:-mt-20" id="다음-편에서">&lt;/span>
&lt;a href="#%eb%8b%a4%ec%9d%8c-%ed%8e%b8%ec%97%90%ec%84%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>통신 방식도 정했고, 장애 대응 방법도 알게 되었습니다. 그런데 MSA에서 가장 까다로운 문제가 남았습니다.&lt;/p>
&lt;p>&lt;strong>데이터는 어떻게 분리해야 하는가?&lt;/strong> 입니다.&lt;/p>
&lt;p>다음 5편에서는 왜 DB를 분리해야 하는지, 그리고 분리했을 때 JOIN이 안 되는 문제를 어떻게 해결하는지에 대해 이야기하겠습니다.&lt;/p>
&lt;h2>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>장애 사례&lt;span class="hx:absolute hx:-mt-20" id="장애-사례">&lt;/span>
&lt;a href="#%ec%9e%a5%ec%95%a0-%ec%82%ac%eb%a1%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://aws.amazon.com/message/41926/"target="_blank" rel="noopener">Summary of the Amazon S3 Service Disruption (2017)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>장애 대응 패턴&lt;span class="hx:absolute hx:-mt-20" id="장애-대응-패턴">&lt;/span>
&lt;a href="#%ec%9e%a5%ec%95%a0-%eb%8c%80%ec%9d%91-%ed%8c%a8%ed%84%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>Michael Nygard - &lt;em>Release It!: Design and Deploy Production-Ready Software&lt;/em> (Pragmatic Bookshelf, 2018)&lt;/li>
&lt;li>&lt;a href="https://resilience4j.readme.io/"target="_blank" rel="noopener">Resilience4j Documentation&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>Chaos Engineering&lt;span class="hx:absolute hx:-mt-20" id="chaos-engineering">&lt;/span>
&lt;a href="#chaos-engineering" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://principlesofchaos.org/"target="_blank" rel="noopener">Principles of Chaos Engineering&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://netflix.github.io/chaosmonkey/"target="_blank" rel="noopener">Netflix Chaos Monkey&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>Service Mesh&lt;span class="hx:absolute hx:-mt-20" id="service-mesh">&lt;/span>
&lt;a href="#service-mesh" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://istio.io/latest/docs/"target="_blank" rel="noopener">Istio Documentation&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://linkerd.io/docs/"target="_blank" rel="noopener">Linkerd Documentation&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>[MSA에 관한 고찰 3/7편] MSA에서의 서비스간 통신 - 어떻게 해야 하는가</title><link>https://jeongil.dev/ko/blog/architecture/msa-series-3-communication/</link><pubDate>Fri, 16 Jan 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/architecture/msa-series-3-communication/</guid><description>
&lt;p>전편: &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-2-boundary/">[MSA에 관한 고찰 2/7편] MSA에서 서비스는 어떻게 나눌 것인가&lt;/a>&lt;/p>
&lt;hr>
&lt;p>저번 편에서 우리는 서비스를 어떻게 나눌 것인지, 경계 설정의 원칙과 주의점에 대해 살펴보았습니다.&lt;/p>
&lt;p>실제로 MSA 환경에서 일하면서 &lt;strong>가장 많이 고민했던 부분 중 하나가 바로 &amp;ldquo;서비스 간 통신&amp;rdquo;&lt;/strong> 이었습니다. 모놀리식에서는 메서드 호출 한 번이면 끝났던 일이, MSA에서는 생각보다 복잡한 의사결정을 요구하더라구요.&lt;/p>
&lt;p>이번에는 MSA의 러닝커브와 복잡성을 고려하고도 트레이드오프를 감안하여 MSA를 선택했다고 가정하고, MSA 환경에서 서비스 간 통신을 어떻게 설계하고 구현할 것인지에 대해 고민해보는 시간을 가져보려 합니다.&lt;/p>
&lt;p>우선 문제의 시작으로 가보겠습니다.&lt;/p>
&lt;p>MSA 환경에서는 각 서비스가 독립적으로 배포, 운영된다고 했는데, &lt;strong>이런 환경에서 서비스 간 통신은 필수적인 걸까요?&lt;/strong>&lt;/p>
&lt;p>무조건이라고 할 수는 없겠지만, 대부분의 경우 서비스 간 통신은 불가피합니다.&lt;/p>
&lt;p>하나의 비즈니스 목적을 이루기 위해 시스템을 설계하는 경우가 대부분일 텐데, 이런 경우 &lt;strong>각 도메인 혹은 기능별로 나누어진 서비스들은 보통 서로 협력하거나 서로의 데이터를 필요로 하기 마련이기 때문&lt;/strong>입니다.&lt;/p>
&lt;p>그런데 여기서 한 가지 중요한 사실을 먼저 짚고 넘어가야 합니다.&lt;/p>
&lt;h2>모놀리식과 MSA, 통신의 차이&lt;span class="hx:absolute hx:-mt-20" id="모놀리식과-msa-통신의-차이">&lt;/span>
&lt;a href="#%eb%aa%a8%eb%86%80%eb%a6%ac%ec%8b%9d%ea%b3%bc-msa-%ed%86%b5%ec%8b%a0%ec%9d%98-%ec%b0%a8%ec%9d%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>모놀리식에서의 통신&lt;span class="hx:absolute hx:-mt-20" id="모놀리식에서의-통신">&lt;/span>
&lt;a href="#%eb%aa%a8%eb%86%80%eb%a6%ac%ec%8b%9d%ec%97%90%ec%84%9c%ec%9d%98-%ed%86%b5%ec%8b%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>모놀리식 아키텍처에서는 모든 기능이 하나의 코드베이스와 배포 단위에 포함되어 있다는 점은 저번 편에서 살펴보았습니다.&lt;/p>
&lt;p>그렇다면 모놀리식 환경에서의 서비스 간 통신은 어떻게 이루어질까요?&lt;/p>
&lt;p>사실 모놀리식 환경에서는 엄밀한 의미에서 서비스 간 통신이 존재하지 않습니다. 모든 기능이 &lt;strong>하나의 프로세스 내에서 실행되기 때문에, 함수 호출이나 메서드 호출을 통해 서로의 기능을 직접 호출할 수 있습니다.&lt;/strong>&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Monolith[&amp;#34;Monolithic Application&amp;#34;]
direction TB
subgraph Row1[&amp;#34; &amp;#34;]
direction LR
Order[&amp;#34;주문&amp;#34;]
Product[&amp;#34;상품&amp;#34;]
end
subgraph Row2[&amp;#34; &amp;#34;]
direction LR
User[&amp;#34;회원&amp;#34;]
Payment[&amp;#34;결제&amp;#34;]
end
Order -.-&amp;gt;|&amp;#34;메서드 호출&amp;#34;| User
Order -.-&amp;gt;|&amp;#34;메서드 호출&amp;#34;| Payment
end
Monolith --&amp;gt; DB[(Database)]
&lt;/pre>&lt;p>저번 편의 콘서트 예매 서비스를 예로 들어보겠습니다. 주문 기능에서 회원 정보가 필요하다면 &lt;code>userService.getUser(userId)&lt;/code>처럼 메서드를 호출하면 됩니다.&lt;/p>
&lt;p>이로 인해 모놀리식 환경에서는 &lt;strong>네트워크 통신의 오버헤드가 없고, 데이터 일관성 유지가 상대적으로 용이하다&lt;/strong>는 장점이 있습니다.&lt;/p>
&lt;h3>MSA에서의 통신&lt;span class="hx:absolute hx:-mt-20" id="msa에서의-통신">&lt;/span>
&lt;a href="#msa%ec%97%90%ec%84%9c%ec%9d%98-%ed%86%b5%ec%8b%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그렇다면 MSA 환경에서는 어떨까요?&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Order[&amp;#34;주문 서비스&amp;#34;]
OrderApp[&amp;#34;주문&amp;#34;]
end
subgraph User[&amp;#34;회원 서비스&amp;#34;]
UserApp[&amp;#34;회원&amp;#34;]
end
subgraph Payment[&amp;#34;결제 서비스&amp;#34;]
PaymentApp[&amp;#34;결제&amp;#34;]
end
OrderApp --&amp;gt;|&amp;#34;HTTP/gRPC&amp;#34;| UserApp
OrderApp --&amp;gt;|&amp;#34;HTTP/gRPC&amp;#34;| PaymentApp
Order --&amp;gt; OrderDB[(주문 DB)]
User --&amp;gt; UserDB[(회원 DB)]
Payment --&amp;gt; PaymentDB[(결제 DB)]
&lt;/pre>&lt;p>MSA에서는 각 서비스가 독립적인 프로세스로 실행됩니다. 주문 서비스에서 회원 정보가 필요하다면 더 이상 &lt;code>userService.getUser(userId)&lt;/code> 메서드 호출로 끝나지 않습니다.&lt;/p>
&lt;p>네트워크를 통해 회원 서비스에 요청을 보내고, 응답을 받아야 합니다. 이 과정에서 모놀리식에서는 고려하지 않아도 됐던 여러 가지 문제들이 발생할 수 있습니다.&lt;/p>
&lt;p>네트워크 지연이 발생하거나, 회원 서비스가 다운되어 있을 수도 있습니다. 요청이 중간에 유실되거나 타임아웃이 발생할 수도 있죠.&lt;/p>
&lt;p>저는 이러한 문제들이 MSA 환경에서 반드시 고려해야 할 부분들이라고 생각합니다.&lt;/p>
&lt;h3>분산 컴퓨팅의 8가지 오류 (Fallacies of Distributed Computing)&lt;span class="hx:absolute hx:-mt-20" id="분산-컴퓨팅의-8가지-오류-fallacies-of-distributed-computing">&lt;/span>
&lt;a href="#%eb%b6%84%ec%82%b0-%ec%bb%b4%ed%93%a8%ed%8c%85%ec%9d%98-8%ea%b0%80%ec%a7%80-%ec%98%a4%eb%a5%98-fallacies-of-distributed-computing" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이러한 문제들을 이해하는 데 도움이 되는 개념이 하나 있습니다. 바로 &lt;strong>분산 컴퓨팅의 8가지 오류(Fallacies of Distributed Computing)&lt;/strong> 입니다.&lt;/p>
&lt;p>이 개념은 1994년 &lt;strong>Sun Microsystems의 Peter Deutsch&lt;/strong>가 처음 7가지를 정리하고, 이후 &lt;strong>James Gosling&lt;/strong>(Java 창시자)이 8번째를 추가하여 완성되었습니다. 분산 시스템을 설계할 때 흔히 저지르는 잘못된 가정들을 정리한 것인데, MSA를 경험하기 전에는 개념적으로만 알고 있던 내용이었지만 실제로 MSA 환경에서 일하면서 더 와닿는 부분들이 있었습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>네트워크는 신뢰할 수 있다&lt;/strong> (The network is reliable): 네트워크는 언제든지 끊어지거나 패킷이 손실될 수 있습니다.&lt;/li>
&lt;li>&lt;strong>지연 시간은 0이다&lt;/strong> (Latency is zero): 데이터 전송에는 항상 시간이 소요되며, 이는 예측 불가능할 수 있습니다.&lt;/li>
&lt;li>&lt;strong>대역폭은 무한하다&lt;/strong> (Bandwidth is infinite): 네트워크 용량에는 한계가 있으며, 트래픽이 몰리면 병목 현상이 발생합니다.&lt;/li>
&lt;li>&lt;strong>네트워크는 안전하다&lt;/strong> (The network is secure): 악의적인 공격이나 보안 위협에 항상 노출될 수 있습니다.&lt;/li>
&lt;li>&lt;strong>토폴로지는 변하지 않는다&lt;/strong> (Topology doesn&amp;rsquo;t change): 네트워크 구성은 동적으로 변할 수 있습니다.&lt;/li>
&lt;li>&lt;strong>관리자는 한 명이다&lt;/strong> (There is one administrator): 분산 시스템은 여러 관리 주체와 환경을 가질 수 있습니다.&lt;/li>
&lt;li>&lt;strong>전송 비용은 0이다&lt;/strong> (Transport cost is zero): 네트워크 통신에는 자원과 비용이 발생합니다.&lt;/li>
&lt;li>&lt;strong>네트워크는 균일하다&lt;/strong> (The network is homogeneous): 다양한 종류의 기기와 네트워크 환경이 혼재할 수 있습니다.&lt;/li>
&lt;/ol>
&lt;p>저는 이러한 오류들이 MSA 환경에서 서비스 간 통신을 설계할 때 반드시 염두에 두어야 할 중요한 고려사항들이라고 생각합니다. 실제로 MSA 환경에서 일하다 보면 이 8가지 오류가 정말 피부로 와닿는 순간들이 있더라구요.&lt;/p>
&lt;p>결국 &lt;strong>분산 시스템에서는 네트워크 통신이 필수적이기 때문에 어떤 방식으로 서비스 간 통신을 설계할지에 대한 고민이 매우 중요&lt;/strong>한 것 같습니다.&lt;/p>
&lt;h2>첫 번째 갈림길: 동기 vs 비동기&lt;span class="hx:absolute hx:-mt-20" id="첫-번째-갈림길-동기-vs-비동기">&lt;/span>
&lt;a href="#%ec%b2%ab-%eb%b2%88%ec%a7%b8-%ea%b0%88%eb%a6%bc%ea%b8%b8-%eb%8f%99%ea%b8%b0-vs-%eb%b9%84%eb%8f%99%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>그렇다면 MSA 환경에서 서비스 간 통신에는 어떤 방식들이 있을까요?&lt;/p>
&lt;p>먼저 가장 근본적인 선택지부터 살펴보겠습니다. &lt;strong>동기 통신&lt;/strong>과 &lt;strong>비동기 통신&lt;/strong>입니다.&lt;/p>
&lt;p>동기 통신과 비동기 통신에 대해 검색해보시면 흔히 이런 그림을 많이 보실 수 있으실 것 같습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/4cf0jqk0bqa81ep3zhc51/async.png?rlkey=mc19q5sp67f0ourpzj8ru73wu&amp;amp;st=kjr6kgqx&amp;amp;raw=1" alt="async" loading="lazy" />&lt;/p>
&lt;p>위 그림을 보시면 동기/비동기와 블로킹/논블로킹이라는 두 가지 축이 있는 것을 확인하실 수 있습니다. 이 두 개념은 흔히 혼용되어 사용되기도 하는데, 엄밀히 말하면 서로 다른 관점의 개념입니다.&lt;/p>
&lt;p>먼저 각 개념을 정리해보겠습니다.&lt;/p>
&lt;p>&lt;strong>동기(Synchronous) vs 비동기(Asynchronous)&lt;/strong> 는 &lt;strong>호출자가 결과를 어떻게 받는가&lt;/strong>에 대한 관점입니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>동기&lt;/strong>: 호출 후 결과가 반환될 때까지 대기합니다. 결과를 함수의 반환값으로 직접 받습니다.&lt;/li>
&lt;li>&lt;strong>비동기&lt;/strong>: 호출 즉시 제어권이 반환되며, 결과는 나중에 콜백, 이벤트, Future/Promise 등을 통해 받습니다.&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>블로킹(Blocking) vs 논블로킹(Non-blocking)&lt;/strong> 은 &lt;strong>제어권을 언제 반환하는가&lt;/strong>에 대한 관점입니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>블로킹&lt;/strong>: 작업이 완료될 때까지 제어권을 반환하지 않습니다 (대기)&lt;/li>
&lt;li>&lt;strong>논블로킹&lt;/strong>: 작업 완료 여부와 관계없이 제어권을 즉시 반환합니다&lt;/li>
&lt;/ul>
&lt;p>이 두 개념을 조합하면 &lt;strong>동기+블로킹&lt;/strong>, &lt;strong>동기+논블로킹&lt;/strong>, &lt;strong>비동기+블로킹&lt;/strong>, &lt;strong>비동기+논블로킹&lt;/strong> 4가지 경우가 나옵니다. 각 조합의 특성과 실무에서 주의해야 할 점들이 있는데, 이 부분은 MSA와 직접적인 관련보다는 일반적인 프로그래밍 개념에 가깝기 때문에 별도의 글에서 자세히 다루도록 하겠습니다.&lt;/p>
&lt;p>MSA 관점에서 중요한 건 이겁니다: &lt;strong>동기 통신은 호출하는 쪽이 응답을 기다리고, 비동기 통신은 기다리지 않는다.&lt;/strong>&lt;/p>
&lt;h3>동기 통신&lt;span class="hx:absolute hx:-mt-20" id="동기-통신">&lt;/span>
&lt;a href="#%eb%8f%99%ea%b8%b0-%ed%86%b5%ec%8b%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그렇다면 동기 통신은 언제 필요하고 비동기 통신은 언제 필요할까요?&lt;/p>
&lt;p>동기 통신은 주로 &lt;strong>즉시 응답이 필요한 경우&lt;/strong>에 사용됩니다.&lt;/p>
&lt;p>주문 서비스에서 결제를 진행하기 전에 회원의 잔액을 확인해야 하는 상황을 생각해보겠습니다.&lt;/p>
&lt;p>잔액 정보 없이 진행했다가는 결제 실패로 이어질 수 있기 때문에 주문 서비스는 회원 서비스의 잔액 응답을 기다려야 합니다. 이런 경우에는 동기 통신이 적합하다고 생각합니다.&lt;/p>
&lt;p>물론 결제 시도하는 방식으로 Queue를 사용하여 비동기 통신으로 구현할 수 도 있겠지만, 이는 결제 지연이나 실패에 대한 사용자 경험(UX) 측면에서 부정적인 영향을 미칠 수 있습니다.&lt;/p>
&lt;h3>비동기 통신&lt;span class="hx:absolute hx:-mt-20" id="비동기-통신">&lt;/span>
&lt;a href="#%eb%b9%84%eb%8f%99%ea%b8%b0-%ed%86%b5%ec%8b%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>비동기 통신은 &lt;strong>즉시 응답이 필요하지 않거나, 작업이 오래 걸리는 경우&lt;/strong>에 사용됩니다.&lt;/p>
&lt;p>주문이 완료된 후 알림을 보내는 상황을 생각해보겠습니다. 알림 발송이 완료될 때까지 주문 응답을 기다릴 필요는 없습니다. 주문 서비스는 &amp;ldquo;주문 완료&amp;rdquo; 이벤트만 발행하고 바로 사용자에게 응답을 반환하면 됩니다. 알림 서비스는 나중에 해당 이벤트를 받아서 알림을 발송하면 되죠.&lt;/p>
&lt;p>자 그렇다면 동기 통신과 비동기 통신을 통해 서비스 간 통신을 구현하는 방법에는 어떤 것들이 있을까요? 그리고 우리는 어떤 방법을 선택해야 할까요?&lt;/p>
&lt;p>구체적인 구현 방법을 살펴보기 전에, 한 가지 짚고 넘어가고 싶은 부분이 있습니다.&lt;/p>
&lt;h3>비동기라고 다 비동기가 아니다&lt;span class="hx:absolute hx:-mt-20" id="비동기라고-다-비동기가-아니다">&lt;/span>
&lt;a href="#%eb%b9%84%eb%8f%99%ea%b8%b0%eb%9d%bc%ea%b3%a0-%eb%8b%a4-%eb%b9%84%eb%8f%99%ea%b8%b0%ea%b0%80-%ec%95%84%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>동기 호출은 상대 서비스가 다운되면 장애가 전파됩니다. 물론 Fallback이나 Circuit Breaker로 어느 정도 막을 수 있지만, &lt;strong>호출 시점에 상대 서비스 상태에 의존하게 되는 건 변하지 않습니다.&lt;/strong> 비동기로 전환하면 이 의존성을 덜어낼 수 있어요.&lt;/p>
&lt;p>하지만 비동기로 바꿨다고 해서 무조건 의존성이 사라지는 건 아닙니다. 예를 들어 &amp;ldquo;이 이벤트가 5초 안에는 처리되어야 해&amp;quot;라고 기대하거나, 처리 결과를 기다리며 폴링하기 시작하면 어떻게 될까요?&lt;/p>
&lt;p>이런 상황을 &lt;strong>Hidden Synchronous Dependency(숨겨진 동기적 의존성)&lt;/strong> 라고 부릅니다. 겉으로는 비동기인데 실제로는 동기처럼 동작하는 셈이죠. 비동기의 장점인 &amp;ldquo;느슨한 결합&amp;quot;을 제대로 누리려면 이 부분을 주의해야 한다고 생각합니다.&lt;/p>
&lt;p>이런 상황은 주로 메시지가 특정 동작을 요청하는 형태일 때 발생하기 쉬운데요. 참고로 EDA(Event-Driven Architecture)에서는 &lt;strong>Event&lt;/strong>와 &lt;strong>Command&lt;/strong>를 구분합니다. &amp;ldquo;주문완료(OrderCompleted)&amp;ldquo;처럼 이미 발생한 사실을 알리는 게 Event이고, &amp;ldquo;결제처리(ProcessPayment)&amp;ldquo;처럼 특정 동작을 요청하는 게 Command입니다. Event는 발행자가 구독자가 뭘 할지 모르고 그냥 사실만 알리는 거라 느슨한 결합이 되는 반면, Command는 비동기 메시징을 쓰더라도 특정 서비스의 특정 동작을 기대하게 돼 숨겨진 동기적 의존성이 될 가능성이 높아집니다. EDA도 별도 포스트할 정도로 방대한 주제라 여기서는 간단히 언급만 하고 기회가 되면 따로 더 깊이 다뤄보겠습니다.&lt;/p>
&lt;p>결국 동기냐 비동기냐는 단순히 &amp;ldquo;기다리느냐 안 기다리느냐&amp;quot;가 아니라 &lt;strong>&amp;ldquo;얼마나 느슨하게 결합할 수 있는가&amp;quot;의 문제&lt;/strong>라고 생각합니다.&lt;/p>
&lt;h2>동기 통신: REST vs gRPC vs GraphQL&lt;span class="hx:absolute hx:-mt-20" id="동기-통신-rest-vs-grpc-vs-graphql">&lt;/span>
&lt;a href="#%eb%8f%99%ea%b8%b0-%ed%86%b5%ec%8b%a0-rest-vs-grpc-vs-graphql" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>우선 동기 통신부터 살펴보겠습니다. 동기 통신에는 대표적으로 세 가지 방식이 있습니다.&lt;/p>
&lt;p>가장 저희에게 익숙한 &lt;strong>REST API&lt;/strong>, 구글에서 개발한 &lt;strong>gRPC&lt;/strong>, 그리고 페이스북에서 개발한 &lt;strong>GraphQL Federation&lt;/strong>입니다.&lt;/p>
&lt;h3>REST API&lt;span class="hx:absolute hx:-mt-20" id="rest-api">&lt;/span>
&lt;a href="#rest-api" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>REST(Representational State Transfer)는 HTTP 프로토콜을 기반으로 하는 아키텍처 스타일입니다. 자원을 URI로 표현하고, HTTP 메서드(GET, POST, PUT, DELETE 등)를 사용하여 자원에 대한 작업을 수행하는 방식입니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant Client as 클라이언트
participant Server as 서버
Client-&amp;gt;&amp;gt;Server: GET /users/123
Note right of Server: JSON 파싱 및 처리
Server--&amp;gt;&amp;gt;Client: HTTP 200&amp;lt;br/&amp;gt;{&amp;#34;id&amp;#34;: 123, &amp;#34;name&amp;#34;: &amp;#34;홍길동&amp;#34;, ...}
Client-&amp;gt;&amp;gt;Server: POST /orders
Note right of Server: 주문 생성
Server--&amp;gt;&amp;gt;Client: HTTP 201&amp;lt;br/&amp;gt;{&amp;#34;orderId&amp;#34;: &amp;#34;order-456&amp;#34;, ...}
&lt;/pre>&lt;p>아마 대부분의 개발자분들이 가장 익숙한 방식이 아닐까요? 저도 처음 개발을 배울 때부터 REST API를 사용해왔고, 지금도 가장 많이 사용하는 방식입니다.&lt;/p>
&lt;p>REST API의 장점은 여러 가지가 있겠지만, 저는 가장 큰 장점이 &lt;strong>범용성&lt;/strong>이라고 생각합니다. HTTP를 지원하는 거의 모든 환경에서 사용할 수 있고, JSON 형식의 데이터는 사람이 읽기에도 편합니다. 디버깅할 때 응답을 바로 확인할 수 있다는 점도 큰 장점입니다.&lt;/p>
&lt;p>하지만 단점도 있습니다. REST API도 &lt;code>HTTP/2&lt;/code> 위에서 동작할 수 있고, JSON 대신 Protobuf를 사용하거나 SSE/WebSocket을 조합하는 것도 가능합니다. 다만 &lt;strong>일반적으로 사용되는 REST + JSON + 요청/응답 모델&lt;/strong>에서는 몇 가지 한계가 있습니다. JSON은 텍스트 기반이기 때문에 바이너리 형식에 비해 데이터 크기가 크고 파싱 비용도 발생합니다. 또한 요청마다 독립적인 응답을 기다리는 구조라서, 여러 데이터를 한 번에 가져오려면 여러 번 요청하거나 API를 별도로 만들어야 합니다.&lt;/p>
&lt;h3>gRPC&lt;span class="hx:absolute hx:-mt-20" id="grpc">&lt;/span>
&lt;a href="#grpc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>gRPC는 구글에서 개발한 고성능 RPC(Remote Procedure Call) 프레임워크입니다. &lt;code>HTTP/2&lt;/code>를 기반으로 동작하며, Protocol Buffers(protobuf)라는 바이너리 직렬화 형식을 사용합니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant Client as 클라이언트
participant Server as 서버
Note over Client,Server: HTTP/2 연결 (멀티플렉싱)
par 동시 요청
Client-&amp;gt;&amp;gt;Server: GetUser(id=123) [Stream 1]
Client-&amp;gt;&amp;gt;Server: GetOrder(id=456) [Stream 2]
end
Note right of Server: Protobuf 바이너리 처리&amp;lt;br/&amp;gt;(빠른 직렬화/역직렬화)
par 동시 응답
Server--&amp;gt;&amp;gt;Client: User(바이너리) [Stream 1]
Server--&amp;gt;&amp;gt;Client: Order(바이너리) [Stream 2]
end
&lt;/pre>&lt;p>gRPC의 가장 큰 장점은 역시 &lt;strong>성능&lt;/strong>입니다. &lt;code>HTTP/2&lt;/code>의 멀티플렉싱 덕분에 하나의 연결에서 여러 요청을 동시에 처리할 수 있고, Protocol Buffers는 JSON에 비해 데이터 크기가 작고 직렬화/역직렬화 속도도 빠릅니다.&lt;/p>
&lt;p>또한 &lt;code>.proto&lt;/code> 파일을 통해 API 스펙을 정의하기 때문에 &lt;strong>타입 안전성&lt;/strong>이 보장됩니다. 클라이언트와 서버가 동일한 proto 파일을 공유하면 컴파일 타임에 타입 오류를 잡을 수 있습니다. 이는 MSA 환경에서 여러 서비스가 통신할 때 큰 장점이 된다고 생각합니다.&lt;/p>
&lt;p>그렇다면 gRPC가 무조건 좋은 걸까요? 꼭 그렇지만은 않습니다.&lt;/p>
&lt;p>여기서 한 가지 중요한 점을 짚고 넘어가야 할 것 같습니다. &lt;strong>서비스 간 통신(Internal)&lt;/strong> 과 &lt;strong>클라이언트-서버 통신(External)&lt;/strong> 을 구분해서 생각해야 한다는 점입니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph External[&amp;#34;External (클라이언트-서버)&amp;#34;]
Browser[&amp;#34;🌐 브라우저&amp;#34;]
Mobile[&amp;#34;📱 모바일 앱&amp;#34;]
end
subgraph Gateway[&amp;#34;API Gateway&amp;#34;]
GW[&amp;#34;Gateway&amp;lt;br/&amp;gt;(REST API)&amp;#34;]
end
subgraph Internal[&amp;#34;Internal (서비스 간)&amp;#34;]
Order[&amp;#34;주문 서비스&amp;#34;]
User[&amp;#34;회원 서비스&amp;#34;]
Payment[&amp;#34;결제 서비스&amp;#34;]
end
Browser --&amp;gt;|&amp;#34;REST API&amp;lt;br/&amp;gt;(HTTP/1.1, JSON)&amp;#34;| GW
Mobile --&amp;gt;|&amp;#34;REST API&amp;lt;br/&amp;gt;(HTTP/1.1, JSON)&amp;#34;| GW
GW --&amp;gt;|&amp;#34;gRPC&amp;lt;br/&amp;gt;(HTTP/2, Protobuf)&amp;#34;| Order
Order --&amp;gt;|&amp;#34;gRPC&amp;#34;| User
Order --&amp;gt;|&amp;#34;gRPC&amp;#34;| Payment
&lt;/pre>&lt;p>MSA 환경에서 백엔드 서비스들끼리 통신하는 경우(Internal)에는 gRPC가 좋은 선택이 될 수 있습니다. 서버 환경은 &lt;code>HTTP/2&lt;/code>를 완벽하게 지원하고, 성능과 타입 안전성의 이점을 충분히 누릴 수 있기 때문입니다.&lt;/p>
&lt;p>하지만 브라우저나 모바일 앱과 같은 클라이언트와 통신하는 경우(External)에는 상황이 다릅니다. 브라우저의 경우 &lt;code>HTTP/2&lt;/code> 자체는 지원하지만, gRPC가 사용하는 &lt;code>HTTP/2&lt;/code>의 특정 기능들(trailer, full-duplex streaming 등)을 브라우저의 fetch/XHR API가 완전히 지원하지 않습니다. 그래서 브라우저에서 gRPC를 사용하려면 gRPC-Web이라는 별도의 프록시 계층이 필요합니다.&lt;/p>
&lt;p>이러한 이유로 많은 조직에서는 &lt;strong>서비스 간 통신에는 gRPC&lt;/strong>, &lt;strong>클라이언트-서버 통신에는 REST API&lt;/strong>를 사용하는 하이브리드 방식을 채택하기도 합니다.&lt;/p>
&lt;h4>gRPC의 4가지 통신 패턴&lt;span class="hx:absolute hx:-mt-20" id="grpc의-4가지-통신-패턴">&lt;/span>
&lt;a href="#grpc%ec%9d%98-4%ea%b0%80%ec%a7%80-%ed%86%b5%ec%8b%a0-%ed%8c%a8%ed%84%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>gRPC는 단순한 요청-응답(Unary) 외에도 &lt;strong>스트리밍&lt;/strong>을 지원합니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>패턴&lt;/th>
&lt;th>흐름&lt;/th>
&lt;th>사용 사례&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Unary&lt;/strong>&lt;/td>
&lt;td>Client → Server → Client&lt;/td>
&lt;td>단순 CRUD&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Server Streaming&lt;/strong>&lt;/td>
&lt;td>Client → Server ⇒ Client&lt;/td>
&lt;td>실시간 피드, 대용량 다운로드&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Client Streaming&lt;/strong>&lt;/td>
&lt;td>Client ⇒ Server → Client&lt;/td>
&lt;td>파일 업로드, 센서 데이터&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Bidirectional&lt;/strong>&lt;/td>
&lt;td>Client ⇔ Server&lt;/td>
&lt;td>채팅, 실시간 게임&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;code>.proto&lt;/code> 파일에서 &lt;code>stream&lt;/code> 키워드로 스트리밍 여부를 정의합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-protobuf" data-lang="protobuf">&lt;span class="line">&lt;span class="cl">&lt;span class="n">syntax&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s">&amp;#34;proto3&amp;#34;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="kn">package&lt;/span> &lt;span class="nn">user&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="kd">service&lt;/span> &lt;span class="n">UserService&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span> &lt;span class="c1">// Unary - 단순 요청/응답
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">rpc&lt;/span> &lt;span class="n">GetUser&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">GetUserRequest&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="k">returns&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">User&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span> &lt;span class="c1">// Server Streaming - 서버가 여러 응답을 스트리밍
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">rpc&lt;/span> &lt;span class="n">ListUsers&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">ListUsersRequest&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="k">returns&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">stream&lt;/span> &lt;span class="n">User&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="kd">message&lt;/span> &lt;span class="nc">GetUserRequest&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span> &lt;span class="kt">int64&lt;/span> &lt;span class="n">id&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="kd">message&lt;/span> &lt;span class="nc">ListUsersRequest&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span> &lt;span class="kt">int32&lt;/span> &lt;span class="n">page_size&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="kd">message&lt;/span> &lt;span class="nc">User&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span> &lt;span class="kt">int64&lt;/span> &lt;span class="n">id&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span> &lt;span class="kt">string&lt;/span> &lt;span class="n">name&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="mi">2&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span> &lt;span class="kt">string&lt;/span> &lt;span class="n">email&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="mi">3&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이처럼 &lt;code>.proto&lt;/code> 파일 하나로 서비스 인터페이스와 메시지 타입을 정의하면, 클라이언트와 서버 양쪽에서 동일한 타입을 사용할 수 있습니다.&lt;/p>
&lt;h3>GraphQL Federation&lt;span class="hx:absolute hx:-mt-20" id="graphql-federation">&lt;/span>
&lt;a href="#graphql-federation" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>GraphQL은 페이스북에서 개발한 쿼리 언어로, 클라이언트가 필요한 데이터만 정확하게 요청할 수 있다는 특징이 있습니다.&lt;/p>
&lt;p>REST API를 사용하다 보면 Over-fetching(필요 이상의 데이터를 받아오는 것)이나 Under-fetching(필요한 데이터를 받기 위해 여러 번 요청해야 하는 것) 문제를 경험하셨을 수 있을 텐데요. GraphQL은 이러한 문제를 해결하기 위해 등장했습니다.&lt;/p>
&lt;p>GraphQL Federation은 여러 GraphQL 서비스를 하나의 통합된 그래프로 제공하는 아키텍처입니다. 한 가지 짚고 넘어갈 점은, &lt;strong>GraphQL Federation은 내부 서비스 간 직접 통신보다는 클라이언트 요구사항을 조합하기 위한 API 집계 레이어(BFF)에 가깝다&lt;/strong>는 것입니다. 즉, REST나 gRPC처럼 서비스 A가 서비스 B를 직접 호출하는 용도보다는, Gateway에서 여러 서비스의 데이터를 조합하여 클라이언트에게 하나의 API처럼 제공하는 방식입니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
Client[&amp;#34;클라이언트&amp;#34;]
subgraph Federation[&amp;#34;GraphQL Federation&amp;#34;]
Gateway[&amp;#34;GraphQL Gateway&amp;lt;br/&amp;gt;(통합 스키마)&amp;#34;]
subgraph Services[&amp;#34;각 서비스의 Subgraph&amp;#34;]
UserGraph[&amp;#34;User Subgraph&amp;lt;br/&amp;gt;(회원 스키마)&amp;#34;]
OrderGraph[&amp;#34;Order Subgraph&amp;lt;br/&amp;gt;(주문 스키마)&amp;#34;]
ProductGraph[&amp;#34;Product Subgraph&amp;lt;br/&amp;gt;(상품 스키마)&amp;#34;]
end
end
Client --&amp;gt;|&amp;#34;query {&amp;lt;br/&amp;gt; user(id: 123) {&amp;lt;br/&amp;gt; name&amp;lt;br/&amp;gt; orders { id, total }&amp;lt;br/&amp;gt; }&amp;lt;br/&amp;gt;}&amp;#34;| Gateway
Gateway --&amp;gt; UserGraph
Gateway --&amp;gt; OrderGraph
Gateway --&amp;gt; ProductGraph
&lt;/pre>&lt;p>하지만 GraphQL도 만능은 아닙니다. 학습 곡선이 존재하고, HTTP 캐싱을 활용하기 어렵다는 단점이 있습니다. 또한 간단한 CRUD 작업에는 REST API가 더 직관적일 수 있습니다.&lt;/p>
&lt;h4>N+1 문제와 DataLoader&lt;span class="hx:absolute hx:-mt-20" id="n1-문제와-dataloader">&lt;/span>
&lt;a href="#n1-%eb%ac%b8%ec%a0%9c%ec%99%80-dataloader" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>GraphQL 도입 시 반드시 알아야 할 문제가 &lt;strong>N+1 쿼리&lt;/strong>입니다. &lt;code>orders { user { name } }&lt;/code> 같은 쿼리에서 주문 100개를 조회하면, 각 주문마다 user를 조회해서 총 101번의 쿼리가 발생합니다.&lt;/p>
&lt;p>해결책은 &lt;strong>DataLoader&lt;/strong>입니다. 같은 틱 내의 요청을 모아서 &lt;code>WHERE id IN (1,2,3...)&lt;/code> 형태로 배치 처리하면 N+1이 1+1로 바뀝니다. GraphQL Federation을 도입한다면 DataLoader 활용이 성능의 핵심입니다.&lt;/p>
&lt;p>실무에서 GraphQL Federation은 클라이언트 요구사항이 복잡하고 다양할 때 효과적이지만, 그렇지 않으면 오히려 복잡성만 증가시킬 수 있습니다.&lt;/p>
&lt;h3>언제 무엇을?&lt;span class="hx:absolute hx:-mt-20" id="언제-무엇을">&lt;/span>
&lt;a href="#%ec%96%b8%ec%a0%9c-%eb%ac%b4%ec%97%87%ec%9d%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>방식&lt;/th>
&lt;th>장점&lt;/th>
&lt;th>단점&lt;/th>
&lt;th>적합한 상황&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>REST API&lt;/td>
&lt;td>범용성, 간단함, 디버깅 용이&lt;/td>
&lt;td>성능, Over/Under-fetching&lt;/td>
&lt;td>클라이언트-서버 통신, 간단한 CRUD&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>gRPC&lt;/td>
&lt;td>고성능, 타입 안전성, 스트리밍&lt;/td>
&lt;td>브라우저 지원 제한, 디버깅 어려움&lt;/td>
&lt;td>서비스 간 내부 통신, 고성능 필요 시&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>GraphQL&lt;/td>
&lt;td>유연한 쿼리, Over/Under-fetching 해결&lt;/td>
&lt;td>학습 곡선, 캐싱 복잡&lt;/td>
&lt;td>복잡한 데이터 요구사항, BFF 패턴&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>물론 이 표는 일반적인 가이드라인일 뿐입니다. 실제로는 팀의 기술 스택, 기존 인프라, 서비스의 특성 등을 종합적으로 고려해서 결정해야 한다고 생각합니다. 정답이 없는 영역이기도 하구요.&lt;/p>
&lt;p>한 가지 확실한 건, &lt;strong>기술 선택보다 중요한 건 일관성&lt;/strong>이라는 점입니다. 서비스마다 REST, gRPC, GraphQL을 혼용하면 오히려 복잡성만 증가합니다. 팀 내에서 합의된 기준을 세우고 일관되게 적용하는 게 더 중요하다고 생각해요. 예를 들어 &amp;ldquo;클라이언트-서버 통신은 REST API, 서비스 간 통신은 gRPC&amp;quot;와 같은 기준을 세우는 것이죠.&lt;/p>
&lt;h4>언제 쓰면 안 되는가?&lt;span class="hx:absolute hx:-mt-20" id="언제-쓰면-안-되는가">&lt;/span>
&lt;a href="#%ec%96%b8%ec%a0%9c-%ec%93%b0%eb%a9%b4-%ec%95%88-%eb%90%98%eb%8a%94%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>각 기술의 장점만큼 &lt;strong>피해야 할 상황&lt;/strong>도 명확합니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>gRPC를 피해야 할 때&lt;/strong>: 팀에 protobuf 경험이 없고 학습 여유가 없을 때, 브라우저 직접 통신이 필요할 때, 디버깅 편의성이 중요한 초기 MVP 단계&lt;/li>
&lt;li>&lt;strong>GraphQL을 피해야 할 때&lt;/strong>: 단순 CRUD 위주의 서비스, 팀 내 GraphQL 운영 경험이 없을 때, 캐싱이 핵심인 읽기 중심 서비스&lt;/li>
&lt;li>&lt;strong>REST를 피해야 할 때&lt;/strong>: 서비스 간 호출이 초당 수천 건 이상으로 성능이 병목일 때, 스키마 변경이 잦아서 타입 안전성이 중요할 때&lt;/li>
&lt;/ul>
&lt;p>기술 선택에서 가장 위험한 건 &lt;strong>&amp;ldquo;좋아 보여서&amp;rdquo;&lt;/strong> 라고 생각합니다. gRPC의 성능이 좋다고 해서 모든 곳에 도입하면, 디버깅과 운영 및 유지보수의 어려움과 학습 비용이 그 성능 이득을 상쇄할 수 있도 있으니까요.&lt;/p>
&lt;h3>서비스를 어떻게 찾을 것인가: Service Discovery&lt;span class="hx:absolute hx:-mt-20" id="서비스를-어떻게-찾을-것인가-service-discovery">&lt;/span>
&lt;a href="#%ec%84%9c%eb%b9%84%ec%8a%a4%eb%a5%bc-%ec%96%b4%eb%96%bb%ea%b2%8c-%ec%b0%be%ec%9d%84-%ea%b2%83%ec%9d%b8%ea%b0%80-service-discovery" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>REST, gRPC, GraphQL 어떤 프로토콜을 사용하든, 서비스 간 통신을 하려면 &lt;strong>상대 서비스의 위치를 알아야 합니다.&lt;/strong> 모놀리식에서는 고민할 필요 없던 문제죠.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
OrderService[&amp;#34;주문 서비스&amp;#34;] --&amp;gt;|&amp;#34;1. 회원 서비스 어디있어?&amp;#34;| Registry[&amp;#34;Service Registry&amp;#34;]
Registry --&amp;gt;|&amp;#34;2. 10.0.1.5:8080&amp;#34;| OrderService
OrderService --&amp;gt;|&amp;#34;3. 실제 호출&amp;#34;| UserService[&amp;#34;회원 서비스&amp;#34;]
&lt;/pre>&lt;p>대표적인 방식:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Client-side Discovery&lt;/strong>: 클라이언트가 Registry에서 직접 조회 (Eureka, Consul)&lt;/li>
&lt;li>&lt;strong>Server-side Discovery&lt;/strong>: 로드밸런서/Gateway가 라우팅 (AWS ALB, K8s Service)&lt;/li>
&lt;li>&lt;strong>DNS 기반&lt;/strong>: &lt;code>user-service.default.svc.cluster.local&lt;/code> 형태로 접근 (Kubernetes)&lt;/li>
&lt;/ul>
&lt;p>Kubernetes 환경이라면 내장 DNS로 충분하고, 그렇지 않다면 Consul이나 Eureka를 검토해보세요. Service Discovery 자체로도 큰 주제이지만, 여기서는 &amp;ldquo;통신 전에 이 문제를 먼저 해결해야 한다&amp;quot;는 점만 짚고 넘어가겠습니다.&lt;/p>
&lt;h3>API Gateway: 외부와 내부의 경계&lt;span class="hx:absolute hx:-mt-20" id="api-gateway-외부와-내부의-경계">&lt;/span>
&lt;a href="#api-gateway-%ec%99%b8%eb%b6%80%ec%99%80-%eb%82%b4%eb%b6%80%ec%9d%98-%ea%b2%bd%ea%b3%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>앞서 Internal/External 통신을 구분해야 한다고 했습니다. 이 경계에서 핵심 역할을 하는 것이 &lt;strong>API Gateway&lt;/strong>입니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
Client[&amp;#34;클라이언트&amp;#34;] --&amp;gt;|&amp;#34;REST/JSON&amp;#34;| GW[&amp;#34;API Gateway&amp;lt;br/&amp;gt;───────────&amp;lt;br/&amp;gt;• 인증/인가&amp;lt;br/&amp;gt;• Rate Limiting&amp;lt;br/&amp;gt;• 프로토콜 변환&amp;#34;]
GW --&amp;gt;|&amp;#34;gRPC&amp;#34;| Services[&amp;#34;내부 서비스들&amp;#34;]
&lt;/pre>&lt;p>API Gateway의 주요 역할:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>프로토콜 변환&lt;/strong>: 외부는 REST, 내부는 gRPC&lt;/li>
&lt;li>&lt;strong>인증 일원화&lt;/strong>: JWT 검증을 Gateway에서 처리, 내부 서비스는 신뢰&lt;/li>
&lt;li>&lt;strong>Rate Limiting&lt;/strong>: 클라이언트별 요청 제한으로 내부 서비스 보호&lt;/li>
&lt;li>&lt;strong>요청 집계 (BFF)&lt;/strong>: 여러 내부 호출을 하나의 응답으로 조합&lt;/li>
&lt;/ul>
&lt;p>대표 구현체: Kong, AWS API Gateway, Spring Cloud Gateway&lt;/p>
&lt;p>&lt;strong>주의점&lt;/strong>: Gateway가 Single Point of Failure가 될 수 있습니다. Gateway 장애 = 전체 시스템 마비이므로, 다중화와 헬스체크는 필수라고 생각합니다.&lt;/p>
&lt;h2>비동기 통신: Message Queue vs Event Broker&lt;span class="hx:absolute hx:-mt-20" id="비동기-통신-message-queue-vs-event-broker">&lt;/span>
&lt;a href="#%eb%b9%84%eb%8f%99%ea%b8%b0-%ed%86%b5%ec%8b%a0-message-queue-vs-event-broker" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>자 이제 동기 통신은 알아봤으니 이제 비동기 통신에 대해 살펴보겠습니다. 비동기 통신에는 어떤 방법들이 있을까요?&lt;/p>
&lt;p>비동기 통신에서 가장 많이 언급되는 것은 &lt;strong>Message Queue&lt;/strong>와 &lt;strong>Event Broker&lt;/strong>입니다.&lt;/p>
&lt;p>두 개념이 혼용되어 사용되는 경우도 있는데, 엄밀히 말하면 서로 다른 패턴과 사용 목적을 가지고 있습니다.&lt;/p>
&lt;h3>Message Queue (SQS, RabbitMQ)&lt;span class="hx:absolute hx:-mt-20" id="message-queue-sqs-rabbitmq">&lt;/span>
&lt;a href="#message-queue-sqs-rabbitmq" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Message Queue는 &lt;strong>점대점(Point-to-Point)&lt;/strong> 통신 패턴이라고 할 수 있습니다. 하나의 메시지는 하나의 소비자(Consumer)만 처리합니다. Message Queue의 대표적인 구현체로는 AWS SQS, RabbitMQ 등이 있습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
Producer[&amp;#34;주문 서비스&amp;lt;br/&amp;gt;(Producer)&amp;#34;] --&amp;gt; Queue[&amp;#34;Message Queue&amp;#34;]
Queue --&amp;gt; Consumer[&amp;#34;결제 서비스&amp;lt;br/&amp;gt;(Consumer)&amp;#34;]
&lt;/pre>&lt;p>콘서트 예매 서비스를 예로 들어보겠습니다. 주문 서비스에서 결제 요청을 Message Queue에 넣으면, 결제 서비스가 해당 메시지를 가져가서 처리합니다. 이때 메시지는 한 번 소비되면 Queue에서 사라지기 때문에, 다른 서비스가 같은 메시지를 다시 처리할 수 없습니다.&lt;/p>
&lt;p>Message Queue는 다음과 같은 상황에 적합합니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>작업을 하나의 서비스에만 전달&lt;/strong>해야 하는 경우&lt;/li>
&lt;li>&lt;strong>작업 부하를 분산&lt;/strong>해야 하는 경우 (여러 Consumer가 하나의 Queue를 바라보며 작업을 나눠 처리)&lt;/li>
&lt;li>&lt;strong>순서가 중요한 작업&lt;/strong>을 처리해야 하는 경우 (FIFO Queue)&lt;/li>
&lt;/ul>
&lt;h3>Event Broker (SNS, Redis Pub/Sub)&lt;span class="hx:absolute hx:-mt-20" id="event-broker-sns-redis-pubsub">&lt;/span>
&lt;a href="#event-broker-sns-redis-pubsub" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>반면 Event Broker는 &lt;strong>발행-구독(Pub/Sub)&lt;/strong> 패턴이라고 할 수 있습니다. 하나의 이벤트를 여러 구독자(Subscriber)가 동시에 받아서 처리할 수 있습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
Producer[&amp;#34;주문 서비스&amp;lt;br/&amp;gt;(Publisher)&amp;#34;] --&amp;gt; Broker[&amp;#34;Event Broker&amp;lt;br/&amp;gt;(Topic: 주문완료)&amp;#34;]
Broker --&amp;gt; Consumer1[&amp;#34;알림 서비스&amp;lt;br/&amp;gt;(Subscriber)&amp;#34;]
Broker --&amp;gt; Consumer2[&amp;#34;정산 서비스&amp;lt;br/&amp;gt;(Subscriber)&amp;#34;]
Broker --&amp;gt; Consumer3[&amp;#34;재고 서비스&amp;lt;br/&amp;gt;(Subscriber)&amp;#34;]
&lt;/pre>&lt;p>다시 콘서트 예매 서비스로 예를 들어보겠습니다. 주문이 완료되면 여러 가지 후속 작업이 필요합니다. 사용자에게 알림을 보내야 하고, 정산 데이터를 기록해야 하고, 재고를 차감해야 합니다.&lt;/p>
&lt;p>이때 주문 서비스가 &amp;ldquo;주문 완료&amp;rdquo; 이벤트를 Event Broker에 발행하면, 알림 서비스, 정산 서비스, 재고 서비스가 각각 해당 이벤트를 구독하여 자신의 작업을 수행합니다. &lt;strong>하나의 이벤트가 여러 서비스에 전달&lt;/strong>되는 것입니다.&lt;/p>
&lt;p>Event Broker의 대표적인 구현체로는 AWS SNS, Redis Pub/Sub 등이 있습니다. 다만 구현체마다 전달 보장 수준이 다르다는 점을 주의해야 합니다. Redis Pub/Sub은 진짜 Fire-and-forget으로 구독자가 없으면 메시지가 유실되지만, SNS는 SQS와 연동하면 메시지가 영속화되어 재처리가 가능합니다. 실무에서는 SNS+SQS 조합을 많이 사용하는데, 이 경우 Event Broker의 Fan-out 특성과 Message Queue의 영속성을 함께 얻을 수 있습니다.&lt;/p>
&lt;p>Event Broker는 다음과 같은 상황에 적합합니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>하나의 이벤트를 여러 서비스가 처리&lt;/strong>해야 하는 경우&lt;/li>
&lt;li>&lt;strong>서비스 간 결합도를 낮추고 싶은 경우&lt;/strong> (발행자는 구독자를 알 필요가 없음)&lt;/li>
&lt;li>&lt;strong>이벤트 기반 아키텍처&lt;/strong>를 구축하려는 경우&lt;/li>
&lt;/ul>
&lt;h3>그렇다면 Kafka는?&lt;span class="hx:absolute hx:-mt-20" id="그렇다면-kafka는">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%a0%87%eb%8b%a4%eb%a9%b4-kafka%eb%8a%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>여기서 한 가지 짚고 넘어가야 할 점이 있습니다. &lt;strong>Kafka는 단순한 Event Broker가 아닙니다.&lt;/strong> Kafka는 &lt;strong>이벤트 스트리밍 플랫폼&lt;/strong>으로, Message Queue나 Event Broker와는 근본적으로 다른 특성을 가지고 있습니다.&lt;/p>
&lt;p>가장 큰 차이점은 &lt;strong>Append-only 로그&lt;/strong> 기반이라는 점입니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
subgraph Kafka[&amp;#34;Kafka Topic (Partition)&amp;#34;]
direction LR
M1[&amp;#34;메시지 1&amp;#34;] --&amp;gt; M2[&amp;#34;메시지 2&amp;#34;] --&amp;gt; M3[&amp;#34;메시지 3&amp;#34;] --&amp;gt; M4[&amp;#34;메시지 4&amp;#34;] --&amp;gt; M5[&amp;#34;...&amp;#34;]
end
Consumer1[&amp;#34;Consumer A&amp;lt;br/&amp;gt;offset: 2&amp;#34;]
Consumer2[&amp;#34;Consumer B&amp;lt;br/&amp;gt;offset: 4&amp;#34;]
M2 -.-&amp;gt; Consumer1
M4 -.-&amp;gt; Consumer2
&lt;/pre>&lt;p>일반적인 Message Queue에서는 메시지가 소비되면 Queue에서 삭제됩니다. 하지만 Kafka에서는 &lt;strong>메시지가 소비되어도 삭제되지 않고 retention period 동안 유지&lt;/strong>됩니다. 각 Consumer는 자신만의 offset을 관리하며, 같은 메시지를 여러 번 읽을 수도 있습니다.&lt;/p>
&lt;p>이 특성 덕분에 Kafka는 다음과 같은 상황에서 장점을 발휘합니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>이벤트 리플레이&lt;/strong>: Consumer의 offset을 처음으로 되돌려서 모든 이벤트를 재처리할 수 있습니다. 새로운 서비스를 추가하거나, 버그로 인해 데이터를 다시 처리해야 할 때 유용합니다.&lt;/li>
&lt;li>&lt;strong>이벤트 소싱(Event Sourcing)&lt;/strong>: 상태 변경 이력을 모두 보관하고, 필요할 때 이벤트를 재생하여 현재 상태를 재구성할 수 있습니다.&lt;/li>
&lt;li>&lt;strong>감사 로그(Audit Log)&lt;/strong>: 모든 이벤트가 보관되므로 언제든 과거 기록을 조회할 수 있습니다.&lt;/li>
&lt;/ul>
&lt;p>물론 Kafka도 Pub/Sub 패턴을 지원하기 때문에 Event Broker처럼 사용할 수 있습니다. 하지만 Kafka를 단순히 &amp;ldquo;여러 구독자에게 이벤트를 전달하는 도구&amp;quot;로만 보기보다는, &lt;strong>이벤트의 영속성과 재처리 가능성&lt;/strong>이 필요한 경우에 선택하는 것이 바람직하지 않나 싶습니다.&lt;/p>
&lt;p>다만 한 가지 주의할 점이 있습니다. Kafka가 강력하고 좋은 도구인 것은 맞지만, 그만큼 &lt;strong>트레이드오프&lt;/strong>가 존재합니다. 파티션, 오프셋, 컨슈머 그룹 등 학습해야 할 개념들이 많고, 클러스터 운영과 모니터링에 들어가는 리소스도 만만치 않습니다. 저도 처음 Kafka를 도입했을 때 &amp;ldquo;이벤트 재처리가 가능하다&amp;quot;는 장점에 끌렸는데, 막상 운영해보니 그 장점을 누리기 위해 감수해야 할 복잡성이 상당하더라구요. 단순한 이벤트 전파가 목적이라면 SNS+SQS 조합이 훨씬 가볍고 관리하기 편한 것 같습니다.&lt;/p>
&lt;p>또 하나 반드시 알아야 할 점이 있습니다. &lt;strong>Kafka는 기본적으로 At-least-once 전달을 보장합니다.&lt;/strong> 즉, 메시지가 최소 한 번은 전달되지만, 네트워크 문제나 Consumer 재시작 등으로 인해 &lt;strong>같은 메시지가 중복 처리될 수 있습니다.&lt;/strong> Exactly-once 시맨틱을 지원하긴 하지만 설정이 복잡하고 성능 오버헤드가 있어서, 대부분의 경우 &lt;strong>Consumer 쪽에서 멱등성(Idempotency)을 보장하도록 설계&lt;/strong>하는 것이 좋다고 생각합니다. &amp;ldquo;이벤트니까 한 번만 처리되겠지&amp;quot;라고 생각하면 나중에 중복 처리 버그로 고생할 수 있습니다.&lt;/p>
&lt;p>Kafka에 대해 너무 잘 정리된 글이 있어 혹시 Kafka를 더 깊이 이해하고 싶으신 분들은 다음 글을 참고하시면 좋을 것 같습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://medium.com/rate-labs/%EC%86%8C%ED%94%84%ED%8A%B8%EC%9B%A8%EC%96%B4-%EC%97%94%EC%A7%80%EB%8B%88%EC%96%B4%EA%B0%80-%EC%95%8C%EC%95%84%EC%95%BC-%ED%95%A0-%EB%A1%9C%EA%B7%B8%EC%97%90-%EB%8C%80%ED%95%9C-%EB%AA%A8%EB%93%A0-%EA%B2%83-11513af8b998"target="_blank" rel="noopener">소프트웨어 엔지니어가 알아야 할 로그에 대한 모든 것&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>Linkedin에서 Apache Kafka를 개발한 Jay Kreps가 2013년에 쓴 글을 번역 및 해석한 아티클인데 로그에서 시작해서 Kafka가 만들어진 배경과 설계 철학, 그리고 Kafka의 내부 동작 원리까지 아주 잘 설명되어 있습니다. 저도 기회가 된다면 따로 Kafka 분석 글을 써보고 싶네요.&lt;/p>
&lt;p>다시 본론으로 돌아가 보겠습니다. 그렇다면 저희는 어떤 도구를 선택해야 할까요?&lt;/p>
&lt;h3>Message Queue vs Event Broker vs Kafka 비교&lt;span class="hx:absolute hx:-mt-20" id="message-queue-vs-event-broker-vs-kafka-비교">&lt;/span>
&lt;a href="#message-queue-vs-event-broker-vs-kafka-%eb%b9%84%ea%b5%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>항목&lt;/th>
&lt;th>Message Queue&lt;/th>
&lt;th>Event Broker&lt;/th>
&lt;th>Kafka&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>통신 패턴&lt;/td>
&lt;td>점대점 (1:1)&lt;/td>
&lt;td>발행-구독 (1:N)&lt;/td>
&lt;td>발행-구독 (1:N)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>소비 방식&lt;/td>
&lt;td>하나의 메시지는 하나의 Consumer만 처리&lt;/td>
&lt;td>모든 Subscriber에게 전달&lt;/td>
&lt;td>Consumer Group별로 분배&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>메시지 저장&lt;/td>
&lt;td>소비(ACK) 후 삭제&lt;/td>
&lt;td>기본적으로 영속화 안 함 (구현체마다 다름)&lt;/td>
&lt;td>Retention 기간 동안 보관&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>재처리&lt;/td>
&lt;td>DLQ로 실패 메시지만 재처리&lt;/td>
&lt;td>불가&lt;/td>
&lt;td>Offset 리셋으로 전체 재처리 가능&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>순서 보장&lt;/td>
&lt;td>FIFO Queue로 가능&lt;/td>
&lt;td>보장 안 됨&lt;/td>
&lt;td>Partition 내에서 보장&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>주요 용도&lt;/td>
&lt;td>작업 분배, 비동기 처리&lt;/td>
&lt;td>이벤트 브로드캐스트&lt;/td>
&lt;td>이벤트 스트리밍, 이벤트 소싱&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>대표 구현체&lt;/td>
&lt;td>SQS, RabbitMQ&lt;/td>
&lt;td>SNS, Redis Pub/Sub&lt;/td>
&lt;td>Apache Kafka, AWS MSK&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>실제로는 이것들을 함께 사용하는 경우가 많습니다. 예를 들어 SNS로 이벤트를 발행하고, 각 서비스는 자신만의 SQS를 구독하여 메시지를 처리하는 방식입니다. 또는 Kafka에 이벤트를 발행하고, 각 서비스가 Consumer Group으로 구독하는 방식도 있습니다. &lt;strong>어떤 조합이 적합한지는 이벤트 재처리 필요성, 메시지 순서 보장, 처리량 등을 고려해서 결정&lt;/strong>해야 합니다.&lt;/p>
&lt;h3>Choreography vs Orchestration&lt;span class="hx:absolute hx:-mt-20" id="choreography-vs-orchestration">&lt;/span>
&lt;a href="#choreography-vs-orchestration" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>비동기 통신에서 또 하나 중요한 개념이 있습니다. 바로 여러 서비스 간의 &lt;strong>워크플로우를 어떻게 관리할 것인가&lt;/strong>에 대한 문제입니다.&lt;/p>
&lt;p>이에 대한 대표적인 두 가지 접근 방식이 &lt;strong>Choreography&lt;/strong>와 &lt;strong>Orchestration&lt;/strong>입니다.&lt;/p>
&lt;h4>Choreography (안무)&lt;span class="hx:absolute hx:-mt-20" id="choreography-안무">&lt;/span>
&lt;a href="#choreography-%ec%95%88%eb%ac%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>Choreography는 중앙 조정자 없이 &lt;strong>각 서비스가 이벤트에 반응하여 자율적으로 동작&lt;/strong>하는 방식입니다. 마치 춤을 출 때 안무가 없이 각자가 음악에 맞춰 자유롭게 움직이는 것과 비슷하다고 할 수 있습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
Order[&amp;#34;주문 서비스&amp;#34;] --&amp;gt;|&amp;#34;주문완료 이벤트&amp;#34;| Broker[&amp;#34;Event Broker&amp;#34;]
Broker --&amp;gt;|&amp;#34;구독&amp;#34;| Payment[&amp;#34;결제 서비스&amp;#34;]
Payment --&amp;gt;|&amp;#34;결제완료 이벤트&amp;#34;| Broker
Broker --&amp;gt;|&amp;#34;구독&amp;#34;| Inventory[&amp;#34;재고 서비스&amp;#34;]
Inventory --&amp;gt;|&amp;#34;재고차감완료 이벤트&amp;#34;| Broker
Broker --&amp;gt;|&amp;#34;구독&amp;#34;| Notification[&amp;#34;알림 서비스&amp;#34;]
&lt;/pre>&lt;p>각 서비스는 자신이 관심 있는 이벤트만 구독하고, 자신의 작업이 완료되면 새로운 이벤트를 발행합니다. 전체 워크플로우를 관리하는 중앙 컴포넌트가 없기 때문에 &lt;strong>서비스 간 결합도가 낮고&lt;/strong>, 새로운 서비스를 추가하기도 쉽습니다.&lt;/p>
&lt;p>하지만 단점도 존재합니다. 전체 워크플로우가 여러 서비스에 분산되어 있기 때문에 &lt;strong>흐름을 파악하기 어렵고&lt;/strong>, 문제가 발생했을 때 &lt;strong>디버깅이 복잡&lt;/strong>해질 수 있습니다. 또한 서비스가 많아질수록 이벤트 간의 관계가 복잡해져서 관리가 어려워질 수 있습니다.&lt;/p>
&lt;h4>Orchestration (오케스트라)&lt;span class="hx:absolute hx:-mt-20" id="orchestration-오케스트라">&lt;/span>
&lt;a href="#orchestration-%ec%98%a4%ec%bc%80%ec%8a%a4%ed%8a%b8%eb%9d%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>Orchestration은 &lt;strong>중앙 조정자(Orchestrator)가 전체 워크플로우를 관리&lt;/strong>하는 방식입니다. 마치 오케스트라의 지휘자가 각 악기의 연주를 조율하는 것과 비슷하다고 할 수 있습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
Orchestrator[&amp;#34;주문 오케스트레이터&amp;#34;]
Orchestrator --&amp;gt;|&amp;#34;1. 결제 요청&amp;#34;| Payment[&amp;#34;결제 서비스&amp;#34;]
Payment --&amp;gt;|&amp;#34;결제 완료&amp;#34;| Orchestrator
Orchestrator --&amp;gt;|&amp;#34;2. 재고 차감&amp;#34;| Inventory[&amp;#34;재고 서비스&amp;#34;]
Inventory --&amp;gt;|&amp;#34;차감 완료&amp;#34;| Orchestrator
Orchestrator --&amp;gt;|&amp;#34;3. 알림 발송&amp;#34;| Notification[&amp;#34;알림 서비스&amp;#34;]
&lt;/pre>&lt;p>Orchestrator가 워크플로우의 각 단계를 순차적으로 호출하고, 각 서비스의 응답을 받아서 다음 단계를 진행합니다. &lt;strong>전체 흐름이 한 곳에 집중&lt;/strong>되어 있기 때문에 워크플로우를 파악하기 쉽고, 에러 처리나 보상 트랜잭션 구현도 상대적으로 용이합니다.&lt;/p>
&lt;p>하지만 Orchestrator가 &lt;strong>단일 장애점(Single Point of Failure)&lt;/strong> 이 될 수 있고, 모든 서비스가 Orchestrator에 의존하기 때문에 &lt;strong>결합도가 높아질 수 있다는 점&lt;/strong>을 고려해야 합니다.&lt;/p>
&lt;h4>언제 무엇을?&lt;span class="hx:absolute hx:-mt-20" id="언제-무엇을-1">&lt;/span>
&lt;a href="#%ec%96%b8%ec%a0%9c-%eb%ac%b4%ec%97%87%ec%9d%84-1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>항목&lt;/th>
&lt;th>Choreography&lt;/th>
&lt;th>Orchestration&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>결합도&lt;/td>
&lt;td>낮음&lt;/td>
&lt;td>높음&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>흐름 파악&lt;/td>
&lt;td>어려움&lt;/td>
&lt;td>쉬움&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>확장성&lt;/td>
&lt;td>좋음&lt;/td>
&lt;td>보통&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>에러 처리&lt;/td>
&lt;td>복잡함&lt;/td>
&lt;td>상대적으로 용이&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>적합한 상황&lt;/td>
&lt;td>단순한 이벤트 전파, 느슨한 결합 필요 시&lt;/td>
&lt;td>복잡한 비즈니스 로직, 트랜잭션 관리 필요 시&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>제 경험상 두 가지를 명확하게 구분해서 사용하기보다는, &lt;strong>상황에 따라 혼합해서 사용&lt;/strong>하는 경우가 많았습니다.&lt;/p>
&lt;p>단순한 이벤트 전파(알림 발송, 로그 기록 등)에는 Choreography를, 복잡한 비즈니스 트랜잭션(주문-결제-재고 처리 등)에는 Orchestration을 적용하는 식입니다.&lt;/p>
&lt;p>결국 &lt;strong>비동기 통신은 &amp;ldquo;의존성을 덜어내는&amp;rdquo; 시스템에 만드는 것&lt;/strong>이라고 생각합니다. 메시지가 쌓여있다가 나중에 처리되어도 괜찮은 작업, 잠시 지연되어도 비즈니스에 큰 영향이 없는 작업을 분리해내는 거죠.&lt;/p>
&lt;h4>언제 쓰면 안 되는가?&lt;span class="hx:absolute hx:-mt-20" id="언제-쓰면-안-되는가-1">&lt;/span>
&lt;a href="#%ec%96%b8%ec%a0%9c-%ec%93%b0%eb%a9%b4-%ec%95%88-%eb%90%98%eb%8a%94%ea%b0%80-1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>비동기 통신도 마찬가지로 &lt;strong>피해야 할 상황&lt;/strong>이 있습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Kafka를 피해야 할 때&lt;/strong>: 단순한 이벤트 전파가 목적일 때 (SNS+SQS가 훨씬 가벼움), 클러스터 운영 역량이 부족할 때, 이벤트 재처리가 필요 없는 경우&lt;/li>
&lt;li>&lt;strong>Choreography를 피해야 할 때&lt;/strong>: 워크플로우가 5단계 이상으로 복잡할 때, 보상 트랜잭션이 필요할 때, &amp;ldquo;지금 전체 흐름이 어디까지 진행됐지?&amp;ldquo;를 알아야 할 때&lt;/li>
&lt;li>&lt;strong>비동기 자체를 피해야 할 때&lt;/strong>: 사용자가 즉시 결과를 확인해야 할 때, 순서 보장이 까다로운 작업, 디버깅 복잡도를 감당할 팀 역량이 없을 때&lt;/li>
&lt;/ul>
&lt;p>또한 비동기 통신을 도입할 때 주의해야 할 점이 하나 더 있는 것 같습니다. &lt;strong>이벤트 처리를 남발하거나, 제대로 문서화하지 않거나, 일관성 없이 개발하면 복잡도가 심각하게 증가할 수 있습니다.&lt;/strong> 언제, 누구에 의해 이벤트가 발행되고, 누가 그 이벤트를 처리하는지 파악할 수 없게 되면 서비스 전체를 이해하기 어렵게 만드는 주범이 되더라구요.&lt;/p>
&lt;p>실제로 제가 팀에 합류했을 때 이미 MSA 전환이 진행 중이었는데, 서비스 파악에서 가장 어려웠던 부분 중 하나가 SNS+SQS 조합이었습니다. 문서화가 전혀 되어 있지 않아서 각 서비스 코드에서 Ctrl+F로 토픽 이름을 검색하며 발행하는 곳과 구독하는 곳을 하나하나 찾아다녀야 했습니다. 이벤트 기반 아키텍처의 장점인 &amp;ldquo;느슨한 결합&amp;quot;이 오히려 &amp;ldquo;아무도 전체 흐름을 모르는 상태&amp;quot;로 변질될 수 있다고 생각합니다.&lt;/p>
&lt;p>개인적으로 비동기는 &lt;strong>복잡도와 장애전파를 트레이드 오프를 통해 바꾼 것&lt;/strong>인 것 같습니다. 동기 호출의 &amp;ldquo;장애 전파&amp;rdquo; 문제가 비동기에서는 &amp;ldquo;메시지 유실&amp;rdquo;, &amp;ldquo;순서 역전&amp;rdquo;, &amp;ldquo;중복 처리&amp;rdquo; 문제로 바뀝니다.&lt;/p>
&lt;h2>정리: 그래서 뭘 선택해야 할까?&lt;span class="hx:absolute hx:-mt-20" id="정리-그래서-뭘-선택해야-할까">&lt;/span>
&lt;a href="#%ec%a0%95%eb%a6%ac-%ea%b7%b8%eb%9e%98%ec%84%9c-%eb%ad%98-%ec%84%a0%ed%83%9d%ed%95%b4%ec%95%bc-%ed%95%a0%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>지금까지 MSA 환경에서의 다양한 통신 방식들을 살펴보았습니다. 그렇다면 실제로 어떤 방식을 선택해야 할까요?&lt;/p>
&lt;p>제 개인적인 생각에 &lt;strong>기술은 양자택일이 아니라는 것&lt;/strong>입니다. 물론 Event-Driven Architecture(EDA)처럼 이벤트 기반 통신만으로 시스템을 구성하는 아키텍처 패턴도 있지만, 실제 MSA 환경에서는 하나의 시스템 내에서 상황에 따라 동기와 비동기를 함께 사용하는 것이 일반적인 것 같습니다.&lt;/p>
&lt;p>예를 들어 주문 플로우를 생각해보면&lt;/p>
&lt;ul>
&lt;li>&lt;strong>주문 → 회원 잔액 조회&lt;/strong>: 동기 (결제 전에 잔액 확인이 필수)&lt;/li>
&lt;li>&lt;strong>주문 → 결제 처리&lt;/strong>: 동기 (결제 결과를 즉시 사용자에게 알려야 함)&lt;/li>
&lt;li>&lt;strong>주문 완료 → 알림 발송&lt;/strong>: 비동기 (알림이 늦어져도 주문 자체엔 영향 없음)&lt;/li>
&lt;li>&lt;strong>주문 완료 → 정산 데이터 기록&lt;/strong>: 비동기 (실시간 처리가 필요 없음)&lt;/li>
&lt;/ul>
&lt;p>이처럼 &lt;strong>즉시 응답이 필요한 핵심 흐름은 동기로, 지연되어도 괜찮은 부가 작업은 비동기로&lt;/strong> 분리하는 것이 일반적인 패턴인 것 같습니다.&lt;/p>
&lt;p>또 동기 비동기를 결정했다면, 그 다음으로 &lt;strong>어떤 프로토콜이나 메시징 시스템을 사용할지&lt;/strong>를 결정해야 합니다. 이 부분도 역시 상황에 따라 다릅니다.&lt;/p>
&lt;p>다만 제가 중요하게 생각하는 부분은 일관성입니다. &lt;strong>한 시스템 내에서는 가능한 한 일관된 통신 방식을 유지하는 것&lt;/strong>이 운영과 유지보수에 큰 도움이 된다고 생각합니다.&lt;/p>
&lt;p>만약 일관되지 않게 어디에선 REST API, 또 어디에선 GraphQL을 사용한다면 서비스 파악과 디버깅이 어려워질 수밖에 없습니다. 팀 내에서 명확한 가이드라인을 세우고, 그에 따라 일관되게 적용하는 것이 중요하다고 생각합니다.&lt;/p>
&lt;h3>통신 방식 결정 플로우차트&lt;span class="hx:absolute hx:-mt-20" id="통신-방식-결정-플로우차트">&lt;/span>
&lt;a href="#%ed%86%b5%ec%8b%a0-%eb%b0%a9%ec%8b%9d-%ea%b2%b0%ec%a0%95-%ed%94%8c%eb%a1%9c%ec%9a%b0%ec%b0%a8%ed%8a%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;pre class="mermaid hx:mt-6">
flowchart TD
Start[&amp;#34;서비스 간 통신이 필요한가?&amp;#34;]
Start --&amp;gt;|Yes| Q1[&amp;#34;즉시 응답이 필요한가?&amp;#34;]
Q1 --&amp;gt;|Yes| Sync[&amp;#34;동기 통신&amp;#34;]
Q1 --&amp;gt;|No| Async[&amp;#34;비동기 통신&amp;#34;]
Sync --&amp;gt; Q2[&amp;#34;서비스 간 내부 통신인가?&amp;#34;]
Q2 --&amp;gt;|Yes| Q3[&amp;#34;고성능이 필요한가?&amp;#34;]
Q2 --&amp;gt;|No| REST[&amp;#34;REST API&amp;#34;]
Q3 --&amp;gt;|Yes| gRPC[&amp;#34;gRPC&amp;#34;]
Q3 --&amp;gt;|No| REST2[&amp;#34;REST API&amp;#34;]
Async --&amp;gt; Q4[&amp;#34;여러 서비스가 같은 이벤트를 처리해야 하는가?&amp;#34;]
Q4 --&amp;gt;|Yes| Q5[&amp;#34;이벤트 재처리/영속성이 필요한가?&amp;#34;]
Q4 --&amp;gt;|No| MessageQueue[&amp;#34;Message Queue&amp;lt;br/&amp;gt;(SQS, RabbitMQ)&amp;#34;]
Q5 --&amp;gt;|Yes| Kafka[&amp;#34;Kafka&amp;#34;]
Q5 --&amp;gt;|No| EventBroker[&amp;#34;Event Broker&amp;lt;br/&amp;gt;(SNS, Redis Pub/Sub)&amp;#34;]
&lt;/pre>&lt;p>물론 이 플로우차트는 일반적인 가이드라인일 뿐입니다. 실제로는 팀의 상황, 기존 인프라, 운영 역량 등을 종합적으로 고려해서 결정해야 한다고 생각합니다.&lt;/p>
&lt;p>결국 저는 &lt;strong>MSA에서 통신 방식을 선택한다는 건 기술의 문제가 아니라, 장애를 어디서 어떻게 감당할 것인가의 문제&lt;/strong>라고 생각합니다. 동기 호출을 하나 추가할 때마다 장애 전파 범위가 넓어지고, 비동기로 전환하면 즉시성을 포기하는 대신 장애 격리를 얻게 되는 것 같습니다.&lt;/p>
&lt;h3>결론&lt;span class="hx:absolute hx:-mt-20" id="결론">&lt;/span>
&lt;a href="#%ea%b2%b0%eb%a1%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>굉장히 진부한 말일 수 있지만 결국 &lt;strong>정답은 없다고 생각합니다&lt;/strong>. 각 방식의 트레이드오프를 이해하고, 우리 팀과 서비스의 상황에 맞는 선택을 하는 것이 중요하지 않을까싶네요.&lt;/p>
&lt;p>그리고 저는 위에서도 언급했지만 기술 선택보다 더 중요한 건 &lt;strong>팀과의 컨벤션을 지키는 것&lt;/strong>이라고 생각합니다. 예를 들어 팀에서 &amp;ldquo;MSA 내부 서비스 간 통신도 REST API를 사용하자&amp;quot;고 협의했다면, 내가 아무리 gRPC가 성능상 더 좋다고 생각하더라도 혼자서 gRPC를 도입하면 안 된다고 생각해요. 그 순간 일관성이 깨지고 복잡도가 올라가서 결국 팀 전체에 안 좋은 영향을 미치게 되니까요. 만약 정말로 더 타당한 기술이 있다고 생각한다면, 팀 전체와 이야기해서 함께 컨벤션을 정하고 그 방향으로 수정해 나가는 게 맞다고 생각합니다.&lt;/p>
&lt;p>MSA에서 서비스 간 통신은 단순히 &amp;ldquo;REST냐 gRPC냐&amp;rdquo;, &amp;ldquo;Kafka를 쓰느냐 마느냐&amp;quot;의 문제가 아니라, 장애를 어디까지 허용할 것인지, 지연을 어디서 감당할 것인지, 그리고 복잡도를 어디에 둘 것인지에 대한 선택에 가깝다고 느꼈습니다.&lt;/p>
&lt;p>이번 편에서는 그 선택의 갈림길들과 그 속에서 제가 했던 고민들을 최대한 구조적으로 정리해보려 했습니다.&lt;/p>
&lt;p>그런데 한 가지 문제가 남습니다. 동기 호출을 선택했다면, 호출 대상 서비스가 죽으면 어떻게 될까요? 결제 서비스가 느려지면 주문 서비스도 느려지고, 주문 서비스가 느려지면 그걸 호출하는 서비스도 덩달아 느려집니다. 장애가 도미노처럼 전파되는 거죠. 이런 연쇄적 장애 전파(Cascading Failure)는 동기 호출의 특성입니다. 호출자가 응답을 기다리기 때문에, 피호출자의 장애가 호출자에게 즉시 영향을 미칩니다.&lt;/p>
&lt;p>비동기는 다릅니다. 메시지를 큐에 넣고 바로 반환하기 때문에, Consumer가 죽어있어도 Producer는 계속 동작할 수 있습니다. 장애가 &amp;ldquo;즉시 전파&amp;quot;되지 않는 거죠. 대신 메시지가 큐에 쌓이고, Consumer가 복구되면 그때 처리됩니다. 하지만 비동기라고 문제가 없는 건 아닙니다. 메시지 유실이나 중복 처리 같은 데이터 일관성 문제가 생깁니다. 결국 어떤 방식을 선택하든 장애에 대한 대응은 필요합니다.&lt;/p>
&lt;p>다음 편에서는 동기 호출에서 장애가 어떻게 전파되고, 이를 어디서 끊어야 하는지에 대해 이야기해보려고 합니다. 비동기의 데이터 일관성 문제는 &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-6-event-consistency/">6편&lt;/a> 이벤트 기반 데이터 정합성에서 다룰 예정입니다.&lt;/p>
&lt;p>후편: &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-4-resilience/">[MSA에 관한 고찰 4/7편] 장애는 어떻게 전파되고, 우리는 어디서 끊어야 하는가&lt;/a>&lt;/p>
&lt;h2>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>분산 시스템 기초&lt;span class="hx:absolute hx:-mt-20" id="분산-시스템-기초">&lt;/span>
&lt;a href="#%eb%b6%84%ec%82%b0-%ec%8b%9c%ec%8a%a4%ed%85%9c-%ea%b8%b0%ec%b4%88" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>Peter Deutsch, James Gosling - &lt;a href="https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing"target="_blank" rel="noopener">Fallacies of Distributed Computing&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>Martin Kleppmann - &lt;em>Designing Data-Intensive Applications&lt;/em> (O&amp;rsquo;Reilly, 2017)&lt;/li>
&lt;/ul>
&lt;h3>통신 프로토콜&lt;span class="hx:absolute hx:-mt-20" id="통신-프로토콜">&lt;/span>
&lt;a href="#%ed%86%b5%ec%8b%a0-%ed%94%84%eb%a1%9c%ed%86%a0%ec%bd%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://grpc.io/docs/"target="_blank" rel="noopener">gRPC Documentation&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://spec.graphql.org/"target="_blank" rel="noopener">GraphQL Specification&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.apollographql.com/docs/federation/"target="_blank" rel="noopener">Apollo Federation&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>메시징 시스템&lt;span class="hx:absolute hx:-mt-20" id="메시징-시스템">&lt;/span>
&lt;a href="#%eb%a9%94%ec%8b%9c%ec%a7%95-%ec%8b%9c%ec%8a%a4%ed%85%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://kafka.apache.org/documentation/"target="_blank" rel="noopener">Apache Kafka Documentation&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.rabbitmq.com/tutorials"target="_blank" rel="noopener">RabbitMQ Tutorials&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://docs.aws.amazon.com/sqs/"target="_blank" rel="noopener">AWS SQS Developer Guide&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>[MSA에 관한 고찰 2/7편] MSA에서 서비스는 어떻게 나눌 것인가</title><link>https://jeongil.dev/ko/blog/architecture/msa-series-2-boundary/</link><pubDate>Thu, 15 Jan 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/architecture/msa-series-2-boundary/</guid><description>
&lt;p>전편: &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-1-introduction/">[MSA에 관한 고찰 1/7편] MSA(Microservices Architecture)란 무엇인가?&lt;/a>&lt;/p>
&lt;hr>
&lt;p>저번 편에서 MSA의 개념과 등장 배경, 그리고 여러 대안들에 대해 살펴보았습니다.&lt;/p>
&lt;p>MSA를 도입하기로 결정했다면, 이제 첫 번째 질문과 마주하게 됩니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;서비스를 어떻게 나눌 것인가?&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>이 질문이 왜 중요할까요? 솔직히 말씀드리면, 저는 이 문제가 MSA에서 &lt;strong>가장 어렵고 중요한 결정&lt;/strong>이지 않나 싶습니다. 통신 방식이나 장애 대응 패턴은 나중에 바꿀 수 있지만, 서비스 경계는 한번 정하면 바꾸기가 정말 쉽지 않은 것 같거든요.&lt;/p>
&lt;h2>잘못 나누면 어떻게 될까요?&lt;span class="hx:absolute hx:-mt-20" id="잘못-나누면-어떻게-될까요">&lt;/span>
&lt;a href="#%ec%9e%98%eb%aa%bb-%eb%82%98%eb%88%84%eb%a9%b4-%ec%96%b4%eb%96%bb%ea%b2%8c-%eb%90%a0%ea%b9%8c%ec%9a%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>본격적으로 &amp;ldquo;어떻게 나눌 것인가&amp;quot;를 이야기하기 전에, 잘못 나누면 어떤 일이 생기는지 먼저 살펴보려 합니다. 문제를 제대로 알면 본질도 파악할 수 있으니까요.&lt;/p>
&lt;h3>Distributed Monolith의 고통&lt;span class="hx:absolute hx:-mt-20" id="distributed-monolith의-고통">&lt;/span>
&lt;a href="#distributed-monolith%ec%9d%98-%ea%b3%a0%ed%86%b5" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>만약 저희가 별다른 고민없이 일단 서비스를 나눠 MSA를 구현했다고 가정하겠습니다. 그런데 나중에 보니 오히려 개발과 운영이 더 힘들어졌다면 어떨까요?&lt;/p>
&lt;p>그런 케이스 중에 하나는 &lt;strong>Distributed Monolith(분산 모놀리식)&lt;/strong> 에 빠졌을 때입니다.&lt;/p>
&lt;p>Distributed Monolith가 뭘까요? 서비스는 여러 개로 나눠져 있는데, 실제로는 모놀리식처럼 동작하는 상태를 말합니다. MSA의 형태만 갖췄을 뿐, MSA의 장점은 하나도 누리지 못하는 거죠.&lt;/p>
&lt;p>어떻게 이런 일이 생길까요? 여러 원인이 있지만, 대표적인 게 &lt;strong>서비스 경계를 잘못 나누는 것&lt;/strong>입니다. 콘서트 예매 서비스를 예로 들어보겠습니다. MSA로 전환하면서 이렇게 나눴다고 가정해보죠.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
subgraph DM[&amp;#34;기술 레이어 기반 분리&amp;#34;]
UI[&amp;#34;UI 서비스&amp;lt;br/&amp;gt;(화면 렌더링)&amp;#34;]
BL[&amp;#34;비즈니스 로직 서비스&amp;lt;br/&amp;gt;(주문, 결제, 재고 처리)&amp;#34;]
Data[&amp;#34;데이터 서비스&amp;lt;br/&amp;gt;(DB 접근)&amp;#34;]
end
UI --&amp;gt; BL --&amp;gt; Data
Data --&amp;gt; DB[(Database)]
&lt;/pre>&lt;p>얼핏 보면 깔끔하게 나눈 것 같은데요. 그런데 이 구조에서 &amp;ldquo;주문 기능&amp;quot;을 추가한다고 생각해보겠습니다. 그럼 우선 UI 서비스에 주문 화면을 추가해야 하고, 비즈니스 로직 서비스에 주문 처리 로직을 추가해야 하며, 데이터 서비스에 주문 데이터 접근 코드를 추가해야 합니다.&lt;/p>
&lt;p>이렇게 되면 &lt;strong>하나의 기능을 위해 세 개의 서비스를 모두 수정해야 합니다.&lt;/strong> 배포도 마찬가지죠. 주문 기능을 배포하려면 세 서비스를 함께 배포해야 하고요.&lt;/p>
&lt;p>어떠신가요? 서비스를 나눴는데도 결국 모놀리식과 똑같은 문제가 생깁니다. 아니, 오히려 더 나빠진 거죠. &lt;strong>모놀리식의 단점(함께 수정, 함께 배포)에 MSA의 단점(네트워크 복잡성, 운영 부담)까지 더해진&lt;/strong> 최악의 상황에 가깝습니다.&lt;/p>
&lt;p>왜 이렇게 됐을까요? &lt;strong>비즈니스 기능이 아닌 기술적 관심사로 서비스를 나눴기 때문&lt;/strong>입니다. &amp;ldquo;주문&amp;quot;이라는 하나의 비즈니스 기능이 세 개의 서비스에 흩어져 버린 거죠. 이게 바로 &amp;ldquo;서비스를 잘못 나눈&amp;rdquo; 전형적인 예시이지 않을까 싶습니다.&lt;/p>
&lt;p>저도 이와 똑같진 않지만 비슷한 상황을 경험한 적이 있습니다. 서비스는 분리되어 있는데, 하나의 기능을 수정하려면 여러 서비스를 동시에 건드려야 했거든요. &amp;ldquo;이게 MSA 맞나?&amp;rdquo; 싶은 순간들이 있었습니다.&lt;/p>
&lt;p>게다가 더 큰 문제가 있습니다. 한번 잘못 나누면 바꾸기가 정말 어렵습니다.&lt;/p>
&lt;h3>왜 바꾸기가 어려울까요?&lt;span class="hx:absolute hx:-mt-20" id="왜-바꾸기가-어려울까요">&lt;/span>
&lt;a href="#%ec%99%9c-%eb%b0%94%ea%be%b8%ea%b8%b0%ea%b0%80-%ec%96%b4%eb%a0%a4%ec%9a%b8%ea%b9%8c%ec%9a%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>서비스 경계를 나중에 바꾸려면 어떤 일이 필요할까요?&lt;/p>
&lt;ul>
&lt;li>&lt;strong>데이터 마이그레이션&lt;/strong>: 분리된 DB의 데이터를 합치거나, 하나의 DB를 나눠야 합니다&lt;/li>
&lt;li>&lt;strong>API 변경&lt;/strong>: 다른 서비스들이 호출하던 API가 바뀝니다. 호출하는 쪽도 다 수정해야 합니다&lt;/li>
&lt;li>&lt;strong>이벤트 재설계&lt;/strong>: 발행하던 이벤트, 구독하던 이벤트가 바뀝니다&lt;/li>
&lt;li>&lt;strong>배포 전략&lt;/strong>: 기존 서비스와 새 서비스를 어떻게 전환할지 고민해야 합니다&lt;/li>
&lt;/ul>
&lt;p>간단한 리팩토링이 아니라 연관된 모든 부분을 다 확인해야 하니, 큰 작업이 될 수밖에 없습니다. 그래서 경험상 서비스 경계를 바꾸는 건 새로 만드는 것보다 힘들 때도 있었습니다.&lt;/p>
&lt;p>개발을 하다보면 가끔 &amp;ldquo;처음부터 만드는게 빠르겠다&amp;quot;라는 생각이 들 때가 있는데, 경계 변경이 그런 경우가 꽤 있었습니다.&lt;/p>
&lt;p>그래서 저는 &lt;strong>처음에 경계를 잘 설정하는 것도 중요하지만, 변경이 용이한 구조를 유지하는 것도 그만큼 중요하다&lt;/strong>고 생각합니다. 완벽한 경계란 없으니까요. 최소한 큰 방향은 맞추되, 나중에 조정할 여지를 남겨두는 게 현실적인 것 같습니다.&lt;/p>
&lt;p>그렇다면 서비스 경계를 어떻게 설정해야 할까요?&lt;/p>
&lt;h2>무엇을 기준으로 나눌 것인가&lt;span class="hx:absolute hx:-mt-20" id="무엇을-기준으로-나눌-것인가">&lt;/span>
&lt;a href="#%eb%ac%b4%ec%97%87%ec%9d%84-%ea%b8%b0%ec%a4%80%ec%9c%bc%eb%a1%9c-%eb%82%98%eb%88%8c-%ea%b2%83%ec%9d%b8%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>서비스를 나누는 기준은 여러 가지가 있습니다. 그런데 기준을 이야기하기 전에, 한 가지 질문을 먼저 던져보고 싶습니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;왜 기준이 필요할까요?&amp;rdquo;&lt;/strong> 그냥 느낌대로, 혹은 팀 구조대로 나누면 안 될까요?&lt;/p>
&lt;p>너무 당연해서 생각해 보신 적조차 없으신 질문이실 수도 있을 것 같습니다. 그런데 저는 이 질문이 굉장히 중요하다고 생각합니다. 기준이 없다면, 서비스 경계를 나누는 건 결국 &lt;strong>임의적 결정&lt;/strong>이 되기 쉽거든요.&lt;/p>
&lt;p>안타깝게도 그렇게 하면 앞서 본 Distributed Monolith가 될 가능성이 높습니다. 서로 강하게 엮인 기능들이 다른 서비스로 갈라지거나, 별 상관없는 기능들이 한 서비스에 뭉치게 되거든요.&lt;/p>
&lt;p>그래서 &lt;strong>&amp;ldquo;무엇이 함께 있어야 하고, 무엇이 분리되어야 하는가&amp;rdquo;&lt;/strong> 를 판단할 기준이 필요한 겁니다. 개발을 하면서 컨벤션을 정하는 것과 동일한 맥락이라고 생각합니다. 그래야 일관된 결정을 내릴 수 있고, 모호함을 줄일 수 있으니까요.&lt;/p>
&lt;p>그렇다면 어떤 기준으로 나눠야 할까요?&lt;/p>
&lt;h3>DDD와 Bounded Context&lt;span class="hx:absolute hx:-mt-20" id="ddd와-bounded-context">&lt;/span>
&lt;a href="#ddd%ec%99%80-bounded-context" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>서비스 경계를 이야기할 때 가장 많이 언급되는 개념이 &lt;strong>DDD(Domain-Driven Design)&lt;/strong> 와 &lt;strong>Bounded Context&lt;/strong>입니다.&lt;/p>
&lt;p>DDD는 &lt;strong>도메인(비즈니스 영역)을 중심으로 소프트웨어를 설계하는 접근 방식&lt;/strong>입니다. Aggregate, Entity, Value Object 등 다양한 개념이 있는데, DDD만 해도 책 한 권 분량이라 여기서 다 다루기는 어렵습니다. 기회가 되면 DDD에 대해서도 따로 다뤄보도록 하겠습니다.&lt;/p>
&lt;p>이 글에서는 서비스 경계와 가장 직접적으로 관련된 &lt;strong>Bounded Context&lt;/strong>에 집중해보겠습니다.&lt;/p>
&lt;p>Bounded Context가 뭘까요? 쉽게 말해 &lt;strong>같은 용어가 같은 의미로 통하는 범위&lt;/strong>입니다. 아마 잘 와닿지 않으실 수도 있을 것 같습니다. 저도 처음 이 개념을 접했을 때 솔직히 잘 와닿지 않았는데, 이해를 돕기 위해 예를 들어 설명해보겠습니다.&lt;/p>
&lt;p>콘서트 예매 서비스에서 &lt;strong>&amp;ldquo;고객&amp;rdquo;&lt;/strong> 이라는 용어를 생각해보죠.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>주문 컨텍스트&lt;/strong>에서 &amp;lsquo;고객&amp;rsquo;은 티켓을 구매하는 사람, 배송지 정보를 가진 사람을 의미 합니다.&lt;/li>
&lt;li>&lt;strong>마케팅 컨텍스트&lt;/strong>에서 &amp;lsquo;고객&amp;rsquo;은 마케팅 대상, 구매 이력과 선호 장르를 가진 사람을 의미 합니다.&lt;/li>
&lt;li>&lt;strong>정산 컨텍스트&lt;/strong>에서 &amp;lsquo;고객&amp;rsquo;은 결제 수단을 가진 사람, 환불 대상을 의미 합니다.&lt;/li>
&lt;/ul>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph OrderContext[&amp;#34;주문 컨텍스트&amp;#34;]
OrderCustomer[&amp;#34;고객&amp;lt;br/&amp;gt;- 이름&amp;lt;br/&amp;gt;- 배송지&amp;lt;br/&amp;gt;- 연락처&amp;#34;]
end
subgraph MarketingContext[&amp;#34;마케팅 컨텍스트&amp;#34;]
MarketingCustomer[&amp;#34;고객&amp;lt;br/&amp;gt;- 이름&amp;lt;br/&amp;gt;- 구매 이력&amp;lt;br/&amp;gt;- 선호 장르&amp;#34;]
end
subgraph SettlementContext[&amp;#34;정산 컨텍스트&amp;#34;]
SettlementCustomer[&amp;#34;고객&amp;lt;br/&amp;gt;- 이름&amp;lt;br/&amp;gt;- 결제 수단&amp;lt;br/&amp;gt;- 환불 계좌&amp;#34;]
end
&lt;/pre>&lt;p>같은 &amp;ldquo;고객&amp;quot;이라는 용어지만, 각 컨텍스트에서 관심 있는 속성과 행위가 다릅니다. 주문 컨텍스트에서는 고객의 마케팅 선호도가 중요하지 않고, 마케팅 컨텍스트에서는 고객의 결제 수단이 필요 없죠.&lt;/p>
&lt;p>이처럼 &lt;strong>같은 용어가 다른 의미로 사용되는 지점, 그게 바로 컨텍스트의 경계&lt;/strong>입니다. 그리고 이 Bounded Context가 서비스를 나누는 자연스러운 기준이 될 수 있죠.&lt;/p>
&lt;p>다만 한 가지 주의할 점은 &lt;strong>Bounded Context가 곧바로 하나의 마이크로서비스가 되는 건 아닙니다.&lt;/strong> 하나의 서비스 안에 여러 컨텍스트가 공존할 수도 있고, 반대로 하나의 컨텍스트가 여러 서비스로 구현될 수도 있습니다. Bounded Context는 &amp;ldquo;이렇게 나누면 자연스러울 수 있다&amp;quot;는 힌트를 주는 거지, 1:1 매핑을 강제하는 건 아니라고 생각합니다.&lt;/p>
&lt;p>그렇다면 Bounded Context만 알면 서비스 경계를 잘 나눌 수 있을까요? 저는 꼭 그렇지는 않다고 생각합니다. 다른 관점에서도 한번 살펴볼 필요가 있거든요.&lt;/p>
&lt;h3>Business Capability 기반 분해&lt;span class="hx:absolute hx:-mt-20" id="business-capability-기반-분해">&lt;/span>
&lt;a href="#business-capability-%ea%b8%b0%eb%b0%98-%eb%b6%84%ed%95%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Bounded Context가 &lt;strong>도메인 모델&lt;/strong> 관점에서 경계를 본다면, &lt;strong>Business Capability(비즈니스 역량)&lt;/strong> 는 &lt;strong>&amp;ldquo;이 비즈니스가 뭘 하는가&amp;rdquo;&lt;/strong> 의 관점에서 경계를 보는 방법입니다.&lt;/p>
&lt;p>Business Capability란 쉽게 말해 &amp;ldquo;비즈니스가 가치를 만들기 위해 갖춰야 하는 역량&amp;quot;입니다. 콘서트 예매 서비스라면 어떤 역량들이 있을까요?&lt;/p>
&lt;ul>
&lt;li>&lt;strong>티켓 판매&lt;/strong>: 콘서트 티켓을 판매하는 역량&lt;/li>
&lt;li>&lt;strong>좌석 관리&lt;/strong>: 좌석 배치와 가용성을 관리하는 역량&lt;/li>
&lt;li>&lt;strong>결제 처리&lt;/strong>: 결제를 수행하고 환불을 처리하는 역량&lt;/li>
&lt;li>&lt;strong>알림 발송&lt;/strong>: 사용자에게 알림을 보내는 역량&lt;/li>
&lt;/ul>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
subgraph Concert[&amp;#34;콘서트 예매 서비스&amp;#34;]
Ticketing[&amp;#34;티켓 서비스&amp;lt;br/&amp;gt;(티켓 판매)&amp;#34;]
Seat[&amp;#34;좌석 서비스&amp;lt;br/&amp;gt;(좌석 관리)&amp;#34;]
Payment[&amp;#34;결제 서비스&amp;lt;br/&amp;gt;(결제 처리)&amp;#34;]
Notification[&amp;#34;알림 서비스&amp;lt;br/&amp;gt;(알림 발송)&amp;#34;]
end
&lt;/pre>&lt;p>위 역량들이 각각 독립적으로 존재할 수 있다면, 이를 기준으로 서비스를 나누는 것도 자연스러운 방법입니다. 티켓 판매 기능을 개선할 때 좌석 관리나 결제 처리에 영향을 주지 않는다면, 이 둘은 분리하는 게 맞겠죠.&lt;/p>
&lt;p>다만 이 기준도 서비스 경계를 완벽히 정해주지는 않습니다. Business Capability 역시 하나의 서비스에 여러 역량이 포함될 수도 있고, 하나의 역량이 여러 서비스에 걸쳐 있을 수도 있기 때문에 서비스 후보군을 제시하는 정도로 이해하는 게 좋다고 생각합니다.&lt;/p>
&lt;p>Bounded Context와 Business Capability, 둘 다 서비스 경계를 나누는 기준이 될 수 있죠. 그렇다면 뭘 써야 할까요?&lt;/p>
&lt;p>제 경험상 &lt;strong>둘을 함께 사용&lt;/strong>하는 게 효과적이었던 것 같습니다. Business Capability로 먼저 큰 그림을 그리고, Bounded Context로 세부적인 경계를 검증하는 식이죠. &amp;ldquo;이 역량은 정말 하나의 컨텍스트인가? 아니면 여러 컨텍스트가 섞여 있는가?&amp;rdquo; 를 확인하는 겁니다.&lt;/p>
&lt;p>이때 혼자 혹은 개발팀만으로 결정하기보다는 도메인 전문가들과 함께 논의하는 게 중요하다고 생각합니다. 개발팀에서 생각하는 경계와 도메인 전문가가 생각하는 경계가 다를 수 있기 때문이죠. 여러 시각을 반영할수록 더 나은 결정을 내릴 수 있다고 믿습니다.&lt;/p>
&lt;h3>Conway의 법칙&lt;span class="hx:absolute hx:-mt-20" id="conway의-법칙">&lt;/span>
&lt;a href="#conway%ec%9d%98-%eb%b2%95%ec%b9%99" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>여기서 한 가지 더 고려해야 할 게 있습니다. 바로 &lt;strong>조직 구조&lt;/strong>입니다.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;시스템을 설계하는 조직은 그 조직의 커뮤니케이션 구조를 반영한 설계를 만들게 된다.&amp;rdquo;&lt;/p>
&lt;ul>
&lt;li>Melvin Conway, 1967&lt;/li>
&lt;/ul>
&lt;/blockquote>
&lt;p>처음 이 법칙을 들었을 때는 &amp;ldquo;당연한 얘기 아닌가?&amp;rdquo; 싶었습니다. 그런데 MSA를 경험하면서 이 법칙의 무게를 꽤나 실감하게 되었습니다.&lt;/p>
&lt;p>예를 들어, 주문팀과 결제팀이 분리되어 있다면 자연스럽게 주문 서비스와 결제 서비스가 분리될 가능성이 높습니다. 반대로 하나의 팀이 주문과 결제를 모두 담당한다면 두 기능이 하나의 서비스에 들어갈 가능성이 높아지죠.&lt;/p>
&lt;p>문제는 &lt;strong>조직 구조가 항상 합리적인 건 아니라는 점&lt;/strong>입니다. &amp;ldquo;원래 그래왔으니까&amp;quot;와 같은 이유로 팀 구조가 유지되는 경우가 많거든요. 그러다 보니 이상적인 서비스 구조와 현실의 조직 구조가 맞지 않는 경우가 자주 발생하는 것 같습니다.&lt;/p>
&lt;p>그래서 등장한 개념이 &lt;strong>Inverse Conway Maneuver(역 콘웨이 전략)&lt;/strong> 입니다. 원하는 시스템 구조에 맞게 &lt;strong>조직 구조를 먼저 바꾸는&lt;/strong> 거죠.&lt;/p>
&lt;p>물론 조직 구조를 바꾸는 건 쉬운 일이 아닙니다. 하지만 &amp;ldquo;우리 팀 구조가 이래서 이렇게 나눌 수밖에 없어&amp;quot;라고 체념하기보다는, &amp;ldquo;이상적인 시스템 구조가 뭘까?&amp;rdquo; 먼저 그려보고 조직 변경도 검토해보는 게 맞는 것 같습니다.&lt;/p>
&lt;p>다만 이러려면 조직 내에서 충분한 합의가 필요합니다. 조직 변경이 쉽지 않다는 걸 모두가 이해하고, 변화에 동의해야 하니까요.&lt;/p>
&lt;p>이상적으로는 조직과 시스템이 서로 맞물려 돌아가는 게 가장 좋겠지만, 현실적으로는 어려운 경우가 더 많은 것 같습니다. 다만 중요한 건 &lt;strong>조직과 시스템이 서로 영향을 주고받는다는 점을 인지하는 것&lt;/strong>이라고 생각합니다.&lt;/p>
&lt;h2>서비스 크기에 대한 고민&lt;span class="hx:absolute hx:-mt-20" id="서비스-크기에-대한-고민">&lt;/span>
&lt;a href="#%ec%84%9c%eb%b9%84%ec%8a%a4-%ed%81%ac%ea%b8%b0%ec%97%90-%eb%8c%80%ed%95%9c-%ea%b3%a0%eb%af%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>자, 이제 어떤 기준으로 나눌지는 어느 정도 감이 오셨을 겁니다. 그런데 또 다른 고민이 아직 남아 있습니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;얼마나 잘게 나눠야 할까요?&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>&amp;lsquo;어떻게?&amp;lsquo;를 생각했다면 이제는 &amp;lsquo;얼마나?&amp;lsquo;를 생각할 차례입니다.&lt;/p>
&lt;p>&amp;ldquo;마이크로서비스&amp;quot;라는 이름 때문에 서비스를 최대한 작게 나눠야 한다고 생각하시는 분들도 계신 것 같습니다. 그런데 정말 작을수록 좋을까요?&lt;/p>
&lt;h3>너무 작으면 어떻게 될까요?&lt;span class="hx:absolute hx:-mt-20" id="너무-작으면-어떻게-될까요">&lt;/span>
&lt;a href="#%eb%84%88%eb%ac%b4-%ec%9e%91%ec%9c%bc%eb%a9%b4-%ec%96%b4%eb%96%bb%ea%b2%8c-%eb%90%a0%ea%b9%8c%ec%9a%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>콘서트 예매 서비스에서 &amp;ldquo;고객 서비스&amp;quot;를 가능한 한 아주 잘게 나눴다고 가정해보겠습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
API[&amp;#34;API Gateway&amp;#34;]
API --&amp;gt; Profile[&amp;#34;고객 프로필 서비스&amp;#34;]
API --&amp;gt; Auth[&amp;#34;고객 인증 서비스&amp;#34;]
API --&amp;gt; Preference[&amp;#34;고객 선호도 서비스&amp;#34;]
Profile --&amp;gt; ProfileDB[(프로필 DB)]
Auth --&amp;gt; AuthDB[(인증 DB)]
Preference --&amp;gt; PrefDB[(선호도 DB)]
&lt;/pre>&lt;p>언뜻 봐도 좋지 않아보인다는 생각이 자연스레 드실 것 같습니다. 이렇게 되면 고객분이 로그인하면서 프로필과 선호도를 함께 보여줘야 한다면 &lt;strong>세 서비스를 모두 호출&lt;/strong>해야 합니다. 모놀리식에서는 메서드 호출 세 번이면 끝났을 일이 네트워크 호출 세 번으로 바뀐 거죠.&lt;/p>
&lt;p>이처럼 서비스를 너무 잘게 나누게 되면 &lt;strong>네트워크 호출&lt;/strong>이 증가하며 지연 시간이 늘어나고, 시스템 복잡도가 높아집니다. 또 하나의 트랜잭션으로 처리할 수 있는 일이 여러 서비스에 걸치게 되죠. 자연스레 &lt;strong>운영 복잡도&lt;/strong>도 증가하게 됩니다.&lt;/p>
&lt;h3>너무 크면 어떻게 될까요?&lt;span class="hx:absolute hx:-mt-20" id="너무-크면-어떻게-될까요">&lt;/span>
&lt;a href="#%eb%84%88%eb%ac%b4-%ed%81%ac%eb%a9%b4-%ec%96%b4%eb%96%bb%ea%b2%8c-%eb%90%a0%ea%b9%8c%ec%9a%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>반대로 서비스를 너무 크게 나누면 어떻게 될까요?&lt;/p>
&lt;p>만약 너무 크게 나누게 되면 결국 &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-1-introduction/">1편&lt;/a>에서 이야기한 모놀리식의 문제점들이 다시 나타납니다. 독립적 배포가 어려워지고, 특정 기능만 스케일 아웃 하기가 어려워 집니다. 여러 팀이 하나의 서비스를 담당하면 또 조율이 필요하게 되죠.&lt;/p>
&lt;p>결국 MSA를 도입한 의미 자체가 희미해질 수밖에 없다고 생각합니다.&lt;/p>
&lt;h3>그렇다면 적절한 크기는?&lt;span class="hx:absolute hx:-mt-20" id="그렇다면-적절한-크기는">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%a0%87%eb%8b%a4%eb%a9%b4-%ec%a0%81%ec%a0%88%ed%95%9c-%ed%81%ac%ea%b8%b0%eb%8a%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>결국 &amp;ldquo;뭐든 적당히가 최고더라&amp;quot;라는 말이 맞는 것 같습니다. 너무 작지도, 너무 크지도 않은 적절한 크기 말이죠.&lt;/p>
&lt;p>문제는 이 &amp;ldquo;적당히&amp;quot;가 어느 정도인가입니다. 이건 정말 정답이 없는 문제인 것 같습니다. 많은 회사들에서 여러 개발자들이 이 &amp;ldquo;적당히&amp;quot;를 찾기 위해 시행착오를 겪는 것 같고요.&lt;/p>
&lt;p>저는 개인적으로 &amp;ldquo;적당히&amp;quot;의 단위는 &lt;strong>&amp;ldquo;한 팀이 온전히 소유하고 운영할 수 있는 크기&amp;rdquo;&lt;/strong> 가 하나의 기준이 될 수 있다고 봅니다.&lt;/p>
&lt;p>Amazon에서 이야기하는 &amp;ldquo;Two Pizza Team&amp;rdquo; 개념이 있습니다. 피자 두 판으로 식사할 수 있는 규모, 대략 6~10명 정도의 팀이 하나의 서비스를 담당하는 거죠.&lt;/p>
&lt;p>팀 규모뿐만 아니라 &lt;strong>변경 빈도&lt;/strong>도 중요한 기준인 것 같습니다. 자주 함께 변경되는 기능들은 같은 서비스에 두고, 독립적으로 변경되는 기능들은 분리하는 거죠.&lt;/p>
&lt;p>예를 들어, 주문 로직과 결제 로직이 항상 함께 변경된다면 같은 서비스에 두는 게 나을 수 있습니다. 하지만 주문은 자주 바뀌는데 결제는 안정적이라면 분리하는 게 맞겠죠.&lt;/p>
&lt;p>결국 &lt;strong>서비스 크기에 정답은 없는 것 같습니다&lt;/strong>. 도메인 특성, 팀 구조, 변경 빈도를 종합적으로 고려해서 결정할 수밖에 없죠. 너무 진부한 답변일 수 있지만, 경험상 이 문제에 대한 최선의 답은 &amp;ldquo;상황에 맞게 판단하는 수밖에 없다&amp;quot;인 것 같습니다.&lt;/p>
&lt;h2>흔히 하는 실수들&lt;span class="hx:absolute hx:-mt-20" id="흔히-하는-실수들">&lt;/span>
&lt;a href="#%ed%9d%94%ed%9e%88-%ed%95%98%eb%8a%94-%ec%8b%a4%ec%88%98%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>지금까지 서비스 경계를 나누는 기준과 크기에 대해 이야기했습니다. 그런데 이론을 알아도 실제로는 실수하기 쉽습니다. 저 역시 많이 실수했고요.&lt;/p>
&lt;p>왜 그럴까요? 제 생각에는 &lt;strong>익숙한 방식대로 나누려는 경향&lt;/strong> 때문인 것 같습니다. 기존에 해오던 방식, 눈에 보이는 구조대로 나누면 편하니까요.&lt;/p>
&lt;p>앞에서 기술 레이어로 나누는 실수를 살펴봤는데요. 그 외에도 몇 가지 흔한 실수들이 있습니다.&lt;/p>
&lt;h3>1. 엔티티마다 서비스 만들기&lt;span class="hx:absolute hx:-mt-20" id="1-엔티티마다-서비스-만들기">&lt;/span>
&lt;a href="#1-%ec%97%94%ed%8b%b0%ed%8b%b0%eb%a7%88%eb%8b%a4-%ec%84%9c%eb%b9%84%ec%8a%a4-%eb%a7%8c%eb%93%a4%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>데이터베이스 테이블이나 엔티티를 기준으로 서비스를 나누는 것&lt;/strong>도 흔한 실수인 것 같습니다.&lt;/p>
&lt;p>주문, 주문 항목, 상품이 각각 별도 서비스라면?&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
OrderService[&amp;#34;주문 서비스&amp;#34;]
OrderItemService[&amp;#34;주문 항목 서비스&amp;#34;]
ProductService[&amp;#34;상품 서비스&amp;#34;]
OrderService --&amp;gt; OrderItemService
OrderItemService --&amp;gt; ProductService
&lt;/pre>&lt;p>주문을 조회하려면 세 서비스를 순차적으로 호출해야 합니다. 아까 말씀드린 &amp;ldquo;너무 작으면&amp;rdquo; 생기는 문제가 그대로 나타나죠.&lt;/p>
&lt;p>엔티티가 아닌 &lt;strong>비즈니스 유스케이스&lt;/strong>를 기준으로 생각하는 게 좋은 것 같습니다. &amp;ldquo;주문 생성&amp;rdquo;, &amp;ldquo;주문 조회&amp;rdquo;, &amp;ldquo;주문 취소&amp;rdquo; 같은 유스케이스에 필요한 데이터를 하나의 서비스에서 관리하는 게 자연스럽죠.&lt;/p>
&lt;h3>2. 조직도 그대로 따라가기&lt;span class="hx:absolute hx:-mt-20" id="2-조직도-그대로-따라가기">&lt;/span>
&lt;a href="#2-%ec%a1%b0%ec%a7%81%eb%8f%84-%ea%b7%b8%eb%8c%80%eb%a1%9c-%eb%94%b0%eb%9d%bc%ea%b0%80%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>또 앞서 Conway의 법칙을 이야기했지만, &lt;strong>현재 조직 구조를 그대로 서비스 구조로 옮기는 것&lt;/strong>도 위험할 수 있는 것 같습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Org[&amp;#34;현재 조직 구조&amp;#34;]
Team1[&amp;#34;A팀&amp;lt;br/&amp;gt;(주문 + 상품)&amp;#34;]
Team2[&amp;#34;B팀&amp;lt;br/&amp;gt;(회원 + 결제 + 알림)&amp;#34;]
end
subgraph System[&amp;#34;서비스 구조?&amp;#34;]
Service1[&amp;#34;A 서비스&amp;lt;br/&amp;gt;(주문 + 상품)&amp;#34;]
Service2[&amp;#34;B 서비스&amp;lt;br/&amp;gt;(회원 + 결제 + 알림)&amp;#34;]
end
&lt;/pre>&lt;p>만약 위와 같은 조직 구조를 가지고 있는 회사라면 저렇게 서비스를 구성했을 때 과연 괜찮을까요?&lt;/p>
&lt;p>B팀이 담당하는 서비스를 보시면 회원, 결제, 알림이 한 서비스에 다 들어있습니다. 비즈니스 관점에서 전혀 응집력이 없고 위에서 저희가 이야기했던 기준에도 맞지 않죠.&lt;/p>
&lt;p>물론 무조건 위에 언급했던 기준이 정답이라고 볼순 없지만 예시의 조직구조를 토대로 MSA를 설계하는 건 후에 문제가 될 가능성이 높다고 생각합니다.&lt;/p>
&lt;h3>3. 처음부터 너무 잘게 나누기&lt;span class="hx:absolute hx:-mt-20" id="3-처음부터-너무-잘게-나누기">&lt;/span>
&lt;a href="#3-%ec%b2%98%ec%9d%8c%eb%b6%80%ed%84%b0-%eb%84%88%eb%ac%b4-%ec%9e%98%ea%b2%8c-%eb%82%98%eb%88%84%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>마지막으로, &lt;strong>처음부터 서비스를 너무 잘게 나누는 것&lt;/strong>도 피하는 게 좋은 것 같습니다.&lt;/p>
&lt;p>도메인을 충분히 이해하지 못한 상태에서 서비스를 세분화하면, 나중에 경계가 잘못됐다는 걸 깨달았을 때 수정 비용이 꽤 큽니다. 위에서 언급했던 &amp;ldquo;왜 바꾸기가 어려운가&amp;quot;를 여러번 겪게 되실 수 있겠죠.&lt;/p>
&lt;p>저는 &lt;strong>처음에는 좀 더 큰 단위로 시작해서 점진적으로 분리&lt;/strong>하는 방식을 선호하는 편입니다. &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-1-introduction/">1편&lt;/a>에서 이야기한 모듈러 모놀리식에서 시작해서, 도메인 이해가 깊어지면 하나씩 떼어내는 거죠.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
subgraph Phase1[&amp;#34;Phase 1&amp;#34;]
Mono[&amp;#34;모놀리식&amp;#34;]
end
subgraph Phase2[&amp;#34;Phase 2&amp;#34;]
Modular[&amp;#34;모듈러 모놀리식&amp;lt;br/&amp;gt;(모듈 분리)&amp;#34;]
end
subgraph Phase3[&amp;#34;Phase 3&amp;#34;]
MSA[&amp;#34;MSA&amp;lt;br/&amp;gt;(서비스 분리)&amp;#34;]
end
Phase1 --&amp;gt; Phase2 --&amp;gt; Phase3
&lt;/pre>&lt;p>이렇게 되면 경계를 잘못 설정했을 때 수정 비용이 상대적으로 적은 것 같습니다. 물론 처음부터 MSA로 시작해야 하는 상황도 있을 수 있습니다. 그럴 땐 앞서 이야기한 기준들을 최대한 신중하게 적용하는 게 중요하겠죠.&lt;/p>
&lt;h2>경계가 잘못됐다는 신호들&lt;span class="hx:absolute hx:-mt-20" id="경계가-잘못됐다는-신호들">&lt;/span>
&lt;a href="#%ea%b2%bd%ea%b3%84%ea%b0%80-%ec%9e%98%eb%aa%bb%eb%90%90%eb%8b%a4%eb%8a%94-%ec%8b%a0%ed%98%b8%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>아무리 신중하게 경계를 설정해도 나중에 &amp;ldquo;아, 이게 아니었구나&amp;rdquo; 싶을 때가 있습니다. 그럴때는 어떤 신호들이 있을까요?&lt;/p>
&lt;h3>Distributed Monolith&lt;span class="hx:absolute hx:-mt-20" id="distributed-monolith">&lt;/span>
&lt;a href="#distributed-monolith" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>먼저 글 초반에 이야기했던 Distributed Monolith가 가장 심각한 신호인 것 같습니다. 하나의 기능을 수정하려면 여러 서비스를 동시에 수정해야하거나 하나의 서비스를 배포하려면 다른 서비스도 함께 배포해야 한다는 문제 말이죠.&lt;/p>
&lt;p>물론 완벽한 독립성을 기대하는 건 무리일 수 있기 때문에 특정 상황에서 한두번 겪는 건 괜찮습니다. 하지만 자주 반복되고, 점점 심해진다면 Distributed Monolith 상황을 의심해봐야 한다고 생각합니다.&lt;/p>
&lt;p>이런 상황이라면 경계를 다시 검토해봐야 합니다. 심한 경우 차라리 다시 합치는 게 나을 수도 있죠.&lt;/p>
&lt;h3>서비스 간 과도한 통신&lt;span class="hx:absolute hx:-mt-20" id="서비스-간-과도한-통신">&lt;/span>
&lt;a href="#%ec%84%9c%eb%b9%84%ec%8a%a4-%ea%b0%84-%ea%b3%bc%eb%8f%84%ed%95%9c-%ed%86%b5%ec%8b%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>또 특정 서비스들 사이에 API 호출이 너무 빈번하다면, 그 서비스들이 사실 하나로 합쳐져야 하는 건 아닌지 고민해봐야 하는 것 같습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>주문 서비스 → 상품 서비스: 100,000 calls/day
주문 서비스 → 재고 서비스: 95,000 calls/day
주문 서비스 → 결제 서비스: 5,000 calls/day&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>주문, 상품, 재고가 이렇게 빈번하게 통신한다면, 어쩌면 &amp;ldquo;주문 처리 서비스&amp;quot;로 합쳐지는 게 맞을 수도 있겠죠. 그만큼 서로 강하게 엮여 있다는 뜻이니까요.&lt;/p>
&lt;h3>순환 의존성&lt;span class="hx:absolute hx:-mt-20" id="순환-의존성">&lt;/span>
&lt;a href="#%ec%88%9c%ed%99%98-%ec%9d%98%ec%a1%b4%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그리고 만약 A → B → C → A 같은 순환 의존성이 생겼다면 경계 설정에 문제가 있을 가능성이 있습니다. 이 역시 서로 강하게 엮여 있다는 신호이기 때문이죠.&lt;/p>
&lt;p>또 순환 의존성은 배포 순서를 복잡하게 만들고, 장애가 어디로 퍼질지 예측하기 어렵게 만듭니다. 의존성을 끊거나, 서비스를 합치거나, 공통 기능을 새 서비스로 빼내는 등의 조치가 필요하다고 생각합니다.&lt;/p>
&lt;p>그리고 이 순환 의존성은 서비스 파악도 어렵게 만듭니다. 서비스 간 관계를 이해하기 힘들어지거든요. 결국 유지보수 비용이 증가하게 되고, 새로운 기능을 추가하는 것도 어려워집니다.&lt;/p>
&lt;p>이런 경계가 잘못됐다는 신호들을 받게 된다면 팀원 분들께 공유하고 함께 고민하는 시간을 갖는 게 중요하다고 생각합니다. 나 혼자만 이런 신호를 느낀건지 팀 전체가 받고 있는지 확인하는 거죠.&lt;/p>
&lt;p>그리고 만약 팀원 모두가 공감하고 있다면, 경계를 재설정하는 작업을 진지하게 고려해봐야 한다고 생각합니다.&lt;/p>
&lt;h2>경계는 변할 수 있다&lt;span class="hx:absolute hx:-mt-20" id="경계는-변할-수-있다">&lt;/span>
&lt;a href="#%ea%b2%bd%ea%b3%84%eb%8a%94-%eb%b3%80%ed%95%a0-%ec%88%98-%ec%9e%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>마지막으로 한 가지 중요한 점을 말씀드리고 싶습니다.&lt;/p>
&lt;p>제가 개발을 하면서 느낀 건, &lt;strong>서비스와 요구사항은 계속해서 바뀌고 진화한다&lt;/strong>는 점입니다. 처음에는 변하지 않을 것 처럼 느껴지는 설계나 요구사항도 시간이 지나면 바뀌기 마련이죠.&lt;/p>
&lt;p>서비스는 비즈니스 요구사항에 맞춰 계속 발전합니다. 새로운 기능이 추가되고, 기존 기능이 변경되며, 때로는 제거되기도 하죠. 이러한 변화는 서비스 경계에도 영향을 미칩니다.&lt;/p>
&lt;p>그리고 앞서 이야기한 기준들을 실제로 적용하는 것도 쉽지 않습니다. 도메인을 깊이 이해해야 하는데 프로젝트 초기에는 그게 부족한 경우가 많고, 통신 방식처럼 정형화된 가이드가 있는 것도 아니거든요. 비즈니스마다, 팀마다, 상황마다 답이 다릅니다.&lt;/p>
&lt;p>그래서 &lt;strong>서비스 경계도 영원히 고정된 게 아닙니다.&lt;/strong>&lt;/p>
&lt;p>비즈니스가 변하면 도메인도 변하고, 도메인이 변하면 최적의 서비스 경계도 변합니다. 처음에 잘 나눴다고 생각했던 경계가 1년 후에는 맞지 않을 수 있죠.&lt;/p>
&lt;p>그래서 저는 &lt;strong>처음부터 완벽하게 설정하려고 너무 고민하기보다는, 나중에 바꾸기 쉬운 구조를 유지하는 게 더 중요하다&lt;/strong>고 봅니다.&lt;/p>
&lt;p>서비스 간 계약(API)을 명확하게 정의하고, 내부 구현은 숨기고, 의존성을 최소화해두면 나중에 경계를 조정하기가 훨씬 수월해지거든요. 결국은 돌고돌아 추상화인 것 같습니다.&lt;/p>
&lt;h2>정리&lt;span class="hx:absolute hx:-mt-20" id="정리">&lt;/span>
&lt;a href="#%ec%a0%95%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이번 편에서는 MSA에서 서비스를 어떻게 나눌 것인지에 대해 살펴보았습니다.&lt;/p>
&lt;p>결국 제가 하고 싶었던 말은 &lt;strong>&amp;ldquo;처음부터 완벽하게 나누려고 하지 않아도 된다&amp;rdquo;&lt;/strong> 입니다. 제 경험상 어차피 변하는 경우가 많더라고요.&lt;/p>
&lt;p>자 이제 서비스를 어떻게 나눌지 결정했다면, 다음 문제가 저희를 기다립니다.&lt;/p>
&lt;p>&lt;strong>분리된 서비스들은 어떻게 서로 대화할 것인가?&lt;/strong>&lt;/p>
&lt;p>다음 편에서는 서비스 간 통신 방식(동기/비동기, REST/gRPC/메시지 큐)과 각각의 트레이드오프에 대해 이야기해보겠습니다.&lt;/p>
&lt;p>후편: &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-3-communication/">[MSA에 관한 고찰 3/7편] MSA에서의 서비스간 통신 - 어떻게 해야 하는가&lt;/a>&lt;/p>
&lt;h2>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>DDD와 Bounded Context&lt;span class="hx:absolute hx:-mt-20" id="ddd와-bounded-context-1">&lt;/span>
&lt;a href="#ddd%ec%99%80-bounded-context-1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>Eric Evans - &lt;em>Domain-Driven Design: Tackling Complexity in the Heart of Software&lt;/em> (Addison-Wesley, 2003)&lt;/li>
&lt;li>Vaughn Vernon - &lt;em>Implementing Domain-Driven Design&lt;/em> (Addison-Wesley, 2013)&lt;/li>
&lt;/ul>
&lt;h3>서비스 분해 전략&lt;span class="hx:absolute hx:-mt-20" id="서비스-분해-전략">&lt;/span>
&lt;a href="#%ec%84%9c%eb%b9%84%ec%8a%a4-%eb%b6%84%ed%95%b4-%ec%a0%84%eb%9e%b5" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>Sam Newman - &lt;em>Building Microservices&lt;/em> (O&amp;rsquo;Reilly, 2021, 2nd Edition)&lt;/li>
&lt;li>Chris Richardson - &lt;em>Microservices Patterns&lt;/em> (Manning, 2018)&lt;/li>
&lt;/ul>
&lt;h3>Conway의 법칙&lt;span class="hx:absolute hx:-mt-20" id="conway의-법칙-1">&lt;/span>
&lt;a href="#conway%ec%9d%98-%eb%b2%95%ec%b9%99-1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>Melvin Conway - &lt;a href="http://www.melconway.com/Home/Committees_Paper.html"target="_blank" rel="noopener">How Do Committees Invent?&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> (1968)&lt;/li>
&lt;/ul></description></item><item><title>[MSA에 관한 고찰 1/7편] MSA(Microservices Architecture)란 무엇인가?</title><link>https://jeongil.dev/ko/blog/architecture/msa-series-1-introduction/</link><pubDate>Wed, 14 Jan 2026 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/architecture/msa-series-1-introduction/</guid><description>
&lt;p>개발을 하다보면 MSA(Microservices Architecture)에 대해 고민하는 순간들이 간혹 찾아온다고 생각합니다. 그런 순간마다 여러 고민에 빠지게 되죠.&lt;/p>
&lt;p>저 역시 그 전에는 MSA에 대해 고민을 하게 되는 순간들이 있었습니다. 다만 사이드 프로젝트 수준, 혹은 개발 아티클에서 접하는 수준에서의 고민이었지 실제 업무에서 MSA 전환을 겪어본 적은 없었습니다.&lt;/p>
&lt;p>현재 회사로 이직하면서 MSA로의 전환 및 운영 경험을 겪게 되었고 덕분에 여러 고민을 할 수 있는 좋은 기회가 되었습니다.&lt;/p>
&lt;p>이번에 제가 그 과정에서 했던 여러 고민들과 경험들을 스스로 정리하며 MSA에 대해 다시 한번 생각해보는 시간을 가져보고자 합니다.&lt;/p>
&lt;h2>MSA란 무엇인가?&lt;span class="hx:absolute hx:-mt-20" id="msa란-무엇인가">&lt;/span>
&lt;a href="#msa%eb%9e%80-%eb%ac%b4%ec%97%87%ec%9d%b8%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>MSA란 뭘까요? 흔히 검색해보면 다음과 같은 정의가 나옵니다.&lt;/p>
&lt;blockquote>
&lt;p>MSA란 마이크로서비스 아키텍처(Microservices Architecture)의 약자로, 하나의 애플리케이션을 작고 독립적인 서비스 단위로 분해하는 아키텍처 스타일을 의미합니다.&lt;/p>
&lt;/blockquote>
&lt;p>위 문장이 MSA를 정의하는 가장 일반적인 문장인데 이렇게 읽고 보니 사실 위 문장이 전부라고 해도 과언이 아닐 것 같다는 생각이 듭니다. 다만 문제는 &lt;strong>위 문장을 지키기 위해선 수많은 고민과 선택이 필요하다는 점&lt;/strong>인 것 같습니다.&lt;/p>
&lt;p>처음 MSA에 대해 접하게 되면 사람마다 다르겠지만 저는 &amp;ldquo;어째서?&amp;rdquo;, &amp;ldquo;어떻게?&amp;rdquo; 라는 질문이 자연스럽게 떠올랐습니다.&lt;/p>
&lt;p>그래서 MSA를 이해하기 위해 어째서 MSA가 등장하게 되었는지부터 이야기를 시작해보려합니다.&lt;/p>
&lt;p>대부분의 기술은 &lt;strong>어떤 특정한 문제&lt;/strong>를 해결하기 위해 등장한다고 생각합니다. 그리고 문제를 이해하면 그 기술이 가지는 본질도 어느정도 이해할 수 있다고 저는 생각합니다.&lt;/p>
&lt;p>MSA 역시 마찬가지인데, MSA가 등장하게 된 배경에는 기존의 모놀리식 아키텍처(Monolithic Architecture)가 가진 여러 한계점들에 있었습니다.&lt;/p>
&lt;p>그럼 모놀리식 아키텍처는 뭘까요? 그리고 어떤 한계점이 있어 MSA가 등장하게 되었을까요?&lt;/p>
&lt;h3>모놀리식 아키텍처란&lt;span class="hx:absolute hx:-mt-20" id="모놀리식-아키텍처란">&lt;/span>
&lt;a href="#%eb%aa%a8%eb%86%80%eb%a6%ac%ec%8b%9d-%ec%95%84%ed%82%a4%ed%85%8d%ec%b2%98%eb%9e%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>모놀리식 아키텍처란 하나의 코드 베이스를 사용하여 여러 비즈니스 기능을 수행하는 전통적인 소프트웨어 개발 모델입니다.&lt;/p>
&lt;p>쉽게 말하자면 &lt;strong>&amp;ldquo;모든 코드를 한 곳에 다 때려박는&amp;rdquo;&lt;/strong> 형태의 아키텍처 스타일을 의미합니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Monolith[&amp;#34;Monolithic Application&amp;#34;]
direction TB
subgraph Row1[&amp;#34; &amp;#34;]
direction LR
Order[&amp;#34;주문&amp;#34;]
Product[&amp;#34;상품&amp;#34;]
end
subgraph Row2[&amp;#34; &amp;#34;]
direction LR
User[&amp;#34;회원&amp;#34;]
Payment[&amp;#34;결제&amp;#34;]
end
end
Monolith --&amp;gt; DB[(Database)]
&lt;/pre>&lt;p>과거 전통적인 웹 애플리케이션 개발에서는 모놀리식 아키텍처가 주로 사용되었습니다. 모든 기능이 하나의 코드베이스에 포함되어 있어 개발과 배포가 비교적 간단했죠.&lt;/p>
&lt;p>사실 지금도 많은 회사에서 모놀리식 아키텍처를 사용하고 있습니다. &lt;strong>모놀리식 아키텍처에 한계점이 있다고 해서 무조건 MSA가 더 좋은 것은 아니기 때문입니다.&lt;/strong> 마찬가지로 MSA에도 한계점이 존재하지만 이는 후에 다루도록 하겠습니다.&lt;/p>
&lt;p>그렇다면 모놀리식 아키텍처의 어떤 한계점들이 MSA의 등장을 이끌었을까요?&lt;/p>
&lt;h3>모놀리식의 한계&lt;span class="hx:absolute hx:-mt-20" id="모놀리식의-한계">&lt;/span>
&lt;a href="#%eb%aa%a8%eb%86%80%eb%a6%ac%ec%8b%9d%ec%9d%98-%ed%95%9c%ea%b3%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>모놀리식 아키텍처는 단순하고 개발이 쉬운 장점이 있지만, 다음과 같은 한계점들이 존재합니다.&lt;/p>
&lt;h4>1. 스케일링의 어려움&lt;span class="hx:absolute hx:-mt-20" id="1-스케일링의-어려움">&lt;/span>
&lt;a href="#1-%ec%8a%a4%ec%bc%80%ec%9d%bc%eb%a7%81%ec%9d%98-%ec%96%b4%eb%a0%a4%ec%9b%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>모놀리식 아키텍처는 하나의 서버에 모든 기능이 올라가 있었기 때문에, 특정 기능에 트래픽이 몰리더라도 스케일 아웃을 하기 위해서는 전체 애플리케이션을 새로 배포해야 했습니다.&lt;/p>
&lt;p>예를 들어 제가 만든 콘서트 예매 서비스에서 어느날 유명한 가수의 콘서트 티켓 예매가 시작되었고, 주문 기능에 트래픽이 몰리게 되었다고 가정해보겠습니다.&lt;/p>
&lt;p>저는 안정적인 서비스를 위해 트래픽을 대비해 서버를 늘리기로 결정했습니다. 주문 기능에만 트래픽이 몰릴 예정이고 다른 기능들은 평소와 비슷한 트래픽이 예상되었기 때문에 주문 기능만 스케일 아웃해 로드밸런서를 달고 트래픽을 분산시키고자 했습니다.&lt;/p>
&lt;p>이랬을 때 모놀리식 아키텍처에서는 주문 기능만 스케일 아웃을 할 수 없습니다. 전체 애플리케이션을 새로 배포해 서버를 늘려야 했기 때문에 불필요한 리소스 낭비가 발생하게 됩니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
LB[Load Balancer]
subgraph Server1[&amp;#34;Server 1&amp;#34;]
direction TB
subgraph S1R1[&amp;#34; &amp;#34;]
direction LR
S1_Order[&amp;#34;💥 주문&amp;#34;]
S1_Product[&amp;#34;상품&amp;#34;]
end
subgraph S1R2[&amp;#34; &amp;#34;]
direction LR
S1_User[&amp;#34;회원&amp;#34;]
S1_Payment[&amp;#34;결제&amp;#34;]
end
end
subgraph Server2[&amp;#34;Server 2&amp;#34;]
direction TB
subgraph S2R1[&amp;#34; &amp;#34;]
direction LR
S2_Order[&amp;#34;💥 주문&amp;#34;]
S2_Product[&amp;#34;상품&amp;#34;]
end
subgraph S2R2[&amp;#34; &amp;#34;]
direction LR
S2_User[&amp;#34;회원&amp;#34;]
S2_Payment[&amp;#34;결제&amp;#34;]
end
end
LB --&amp;gt; Server1
LB --&amp;gt; Server2
Server1 --&amp;gt; DB[(Database)]
Server2 --&amp;gt; DB
&lt;/pre>&lt;h4>2. 배포의 어려움&lt;span class="hx:absolute hx:-mt-20" id="2-배포의-어려움">&lt;/span>
&lt;a href="#2-%eb%b0%b0%ed%8f%ac%ec%9d%98-%ec%96%b4%eb%a0%a4%ec%9b%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>또 모놀리식 아키텍처에서는 모든 기능이 하나의 코드베이스에 포함되어 있기 때문에, 작은 변경 사항이라도 전체 애플리케이션을 다시 빌드하고 배포해야 합니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
subgraph Deploy[&amp;#34;배포 파이프라인&amp;#34;]
direction LR
Change[&amp;#34;주문 버그 수정&amp;lt;br/&amp;gt;(10초)&amp;#34;]
Build[&amp;#34;전체 빌드&amp;lt;br/&amp;gt;(30분+)&amp;#34;]
Test[&amp;#34;전체 테스트&amp;lt;br/&amp;gt;(주문+상품+회원+결제)&amp;#34;]
Release[&amp;#34;전체 배포&amp;#34;]
end
Change --&amp;gt; Build --&amp;gt; Test --&amp;gt; Release
&lt;/pre>&lt;p>위 다이어그램에서 주문 기능에만 작은 버그가 발생했다고 가정해보겠습니다. 저는 빠르게 해당 버그를 수정하고 배포하고자 했습니다.&lt;/p>
&lt;p>고치는데는 10초도 걸리지 않았고 주문 기능의 단위 테스트 전체를 돌려도 1분이면 충분했다고 가정해보겠습니다.&lt;/p>
&lt;p>하지만 결제 기능은 돈과 관련된 부분이다 보니 더 꼼꼼한 테스트 코드들이 많았고 약간 과장하여 결제의 단위 테스트만 돌려도 30분이 걸린다고 가정해보면 모놀리식 아키텍처에서는 주문 기능의 &lt;strong>아주 작은 버그를 고치기 위해 전체 애플리케이션을 다시 빌드하고 배포해야&lt;/strong> 하기 때문에 빌드에 테스트가 포함된다는 전제하에 최소 30분은 기다려야 했습니다.&lt;/p>
&lt;p>겪어 보셔서 아시겠지만 버그를 유발시킨 코드를 작성한 사람이 나라면 이 30분이 정말 피말립니다. 식은땀 나고 발만 동동 구르고 있게 되고 말이죠. 30분이 넘는 시간 동안 사용자분들이 서비스를 제대로 이용하지 못하는 상황도 발생할 수 있으니까요.&lt;/p>
&lt;p>이런 경우 보통 CI/CD 파이프라인이 돌아가는 화면을 바라보고 있는 제 뒤로 관리자분이 다가와서 &amp;ldquo;배포 언제 돼..?&amp;ldquo;하는 눈빛을 보내시곤 합니다.&lt;/p>
&lt;p>결국 이는 생산성의 저하로 이어지는 문제가 발생하게 되는 거죠.&lt;/p>
&lt;h4>3. 장애 격리(Fault Isolation)&lt;span class="hx:absolute hx:-mt-20" id="3-장애-격리fault-isolation">&lt;/span>
&lt;a href="#3-%ec%9e%a5%ec%95%a0-%ea%b2%a9%eb%a6%acfault-isolation" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>또 다른 문제로는 &lt;strong>장애 격리(Fault Isolation)&lt;/strong> 가 어렵다는 점입니다. 모놀리식 아키텍처에서는 하나의 애플리케이션이 모든 기능을 담당하기 때문에, 애플리케이션에 장애가 발생하면 전체 서비스가 중단되는 문제가 발생할 수 있습니다.&lt;/p>
&lt;p>이번에도 역시 콘서트 예매 서비스를 예로 들어보겠습니다. 이제까지 잘 운영 되던 콘서트 예매 서비스에 어느날 갑자기 결제 기능에 장애가 발생했다고 가정해보겠습니다.&lt;/p>
&lt;p>결제에 장애가 발생했으니 결제가 안되는건 당연한 일이지만 문제는 결제 기능에 장애가 발생하면서 리소스 과부하가 걸리게 되었고, 이로 인해 전체 애플리케이션이 느려지거나 다운되는 문제가 발생하게 되었다고 가정해보겠습니다.&lt;/p>
&lt;p>장애가 발생한건 결제 기능이지만 모놀리식 아키텍처에서는 전체 애플리케이션이 하나의 프로세스로 묶여있기 때문에 결제 기능의 장애가 전체 서비스 장애로 이어지게 됩니다.&lt;/p>
&lt;p>물론 서버를 여러 대 띄우고 로드밸런서를 달아 인프라 레벨의 장애에는 대응할 수 있습니다. 하지만 &lt;strong>같은 프로세스 안에서 실행되는 모듈 간의 장애 전파는 막기 어렵습니다.&lt;/strong> 결제 모듈의 메모리 누수가 같은 JVM의 다른 모듈에 영향을 주거나, 한 모듈의 무한루프가 전체 CPU를 점유하는 상황은 인프라 다중화로 해결되지 않기 때문입니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant User as 사용자
participant Order as 주문
participant Payment as 결제
Note over Order,Payment: 동일 JVM에서 실행
User-&amp;gt;&amp;gt;Order: 주문 요청
Order-&amp;gt;&amp;gt;Payment: 결제 요청
Note over Payment: 💥 메모리 누수 발생
Note over Order,Payment: JVM 메모리 고갈
Order--xUser: 주문도 응답 불가
&lt;/pre>&lt;h4>4. 기술 스택의 제약&lt;span class="hx:absolute hx:-mt-20" id="4-기술-스택의-제약">&lt;/span>
&lt;a href="#4-%ea%b8%b0%ec%88%a0-%ec%8a%a4%ed%83%9d%ec%9d%98-%ec%a0%9c%ec%95%bd" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>모놀리식 아키텍처는 하나의 코드베이스를 사용하기 때문에, 대부분의 경우 &lt;strong>하나의 프로그래밍 언어나 프레임워크에 종속되는 경향이 있습니다.&lt;/strong>&lt;/p>
&lt;p>JDK를 기반으로 한 Spring Boot 애플리케이션이라면 모든 기능이 Java 혹은 Kotlin으로 작성되어야 하며, Node.js 기반의 애플리케이션이라면 모든 기능이 JavaScript 혹은 TypeScript로 작성되어야 합니다.&lt;/p>
&lt;p>이로 인해 특정 기능에 더 적합한 기술 스택을 사용하지 못하는 제약이 발생할 수 있습니다. 예를 들어, 데이터 과학이나 머신러닝과 같은 특정 도메인에서는 Python이 더 적합할 수 있지만, 모놀리식 아키텍처에서는 전체 애플리케이션이 하나의 언어로 작성되어야 하기 때문에 이를 활용하기 어렵습니다.&lt;/p>
&lt;p>또 회사에서 신규로 개발자를 채용할 때도 마찬가지입니다. 만약 회사가 C++ 기반의 모놀리식 애플리케이션을 운영하고 있다면, C++ 개발자만 채용할 수밖에 없는 제약이 발생하게 됩니다.&lt;/p>
&lt;p>회사가 특정 기술 스택에 대한 의존도가 높아지면 채용 시장에서의 유연성이 떨어질 수 있습니다. 굉장히 사측인 것 같은 발언이긴 하지만 회사 입장에서는 채용 시장에서의 유연성은 회사 수익과도 연결되는 중요한 문제이기 때문에 무시할 수 없는 부분이라고 생각합니다.&lt;/p>
&lt;h4>5. 팀 자율성의 부족&lt;span class="hx:absolute hx:-mt-20" id="5-팀-자율성의-부족">&lt;/span>
&lt;a href="#5-%ed%8c%80-%ec%9e%90%ec%9c%a8%ec%84%b1%ec%9d%98-%eb%b6%80%ec%a1%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>마지막으로 모놀리식 아키텍처에서는 팀 자율성이 부족하다는 문제가 있습니다. 모든 기능이 하나의 코드베이스에 포함되어 있기 때문에, &lt;strong>여러 팀이 동시에 작업할 때 충돌이 발생할 가능성이 높아집니다.&lt;/strong>&lt;/p>
&lt;p>전체 코드베이스를 작업하는 개발자 수가 적으면 문제가 덜할 수 있지만, 만약 제가 엄청난 규모의 팀에 속한 개발자라고 가정해보겠습니다.&lt;/p>
&lt;p>앞서 본 콘서트 예매 서비스에서 기능별로 팀이 총 4개, 많이 과장해서 각 팀의 개발자가 30명이라고 가정해보면 총 120명의 개발자가 하나의 코드베이스를 동시에 작업하게 됩니다.&lt;/p>
&lt;p>어떠신가요? 듣기만해도 Git Conflict를 해결해야할 생각에 머리가 지끈거리진 않으신가요? 만약 모든 기능에서 공통으로 쓰이는 Util 클래스라도 있다면 충돌이 빈번하게 발생할 수밖에 없습니다.&lt;/p>
&lt;p>또 충돌을 해결하기 위해서는 팀 간의 조율과 커뮤니케이션 과정이 필수적이게 될 것이고, 이는 개발 속도의 저하로 이어질 수 있을 겁니다.&lt;/p>
&lt;h2>MSA의 등장&lt;span class="hx:absolute hx:-mt-20" id="msa의-등장">&lt;/span>
&lt;a href="#msa%ec%9d%98-%eb%93%b1%ec%9e%a5" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이러한 한계점들을 극복하기 위해 MSA가 등장하게 되었습니다.&lt;/p>
&lt;p>위 문제점들의 대부분은 &lt;strong>&amp;ldquo;하나의 애플리케이션이 모든 기능을 담당한다&amp;rdquo;&lt;/strong> 는 공통점이 있었습니다. 그렇다면 &amp;ldquo;하나의 애플리케이션을 여러 개의 작은 서비스로 나누면 어떨까?&amp;rdquo; 라는 생각에서 MSA가 등장하게 되었습니다.&lt;/p>
&lt;p>이제 위에 MSA의 정의에 나왔던 문장 중 일부인 &lt;strong>&amp;ldquo;하나의 애플리케이션을 작고 독립적인 서비스 단위로 분해하는 아키텍처 스타일&amp;rdquo;&lt;/strong> 이라는 문장에 &amp;ldquo;어째서?&amp;ldquo;는 이해가 되셨을 거라 생각합니다.&lt;/p>
&lt;p>그렇다면 어느정도까지 작고 독립적인 서비스 단위로 분해해야 할까요? 가장 널리 사용되는 기준은 DDD의 Bounded Context입니다만 정답은 없다고 생각합니다. 이 부분은 후에 다시 다루도록 하겠습니다.&lt;/p>
&lt;p>다시 본론으로 돌아와서 그럼 MSA는 어떤 장단점과 특성을 가지고 있을까요?&lt;/p>
&lt;h3>MSA의 장점과 특성&lt;span class="hx:absolute hx:-mt-20" id="msa의-장점과-특성">&lt;/span>
&lt;a href="#msa%ec%9d%98-%ec%9e%a5%ec%a0%90%ea%b3%bc-%ed%8a%b9%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>MSA의 장점은 위에서 이야기한 모놀리식의 한계점들을 해결하는 특성&lt;/strong>들로 요약할 수 있습니다. 기능 단위로 MSA를 구성했다고 가정하고 살펴보겠습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Order[&amp;#34;주문 서비스 (Scale Out)&amp;#34;]
Order1[&amp;#34;주문 #1&amp;#34;]
Order2[&amp;#34;주문 #2&amp;#34;]
Order3[&amp;#34;주문 #3&amp;#34;]
end
subgraph Product[&amp;#34;상품 서비스&amp;#34;]
Product1[&amp;#34;상품&amp;#34;]
end
subgraph User[&amp;#34;회원 서비스&amp;#34;]
User1[&amp;#34;회원&amp;#34;]
end
subgraph Payment[&amp;#34;결제 서비스&amp;#34;]
Payment1[&amp;#34;결제&amp;#34;]
end
Order1 --&amp;gt; OrderDB[(주문 DB)]
Order2 --&amp;gt; OrderDB
Order3 --&amp;gt; OrderDB
Product1 --&amp;gt; ProductDB[(상품 DB)]
User1 --&amp;gt; UserDB[(회원 DB)]
Payment1 --&amp;gt; PaymentDB[(결제 DB)]
&lt;/pre>&lt;p>위 다이어그램처럼 MSA에서는 주문에만 트래픽이 몰리면 &lt;strong>주문 서비스만 스케일 아웃&lt;/strong>할 수 있고, 주문 서비스에 버그가 발생하면 &lt;strong>주문 서비스만 빌드하고 배포&lt;/strong>할 수 있습니다. 주문 서비스에 장애가 발생해도 &lt;strong>다른 서비스에는 영향이 없고&lt;/strong>, 주문 서비스 팀은 &lt;strong>결제 서비스 팀과 충돌 없이 독립적으로 개발&lt;/strong>할 수 있습니다.&lt;/p>
&lt;p>이렇게 보면 MSA가 완벽한 해결책처럼 보이기도 합니다. &lt;strong>하지만 MSA에도 단점과 한계점들이 명확히 존재한다고 생각합니다.&lt;/strong>&lt;/p>
&lt;h3>MSA의 단점&lt;span class="hx:absolute hx:-mt-20" id="msa의-단점">&lt;/span>
&lt;a href="#msa%ec%9d%98-%eb%8b%a8%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>우선 &lt;strong>제가 생각하는 첫번째 단점은 러닝커브가 존재&lt;/strong>한다는 점입니다. 모놀리식 아키텍처는 따로 공부하지 않으셔도 자연스레 이미 그렇게 개발을 하고 계셨던 개발자분들이 대부분이실 겁니다.&lt;/p>
&lt;p>그러나 지금 이 글을 찾아보신 분들이라면 MSA를 학습하기 위해 찾아보신 분들이 대부분이실텐데, 이것부터가 MSA의 러닝커브가 존재한다는 증거라고 생각합니다.&lt;/p>
&lt;p>또 &lt;strong>MSA는 여러 서비스로 구성되기 때문에 분산 시스템의 복잡성이 존재합니다.&lt;/strong> 서비스 간의 통신, 데이터 일관성 문제, 네트워크 의존성 등 여러 가지 복잡한 문제들이 발생할 수 있습니다.&lt;/p>
&lt;p>당연하게도 서비스가 늘어난만큼 운영 난이도도 높아집니다. 서비스 모니터링, 로깅, 배포 파이프라인 관리 등 여러 가지 운영 작업들이 복잡해질 수밖에 없습니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
User[&amp;#34;사용자&amp;#34;] --&amp;gt; Order[&amp;#34;주문 서비스&amp;#34;]
Order --&amp;gt;|&amp;#34;HTTP/gRPC&amp;#34;| Product[&amp;#34;상품 서비스&amp;#34;]
Order --&amp;gt;|&amp;#34;HTTP/gRPC&amp;#34;| Payment[&amp;#34;결제 서비스&amp;#34;]
Order --&amp;gt;|&amp;#34;이벤트 발행&amp;#34;| MQ[&amp;#34;Message Queue&amp;#34;]
MQ --&amp;gt;|&amp;#34;이벤트 구독&amp;#34;| User2[&amp;#34;회원 서비스&amp;#34;]
MQ --&amp;gt;|&amp;#34;이벤트 구독&amp;#34;| Noti[&amp;#34;알림 서비스&amp;#34;]
Order --&amp;gt; OrderDB[(주문 DB)]
Product --&amp;gt; ProductDB[(상품 DB)]
Payment --&amp;gt; PaymentDB[(결제 DB)]
User2 --&amp;gt; UserDB[(회원 DB)]
style MQ fill:#f9f,stroke:#333
&lt;/pre>&lt;p>이런 질문들이 자연스럽게 떠오르실 겁니다.&lt;/p>
&lt;ul>
&lt;li>&amp;ldquo;주문이랑 결제 정보 둘다 필요한 경우 어떻게 하지?&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;서비스 간 통신은 어떻게 하지?&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;서비스가 많아지면 네트워크 비용이 너무 많이 들지 않을까?&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;공통 코드들은 어떻게 관리하지?&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;DB는 어떻게 하지?&amp;rdquo;&lt;/li>
&lt;/ul>
&lt;p>당연한 질문들이라고 생각합니다. &lt;strong>이런 질문들에 대한 답변들이 MSA의 단점이자 복잡성이고 MSA를 도입할 때 반드시 고려해야 할 부분들이라고 생각합니다.&lt;/strong>&lt;/p>
&lt;h3>모놀리식 vs MSA 비교&lt;span class="hx:absolute hx:-mt-20" id="모놀리식-vs-msa-비교">&lt;/span>
&lt;a href="#%eb%aa%a8%eb%86%80%eb%a6%ac%ec%8b%9d-vs-msa-%eb%b9%84%ea%b5%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>모놀리식 아키텍처와 MSA의 장단점을 표로 정리해보면 다음과 같습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>항목&lt;/th>
&lt;th>모놀리식&lt;/th>
&lt;th>MSA&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>스케일링&lt;/strong>&lt;/td>
&lt;td>전체 애플리케이션 단위로만 확장&lt;/td>
&lt;td>서비스 단위 독립적 확장 가능&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>배포&lt;/strong>&lt;/td>
&lt;td>작은 변경도 전체 빌드/배포 필요&lt;/td>
&lt;td>서비스별 독립 배포 가능&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>장애 격리&lt;/strong>&lt;/td>
&lt;td>한 모듈 장애가 전체로 전파 가능&lt;/td>
&lt;td>서비스 단위로 장애 격리&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>기술 스택&lt;/strong>&lt;/td>
&lt;td>단일 언어/프레임워크 종속&lt;/td>
&lt;td>Polyglot (서비스별 최적 기술 선택)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>팀 자율성&lt;/strong>&lt;/td>
&lt;td>코드베이스 공유로 충돌 빈번&lt;/td>
&lt;td>독립적 코드베이스로 자율성 높음&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>초기 개발 속도&lt;/strong>&lt;/td>
&lt;td>빠름 (바로 개발 시작 가능)&lt;/td>
&lt;td>느림 (설계 선행 필요)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>러닝커브&lt;/strong>&lt;/td>
&lt;td>낮음&lt;/td>
&lt;td>높음 (분산 시스템 이해 필요)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>운영 복잡도&lt;/strong>&lt;/td>
&lt;td>낮음 (단일 애플리케이션 관리)&lt;/td>
&lt;td>높음 (다수 서비스 모니터링/관리)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>데이터 관리&lt;/strong>&lt;/td>
&lt;td>단일 DB, 트랜잭션 간단&lt;/td>
&lt;td>분산 DB, 데이터 일관성 복잡&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>서비스 간 통신&lt;/strong>&lt;/td>
&lt;td>메서드 호출 (빠르고 안정적)&lt;/td>
&lt;td>네트워크 호출 (지연, 실패 가능)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>적합한 상황&lt;/strong>&lt;/td>
&lt;td>소규모 팀, 초기 스타트업, 단순한 도메인&lt;/td>
&lt;td>대규모 팀, 복잡한 도메인, 독립적 확장 필요&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>표를 보시면 아시겠지만, &lt;strong>MSA가 모놀리식보다 모든 면에서 우월한 것은 아닙니다.&lt;/strong> 오히려 초기 개발 속도, 러닝커브, 운영 복잡도 측면에서는 모놀리식이 더 유리합니다.&lt;/p>
&lt;p>결국 &lt;strong>어떤 아키텍처가 더 좋은지는 팀의 규모, 서비스의 복잡도, 확장 요구사항 등 상황에 따라 달라진다&lt;/strong>고 생각합니다.&lt;/p>
&lt;h2>MSA만이 모놀리식을 대체할 수 있는가?&lt;span class="hx:absolute hx:-mt-20" id="msa만이-모놀리식을-대체할-수-있는가">&lt;/span>
&lt;a href="#msa%eb%a7%8c%ec%9d%b4-%eb%aa%a8%eb%86%80%eb%a6%ac%ec%8b%9d%ec%9d%84-%eb%8c%80%ec%b2%b4%ed%95%a0-%ec%88%98-%ec%9e%88%eb%8a%94%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>그렇다면 모놀리식의 한계를 극복하기 위한 방법은 MSA뿐일까요?&lt;/p>
&lt;p>결론부터 말씀드리자면 &lt;strong>그렇지 않습니다.&lt;/strong> 모놀리식과 MSA 사이에는 여러 중간 지점이 존재합니다. 대표적으로 &lt;strong>모듈러 모놀리식(Modular Monolith)&lt;/strong> 과 &lt;strong>SOA(Service-Oriented Architecture)&lt;/strong> 가 있죠.&lt;/p>
&lt;h3>모듈러 모놀리식 (Modular Monolith)&lt;span class="hx:absolute hx:-mt-20" id="모듈러-모놀리식-modular-monolith">&lt;/span>
&lt;a href="#%eb%aa%a8%eb%93%88%eb%9f%ac-%eb%aa%a8%eb%86%80%eb%a6%ac%ec%8b%9d-modular-monolith" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>모듈러 모놀리식은 이름 그대로 &lt;strong>모놀리식 아키텍처를 유지하면서도 내부적으로 모듈을 명확하게 분리하는 방식&lt;/strong>입니다. 하나의 애플리케이션으로 배포되지만, 내부적으로는 각 모듈이 명확한 경계를 가지고 독립적으로 개발될 수 있도록 설계하는 것이죠.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Modular[&amp;#34;Modular Monolith&amp;#34;]
direction LR
subgraph OrderModule[&amp;#34;주문 모듈&amp;#34;]
OrderAPI[&amp;#34;API&amp;#34;]
OrderDomain[&amp;#34;Domain&amp;#34;]
OrderRepo[&amp;#34;Repository&amp;#34;]
end
subgraph ProductModule[&amp;#34;상품 모듈&amp;#34;]
ProductAPI[&amp;#34;API&amp;#34;]
ProductDomain[&amp;#34;Domain&amp;#34;]
ProductRepo[&amp;#34;Repository&amp;#34;]
end
subgraph UserModule[&amp;#34;회원 모듈&amp;#34;]
UserAPI[&amp;#34;API&amp;#34;]
UserDomain[&amp;#34;Domain&amp;#34;]
UserRepo[&amp;#34;Repository&amp;#34;]
end
end
Modular --&amp;gt; DB[(Database)]
&lt;/pre>&lt;p>위 다이어그램처럼 모듈러 모놀리식에서는 각 모듈이 자신만의 API, 도메인, 레포지토리를 가지며 &lt;strong>모듈 간의 직접적인 참조를 최소화&lt;/strong>합니다. 주문 모듈이 회원 정보가 필요하다면 회원 모듈의 내부 클래스를 직접 참조하는 것이 아니라, 회원 모듈이 제공하는 공개 API를 통해 접근하는 방식이죠.&lt;/p>
&lt;p>이렇게 하면 뭐가 좋을까요?&lt;/p>
&lt;p>우선 &lt;strong>모놀리식의 단순함을 유지하면서도 모듈 간의 결합도를 낮출 수 있습니다.&lt;/strong> 여전히 하나의 애플리케이션이기 때문에 배포가 간단하고, 분산 시스템의 복잡성을 피할 수 있습니다. 트랜잭션도 여전히 단일 DB에서 처리되기 때문에 데이터 일관성 문제도 없죠.&lt;/p>
&lt;p>또한 &lt;strong>나중에 MSA로 전환하기가 비교적 용이해집니다.&lt;/strong> 이미 모듈 간의 경계가 명확하게 나뉘어 있기 때문에, 특정 모듈을 별도의 서비스로 분리하는 것이 상대적으로 쉬워집니다. 모놀리식에서 바로 MSA로 전환하는 것보다 모듈러 모놀리식을 거쳐 MSA로 전환하는 것이 더 안전한 경로라고 생각합니다.&lt;/p>
&lt;h3>SOA (Service-Oriented Architecture)&lt;span class="hx:absolute hx:-mt-20" id="soa-service-oriented-architecture">&lt;/span>
&lt;a href="#soa-service-oriented-architecture" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>SOA는 MSA보다 먼저 등장한 아키텍처로, &lt;strong>서비스 단위로 시스템을 분리한다는 점에서 MSA와 유사&lt;/strong>합니다. 그래서 MSA를 SOA의 진화형이라고 부르기도 하죠.&lt;/p>
&lt;p>그렇다면 SOA와 MSA는 뭐가 다를까요?&lt;/p>
&lt;p>가장 큰 차이점은 &lt;strong>서비스의 크기와 통신 방식&lt;/strong>입니다. SOA는 상대적으로 큰 단위의 서비스를 가지며, &lt;strong>ESB(Enterprise Service Bus)&lt;/strong> 라는 중앙 집중식 통신 버스를 통해 서비스 간 통신을 처리합니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph SOA[&amp;#34;SOA Architecture&amp;#34;]
Service1[&amp;#34;주문 서비스&amp;#34;]
Service2[&amp;#34;상품 서비스&amp;#34;]
Service3[&amp;#34;회원 서비스&amp;#34;]
ESB[&amp;#34;ESB&amp;lt;br/&amp;gt;(Enterprise Service Bus)&amp;#34;]
Service1 &amp;lt;--&amp;gt; ESB
Service2 &amp;lt;--&amp;gt; ESB
Service3 &amp;lt;--&amp;gt; ESB
end
ESB &amp;lt;--&amp;gt; DB[(공유 DB)]
&lt;/pre>&lt;p>SOA에서는 ESB가 서비스 간의 메시지 변환, 라우팅, 프로토콜 변환 등을 담당합니다. 서비스들이 직접 통신하는 것이 아니라 ESB를 통해 통신하는 것이죠.&lt;/p>
&lt;p>이 방식의 장점은 서비스 간의 결합도를 낮출 수 있다는 점입니다. 하지만 &lt;strong>ESB 자체가 단일 장애 지점(SPOF)이 될 수 있고, ESB에 비즈니스 로직이 집중되면서 점점 복잡해지는 문제&lt;/strong>가 발생하기도 했습니다.&lt;/p>
&lt;p>MSA는 이런 SOA의 한계를 극복하기 위해 등장했다고 볼 수 있습니다. &lt;strong>ESB 대신 경량 프로토콜(REST, gRPC 등)을 사용한 직접 통신&lt;/strong>을 하고, &lt;strong>각 서비스가 자신만의 데이터베이스를 가지며&lt;/strong>, &lt;strong>더 작은 단위의 서비스&lt;/strong>로 분리합니다.&lt;/p>
&lt;h3>아키텍처 비교&lt;span class="hx:absolute hx:-mt-20" id="아키텍처-비교">&lt;/span>
&lt;a href="#%ec%95%84%ed%82%a4%ed%85%8d%ec%b2%98-%eb%b9%84%ea%b5%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>지금까지 설명한 아키텍처들을 표로 정리해보면 다음과 같습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;/th>
&lt;th style="text-align: center">모놀리식&lt;/th>
&lt;th style="text-align: center">모듈러 모놀리식&lt;/th>
&lt;th style="text-align: center">SOA&lt;/th>
&lt;th style="text-align: center">MSA&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>배포 단위&lt;/strong>&lt;/td>
&lt;td style="text-align: center">단일&lt;/td>
&lt;td style="text-align: center">단일&lt;/td>
&lt;td style="text-align: center">서비스별&lt;/td>
&lt;td style="text-align: center">서비스별&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>서비스 크기&lt;/strong>&lt;/td>
&lt;td style="text-align: center">-&lt;/td>
&lt;td style="text-align: center">-&lt;/td>
&lt;td style="text-align: center">대규모&lt;/td>
&lt;td style="text-align: center">소규모&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>통신 방식&lt;/strong>&lt;/td>
&lt;td style="text-align: center">메서드 호출&lt;/td>
&lt;td style="text-align: center">메서드 호출&lt;/td>
&lt;td style="text-align: center">ESB&lt;/td>
&lt;td style="text-align: center">경량 프로토콜&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>데이터베이스&lt;/strong>&lt;/td>
&lt;td style="text-align: center">공유&lt;/td>
&lt;td style="text-align: center">공유&lt;/td>
&lt;td style="text-align: center">공유 가능&lt;/td>
&lt;td style="text-align: center">서비스별 분리&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>복잡도&lt;/strong>&lt;/td>
&lt;td style="text-align: center">낮음&lt;/td>
&lt;td style="text-align: center">중간&lt;/td>
&lt;td style="text-align: center">높음&lt;/td>
&lt;td style="text-align: center">매우 높음&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3>그렇다면 왜 MSA인가?&lt;span class="hx:absolute hx:-mt-20" id="그렇다면-왜-msa인가">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%a0%87%eb%8b%a4%eb%a9%b4-%ec%99%9c-msa%ec%9d%b8%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>표를 보시면 MSA로 갈수록 복잡도가 높아지는 것을 알 수 있습니다. 그렇다면 왜 굳이 복잡한 MSA를 선택하는 걸까요?&lt;/p>
&lt;p>제가 생각하는 &lt;strong>MSA가 주는 가장 큰 가치는 바로 &amp;ldquo;독립성&amp;quot;입니다.&lt;/strong> 서비스별 독립 배포, 독립 확장, 독립 개발이 가능해지면서 대규모 조직에서 각 팀이 자율적으로 빠르게 움직일 수 있게 됩니다. 넷플릭스, 아마존, 쿠팡 같은 대규모 서비스들이 MSA를 선택한 이유도 바로 이 독립성 때문이라고 생각합니다.&lt;/p>
&lt;p>개발을 할 때도 의존성을 최소화하는 방향과 추상화에 대해 많이 고민하는데, 제 개인적인 생각에는 MSA도 결국에는 추상화와 의존성 최소화의 형태 중 하나라고 생각합니다.&lt;/p>
&lt;p>하지만 이 독립성을 얻기 위해 치러야 하는 대가가 있습니다. 분산 시스템의 복잡성, 네트워크 의존성, 데이터 일관성 문제 등 앞서 언급한 여러 문제들을 감수해야 합니다.&lt;/p>
&lt;p>그래서 저는 개인적으로 &lt;strong>처음부터 MSA로 시작하는 것보다 필요에 따라 전환하는 방식을 선호&lt;/strong>합니다.&lt;/p>
&lt;p>소프트웨어 개발 규칙 중 YAGNI(You Aren&amp;rsquo;t Gonna Need It)라는 규칙이 있습니다. 즉 필요에 의해 한 선택이 아닌 미리 필요할 것이라고 예상하여 선택하는 것은 되도록 피하라는 뜻이죠.&lt;/p>
&lt;p>섣불리 MSA를 도입하면 앞서 언급한 여러 문제들과 잘못 나눈 서비스 경계 때문에 오히려 더 큰 고통을 겪을 수 있다고 생각합니다.&lt;/p>
&lt;p>그렇다면 언제 MSA를 선택해야 하고, 언제 피해야 할까요? 이 질문에 대한 답은 시리즈의 마지막 편에서 자세히 다루겠습니다.&lt;/p>
&lt;h2>다음 편에서&lt;span class="hx:absolute hx:-mt-20" id="다음-편에서">&lt;/span>
&lt;a href="#%eb%8b%a4%ec%9d%8c-%ed%8e%b8%ec%97%90%ec%84%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>MSA가 무엇인지, 왜 등장했는지, 그리고 어떤 대안들이 있는지 알아보았습니다.&lt;/p>
&lt;p>그렇다면 이제 만약 저와 여러분들이 MSA를 선택했다고 가정하고, 첫 번째 현실적인 문제와 마주할 시간입니다.&lt;/p>
&lt;p>&lt;strong>서비스를 어떻게 나눌 것인가?&lt;/strong>&lt;/p>
&lt;p>다음 편에서는 DDD와 Bounded Context, Business Capability 기반 분해, 그리고 서비스 경계 설정 시 주의할 점들에 대해 이야기해보려합니다.&lt;/p>
&lt;p>후편: &lt;a href="https://jeongil.dev/ko/blog/architecture/msa-series-2-boundary/">[MSA에 관한 고찰 2/7편] MSA에서 서비스는 어떻게 나눌 것인가&lt;/a>&lt;/p></description></item><item><title>LLM을 내 두 번째 뇌로 만들기: MCP 서버로 개인 블로그를 RAG로 활용하는 방법</title><link>https://jeongil.dev/ko/blog/trends/llms-txt-mcp-second-brain/</link><pubDate>Wed, 31 Dec 2025 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/trends/llms-txt-mcp-second-brain/</guid><description>
&lt;p>안녕하세요. 프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 3년차 백엔드 개발자 정정일입니다.&lt;/p>
&lt;p>최근 AI, 특히 LLM(대형 언어 모델)이 개발자들 사이에서 큰 관심을 받고 있습니다.
물론 최근이라기엔 시간이 조금 되긴 했지만 날이 갈수록 개발자들의 일상에 또 여러 산업에서 AI 기술이 스며들고 있죠.
저 역시 LLM을 활용해 생산성을 높이고 학습에 활용하기도 하며 지식을 관리하는 방법에 대해 고민해왔습니다.&lt;/p>
&lt;p>그 방법 중에 하나로 LLM과 MCP(Model Context Protocol) Server를 활용해 제가 가진 경험들과 규칙들을 LLM이 활용할 수 있도록 구성해보았고 이번 글에서 이에 관해 적어보려 합니다.&lt;/p>
&lt;h2>두번째 뇌&lt;span class="hx:absolute hx:-mt-20" id="두번째-뇌">&lt;/span>
&lt;a href="#%eb%91%90%eb%b2%88%ec%a7%b8-%eb%87%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>&lt;img src="https://l2hyunn.github.io/assets/img/posts/2024-01-31-Obsidian---/obsidian-logo.webp" alt="" loading="lazy" />&lt;/p>
&lt;p>&lt;strong>Obsidian&lt;/strong>이라는 툴을 아시나요? Obsidian 은 Notion 혹은 OneNote 와 마찬가지로 필기 혹은 메모를 위한 개발자 도구 입니다. 개발자들에게 친숙한 Markdown 형식을 지원하고, 로컬 파일로 저장되며, 강력한 링크 기능과 플러그인 생태계를 가지고 있죠.&lt;/p>
&lt;p>갑자기 Obsidian 이야기를 왜 꺼내지? 하실 수 있습니다. Obsidian 이야기를 꺼내는 이유는 저는 개발자들이 Obsidian을 많이 사용하는 이유중 하나가 &lt;strong>&amp;ldquo;두 번째 뇌(Second Brain)&amp;rdquo;&lt;/strong> 로 활용하기 위한 시도라고 생각합니다.&lt;/p>
&lt;p>Obsidian만 검색해봐도 &amp;ldquo;Obsidian 두번째 뇌로 활용하는법!&amp;rdquo;, &amp;ldquo;개발자를 위한 두번째 뇌 구축하기&amp;rdquo; 등과 같은 글들이 나오니까요. 개발자들이 Obsidian 을 활용해 자신의 지식을 체계적으로 정리하고 관리하는 사례가 많기 때문이라고 저는 생각합니다.&lt;/p>
&lt;blockquote>
&lt;p>두 번째 뇌(Second Brain)란? &lt;strong>내 머릿속 지식을 외부화&lt;/strong>하여 저장하고 관리하는 시스템을 의미합니다. Obsidian, Notion, Roam Research 등 다양한 도구들이 두 번째 뇌 구축에 활용될 수 있습니다.&lt;/p>
&lt;/blockquote>
&lt;h3>왜 사람들은 두 번째 뇌를 원할까?&lt;span class="hx:absolute hx:-mt-20" id="왜-사람들은-두-번째-뇌를-원할까">&lt;/span>
&lt;a href="#%ec%99%9c-%ec%82%ac%eb%9e%8c%eb%93%a4%ec%9d%80-%eb%91%90-%eb%b2%88%ec%a7%b8-%eb%87%8c%eb%a5%bc-%ec%9b%90%ed%95%a0%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그렇다면 왜 사람들은 두 번째 뇌를 원할까요?&lt;/p>
&lt;p>개발자들은 매일 새로운 문제를 해결하고, 복잡한 시스템을 설계하며, 다양한 도구와 기술을 사용합니다. 이 과정에서 많은 지식과 경험이 쌓이지만, 이를 체계적으로 관리하지 않으면 쉽게 잊혀지거나 활용되지 못할 수 있습니다. 시간이 지나면 자연스레 기억이 희미해지기도 하구요. 물론 이는 꼭 개발자 뿐만 아니라 모든 직군에 해당되는 이야기이긴 합니다.&lt;/p>
&lt;p>개발하면서 마주치는 수많은 지식과 경험들인 트러블슈팅 경험, 아키텍처 결정 과정에서의 고민들, 컨벤션과 규칙, 성능 개선 노하우, 배우고 공부한 것들에 대한 정리 이런 지식들을 Obsidian에 정리하고, 링크로 연결하고, 필요할 때 꺼내 보면서 개발자들은 &lt;strong>&amp;ldquo;내 머릿속 지식을 외부화&amp;rdquo;&lt;/strong> 할 수 있었습니다.&lt;/p>
&lt;p>첫 번째 뇌(머리)는 &lt;strong>새로운 문제를 고민&lt;/strong>하는 데 집중하고, 두 번째 뇌(Obsidian)는 &lt;strong>과거 경험을 저장&lt;/strong>하는 역할 분담이 가능해진 거죠.&lt;/p>
&lt;h3>하지만 Obsidian에는 한계가 있었습니다&lt;span class="hx:absolute hx:-mt-20" id="하지만-obsidian에는-한계가-있었습니다">&lt;/span>
&lt;a href="#%ed%95%98%ec%a7%80%eb%a7%8c-obsidian%ec%97%90%eb%8a%94-%ed%95%9c%ea%b3%84%ea%b0%80-%ec%9e%88%ec%97%88%ec%8a%b5%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>모든 도구들이 그렇듯 Obsidian도 장점이 있다면 단점도 있다고 생각합니다. 제가 생각했던 두번째 뇌로써의 Obsidian의 단점은 &lt;strong>수동적&lt;/strong>이라는 점이라고 생각합니다.&lt;/p>
&lt;p>과거에 제가 어떤 경험을 했는지, 어떤 문제를 어떻게 해결했는지에 대한 지식이 Obsidian에 잘 정리되어 있다고 해도, 이를 찾고 활용하는 과정이 &lt;strong>직접적&lt;/strong>이어야 했습니다.&lt;/p>
&lt;p>예를 들어, 새로운 문제에 직면했을 때 Obsidian을 열고, 관련된 키워드로 검색을 해야 했습니다. 그리고 검색 결과에서 관련된 노트를 찾아 읽고, 그 내용을 현재 문제에 적용해야 했죠.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;이 문제 어떻게 해결했더라?&amp;rdquo;&lt;/strong> 하고 검색창을 열어야 하고, 여러 노트를 뒤적이며 관련 내용을 찾아야 합니다. 정리해두었던 컨벤션 문서를 찾기위해 이 문서 저 문서를 뒤지면서 시간을 허비하는 경험, 다들 있으시죠?&lt;/p>
&lt;h2>AI 시대, LLM으로 Second Brain을 만들 수 있을까?&lt;span class="hx:absolute hx:-mt-20" id="ai-시대-llm으로-second-brain을-만들-수-있을까">&lt;/span>
&lt;a href="#ai-%ec%8b%9c%eb%8c%80-llm%ec%9c%bc%eb%a1%9c-second-brain%ec%9d%84-%eb%a7%8c%eb%93%a4-%ec%88%98-%ec%9e%88%ec%9d%84%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>그렇다면 수동적이지 않은 두 번째 뇌는 가능할까요? 기존에는 어려웠다 하더라도 AI, 특히 LLM(대형 언어 모델)이 발전하면서 가능해졌다고 생각합니다.&lt;/p>
&lt;p>ChatGPT나 Gemini, Claude와 같은 LLM을 사용하시면서 내 이야기를 기억하고 내 상황에 맞는 답변을 해주는 경험, 다들 해보셨을 겁니다. 이는 LLM이 대화의 맥락을 이해하고, 이전 대화 내용을 기억하며, 사용자 맞춤형 응답을 생성할 수 있기 때문이죠.&lt;/p>
&lt;p>이는 LLM을 제공하는 플랫폼들이 &lt;strong>&amp;ldquo;Memory&amp;rdquo;&lt;/strong>, &lt;strong>&amp;ldquo;Custom Instructions&amp;rdquo;&lt;/strong>, &lt;strong>&amp;ldquo;Projects&amp;rdquo;&lt;/strong> 와 같은 기능들을 제공하기 때문입니다. 내부적으로는 &lt;strong>Short Term Memory&lt;/strong> 와 &lt;strong>Long Term Memory&lt;/strong> 로 나누어져 있기도 하지만 세부적인 것은 이번 주제와는 조금 거리가 있으니 넘어가겠습니다.&lt;/p>
&lt;p>결국은 LLM이 내 말들을 기억하고, &lt;strong>이전에 이야기했던 걸 기억해내&lt;/strong> 이야기 하는거죠. 이 기능들은 개발자들이 원하는 두 번째 뇌의 역할과도 어느정도 일맥상통하다고 생각합니다. 과거에 내가 쌓아둔 지식과 경험을 LLM이 기억하고, 새로운 문제에 맞게 활용해주는 것이니까요.&lt;/p>
&lt;p>그렇다면 &lt;strong>특정 플랫폼에서 꾸준히 LLM과 대화를 나누면서 내 지식과 경험을 쌓아가면, LLM이 내 두 번째 뇌 역할을 해줄 수 있지 않을까요?&lt;/strong>&lt;/p>
&lt;p>어떤 일이 있을때마다 ChatGPT나 Claude에게 물어보고 말하고, 그때그때 답변을 받으면서 점점 내 지식과 경험을 LLM이 쌓아가는 거죠. 그리고 나중에 해당 지식을 활용해야 할때 LLM에게 물어보면, 내가 쌓아둔 지식과 경험을 바탕으로 답변을 해주는 겁니다.&lt;/p>
&lt;p>&lt;strong>과연 이렇게 되면 두번째 뇌를 완성했다고 할 수 있는 것일까요?&lt;/strong>&lt;/p>
&lt;h3>이 방식에는 명확한 한계가 있습니다&lt;span class="hx:absolute hx:-mt-20" id="이-방식에는-명확한-한계가-있습니다">&lt;/span>
&lt;a href="#%ec%9d%b4-%eb%b0%a9%ec%8b%9d%ec%97%90%eb%8a%94-%eb%aa%85%ed%99%95%ed%95%9c-%ed%95%9c%ea%b3%84%ea%b0%80-%ec%9e%88%ec%8a%b5%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;h4>1. Context Window 제한&lt;span class="hx:absolute hx:-mt-20" id="1-context-window-제한">&lt;/span>
&lt;a href="#1-context-window-%ec%a0%9c%ed%95%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>Context Window란 LLM이 한 번에 처리할 수 있는 텍스트의 양을 의미합니다. 초기 GPT-4는 8,000 토큰 정도였지만, 최근에는 128k, 200k 토큰 이상을 지원하는 모델들도 등장했습니다. 하지만 아무리 큰 컨텍스트 윈도우라도 결국 &lt;strong>한계&lt;/strong>가 있습니다.&lt;/p>
&lt;p>토큰을 초과하면, LLM은 이전 대화 내용을 잊어버리기 시작합니다. ChatGPT나 Gemini와 오래 대화를 나누다 보면, 이전에 이야기했던 내용들이 점점 잊는 것 같은 경험을 다들 해보셨을 겁니다. 이런 원인은 Context Window 한계 때문입니다.&lt;/p>
&lt;p>예를 들면 다음과 같은 경험들을 많이 해보셨을 겁니다.&lt;/p>
&lt;ul>
&lt;li>&amp;ldquo;내가 무슨말을 하든 반말로 대답해줘&amp;rdquo; → 처음엔 잘 지키다가, 대화가 길어지면 점점 존댓말로 바뀜&lt;/li>
&lt;/ul>
&lt;p>결국 Memory에 저장돼 있던 기억들도 제가 다시 언급해주지 않으면 &lt;strong>Context Window 한계로 인해 LLM에게 전달되지 못하는 상황&lt;/strong>이 발생할 수 있습니다.&lt;/p>
&lt;h4>2. 플랫폼 종속성&lt;span class="hx:absolute hx:-mt-20" id="2-플랫폼-종속성">&lt;/span>
&lt;a href="#2-%ed%94%8c%eb%9e%ab%ed%8f%bc-%ec%a2%85%ec%86%8d%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>또 커다란 문제중 하나는 &lt;strong>특정 플랫폼에 쌓아둔 &amp;ldquo;기억&amp;rdquo; 들은 플랫폼에 종속적&lt;/strong>이라는 겁니다.&lt;/p>
&lt;p>ChatGPT에 쌓아둔 Memory들은 ChatGPT에만 있고 Gemini에 쌓아둔 Memory들은 Gemini에만 있습니다. 즉, 특정 플랫폼에서 쌓아둔 지식과 경험들은 다른 플랫폼으로 옮겨갈 수 없습니다. &lt;strong>ChatGPT와 대화 하다가 &amp;ldquo;Claude에서 내가 뭐라고 했더라?&amp;rdquo; 라고 하면 ChatGPT는 알수가 없죠.&lt;/strong>&lt;/p>
&lt;p>만약 ChatGPT를 1년간 사용하며 열심히 Memory를 쌓아가며 사용하던 와중에 ChatGPT 에서 유료버전 정책을 바꾸거나, 성능이 떨어지거나, 다른 플랫폼에 더 좋은 모델이 등장하거나, 다른 이유로 인해 Claude나 Gemini로 갈아타야 한다면 어떻게 될까요?&lt;/p>
&lt;p>&lt;strong>절망적이게도 다른 플랫폼에서 처음부터 다시 Memory를 쌓아야 합니다.&lt;/strong>&lt;/p>
&lt;p>개발자들은 의존성을 관리하는 데 익숙합니다. 라이브러리나 프레임워크, 특정 클라우드 서비스에 의존성을 가지게 될 때, 이를 관리하고 최소화하려고 노력하죠. 마찬가지로 &lt;strong>LLM 플랫폼 의존성도 관리해야 하는 상황&lt;/strong>이 되는 거죠.&lt;/p>
&lt;p>&lt;strong>내 지식이 플랫폼에 갇혀버리는 일&lt;/strong>이 발생하는 겁니다.&lt;/p>
&lt;h4>3. 프롬프트로 해결할 수 있을까?&lt;span class="hx:absolute hx:-mt-20" id="3-프롬프트로-해결할-수-있을까">&lt;/span>
&lt;a href="#3-%ed%94%84%eb%a1%ac%ed%94%84%ed%8a%b8%eb%a1%9c-%ed%95%b4%ea%b2%b0%ed%95%a0-%ec%88%98-%ec%9e%88%ec%9d%84%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>그렇다면 종속성을 피하기 위해 특정 프롬프트를 항상 준비해뒀다가 새로운 플랫폼에서 대화를 시작할 때마다 붙여넣으면 될까요?&lt;/p>
&lt;p>실제로 많은 LLM 플랫폼들이 &lt;strong>Custom Instructions&lt;/strong> 나 &lt;strong>프롬프트 템플릿&lt;/strong> 기능을 제공하고 있습니다. 이를 활용하면 어느정도는 해결할 수 있습니다. 다만 이는 몇가지 문제를 안고 있습니다.&lt;/p>
&lt;p>1번과도 연관이 있는데, Context Window 한계로 인해 너무 긴 프롬프트는 결국 기억하지 못하는 일이 발생합니다.&lt;/p>
&lt;p>또 개인 경험과 같은 &lt;strong>두번째 뇌를 만들기 위한 지식은 시간이 지날수록 점점 쌓이게 됩니다.&lt;/strong> 수백, 수천개의 노트와 경험들이 쌓이게 되면, 이를 모두 프롬프트에 담는 것은 불가능해집니다. 게다가 매번 새로운 세션을 시작할 때마다 프롬프트를 붙여넣는 것은 번거로운 일입니다. 비용문제도 있습니다. LLM 플랫폼들은 일반적으로 토큰 사용량에 따라 비용을 측정합니다. 이는 곧 비용 문제로 이어질 수 있겠죠.&lt;/p>
&lt;h2>LLM의 한계를 극복하기 위한 시도들&lt;span class="hx:absolute hx:-mt-20" id="llm의-한계를-극복하기-위한-시도들">&lt;/span>
&lt;a href="#llm%ec%9d%98-%ed%95%9c%ea%b3%84%eb%a5%bc-%ea%b7%b9%eb%b3%b5%ed%95%98%ea%b8%b0-%ec%9c%84%ed%95%9c-%ec%8b%9c%eb%8f%84%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이러한 문제는 사실 두번째 뇌와 관련된 문제에만 국한된 것은 아닙니다. Context Window 문제나 Memory, 비용 문제들은 AI를 활용하는 곳이라면 맞이할 수밖에 없는 공통적인 문제이죠.&lt;/p>
&lt;p>이는 LLM이 등장한 초기부터 제기되어 왔습니다. 그러나 문제가 있다면 항상 극복하기 위한 다양한 시도들이 있기 마련이죠. 대표적으로는 RAG가 있습니다.&lt;/p>
&lt;h3>RAG (Retrieval-Augmented Generation)&lt;span class="hx:absolute hx:-mt-20" id="rag-retrieval-augmented-generation">&lt;/span>
&lt;a href="#rag-retrieval-augmented-generation" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>RAG란 무엇일까요? RAG는 LLM이 외부 지식베이스에서 정보를 검색하여 답변을 생성하는 방법론입니다. 실제 저희 회사에서도 사용하고 있는 방법이기도 합니다.&lt;/p>
&lt;p>LLM이 모든 지식을 내부에 저장하거나 하는 것이 아니라 &lt;strong>문서화된 지식을 임베딩하여 벡터 DB와 같은 외부 지식베이스에 관련된 정보를 저장&lt;/strong>해두고, LLM이 질문을 받으면 &lt;strong>유사도 기반 검색과 같은 검색으로 관련된 정보를 외부 DB에서 검색하여 프롬프트에 포함시켜 답변을 생성&lt;/strong>하는 방식입니다.&lt;/p>
&lt;p>&lt;img src="https://miro.medium.com/v2/resize:fit:1400/0*StVZbRn8kiZ6BvEO.png" alt="" loading="lazy" />&lt;/p>
&lt;blockquote>
&lt;p>임베딩이란? 텍스트 데이터를 벡터(숫자 배열)로 변환하는 과정입니다. 이를 통해 텍스트의 의미를 수치적으로 표현할 수 있어, 유사도 검색 등에 활용됩니다. 이는 이번 주제와는 조금 거리가 있으니 넘어가겠습니다.&lt;/p>
&lt;/blockquote>
&lt;ol>
&lt;li>&lt;strong>검색(Retrieval)&lt;/strong>: 사용자의 질문과 관련된 문서를 외부 데이터베이스나 벡터 DB에서 검색합니다.&lt;/li>
&lt;li>&lt;strong>증강(Augmentation)&lt;/strong>: 검색된 관련 정보를 사용자의 질문과 결합하여 모델에게 전달합니다.&lt;/li>
&lt;li>&lt;strong>생성(Generation)&lt;/strong>: 모델이 제공된 정보를 바탕으로 최종 답변을 생성합니다.&lt;/li>
&lt;/ol>
&lt;p>위와 같은 단계를 거치게 돼죠. 이를 통해 Context Window 한계를 어느정도 극복하고 환각을 방지하며 최신 정보를 활용할 수 있게 됩니다.&lt;/p>
&lt;p>&lt;strong>이 방법론은 많은 기업들과 개발자들이 활용하고 있습니다.&lt;/strong> 예를 들어, 기업들은 자사 문서나 위키, 고객 지원 자료 등을 벡터 DB에 저장해두고, LLM이 고객 문의에 답변할 때 이를 활용하도록 구성할 수 있습니다.&lt;/p>
&lt;p>과거 StackOverflow에서 검색하던 경험을 생각해보면 이해가 쉽습니다. 개발자들이 새로운 문제에 직면했을 때, StackOverflow에서 관련된 질문과 답변을 검색하여 문제를 해결하곤 했습니다. &lt;strong>RAG는 이러한 검색 과정을 LLM이 자동으로 수행하도록 하는 것과 유사합니다.&lt;/strong>&lt;/p>
&lt;p>LLM 플랫폼에서 인터넷 검색과 같은 기능을 제공하기 전에는 RAG로 구축하는 경우가 지금보다 더 많았던 것 같습니다. 왜냐면 &lt;strong>모델은 학습됐을때의 지식까지만 알기 때문에 최신 정보를 반영하기 어렵기 때문이죠.&lt;/strong> RAG를 통해 최신 정보를 벡터 DB에 저장해두고 LLM이 이를 활용할 수 있게 하면 최신 정보를 반영할 수 있게 됩니다.&lt;/p>
&lt;p>그러나 LLM의 성능이 가파르게 상승하고 있는 지금 &lt;strong>LLM 플랫폼들이 웹 서치를 할 수 있는 모델들을 내놓기도 하면서 RAG의 필요성은 다소 줄어들긴 했다고 생각합니다.&lt;/strong>&lt;/p>
&lt;p>하지만 여전히 특정 도메인 지식이나 개인화된 지식을 활용해야 하는 경우에는 RAG가 유용하게 사용되고 있습니다. 또 &lt;strong>웹 서치가 항상 완벽한 답변을 제공하지는 않기 때문에, RAG를 통해 검증된 정보를 제공하는 것이 중요할 수 있다고 생각합니다.&lt;/strong>&lt;/p>
&lt;p>또 RAG에도 한계는 있습니다. 벡터 DB를 구축하고 유지보수하는 비용과 노력이 필요하고, 검색된 정보가 항상 정확하거나 관련성이 높지 않을 수 있습니다. 벡터 DB의 데이터를 최신화를 계속 해줘야 하는 문제도 있죠.&lt;/p>
&lt;p>이런 부분을 감안하더라도 RAG는 LLM의 한계를 극복하기 위한 강력한 방법론 중 하나라고 생각합니다. 물론 제가 모르는 더 좋은 방법론들도 있겠지만 제가 아는 한에서는 RAG가 가장 널리 알려져 있고, 많이 활용되고 있는 방법론인 것 같습니다.&lt;/p>
&lt;h2>MCP 서버: 진짜 Second Brain의 해결책&lt;span class="hx:absolute hx:-mt-20" id="mcp-서버-진짜-second-brain의-해결책">&lt;/span>
&lt;a href="#mcp-%ec%84%9c%eb%b2%84-%ec%a7%84%ec%a7%9c-second-brain%ec%9d%98-%ed%95%b4%ea%b2%b0%ec%b1%85" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>아무래도 저는 회사에서 RAG도 개발하고 운영하고 있다보니 문득 이런 생각이 들었습니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;내 개인 블로그에 있는 문서에 LLM이 자유롭게 접근하게 된다면 RAG처럼 동작하게 한다면 정말 두번째 뇌로써 활용할 수 있지 않을까?&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>LLM에게 질의할때마다 LLM이 적절히 판단해서 내 블로그에서 관련된 글을 찾아서 답변에 활용하게 만드는 거죠. 마치 제 개인 RAG와 같이 동작하게 만드는 겁니다. &lt;strong>그렇게 되면 제 경험과 지식에 기반한 추론과 답변이 가능해지겠죠.&lt;/strong>&lt;/p>
&lt;p>그렇다고 해서 RAG Server를 직접 구축하고 운영하는 것은 번거로운 일입니다. 벡터 DB를 구축하고, 문서를 임베딩하고, 검색 로직을 구현하는 등 많은 노력이 필요하니까요. 그러고 싶진 않았습니다.&lt;/p>
&lt;p>하지만 그렇게 번거로운 방법을 거치지 않고도, &lt;strong>내 블로그를 LLM이 자유롭게 읽고 활용할 수 있게 만드는 방법&lt;/strong>이 있었습니다. 바로 &lt;strong>MCP(Model Context Protocol) 서버&lt;/strong>를 활용하는 방법입니다.&lt;/p>
&lt;blockquote>
&lt;p>물론 이와같은 방법을 이미 다른 분들이 시도하셨고 이를 간단하게 구축할 수 있는 오픈소스 프로젝트들도 있을 수 있을 것 같습니다.
다만 &lt;strong>저는 제가 직접 MCP 서버를 구축하는 경험을 해보고 싶어&lt;/strong> 오픈소스를 찾아보기보다 직접 구축하기로 결심했으니 &lt;strong>이번 글에서는 핵심 아이디어에 대해서만 참고해주시면 감사하겠습니다.&lt;/strong>&lt;/p>
&lt;/blockquote>
&lt;h3>MCP(Model Context Protocol)란?&lt;span class="hx:absolute hx:-mt-20" id="mcpmodel-context-protocol란">&lt;/span>
&lt;a href="#mcpmodel-context-protocol%eb%9e%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>MCP는 LLM이 외부 지식 소스에 접근할 수 있도록 표준화된 프로토콜입니다. 쉽게 생각하시면 MCP는 LLM이 외부와 소통할 수 있는 &lt;strong>공용 인터페이스&lt;/strong>라고 할 수 있습니다.&lt;/p>
&lt;p>MCP에 대해 찾아보시면 LLM의 손과 발 역할을 하는 것이라고도 표현합니다. 이 표현이 저는 정확하다 생각하는데 LLM에게 외부 툴들에 대해 접근하는 방법을 제공하는 역할을 하기 때문이죠.&lt;/p>
&lt;p>&lt;img src="https://assets.apidog.com/blog-next/2025/03/image-253.png" alt="" loading="lazy" />&lt;/p>
&lt;p>예를 들어, MySQL 데이터베이스에 접근하는 MCP 서버를 만들어두면 &lt;strong>LLM이 필요할 때 MCP 서버를 통해 MySQL에 접근하여 데이터를 읽고 쓸 수 있게 됩니다.&lt;/strong> 실제로 &lt;a href="https://github.com/modelcontextprotocol/servers"target="_blank" rel="noopener">공식 MCP 서버 목록&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에 MySQL, PostgreSQL, SQLite 등 다양한 데이터베이스 MCP 서버들이 공개되어 있습니다.&lt;/p>
&lt;p>자 그럼 MCP가 어떻게 두번째 뇌 문제를 해결할 수 있을까요? 생각보다 간단합니다. &lt;strong>제 개인 개발 블로그에 접근하는 방법을 제공하는 MCP 서버를 제가 만들면 됩니다.&lt;/strong>&lt;/p>
&lt;p>이렇게 하면 &lt;strong>MCP를 지원하는 모든 LLM에서 사용 가능하기 때문에 플랫폼 독립적&lt;/strong>입니다. ChatGPT든, Claude든, Gemini든, 회사 자체 LLM이든 MCP를 활용할 수 있기만 하면 제 블로그에 접근할 수 있게 되는 거죠.&lt;/p>
&lt;p>또 &lt;strong>RAG처럼 동작하기 때문에 Context Window 한계도 어느정도 극복&lt;/strong>할 수 있습니다. LLM이 제 블로그에서 관련 글을 검색해서 가져오기 때문에, 블로그에 수백개의 글이 있더라도 필요한 글 몇개만 가져와서 활용할 수 있게 되는 겁니다.&lt;/p>
&lt;p>그리고 &lt;strong>영구적 지식 저장소&lt;/strong>가 됩니다. 제 블로그에 쌓아둔 지식과 경험들은 플랫폼이 바뀌어도 그대로 유지되며, 대화가 삭제되어도 남아있습니다. 언제든 필요할 때만 꺼내 쓸 수 있죠.&lt;/p>
&lt;p>다른 큰 장점중에 하나는 &lt;strong>내가 직접 MCP 서버를 운영하기 때문에, 내가 원하는 방식으로 지식과 경험을 관리할 수 있다&lt;/strong>는 점입니다. 블로그 글을 수정하거나 추가하는 것만으로도 제 두번째 뇌를 쉽게 업데이트할 수 있죠.&lt;/p>
&lt;p>이렇게 되면 저도 모르게 제 블로그를 꾸준히 업데이트하게 된다는 장점도 있게 됩니다. 아무래도 LLM이 참고하는 지식 저장소가 된다면, 더 자주 업데이트하게 되니까요. 😊&lt;/p>
&lt;p>&lt;strong>이렇게 되면 진짜 LLM을 Second Brain으로 활용될 수 있다 생각합니다.&lt;/strong>&lt;/p>
&lt;p>Obsidian처럼 지식을 정리하고 저장하되, LLM이 &lt;strong>능동적으로 찾고, 연결하고, 적용&lt;/strong>하면서도, &lt;strong>플랫폼에 종속되지 않고 영구적으로 유지&lt;/strong>되는 것.&lt;/p>
&lt;h3>그래서 만들었습니다&lt;span class="hx:absolute hx:-mt-20" id="그래서-만들었습니다">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%9e%98%ec%84%9c-%eb%a7%8c%eb%93%a4%ec%97%88%ec%8a%b5%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>제 개발 블로그(&lt;a href="https://jeongil.dev"target="_blank" rel="noopener">jeongil.dev&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>)를 Claude Code가 직접 읽고 활용할 수 있게 만드는 &lt;strong>MCP 서버&lt;/strong>를요.&lt;/p>
&lt;p>이제부터는 제가 실제로 어떻게 MCP 서버를 구축했는지, 구체적인 구현 과정을 적어보겠습니다.&lt;/p>
&lt;hr>
&lt;h2>llms.txt: LLM이 읽을 수 있는 표준 형식&lt;span class="hx:absolute hx:-mt-20" id="llmstxt-llm이-읽을-수-있는-표준-형식">&lt;/span>
&lt;a href="#llmstxt-llm%ec%9d%b4-%ec%9d%bd%ec%9d%84-%ec%88%98-%ec%9e%88%eb%8a%94-%ed%91%9c%ec%a4%80-%ed%98%95%ec%8b%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>MCP 서버를 만들기로 결심했을 때, 가장 먼저 고민한 것은 &lt;strong>&amp;ldquo;블로그 콘텐츠를 LLM이 어떻게 읽게 할 것인가?&amp;rdquo;&lt;/strong> 였습니다.&lt;/p>
&lt;p>Http 방식으로 html 페이지를 긁어오는 방법도 생각해봤지만, 이는 비효율적인 부분이 있었습니다.&lt;/p>
&lt;p>html은 md 파일보다 불필요한 태그와 스타일 정보가 많아 LLM이 핵심 내용을 파악하는 데 방해가 될 수 있었습니다. 또 블로그 구조가 바뀌면 MCP 서버 코드도 수정해야 하는 번거로움도 있었죠.&lt;/p>
&lt;p>그러던 중 &lt;a href="https://llmstxt.org/"target="_blank" rel="noopener">llms.txt&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>라는 표준의 존재를 알게 되었습니다.&lt;/p>
&lt;h3>llms.txt란?&lt;span class="hx:absolute hx:-mt-20" id="llmstxt란">&lt;/span>
&lt;a href="#llmstxt%eb%9e%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>llms.txt는 &lt;strong>웹사이트가 LLM에게 자신을 소개하는 표준화된 방법&lt;/strong>입니다. &lt;code>robots.txt&lt;/code>가 검색 엔진 크롤러를 위한 파일이라면, &lt;code>llms.txt&lt;/code>는 LLM을 위한 파일인 셈이죠.&lt;/p>
&lt;p>&lt;code>/llms.txt&lt;/code> 경로에 마크다운 형식으로 사이트의 주요 정보를 정리해두면, LLM이 해당 사이트를 이해하고 활용할 수 있게 됩니다.&lt;/p>
&lt;p>&lt;strong>llms.txt를 선택한 이유&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>표준화의 힘&lt;/strong>&lt;/p>
&lt;p>이미 많은 사이트들이 llms.txt를 채택하고 있었습니다. Claude나 ChatGPT 같은 LLM들도 이 표준을 이해하고 있죠. 별도의 설명 없이도 LLM이 바로 내 블로그를 이해할 수 있다는 점이 매력적이었습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>단순함&lt;/strong>&lt;/p>
&lt;p>마크다운 파일 하나면 됩니다. 복잡한 JSON 스키마도, 별도의 메타데이터도 필요 없습니다. Hugo 블로그에서 &lt;code>static/ko/llms.txt&lt;/code> 파일 하나만 추가하면 끝이었죠.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>유연성&lt;/strong>&lt;/p>
&lt;p>블로그에 새 글이 추가되면 llms.txt만 업데이트하면 됩니다. MCP 서버 코드는 건드릴 필요가 없죠. Hugo 빌드 프로세스에 llms.txt 생성 스크립트만 추가하면 자동화도 가능합니다.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h3>제 블로그의 llms.txt 구조&lt;span class="hx:absolute hx:-mt-20" id="제-블로그의-llmstxt-구조">&lt;/span>
&lt;a href="#%ec%a0%9c-%eb%b8%94%eb%a1%9c%ea%b7%b8%ec%9d%98-llmstxt-%ea%b5%ac%ec%a1%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>기존에 저는 제 개인 개발 블로그로 Velog를 사용하고 있었습니다. 하지만 Velog는 llms.txt를 지원하지 않았고, 커스터마이징도 어려웠습니다. 그래서 Hugo + GitHub Pages로 블로그를 이전하면서 llms.txt를 도입하기로 결정했죠.&lt;/p>
&lt;p>물론 Obsidian도 MCP 서버를 제공하기 때문에 Obsidian을 활용하는 방법도 있긴 했지만 Obsidian을 GitHub Pages로 연동하는 방법이 번거로웠고, 저는 개발 블로그와 개인 지식 저장소라는 두마리 토끼를 모두 잡고 싶었기 때문에 Hugo + GitHub Pages로 만든 개인 블로그에 llms.txt를 도입하는 방법을 선택했습니다.&lt;/p>
&lt;p>&lt;a href="https://velog.io/@12onetwo12/%EB%B8%94%EB%A1%9C%EA%B7%B8-%EC%9D%B4%EC%A0%84%ED%96%88%EC%8A%B5%EB%8B%88%EB%8B%A4"target="_blank" rel="noopener">블로그를 GitHub Pages로 이전하면서 적은 글&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에서도 밝혔지만 블로그 이전의 핵심 목표 중 하나가 llms.txt 도입이기도 했습니다.&lt;/p>
&lt;blockquote>
&lt;p>Hugo란 가장 인기 있는 오픈 소스 정적 사이트 생성기 중 하나입니다. Hugo는 마크다운 파일을 기반으로 정적 웹사이트를 생성합니다. &lt;code>static&lt;/code> 폴더에 넣은 파일들은 빌드 시 그대로 복사되어 최종 사이트에 포함됩니다. 그래서 &lt;code>static/ko/llms.txt&lt;/code> 파일을 추가하는 것만으로도 쉽게 llms.txt를 제공할 수 있었습니다.&lt;/p>
&lt;/blockquote>
&lt;p>Go 기반이기 때문에 빌드 속도도 매우 빠르고, 다양한 테마와 플러그인도 지원되어 커스터마이징도 용이했습니다. 또 다양한 테마가 있어서 디자인도 꽤나 마음에 들었죠. GitHub Pages와의 연동도 쉬워서 배포도 간편했습니다.&lt;/p>
&lt;p>블로그를 Hugo + GitHub Pages로 이전하면서 이제 llms.txt를 만드는 것은 간단하게 가능해졌습니다.&lt;/p>
&lt;p>그 다음으로 고민했던 부분은 llms.txt를 만들 때 &lt;strong>&amp;ldquo;LLM이 어떤 정보를 어떻게 쉽게 찾을 수 있게 할 것인가?&amp;rdquo;&lt;/strong> 였습니다.&lt;/p>
&lt;p>그냥 모든 글을 쭉 나열할 수도 있지만, 그러면 LLM이 원하는 정보를 찾기 어려울 것 같았습니다. 그래서 정보의 성격에 따라 두 가지로 나눴습니다.&lt;/p>
&lt;h4>&lt;strong>Documentation (개발 가이드라인)&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="documentation-개발-가이드라인">&lt;/span>
&lt;a href="#documentation-%ea%b0%9c%eb%b0%9c-%ea%b0%80%ec%9d%b4%eb%93%9c%eb%9d%bc%ec%9d%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>팀에서 합의한 규칙, 컨벤션, 원칙들을 모아놓은 카테고리입니다. &lt;strong>&amp;ldquo;어떻게 개발해야 하는가?&amp;rdquo;&lt;/strong> 에 대한 문서를 여기 모아놨습니다.&lt;/p>
&lt;p>코딩 컨벤션, Git 워크플로우, 아키텍처 원칙, API 설계 패턴, 테스트 전략, 데이터베이스 규칙 등입니다.&lt;/p>
&lt;p>예를 들어, Claude Code가 새로운 API를 만들 때 &amp;ldquo;내 개발 규칙을 준수하면서 API를 설계하고 구현해봐&amp;quot;라고 하면 Claude Code가 Documentation를 검색하여 제가 정리해둔 API 설계 원칙과 코딩 컨벤션을 참고해서 코드를 작성합니다.&lt;/p>
&lt;h4>&lt;strong>Tech Blog (실무 경험)&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="tech-blog-실무-경험">&lt;/span>
&lt;a href="#tech-blog-%ec%8b%a4%eb%ac%b4-%ea%b2%bd%ed%97%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>제가 실제로 겪었던 문제들과 해결 과정을 모아놓은 카테고리입니다. &lt;strong>&amp;ldquo;과거에 이 문제를 어떻게 해결했는가?, 예전에 어떤 경험들을 했는지&amp;rdquo;&lt;/strong> 등 에 대한 기록이죠. 세부적으로는 다음과 같은 카테고리로 분류했습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Backend&lt;/strong>: HikariCP Deadlock, Spring Batch Chunk 전환 등&lt;/li>
&lt;li>&lt;strong>Infrastructure &amp;amp; DevOps&lt;/strong>: Docker Compose에서 Kubernetes로 마이그레이션, ArgoCD 도입 등&lt;/li>
&lt;li>&lt;strong>Architecture &amp;amp; Design&lt;/strong>: MSA에서 Multi-Module로 전환, 멀티 모듈 통합 등&lt;/li>
&lt;li>&lt;strong>Development Culture&lt;/strong>: Git Flow 개선, 코드 리뷰 문화 정착 등&lt;/li>
&lt;/ul>
&lt;p>물론 이보다 좀더 있긴하지만 대표적인 카테고리들입니다.&lt;/p>
&lt;p>이렇게 &lt;strong>&amp;ldquo;규칙&amp;quot;과 &amp;ldquo;경험&amp;quot;을 분리&lt;/strong>하니 LLM이 상황에 맞는 정보를 정확히 찾을 수 있게 됐습니다. 제 개발 블로그에 개발 규칙과 같은 문서들을 포함시키고 싶었던 이유도 여기에 있습니다.&lt;/p>
&lt;p>기존에 Velog같은 경우는 문서와 블로그 글을 동시에 관리하기 어려웠습니다. 또 Mintlify와 같은 문서화 도구들은 문서화에는 최적화 돼있고 llms.txt도 지원하긴 하지만 블로그 글을 함께 관리하기엔 적합하지 않았죠.&lt;/p>
&lt;p>하지만 Hugo로 이전하면서 문서와 블로그 글을 모두 포함시킬 수 있었고, llms.txt에서도 이를 명확히 구분할 수 있게 됐죠.&lt;/p>
&lt;p>llms.txt의 전체 내용은 &lt;a href="https://jeongil.dev/ko/llms.txt"target="_blank" rel="noopener">jeongil.dev/ko/llms.txt&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에서 확인할 수 있습니다.&lt;/p>
&lt;hr>
&lt;h2>구현: MCP 서버 만들기&lt;span class="hx:absolute hx:-mt-20" id="구현-mcp-서버-만들기">&lt;/span>
&lt;a href="#%ea%b5%ac%ed%98%84-mcp-%ec%84%9c%eb%b2%84-%eb%a7%8c%eb%93%a4%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>MCP가 무엇인지는 위에서 설명했으니, 이제 실제로 어떻게 만들었는지 이야기해보겠습니다.&lt;/p>
&lt;h3>기술 스택 선택&lt;span class="hx:absolute hx:-mt-20" id="기술-스택-선택">&lt;/span>
&lt;a href="#%ea%b8%b0%ec%88%a0-%ec%8a%a4%ed%83%9d-%ec%84%a0%ed%83%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>FastMCP를 선택한 이유&lt;/strong>&lt;/p>
&lt;p>MCP 서버를 만들 때 공식 MCP SDK 대신 &lt;a href="https://github.com/jlowin/fastmcp"target="_blank" rel="noopener">FastMCP&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>를 선택했습니다.&lt;/p>
&lt;p>아무래도 FastMCP가 제공하는 간결한 API 덕분에 빠르게 개발할 수 있을 것 같았기 때문이죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 공식 MCP SDK는 이렇게 작성합니다 (장황함)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">mcp.server&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">Server&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">mcp.server.models&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">Resource&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">server&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">Server&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;my-blog&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@server.list_resources&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">async&lt;/span> &lt;span class="k">def&lt;/span> &lt;span class="nf">list_resources&lt;/span>&lt;span class="p">():&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">Resource&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">uri&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;blog://llms-txt&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">name&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;Full llms.txt&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">description&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;Complete content...&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">mimeType&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;text/plain&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># FastMCP는 이렇게 작성합니다 (간결함)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">fastmcp&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">FastMCP&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">mcp&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">FastMCP&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;My Tech Blog&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@mcp.resource&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;blog://llms-txt&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">async&lt;/span> &lt;span class="k">def&lt;/span> &lt;span class="nf">get_full_llms_txt&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;Complete llms.txt content from jeongil.dev.&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="k">await&lt;/span> &lt;span class="n">fetch_content&lt;/span>&lt;span class="p">()&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>FastMCP의 장점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>데코레이터 기반 API (Flask/FastAPI 스타일)&lt;/li>
&lt;li>자동 스키마 생성 (Docstring만 작성하면 됨)&lt;/li>
&lt;li>타입 안정성 (Pydantic 통합)&lt;/li>
&lt;li>코드량 50% 이상 감소&lt;/li>
&lt;/ul>
&lt;h3>프로젝트 구조&lt;span class="hx:absolute hx:-mt-20" id="프로젝트-구조">&lt;/span>
&lt;a href="#%ed%94%84%eb%a1%9c%ec%a0%9d%ed%8a%b8-%ea%b5%ac%ec%a1%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>처음에는 모든 코드를 한 파일에 때려박을까 생각했습니다. 간단한 프로젝트니까요. 하지만 나중에 확장할 가능성을 생각해서 관심사를 분리했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>my-tech-blog-mcp-server/
├── src/
│ ├── server.py # MCP 서버 메인 로직 (Resources, Tools, Prompts 정의)
│ └── llms_parser.py # llms.txt 파싱 및 검색 (HTTP 요청, 파싱, 검색)
├── run.py # 서버 실행 진입점
├── requirements.txt # 의존성
└── install.sh # 자동 설치 스크립트&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>왜 이렇게 나눴나?&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;code>llms_parser.py&lt;/code>: llms.txt를 가져오고 파싱하는 &lt;strong>데이터 레이어&lt;/strong>&lt;/li>
&lt;li>&lt;code>server.py&lt;/code>: MCP 프로토콜에 맞춰 데이터를 노출하는 &lt;strong>서비스 레이어&lt;/strong>&lt;/li>
&lt;/ul>
&lt;p>나중에 llms.txt 대신 다른 데이터 소스(Notion, Obsidian 등)를 쓰고 싶다면 &lt;code>llms_parser.py&lt;/code>만 교체하면 됩니다. &lt;code>server.py&lt;/code>는 건드릴 필요가 없죠.&lt;/p>
&lt;h3>1. llms.txt 파서 구현&lt;span class="hx:absolute hx:-mt-20" id="1-llmstxt-파서-구현">&lt;/span>
&lt;a href="#1-llmstxt-%ed%8c%8c%ec%84%9c-%ea%b5%ac%ed%98%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>먼저 llms.txt를 가져오고 검색하는 모듈부터 만들었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># src/llms_parser.py&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">LLMSParser&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="fm">__init__&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">base_url&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="nb">str&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s2">&amp;#34;https://jeongil.dev&amp;#34;&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">llms_url&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">base_url&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">/ko/llms.txt&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">_cache&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="kc">None&lt;/span> &lt;span class="c1"># 캐싱으로 성능 최적화&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">async&lt;/span> &lt;span class="k">def&lt;/span> &lt;span class="nf">fetch_content&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;llms.txt를 HTTP로 가져오기&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">async&lt;/span> &lt;span class="k">with&lt;/span> &lt;span class="n">httpx&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">AsyncClient&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="k">as&lt;/span> &lt;span class="n">client&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">response&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">await&lt;/span> &lt;span class="n">client&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">get&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">llms_url&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">response&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">text&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">async&lt;/span> &lt;span class="k">def&lt;/span> &lt;span class="nf">search_documentation&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">query&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;개발 가이드라인 검색 (간단한 문자열 매칭)&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1"># 일단 단순하게 시작 - 나중에 벡터 검색으로 개선 가능&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">...&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>핵심만 짚으면:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;code>httpx&lt;/code>로 비동기 HTTP 요청 (MCP 서버는 비동기로 동작하니까)&lt;/li>
&lt;li>메모리 캐싱으로 성능 최적화 (llms.txt는 자주 안 바뀌니까)&lt;/li>
&lt;li>간단한 문자열 매칭으로 검색 (YAGNI 원칙 - 일단 단순하게 시작)&lt;/li>
&lt;/ul>
&lt;p>자세한 전체 코드는 &lt;a href="https://github.com/12OneTwo12/my-tech-blog-mcp-server/blob/main/src/llms_parser.py"target="_blank" rel="noopener">제 GitHub 레포&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에서 확인하실 수 있습니다.&lt;/p>
&lt;h3>2. MCP 서버 구현&lt;span class="hx:absolute hx:-mt-20" id="2-mcp-서버-구현">&lt;/span>
&lt;a href="#2-mcp-%ec%84%9c%eb%b2%84-%ea%b5%ac%ed%98%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>파서가 준비됐으니 이제 MCP 서버를 만들 차례입니다. FastMCP를 쓰면 정말 간단합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># src/server.py&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">fastmcp&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">FastMCP&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">mcp&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">FastMCP&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;My Tech Blog&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">parser&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">LLMSParser&lt;/span>&lt;span class="p">()&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>MCP는 크게 3가지 개념이 있습니다.&lt;/p>
&lt;p>&lt;strong>1. Resources (리소스)&lt;/strong> - 읽기 전용 데이터&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@mcp.resource&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;blog://documentation&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">async&lt;/span> &lt;span class="k">def&lt;/span> &lt;span class="nf">get_documentation&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;Development guidelines and conventions.&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">content&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">await&lt;/span> &lt;span class="n">parser&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">get_content&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">format_documentation&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">content&lt;/span>&lt;span class="p">)&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>LLM이 &amp;ldquo;블로그 전체 내용 뭐 있지?&amp;rdquo; 하고 궁금할 때 읽어갑니다. Docstring이 자동으로 설명이 되니 별도 스키마 작성이 불필요합니다.&lt;/p>
&lt;p>&lt;strong>2. Tools (도구)&lt;/strong> - LLM이 실행할 수 있는 함수&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@mcp.tool&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">async&lt;/span> &lt;span class="k">def&lt;/span> &lt;span class="nf">search_experience&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">query&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;Search for past experiences and problem-solving stories.&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">results&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">await&lt;/span> &lt;span class="n">parser&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">search_tech_blog&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">query&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">format_results&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">results&lt;/span>&lt;span class="p">)&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&amp;ldquo;Kubernetes 관련 경험 찾아줘&amp;quot;라고 하면 LLM이 알아서 &lt;code>search_experience(&amp;quot;kubernetes&amp;quot;)&lt;/code>를 호출합니다. 제가 명령할 필요가 없죠.&lt;/p>
&lt;p>&lt;strong>3. Prompts (프롬프트)&lt;/strong> - 재사용 가능한 템플릿&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;span class="lnt">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@mcp.prompt&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">check_past_experience&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">topic&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="nb">str&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;Check if a similar problem was encountered before.&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;I&amp;#39;m working on: &lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">topic&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">Have I encountered this before? Search and summarize:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">1. Similar challenges
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">2. How I solved them
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">3. Lessons learned&amp;#34;&amp;#34;&amp;#34;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>자주 쓰는 질문 패턴을 템플릿으로 만들어두면 매번 긴 프롬프트 입력 안 해도 됩니다.&lt;/p>
&lt;hr>
&lt;p>&lt;strong>이게 FastMCP의 전부입니다.&lt;/strong> 데코레이터만 붙이면 끝이에요. 문서가 너무 잘 되어 있어서 막상 해보시면 구성하기 정말 쉽다는 걸 아실 겁니다.&lt;/p>
&lt;p>MCP 서버를 구현해보기 전에는 복잡할 줄 알았는데, 의외로 간단해서 놀랐습니다. 물론 세부적인 기술은 공부할게 많겠지만 구현자체는 정말 간단했습니다.&lt;/p>
&lt;p>자세한 구현 방법이나 코드는 아래 자료들을 참고해주시면 감사하겠습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://modelcontextprotocol.io/"target="_blank" rel="noopener">Model Context Protocol - Anthropic&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/12OneTwo12/my-tech-blog-mcp-server/blob/main/src/server.py"target="_blank" rel="noopener">제 GitHub 레포&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>3. 설치 자동화&lt;span class="hx:absolute hx:-mt-20" id="3-설치-자동화">&lt;/span>
&lt;a href="#3-%ec%84%a4%ec%b9%98-%ec%9e%90%eb%8f%99%ed%99%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이제 MCP 서버 코드는 다 작성됐습니다. 하지만 매번 새 환경에서 설정하기 귀찮더라구요.
저는 회사 맥북, 개인 맥북, 데스크탑 등 여러 환경에서 Claude Code를 씁니다. 매번 MCP 서버 설정하기 귀찮아서 설치 스크립트를 만들었습니다.&lt;/p>
&lt;p>&lt;strong>한 줄로 설치&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">./install.sh&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>스크립트가 자동으로:&lt;/p>
&lt;ol>
&lt;li>Python 가상 환경 생성&lt;/li>
&lt;li>의존성 설치 (&lt;code>fastmcp&lt;/code>, &lt;code>httpx&lt;/code>, &lt;code>pydantic&lt;/code>)&lt;/li>
&lt;li>Claude Code에 MCP 서버 등록&lt;/li>
&lt;/ol>
&lt;p>Claude Code 재시작하면 바로 쓸 수 있습니다. 새 환경 세팅할 때마다 10분 걸리던 게 1분으로 줄었죠.&lt;/p>
&lt;p>자세한 스크립트는 &lt;a href="https://github.com/12OneTwo12/my-tech-blog-mcp-server/blob/main/install.sh"target="_blank" rel="noopener">Github Repo - install.sh&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에 있으니 궁금하신분들은 참고해주세요.&lt;/p>
&lt;hr>
&lt;h2>실제 사용 결과&lt;span class="hx:absolute hx:-mt-20" id="실제-사용-결과">&lt;/span>
&lt;a href="#%ec%8b%a4%ec%a0%9c-%ec%82%ac%ec%9a%a9-%ea%b2%b0%ea%b3%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>&lt;img src="https://github.com/user-attachments/assets/59e4a407-d4a0-40ea-ae57-7eaeaccb37e8" alt="" loading="lazy" />&lt;/p>
&lt;p>MCP 서버를 구축하고 Claude Code에 연결한 후 사용해보니 &lt;strong>생각한 것 이상으로 두번째 뇌 역할을 톡톡히 해줄 수 있겠다 싶었습니다.&lt;/strong>&lt;/p>
&lt;p>위는 단적인 예시지만 &lt;strong>과거에 제가 겪었던 문제를 제 블로그에서 Claude Code가 바로 파악하여 년도별로 구별해준 모습입니다.&lt;/strong>&lt;/p>
&lt;p>나중에는 &amp;ldquo;내 블로그에서 HikariCP Deadlock 관련된 글 찾아서 요약해줘&amp;rdquo; 라고 하면 바로 찾아서 요약해주더군요.&lt;/p>
&lt;p>또 &amp;ldquo;내 개발 규칙에 맞게 이 코드를 리뷰해줘&amp;rdquo; 라고 하면 제 블로그에서 코딩 컨벤션과 API 설계 원칙을 참고해서 코드 리뷰를 해줍니다.&lt;/p>
&lt;hr>
&lt;h2>결과 및 효과&lt;span class="hx:absolute hx:-mt-20" id="결과-및-효과">&lt;/span>
&lt;a href="#%ea%b2%b0%ea%b3%bc-%eb%b0%8f-%ed%9a%a8%ea%b3%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이제 &lt;strong>AI Agent와 협업할 때 매번 제 상황이나 규칙을 설명할 필요가 없게 됐습니다.&lt;/strong> 그저 &amp;ldquo;내 블로그에 있는 개발 규칙 확인 해서 지금 코드에 미흡한 부분이 있는지 검토해봐&amp;quot;라고 하면 됩니다.&lt;/p>
&lt;p>또 과거에 있었던 일들도 일일히 제가 찾을 필요 없이 AI가 제 블로그에서 알아서 찾아줍니다.&lt;/p>
&lt;p>이렇게 되니 기록만 잘 해두면 AI가 제 두번째 뇌 역할을 톡톡히 해줄수 있게 됐습니다.&lt;/p>
&lt;p>지금 개발 블로그에는 경험과 규칙들만 있지만 예를 들어 향후 있을 Task들을 관리하는 공간을 추가한다고 가정하면, AI가 제 일정과 할일도 관리해줄 수 있게 됩니다.&lt;/p>
&lt;p>&amp;ldquo;오늘 해야할 일 뭐있지?&amp;rdquo; 라고 물어보면 AI가 제 일정과 할일을 확인해서 알려주는 거죠.&lt;/p>
&lt;p>이렇게 MCP 서버를 통해 제 두번째 뇌가 &lt;strong>수동적이지 않고 능동적으로&lt;/strong> 제 업무를 도와주게 되고 기록을 하면 할수록 저에 대해 더 잘 이해하며 추론도 할 수 있게 됩니다.&lt;/p>
&lt;p>경험에 기반한 조언도 해주고, 제가 자주 실수하는 부분도 미리 경고해주고, 규칙도 일관되게 지켜주고 말이죠.&lt;/p>
&lt;p>정말 &lt;strong>&amp;ldquo;두번째 뇌&amp;quot;가 무엇인지 체감할 수 있게 됐습니다.&lt;/strong> 뭔가 계속 이렇게 말하니 과장된 표현 같기도 하지만 실제로 써보면 정말 그런 느낌이 듭니다.&lt;/p>
&lt;hr>
&lt;h2>배운 점&lt;span class="hx:absolute hx:-mt-20" id="배운-점">&lt;/span>
&lt;a href="#%eb%b0%b0%ec%9a%b4-%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>1. 잘 정리해야한다&lt;span class="hx:absolute hx:-mt-20" id="1-잘-정리해야한다">&lt;/span>
&lt;a href="#1-%ec%9e%98-%ec%a0%95%eb%a6%ac%ed%95%b4%ec%95%bc%ed%95%9c%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>블로그를 쓰는 아주 큰 이유가 하나 더 생기고 명확해졌습니다. 기존에는 단순히 제 경험들을 정리해두는 공간이자 제가 글을 적으며 경험을 되새기는 공간이었습니다.&lt;/p>
&lt;p>그러나 LLM이 제 블로그를 읽고 활용할 수 있게 되면서, 블로그는 &lt;strong>나의 경험과 지식을 AI가 실시간으로 활용하는 아주 큰 자산&lt;/strong>이 되었습니다.&lt;/p>
&lt;p>블로그에 많은 글을 적어둔건 아니지만 경험에 관련된 부분들은 정리를 해뒀는데 MCP 서버를 만들 생각을 하면서 적어두길 너무너무 잘했다는 생각이 들었습니다.&lt;/p>
&lt;p>다만 두번째 뇌로써 &lt;strong>잘 활용하려면 잘 정리&lt;/strong>해야한다고 생각합니다. 제대로 정리되지 않은 글들은 AI가 활용하기 어렵기도 하고 어떤 경우에는 잘못된 정보를 줄 수 있으며 환각을 야기할수도 있기 때문입니다.&lt;/p>
&lt;p>그렇게되면 AI와 협업하거나 활용하는데 오히려 방해가 될수도 있죠. 문서화의 중요성은 여기서 다시 한번 강조 되는 것 같습니다. &lt;strong>제대로 정리하고 기록하는 능력은 개발자에게 아주 중요한 역량&lt;/strong>임을 다시 한번 느꼈습니다.&lt;/p>
&lt;p>또 &lt;strong>잘 기록하고 정리하면 그만큼 크나큰 자산이 된다는 점&lt;/strong>을 다시 한번 깨닫게 됐습니다. 앞으로는 그 가치가 더 커질거라 생각하니 더욱 열심히 기록하고 정리해야겠다는 다짐을 하게 됐습니다.&lt;/p>
&lt;h3>2. AI와 협업하려면 컨텍스트가 중요하다&lt;span class="hx:absolute hx:-mt-20" id="2-ai와-협업하려면-컨텍스트가-중요하다">&lt;/span>
&lt;a href="#2-ai%ec%99%80-%ed%98%91%ec%97%85%ed%95%98%eb%a0%a4%eb%a9%b4-%ec%bb%a8%ed%85%8d%ec%8a%a4%ed%8a%b8%ea%b0%80-%ec%a4%91%ec%9a%94%ed%95%98%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>LLM은 똑똑하지만 컨텍스트가 없으면 일반론만 말합니다. 또 잘못된 정보를 줄 수도 있죠. 그렇기 때문에 &lt;strong>내가 미리 검증해둔 컨텍스트를 주입하면, AI는 나만의 전문가가 된다고 생각합니다.&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>내 과거 경험&lt;/li>
&lt;li>내 개발 규칙&lt;/li>
&lt;li>내 아키텍처 결정 및 고민&lt;/li>
&lt;/ul>
&lt;p>이런 컨텍스트가 있어야 제게 더욱 맞는 유용한 조언을 받을 수 있지 않나 싶습니다. 기존에는 이런 문서들을 &lt;code>.claude&lt;/code>에 &lt;code>CLAUDE.md&lt;/code> 혹은 &lt;code>skills&lt;/code>에 문서로 추가해두곤 했습니다.&lt;/p>
&lt;p>&lt;code>CLAUDE.md&lt;/code>에 양이 너무 많아져 &lt;code>skills&lt;/code>로 분리해 토큰양을 줄이기 위한 작업들도 했었죠. [&lt;a href="https://jeongil.dev/ko/blog/trends/ai-agent-co-work/">&lt;strong>나는 미래를 받아들였는가? - 개발자 AI 코딩 툴과 협업하는 법&lt;/strong>&lt;/a>]&lt;/p>
&lt;p>하지만 문서가 많아지면 관리가 어렵고, 매번 업데이트하는 것도 번거로웠습니다.&lt;/p>
&lt;p>또 여러 프로젝트에서 공통적인 규칙들은 프로젝트별로 매번 추가해줘야 했죠.&lt;/p>
&lt;p>MCP 서버를 도입하면서 이런 문제들이 모두 해결됐습니다. &lt;strong>제 블로그가 곧 제 컨텍스트 저장소가 되었고&lt;/strong>, MCP 서버가 이를 LLM에게 실시간으로 제공해주니까요.&lt;/p>
&lt;h3>3. Second Brain의 유용성&lt;span class="hx:absolute hx:-mt-20" id="3-second-brain의-유용성">&lt;/span>
&lt;a href="#3-second-brain%ec%9d%98-%ec%9c%a0%ec%9a%a9%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>AI Agent와 협업할 때 &lt;strong>역할 분담이 명확해졌습니다.&lt;/strong> 저는 의사결정과 고민의 과정에 중점을 가지게 되고 AI는 제 경험과 지식을 제공하는 역할을 맡게 됐습니다.&lt;/p>
&lt;p>제가 하나하나 설명하지 않아도 제 두번째 뇌가 제 경험과 규칙을 알아서 제공해주니까요.&lt;/p>
&lt;p>이게 생각보다 정말 편하더라구요. Obsidian 같은 툴도 있지만, MCP 서버는 LLM과의 협업에 특화되어 있다는 점에서 훨씬 더 유용했습니다.&lt;/p>
&lt;hr>
&lt;h2>마치며&lt;span class="hx:absolute hx:-mt-20" id="마치며">&lt;/span>
&lt;a href="#%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>개발 블로그를 MCP 서버로 만들면서, &lt;strong>블로그의 가치가 제 개인에게는 굉장히 커졌다고 느껴집니다.&lt;/strong>&lt;/p>
&lt;p>단순히 정리용 글이 아니라 제 개인 경험에 대한 벡터 DB이자, LLM이 실시간으로 참고하는 지식 저장소가 되었기 때문입니다.&lt;/p>
&lt;p>&lt;strong>Obsidian이 두번째 뇌가 아닌 두번째 외장하드라면, MCP 서버는 진짜 두번째 뇌가 된 셈&lt;/strong>이라는 생각이 듭니다.&lt;/p>
&lt;p>물론 아직 부족한 점도 많고 개선할 점 역시 많으며 제가 적은 글들중에 잘못된 정보가 있을 수 있다는 점도 감안해야합니다. 하지만 지금까지 경험한 것만으로도 MCP 서버를 구축한 가치는 충분하다고 생각합니다.&lt;/p>
&lt;h3>여러분도 만들어보세요&lt;span class="hx:absolute hx:-mt-20" id="여러분도-만들어보세요">&lt;/span>
&lt;a href="#%ec%97%ac%eb%9f%ac%eb%b6%84%eb%8f%84-%eb%a7%8c%eb%93%a4%ec%96%b4%eb%b3%b4%ec%84%b8%ec%9a%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>제 MCP 서버 코드는 &lt;a href="https://github.com/12OneTwo12/my-tech-blog-mcp-server"target="_blank" rel="noopener">GitHub&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에 있습니다.&lt;/p>
&lt;p>README에 설치 방법과 사용법이 자세히 나와있으니, 참고하셔서 여러분의 블로그도 Second Brain으로 만들어보세요.&lt;/p>
&lt;p>블로그가 없다면 되도록 시작하시면 어떨까 싶습니다. 나중에는 이런 MCP Server들도 직접 만들지 않아도 LLM 플랫폼에서 제공해주지 않을까 싶습니다. 물론 이미 제공하고 있는데 제가 모르는 것일수도 있기도 합니다. ㅎㅎ..&lt;/p>
&lt;p>긴 글 읽어주셔서 감사합니다. 이 글이 여러분께 조금이라도 도움이 되었길 바랍니다. 감사합니다.&lt;/p>
&lt;hr>
&lt;h2>Reference&lt;span class="hx:absolute hx:-mt-20" id="reference">&lt;/span>
&lt;a href="#reference" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;ul>
&lt;li>&lt;a href="https://llmstxt.org/"target="_blank" rel="noopener">llms.txt - Standard for LLM-readable content&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://modelcontextprotocol.io/"target="_blank" rel="noopener">Model Context Protocol - Anthropic&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/jlowin/fastmcp"target="_blank" rel="noopener">FastMCP - Pythonic MCP Framework&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/modelcontextprotocol/python-sdk"target="_blank" rel="noopener">MCP Python SDK&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://toss.tech/article/tosspayments-mcp"target="_blank" rel="noopener">토스페이먼츠 MCP 서버 구현기&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/12OneTwo12/my-tech-blog-mcp-server"target="_blank" rel="noopener">GitHub - my-tech-blog-mcp-server&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://jeongil.dev/ko/llms.txt"target="_blank" rel="noopener">jeongil.dev/ko/llms.txt&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>GitHub Actions 무료 사용량 부족 문제를 Self-hosted Runner와 Jenkins로 해결한 과정</title><link>https://jeongil.dev/ko/blog/infrastructure/github-actions-to-jenkins/</link><pubDate>Tue, 16 Dec 2025 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/infrastructure/github-actions-to-jenkins/</guid><description>
&lt;p>안녕하세요. 프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 3년차 백엔드 개발자 정정일입니다.&lt;/p>
&lt;p>이 글은 회사에서 CI/CD 파이프라인을 개선해나가면서 겪었던 시행착오와 문제 해결 과정을 담은 이야기입니다.&lt;/p>
&lt;p>GitHub Actions로 시작했다가 Self-hosted Runner를 거쳐, 최종적으로 Jenkins on Kubernetes까지 오게 된 여정을 공유하려 합니다.&lt;/p>
&lt;hr>
&lt;h2>시작: GitHub Actions로 시작한 CI/CD&lt;span class="hx:absolute hx:-mt-20" id="시작-github-actions로-시작한-cicd">&lt;/span>
&lt;a href="#%ec%8b%9c%ec%9e%91-github-actions%eb%a1%9c-%ec%8b%9c%ec%9e%91%ed%95%9c-cicd" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>저희 회사는 프롭테크 스타트업입니다. MSA(Microservices Architecture)로 백엔드를 구성하고 있으며, 초기에는 5~6개 정도의 서비스로 시작했습니다. 기존에 CI/CD는 &lt;strong>GitHub Actions&lt;/strong>를 사용하고 있었습니다.&lt;/p>
&lt;p>당시 워크플로우는 상당히 단순했습니다. 아래는 단순화한 예시 입니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># 기존 ci-cd.yml (단순 버전)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">CI/CD&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">on&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">push&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">branches&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="l">main]&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">pull_request&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">branches&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="l">main]&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">jobs&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">build&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">runs-on&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">ubuntu-latest&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">steps&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">uses&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">actions/checkout@v3&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">Set up JDK 17&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">uses&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">actions/setup-java@v3&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">with&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">java-version&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;17&amp;#39;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">Build with Gradle&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">run&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">./gradlew build&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">Build Docker image&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">run&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">docker build -t my-service .&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">Push to registry&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">run&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">docker push my-service&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>간단한 빌드와 배포만 수행했고, 당시에는 GitHub Actions의 무료 플랜(Organization 월 2,000분)으로 충분했습니다.&lt;/p>
&lt;hr>
&lt;h2>전환점: 코드 품질 개선의 필요성&lt;span class="hx:absolute hx:-mt-20" id="전환점-코드-품질-개선의-필요성">&lt;/span>
&lt;a href="#%ec%a0%84%ed%99%98%ec%a0%90-%ec%bd%94%eb%93%9c-%ed%92%88%ec%a7%88-%ea%b0%9c%ec%84%a0%ec%9d%98-%ed%95%84%ec%9a%94%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>시간이 지나면서 회사도 아키텍처도 점차 성장했고, 이에 따라 서비스도 점점 늘어났습니다.&lt;/p>
&lt;p>그러면서 자연스럽게 &lt;strong>코드 품질 관리&lt;/strong>에 대한 고민과 관심이 생기기 시작했습니다.&lt;/p>
&lt;h3>당시 겪었던 문제들&lt;span class="hx:absolute hx:-mt-20" id="당시-겪었던-문제들">&lt;/span>
&lt;a href="#%eb%8b%b9%ec%8b%9c-%ea%b2%aa%ec%97%88%eb%8d%98-%eb%ac%b8%ec%a0%9c%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ol>
&lt;li>
&lt;p>&lt;strong>PR 리뷰 부담 증가&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>팀원의 수는 적었지만 PR이 많아지면서, 리뷰어가 놓치는 코드 컨벤션 위반 사례들이 생겼습니다.&lt;/li>
&lt;li>&amp;ldquo;이런 컨벤션을 자동으로 체크해줬으면 좋겠다.&amp;rdquo;&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>테스트 커버리지 관리 어려움&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>테스트는 작성하고 있지만, 커버리지가 얼마나 되는지 가시적으로 확인하기 어려웠습니다.&lt;/li>
&lt;li>확인하려면 개인이 로컬에서 확인해야했죠.&lt;/li>
&lt;li>또 PR마다 커버리지가 떨어지는지 올라가는지 알 수가 없었습니다.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>잠재적 버그 발견의 어려움&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>간단한 실수들(null 체크 누락, 리소스 미반환 등)을 사람이 일일이 찾는건 놓치는 경우가 발생할 수 있었습니다.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;p>이런 문제들을 해결하기 위해 &lt;strong>정적 분석 도구&lt;/strong>와 &lt;strong>테스트 커버리지 도구&lt;/strong>를 도입하기로 했습니다.&lt;/p>
&lt;h3>도구 선택 과정&lt;span class="hx:absolute hx:-mt-20" id="도구-선택-과정">&lt;/span>
&lt;a href="#%eb%8f%84%ea%b5%ac-%ec%84%a0%ed%83%9d-%ea%b3%bc%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>처음엔 &lt;strong>SonarQube&lt;/strong>나 &lt;strong>SonarCloud&lt;/strong>를 검토했습니다.&lt;/p>
&lt;p>하지만:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>SonarQube&lt;/strong>: 자체 서버를 운영해야 함 (인프라 리소스 소모, 관리 부담)&lt;/li>
&lt;li>&lt;strong>SonarCloud&lt;/strong>: 유료 ($10/month부터 시작, 서비스 늘어날수록 비용 증가)&lt;/li>
&lt;/ul>
&lt;p>스타트업이다 보니 위와같은 툴로 운영하기가 인력과 비용에 한계가 있어 운영이 부담 됐습니다.&lt;/p>
&lt;p>그러다 찾은 게 &lt;strong>ReviewDog&lt;/strong>과 &lt;strong>Jacoco&lt;/strong>였습니다.&lt;/p>
&lt;p>&lt;strong>Detekt, ReviewDog&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Detekt는 Kotlin 정적 분석 도구입니다.&lt;/li>
&lt;li>ReviewDog은 다양한 정적 분석 도구의 결과를 PR 코멘트로 남겨주는 툴입니다.&lt;/li>
&lt;li>위 두가지 툴과 GitHub Actions를 통해 PR 단위에 라인별 코멘트를 자동으로 작성하여 리뷰해줄 수 있습니다.&lt;/li>
&lt;li>Github actions를 기반으로 동작시킬 수 있다보니 별도의 서버가 불필요했습니다.&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Jacoco&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Java 프로젝트 테스트 커버리지 측정 도구입니다.&lt;/li>
&lt;li>Gradle 플러그인으로 간단히 통합할 수 있고&lt;/li>
&lt;li>PR 코멘트에 커버리지 리포트 자동 작성할 수도 있습니다.&lt;/li>
&lt;/ul>
&lt;p>고민은 길지 않았고 바로 위 도구들을 도입하기 시작했습니다.&lt;/p>
&lt;h3>도입 후 효과&lt;span class="hx:absolute hx:-mt-20" id="도입-후-효과">&lt;/span>
&lt;a href="#%eb%8f%84%ec%9e%85-%ed%9b%84-%ed%9a%a8%ea%b3%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>도입 효과는 생각보다 더 좋았습니다.&lt;/p>
&lt;ul>
&lt;li>PR 리뷰 시간 단축 (자동으로 체크되니 리뷰어가 컨벤션 체크에 쓰는 시간 감소)&lt;/li>
&lt;li>코드 품질 향상 (잠재적 버그 사전 발견)&lt;/li>
&lt;li>테스트 커버리지 가시화 (PR마다 커버리지 변화 확인 가능)&lt;/li>
&lt;/ul>
&lt;p>팀원분들도 제가 해당 툴들을 구성한 이후 PR에 데코레이션으로 남은 결과를 보시곤 만족해 해주셨습니다. ㅎㅎ&lt;/p>
&lt;hr>
&lt;h2>문제 발생: GitHub Actions 무료 사용량 문제&lt;span class="hx:absolute hx:-mt-20" id="문제-발생-github-actions-무료-사용량-문제">&lt;/span>
&lt;a href="#%eb%ac%b8%ec%a0%9c-%eb%b0%9c%ec%83%9d-github-actions-%eb%ac%b4%eb%a3%8c-%ec%82%ac%ec%9a%a9%eb%9f%89-%eb%ac%b8%ec%a0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>그런데 2~3주쯤 지나니 문제가 될 수 있는 부분을 인지하게 됐습니다.&lt;/p>
&lt;p>&lt;strong>사용량을 보아하니 GitHub Actions 무료 사용량을 초과할 수 있겠다 싶었습니다.&lt;/strong>&lt;/p>
&lt;p>Github Actions 무료 사용량은 &lt;strong>Organization 단위로 월 2,000분&lt;/strong>인데 이를 간과하고 있었습니다.&lt;/p>
&lt;h3>사용량 분석&lt;span class="hx:absolute hx:-mt-20" id="사용량-분석">&lt;/span>
&lt;a href="#%ec%82%ac%ec%9a%a9%eb%9f%89-%eb%b6%84%ec%84%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>제가 &lt;strong>ReviewDog&lt;/strong>과 &lt;strong>Jacoco&lt;/strong> Workflow를 추가하게 되면서 저희의 워크플로우는 CI/CD까지 포함하여 3개로 늘어나게 됐습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>워크플로우&lt;/th>
&lt;th>실행 조건&lt;/th>
&lt;th>평균 실행 시간&lt;/th>
&lt;th>비고&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>jacoco-rule.yml&lt;/td>
&lt;td>PR 생성/수정 시&lt;/td>
&lt;td>4.60분&lt;/td>
&lt;td>테스트 실행 + 커버리지 측정&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>detekt, review-dog.yml&lt;/td>
&lt;td>PR 생성/수정 시&lt;/td>
&lt;td>1.63분&lt;/td>
&lt;td>정적 분석&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>ci-cd.yml&lt;/td>
&lt;td>main 머지 시&lt;/td>
&lt;td>6.18분&lt;/td>
&lt;td>빌드 + 배포&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>배포 1회당 사용량을 어림잡아 계산해보니&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>feature → develop 단계 (PR 작업):
- PR 작성부터 머지까지 평균 5회 커밋 가정
- jacoco-rule.yml (4.60분) &amp;#43; review-dog.yml (1.63분) = 6.23분
- 총 5회 실행: 6.23분 × 5 = 31.15분
develop → main 단계 (배포):
- jacoco-rule.yml &amp;#43; review-dog.yml &amp;#43; ci-cd.yml = 12.41분
배포 1회 총합: 31.15분 &amp;#43; 12.41분 = 43.56분&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>월 2,000분 ÷ 43.56분 = 약 45회 배포&lt;/strong>할 수 있는 정도였습니다.&lt;/p>
&lt;p>더 큰 문제는 이 2,000분이 &lt;strong>Organization 전체&lt;/strong>에 적용된다는 점이었습니다.&lt;/p>
&lt;p>MSA 환경에서 여러 서비스를 운영하다 보니, 한 달에 45회 배포로는 상당히 부족했습니다.&lt;/p>
&lt;hr>
&lt;h2>고민: 어떻게 해결할 것인가&lt;span class="hx:absolute hx:-mt-20" id="고민-어떻게-해결할-것인가">&lt;/span>
&lt;a href="#%ea%b3%a0%eb%af%bc-%ec%96%b4%eb%96%bb%ea%b2%8c-%ed%95%b4%ea%b2%b0%ed%95%a0-%ea%b2%83%ec%9d%b8%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>팀 내에서 논의가 시작됐습니다. 다양한 옵션을 고려하게 됐는데 고려한 옵션들은 다음과 같습니다.&lt;/p>
&lt;h3>고려했던 옵션들&lt;span class="hx:absolute hx:-mt-20" id="고려했던-옵션들">&lt;/span>
&lt;a href="#%ea%b3%a0%eb%a0%a4%ed%96%88%eb%8d%98-%ec%98%b5%ec%85%98%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>1. GitHub Actions 유료 플랜으로 전환&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>가장 간단한 해결책이였습니다. 하지만 비용이 부담됐습니다.&lt;/li>
&lt;li>서비스가 계속 늘어나는데 그에 따라 비용도 계속 증가할 것으로 예측 됐습니다.&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>2. 정적 분석 도구 제거&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>사용량 문제는 해결되지만 코드 품질 관리를 포기하는게 과연 맞나? 싶었습니다.&lt;/li>
&lt;li>막 좋아지기 시작한 개발 문화를 다시 되돌리는 건 아니다. 로 결론 지었습니다.&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>3. Jenkins 구축&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>장점: 무료, 확장성 좋음&lt;/li>
&lt;li>단점: CI/CD 파이프라인 전면 재구축 필요&lt;/li>
&lt;li>당시에 기능 개발에 집중해야 하는 시기라 시간적 여유가 없었습니다. 그리고 당시에는 구성돼있는 Kubernetes도 없었기 때문에 별도로 Jenkins를 위한 인스턴스를 운영해야 했습니다.&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>4. Self-hosted Runner&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>GitHub Actions는 Self-hosted Runner 사용 시 &lt;strong>무료 사용량 제한 없습니다&lt;/strong> (최근에 안내메일을 받았는데 이제는 2026년 3월부터 분당 0.002달러 과금 정책이 생긴다고 합니다.)&lt;/li>
&lt;li>기존 워크플로우를 그대로 사용 가능하다는 장점이 컸습니다. (영향도 최소)&lt;/li>
&lt;li>빠른 적용이 가능하다는 것도 장점이였습니다. (몇 시간이면 설정 완료)&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2>해결 시도 1: Self-hosted Runner 도입&lt;span class="hx:absolute hx:-mt-20" id="해결-시도-1-self-hosted-runner-도입">&lt;/span>
&lt;a href="#%ed%95%b4%ea%b2%b0-%ec%8b%9c%eb%8f%84-1-self-hosted-runner-%eb%8f%84%ec%9e%85" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>고민 끝에 &lt;strong>Self-hosted Runner&lt;/strong>를 선택했습니다.&lt;/p>
&lt;h3>왜 Self-hosted Runner였나?&lt;span class="hx:absolute hx:-mt-20" id="왜-self-hosted-runner였나">&lt;/span>
&lt;a href="#%ec%99%9c-self-hosted-runner%ec%98%80%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>당시 상황을 고려했을 때는 최선의 선택이었던 것 같습니다.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>시간적, 금전적 여유가 없었습니다&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Jenkins는 파이프라인을 처음부터 다시 작성해야 하기 때문에 트러블슈팅도 필요했고, Jenkins를 별도로 구축하는 과정도 필요했습니다.&lt;/li>
&lt;li>당시에는 기능 개발에 집중해야 하는 시기였기 때문에 시간적 여유가 없었습니다.&lt;/li>
&lt;li>또 언급한대로 별도로 인스턴스를 하나 운영해야했기 때문에 Jenkins를 구성한다면 추가적인 비용이 불가피했습니다.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>영향도가 거의 없었습니다&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>기존 GitHub Actions 워크플로우를 그대로 사용할 수 있다는게 아무래도 큰 장점이였습니다.&lt;/li>
&lt;li>jacoco-rule.yml, review-dog.yml, ci-cd.yml 모두 수정이 거의 불필요 했죠. 단지 실행 환경만 Self-hosted Runner로 바뀔 뿐이니까요. (물론 약간의 설정 변경은 필요했습니다)&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>빠르게 적용 가능했습니다&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Runner 설치와 등록만 하면 끝이였습니다.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;h3>Self-hosted Runner 구성&lt;span class="hx:absolute hx:-mt-20" id="self-hosted-runner-구성">&lt;/span>
&lt;a href="#self-hosted-runner-%ea%b5%ac%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그래서 팀원들의 Macbook에 GitHub Actions Runner를 설치를 부탁드렸습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># GitHub Actions Runner 다운로드 및 설치&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">mkdir actions-runner &lt;span class="o">&amp;amp;&amp;amp;&lt;/span> &lt;span class="nb">cd&lt;/span> actions-runner
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">curl -o actions-runner-linux-x64-2.311.0.tar.gz -L &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> https://github.com/actions/runner/releases/download/v2.311.0/actions-runner-linux-x64-2.311.0.tar.gz
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">tar xzf ./actions-runner-linux-x64-2.311.0.tar.gz
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># GitHub Organization에 Runner 등록&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">./config.sh --url https://github.com/your-organization --token &lt;span class="o">[&lt;/span>토큰 값&lt;span class="o">]&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>별도로 PC가 시작될때 자동으로 실행되도록 설정할 수 있는 가이드도 공유드리게 됐습니다.&lt;/p>
&lt;h3>초기 결과: 문제 해결!&lt;span class="hx:absolute hx:-mt-20" id="초기-결과-문제-해결">&lt;/span>
&lt;a href="#%ec%b4%88%ea%b8%b0-%ea%b2%b0%ea%b3%bc-%eb%ac%b8%ec%a0%9c-%ed%95%b4%ea%b2%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그 결과 처음엔 아주 잘 작동했습니다.&lt;/p>
&lt;ul>
&lt;li>GitHub Actions 무료 사용량 문제도 해결 됐고&lt;/li>
&lt;li>모든 워크플로우도 정상 동작 했죠.&lt;/li>
&lt;/ul>
&lt;p>몇달간은 만족스러웠습니다.&lt;/p>
&lt;hr>
&lt;h2>시간이 흐르고&amp;hellip; 새로운 문제들&lt;span class="hx:absolute hx:-mt-20" id="시간이-흐르고-새로운-문제들">&lt;/span>
&lt;a href="#%ec%8b%9c%ea%b0%84%ec%9d%b4-%ed%9d%90%eb%a5%b4%ea%b3%a0-%ec%83%88%eb%a1%9c%ec%9a%b4-%eb%ac%b8%ec%a0%9c%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>몇 달이 지나면서 상황이 많이 변하게 됐습니다.&lt;/p>
&lt;h3>서비스 증가&lt;span class="hx:absolute hx:-mt-20" id="서비스-증가">&lt;/span>
&lt;a href="#%ec%84%9c%eb%b9%84%ec%8a%a4-%ec%a6%9d%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>회사가 성장하면서 MSA 서비스가 계속 늘어났고 그에 따라 Workflow 실행 횟수도 증가했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>초기: 5~6개 서비스
현재: 14개 이상 서비스&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>횟수가 늘어남에 따라 팀원들의 PC를 기반으로 한 &lt;strong>Self-hosted Runner의 한계&lt;/strong>가 드러나기 시작했습니다. 😢&lt;/p>
&lt;h3>문제 1: Macbook 발열과 성능 저하&lt;span class="hx:absolute hx:-mt-20" id="문제-1-macbook-발열과-성능-저하">&lt;/span>
&lt;a href="#%eb%ac%b8%ec%a0%9c-1-macbook-%eb%b0%9c%ec%97%b4%ea%b3%bc-%ec%84%b1%eb%8a%a5-%ec%a0%80%ed%95%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Self-hosted Runner로 등록한 &lt;strong>팀원들의 Macbook&lt;/strong>에서 문제가 시작됐습니다.&lt;/p>
&lt;p>&lt;strong>증상:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>CI/CD 파이프라인이 돌아갈 때마다 Macbook 발열 심각&lt;/li>
&lt;li>시스템 전체가 느려짐&lt;/li>
&lt;li>코딩하다가 파이프라인 돌아가면 작업 중단 불가피&lt;/li>
&lt;/ul>
&lt;p>특히 Gradle 빌드나 Docker 이미지 빌드가 돌아갈 때는 맥북이 뜨거워져서 팬이 계속 돌아가는 상황이었습니다.&lt;/p>
&lt;p>&lt;strong>왜 이런 일이?&lt;/strong>&lt;/p>
&lt;p>Self-hosted Runner는 로컬 머신의 CPU, 메모리를 직접 사용합니다.&lt;/p>
&lt;p>Spring Boot 빌드 + Docker 이미지 빌드는 리소스를 많이 소모하는 작업입니다:&lt;/p>
&lt;ul>
&lt;li>Gradle 빌드: JVM 메모리 2~3GB 사용&lt;/li>
&lt;li>Docker 이미지 빌드: CPU 집약적 작업&lt;/li>
&lt;/ul>
&lt;p>개발하면서 동시에 CI/CD가 돌아가니, 맥북이 버티지 못한 겁니다.&lt;/p>
&lt;blockquote>
&lt;p>여담이지만 사실 제 노트북이 가장 발열과 성능 저하가 심했습니다&amp;hellip;ㅎ 죄송합니다 팀원분들 ㅠㅜ&lt;/p>
&lt;/blockquote>
&lt;h3>문제 2: 동시 실행 병목&lt;span class="hx:absolute hx:-mt-20" id="문제-2-동시-실행-병목">&lt;/span>
&lt;a href="#%eb%ac%b8%ec%a0%9c-2-%eb%8f%99%ec%8b%9c-%ec%8b%a4%ed%96%89-%eb%b3%91%eb%aa%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>또 서비스가 늘어나면서 여러 서비스에서 동시에 배포가 일어나는 경우가 많아졌습니다.&lt;/p>
&lt;p>&lt;strong>문제:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Runner는 한 번에 하나의 Job만 처리&lt;/li>
&lt;li>여러 서비스 배포가 동시에 발생하면 순차 처리&lt;/li>
&lt;li>앞 배포가 끝나야 다음 배포 시작&lt;/li>
&lt;li>대기 시간 점점 증가&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>실제 사례:&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>12:00 - user-service 배포 시작 (예상 시간: 5분)
12:02 - chat-service 배포 대기 중...
12:04 - match-service 배포 대기 중...
12:05 - user-service 배포 완료
12:05 - chat-service 배포 시작 (예상 시간: 5분)
12:10 - chat-service 배포 완료
12:10 - match-service 배포 시작 (예상 시간: 5분)
12:15 - match-service 배포 완료
총 15분 소요 (동시 실행 시 5분이면 끝날 작업)&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이는 빠른 반영을 위해서는 치명적인 병목이었습니다.&lt;/p>
&lt;h3>문제 3: 유지보수 부담&lt;span class="hx:absolute hx:-mt-20" id="문제-3-유지보수-부담">&lt;/span>
&lt;a href="#%eb%ac%b8%ec%a0%9c-3-%ec%9c%a0%ec%a7%80%eb%b3%b4%ec%88%98-%eb%b6%80%eb%8b%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Runner가 여러 대 있다 보니 유지보수 부담도 커졌습니다.&lt;/p>
&lt;ul>
&lt;li>각 Runner의 상태 관리 필요&lt;/li>
&lt;li>환경 일관성 유지 어려움
&lt;ul>
&lt;li>A Runner: Docker 20.x&lt;/li>
&lt;li>B Runner: Docker 24.x&lt;/li>
&lt;li>어떤 Runner에서 빌드되느냐에 따라 미묘한 차이 발생&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>장애 발생 시 디버깅 복잡
&lt;ul>
&lt;li>&amp;ldquo;왜 이 빌드는 실패했지? 아, A Runner에서 돌아갔네&amp;hellip; 해당 머신 상태 확인해봐야겠다.&amp;rdquo;&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h3>결정적 순간&lt;span class="hx:absolute hx:-mt-20" id="결정적-순간">&lt;/span>
&lt;a href="#%ea%b2%b0%ec%a0%95%ec%a0%81-%ec%88%9c%ea%b0%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>어느 날, 팀원이 Slack에 메시지를 남겨주셨습니다.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;정일님.. CI 돌아가는 동안 맥북 너무 느려서 작업이 어렵습니다 ㅠㅜ 다른 방법 없을까요?&amp;rdquo;&lt;/p>
&lt;/blockquote>
&lt;p>저희는 &lt;strong>비용 문제를 해결하려다 개발자 경험(DX)을 너무나 해치고 있었던 겁니다.&lt;/strong>
이날 결정하게 됐습니다. &lt;strong>&amp;ldquo;더 근본적인 해결책이 필요하다&amp;quot;고요.&lt;/strong>&lt;/p>
&lt;hr>
&lt;h2>다시 고민: 근본적인 해결이 필요하다&lt;span class="hx:absolute hx:-mt-20" id="다시-고민-근본적인-해결이-필요하다">&lt;/span>
&lt;a href="#%eb%8b%a4%ec%8b%9c-%ea%b3%a0%eb%af%bc-%ea%b7%bc%eb%b3%b8%ec%a0%81%ec%9d%b8-%ed%95%b4%ea%b2%b0%ec%9d%b4-%ed%95%84%ec%9a%94%ed%95%98%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>다시 팀 내에서 논의가 시작됐습니다. 이전에 했던 고민들의 재검토가 필요했습니다.&lt;/p>
&lt;h3>다시 검토한 옵션들&lt;span class="hx:absolute hx:-mt-20" id="다시-검토한-옵션들">&lt;/span>
&lt;a href="#%eb%8b%a4%ec%8b%9c-%ea%b2%80%ed%86%a0%ed%95%9c-%ec%98%b5%ec%85%98%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>1. EC2 인스턴스만 Self-hosted Runner로 사용?&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Macbook 발열 문제는 해결&lt;/li>
&lt;li>하지만 동시 실행 병목은 여전&lt;/li>
&lt;li>유지보수 부담도 여전&lt;/li>
&lt;li>EC2 인스턴스 추가 비용 발생 (여러 대 띄워야 동시 실행 가능)&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>2. GitHub Actions 유료 플랜?&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>가장 간단한 해결책&lt;/li>
&lt;li>하지만 서비스가 계속 늘어나는데 비용도 계속 증가&lt;/li>
&lt;li>월 사용량 예측 어려움&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>3. Jenkins?&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>파이프라인 전면 재구축 필요 (여전히 부담)&lt;/li>
&lt;li>하지만 이제는 시간적 여유가 생겼음 (초기 개발 단계 지남)&lt;/li>
&lt;li>스타트업 GCP 크레딧 프로그램 선정으로 비용 부분도 해결 가능한 상태가 됐음&lt;/li>
&lt;li>&lt;strong>Kubernetes 클러스터가 이미 있음&lt;/strong> (서비스 배포용으로 운영 중)&lt;/li>
&lt;li>동적 Pod 프로비저닝으로 리소스 효율적 사용 가능&lt;/li>
&lt;/ul>
&lt;h3>결정: Jenkins로 마이그레이션&lt;span class="hx:absolute hx:-mt-20" id="결정-jenkins로-마이그레이션">&lt;/span>
&lt;a href="#%ea%b2%b0%ec%a0%95-jenkins%eb%a1%9c-%eb%a7%88%ec%9d%b4%ea%b7%b8%eb%a0%88%ec%9d%b4%ec%85%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>고민 끝에 &lt;strong>Jenkins on Kubernetes&lt;/strong>로 마이그레이션하기로 결정했습니다.&lt;/p>
&lt;h3>왜 Jenkins였나?&lt;span class="hx:absolute hx:-mt-20" id="왜-jenkins였나">&lt;/span>
&lt;a href="#%ec%99%9c-jenkins%ec%98%80%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>저희 상황을 고려한 결정적 이유들은 다음과 같습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Kubernetes 클러스터가 이미 있었습니다&lt;/strong>&lt;/li>
&lt;/ol>
&lt;p>이때는 이미 저희가 서비스 배포를 쿠버네티스로 이전했기 때문에 Kubernetes를 운영하고 있었습니다.
관련 경험기를 보시고 싶으시다면 다음 글을 확인해주시면 감사하겠습니다. &lt;a href="https://jeongil.dev/ko/blog/infrastructure/docker-compose-to-k8s/">개발 서버도 없던 팀이 GitOps를 갖추기까지: 맨땅에서 시작한 쿠버네티스 도입기&lt;/a>&lt;/p>
&lt;p>GCP에서 스타트업에 크레딧을 지원해주는 프로그램에도 선정되어서 비용 부담도 크게 줄어든 상태였습니다. 따라서 Jenkins로 구성하더라도 큰 추가 비용 부담 없이 운영할 수 있었습니다.&lt;/p>
&lt;p>&lt;strong>2. 동적 Pod 프로비저닝이 가능합니다&lt;/strong>&lt;/p>
&lt;p>Jenkins Kubernetes Plugin을 사용하면 동적으로 Agent Pod를 생성할 수 있습니다.&lt;/p>
&lt;ul>
&lt;li>파이프라인 실행 시에만 Pod 생성&lt;/li>
&lt;li>완료 후 자동 삭제&lt;/li>
&lt;li>리소스 낭비 없음 (필요할 때만 사용)&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>3. 또 동시 실행 제한이 없습니다&lt;/strong>&lt;/p>
&lt;p>Workflow를 Jenkins 파이프라인으로 옮기면 동시 실행 제한이 사라집니다. 병렬적으로 여러 파이프라인을 실행할 수 있어 배포의 병목을 해결할 수 있었습니다.&lt;/p>
&lt;p>위와 같은 이유들로 저희는 Jenkins on Kubernetes로 전환하기로 결정했습니다.&lt;/p>
&lt;hr>
&lt;h2>구현: Jenkins on Kubernetes 구성&lt;span class="hx:absolute hx:-mt-20" id="구현-jenkins-on-kubernetes-구성">&lt;/span>
&lt;a href="#%ea%b5%ac%ed%98%84-jenkins-on-kubernetes-%ea%b5%ac%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>아키텍처 개요&lt;span class="hx:absolute hx:-mt-20" id="아키텍처-개요">&lt;/span>
&lt;a href="#%ec%95%84%ed%82%a4%ed%85%8d%ec%b2%98-%ea%b0%9c%ec%9a%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>처음에 Jenkins를 구성할때 Master만 하나 운영하는 구조로 할까 아니면 Agent를 동적으로 생성하는 구조로 할까 고민이 많았습니다.
그치만 Master에 모든 빌드가 몰리면 리소스 낭비도 심하고 확장성도 떨어지기 때문에 동적으로 Pod를 생성하는 구조로 결정했습니다.&lt;/p>
&lt;p>결정한대로 Jenkins를 Kubernetes 위에 구성하고, &lt;strong>Jenkins Kubernetes Plugin&lt;/strong>을 활용해 동적으로 Agent Pod를 생성하는 구조를 만들었습니다.
대략적인 아키텍처는 다음과 같습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>┌─────────────────────────────────────────────┐
│ Kubernetes Cluster │
│ │
│ ┌───────────────┐ │
│ │ Jenkins │ │
│ │ Controller │ │
│ │ (Master Pod) │ │
│ └───────┬───────┘ │
│ │ │
│ │ 파이프라인 실행 시 │
│ ↓ │
│ ┌───────────────┐ ┌───────────────┐ │
│ │ Agent Pod #1 │ │ Agent Pod #2 │ │
│ │ (동적 생성) │ │ (동적 생성) │ ... │
│ └───────────────┘ └───────────────┘ │
│ │
└─────────────────────────────────────────────┘&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>핵심은 &lt;strong>필요할 때만 Pod를 생성하고, 완료되면 바로 삭제&lt;/strong>하는 겁니다. 이렇게 되면 불필요하게 Jenkins를 위해 Node를 할당해둘 필요가 없고, 리소스를 효율적으로 사용할 수 있습니다.
또 Jenkins의 Pod가 서버에 영향을 끼치지 않게 하기 위해 K8s Taint와 Node Selector를 활용해 Jenkins 전용 노드 풀에만 스케줄링 되도록 설정했습니다.
Jenkins 전용 노드 풀은 최소 갯수를 0개로 동적으로 늘어나고 줄어들도록 오토스케일링 설정을 해뒀습니다. 이렇게 되면 Jenkins가 사용되지 않을 때는 노드가 0개가 되어 비용이 발생하지 않게 운영할 수 있어 그렇게 설정해뒀습니다.&lt;/p>
&lt;h3>1단계: Jenkins Helm Chart로 설치&lt;span class="hx:absolute hx:-mt-20" id="1단계-jenkins-helm-chart로-설치">&lt;/span>
&lt;a href="#1%eb%8b%a8%ea%b3%84-jenkins-helm-chart%eb%a1%9c-%ec%84%a4%ec%b9%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Kubernetes에 Jenkins를 설치하기 위해 공식 Helm Chart를 사용했습니다. 아무래도 Helm Chart가 제공하는 다양한 설정 옵션들을 활용하면 설치와 관리가 훨씬 수월하기 때문입니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Jenkins Helm Repository 추가&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">helm repo add jenkins https://charts.jenkins.io
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">helm repo update
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># jenkins namespace 생성&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">kubectl create namespace jenkins
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Secret 생성 (GitHub Token, GCP SA Key)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">kubectl create secret generic jenkins-secrets &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> --from-literal&lt;span class="o">=&lt;/span>github-username&lt;span class="o">=&lt;/span>your-username &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> --from-literal&lt;span class="o">=&lt;/span>github-token&lt;span class="o">=&lt;/span>your-token &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> --from-file&lt;span class="o">=&lt;/span>gcp-sa-key-base64&lt;span class="o">=&lt;/span>gcp-sa-key.json &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> -n jenkins&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;code>jenkins-values.yaml&lt;/code> 파일을 작성했습니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt"> 10
&lt;/span>&lt;span class="lnt"> 11
&lt;/span>&lt;span class="lnt"> 12
&lt;/span>&lt;span class="lnt"> 13
&lt;/span>&lt;span class="lnt"> 14
&lt;/span>&lt;span class="lnt"> 15
&lt;/span>&lt;span class="lnt"> 16
&lt;/span>&lt;span class="lnt"> 17
&lt;/span>&lt;span class="lnt"> 18
&lt;/span>&lt;span class="lnt"> 19
&lt;/span>&lt;span class="lnt"> 20
&lt;/span>&lt;span class="lnt"> 21
&lt;/span>&lt;span class="lnt"> 22
&lt;/span>&lt;span class="lnt"> 23
&lt;/span>&lt;span class="lnt"> 24
&lt;/span>&lt;span class="lnt"> 25
&lt;/span>&lt;span class="lnt"> 26
&lt;/span>&lt;span class="lnt"> 27
&lt;/span>&lt;span class="lnt"> 28
&lt;/span>&lt;span class="lnt"> 29
&lt;/span>&lt;span class="lnt"> 30
&lt;/span>&lt;span class="lnt"> 31
&lt;/span>&lt;span class="lnt"> 32
&lt;/span>&lt;span class="lnt"> 33
&lt;/span>&lt;span class="lnt"> 34
&lt;/span>&lt;span class="lnt"> 35
&lt;/span>&lt;span class="lnt"> 36
&lt;/span>&lt;span class="lnt"> 37
&lt;/span>&lt;span class="lnt"> 38
&lt;/span>&lt;span class="lnt"> 39
&lt;/span>&lt;span class="lnt"> 40
&lt;/span>&lt;span class="lnt"> 41
&lt;/span>&lt;span class="lnt"> 42
&lt;/span>&lt;span class="lnt"> 43
&lt;/span>&lt;span class="lnt"> 44
&lt;/span>&lt;span class="lnt"> 45
&lt;/span>&lt;span class="lnt"> 46
&lt;/span>&lt;span class="lnt"> 47
&lt;/span>&lt;span class="lnt"> 48
&lt;/span>&lt;span class="lnt"> 49
&lt;/span>&lt;span class="lnt"> 50
&lt;/span>&lt;span class="lnt"> 51
&lt;/span>&lt;span class="lnt"> 52
&lt;/span>&lt;span class="lnt"> 53
&lt;/span>&lt;span class="lnt"> 54
&lt;/span>&lt;span class="lnt"> 55
&lt;/span>&lt;span class="lnt"> 56
&lt;/span>&lt;span class="lnt"> 57
&lt;/span>&lt;span class="lnt"> 58
&lt;/span>&lt;span class="lnt"> 59
&lt;/span>&lt;span class="lnt"> 60
&lt;/span>&lt;span class="lnt"> 61
&lt;/span>&lt;span class="lnt"> 62
&lt;/span>&lt;span class="lnt"> 63
&lt;/span>&lt;span class="lnt"> 64
&lt;/span>&lt;span class="lnt"> 65
&lt;/span>&lt;span class="lnt"> 66
&lt;/span>&lt;span class="lnt"> 67
&lt;/span>&lt;span class="lnt"> 68
&lt;/span>&lt;span class="lnt"> 69
&lt;/span>&lt;span class="lnt"> 70
&lt;/span>&lt;span class="lnt"> 71
&lt;/span>&lt;span class="lnt"> 72
&lt;/span>&lt;span class="lnt"> 73
&lt;/span>&lt;span class="lnt"> 74
&lt;/span>&lt;span class="lnt"> 75
&lt;/span>&lt;span class="lnt"> 76
&lt;/span>&lt;span class="lnt"> 77
&lt;/span>&lt;span class="lnt"> 78
&lt;/span>&lt;span class="lnt"> 79
&lt;/span>&lt;span class="lnt"> 80
&lt;/span>&lt;span class="lnt"> 81
&lt;/span>&lt;span class="lnt"> 82
&lt;/span>&lt;span class="lnt"> 83
&lt;/span>&lt;span class="lnt"> 84
&lt;/span>&lt;span class="lnt"> 85
&lt;/span>&lt;span class="lnt"> 86
&lt;/span>&lt;span class="lnt"> 87
&lt;/span>&lt;span class="lnt"> 88
&lt;/span>&lt;span class="lnt"> 89
&lt;/span>&lt;span class="lnt"> 90
&lt;/span>&lt;span class="lnt"> 91
&lt;/span>&lt;span class="lnt"> 92
&lt;/span>&lt;span class="lnt"> 93
&lt;/span>&lt;span class="lnt"> 94
&lt;/span>&lt;span class="lnt"> 95
&lt;/span>&lt;span class="lnt"> 96
&lt;/span>&lt;span class="lnt"> 97
&lt;/span>&lt;span class="lnt"> 98
&lt;/span>&lt;span class="lnt"> 99
&lt;/span>&lt;span class="lnt">100
&lt;/span>&lt;span class="lnt">101
&lt;/span>&lt;span class="lnt">102
&lt;/span>&lt;span class="lnt">103
&lt;/span>&lt;span class="lnt">104
&lt;/span>&lt;span class="lnt">105
&lt;/span>&lt;span class="lnt">106
&lt;/span>&lt;span class="lnt">107
&lt;/span>&lt;span class="lnt">108
&lt;/span>&lt;span class="lnt">109
&lt;/span>&lt;span class="lnt">110
&lt;/span>&lt;span class="lnt">111
&lt;/span>&lt;span class="lnt">112
&lt;/span>&lt;span class="lnt">113
&lt;/span>&lt;span class="lnt">114
&lt;/span>&lt;span class="lnt">115
&lt;/span>&lt;span class="lnt">116
&lt;/span>&lt;span class="lnt">117
&lt;/span>&lt;span class="lnt">118
&lt;/span>&lt;span class="lnt">119
&lt;/span>&lt;span class="lnt">120
&lt;/span>&lt;span class="lnt">121
&lt;/span>&lt;span class="lnt">122
&lt;/span>&lt;span class="lnt">123
&lt;/span>&lt;span class="lnt">124
&lt;/span>&lt;span class="lnt">125
&lt;/span>&lt;span class="lnt">126
&lt;/span>&lt;span class="lnt">127
&lt;/span>&lt;span class="lnt">128
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># jenkins-values.yaml&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">controller&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">image&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">repository&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;jenkins/jenkins&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">tag&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;lts-jdk17&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">numExecutors&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">0&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># Controller에서는 빌드 실행 안함&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">nodeSelector&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">node-pool&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">jenkins &lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># Jenkins 전용 노드 풀&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># GitHub Credential 환경변수 주입&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">containerEnv&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">GITHUB_USERNAME&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">valueFrom&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">secretKeyRef&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">jenkins-secrets&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">key&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">github-username&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">GITHUB_TOKEN&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">valueFrom&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">secretKeyRef&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">jenkins-secrets&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">key&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">github-token&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">GCP_SA_KEY_BASE64&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">valueFrom&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">secretKeyRef&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">jenkins-secrets&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">key&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">gcp-sa-key-base64&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># Probe 설정 (시작 시간 충분히 확보)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">probes&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">startupProbe&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">failureThreshold&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">12&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">periodSeconds&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">10&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">initialDelaySeconds&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">60&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">livenessProbe&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">failureThreshold&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">12&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">periodSeconds&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">10&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">initialDelaySeconds&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">180&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">readinessProbe&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">failureThreshold&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">10&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">periodSeconds&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">10&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">initialDelaySeconds&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">60&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># 플러그인 설치&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">installPlugins&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">kubernetes&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">workflow-aggregator&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">git&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">configuration-as-code&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">blueocean&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">job-dsl&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">plain-credentials&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># Ingress 설정&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">ingress&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">enabled&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">ingressClassName&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">nginx&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">hostName&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">jenkins.example.com&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">path&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">/&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">pathType&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">Prefix&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># JCasC (Jenkins Configuration as Code)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">JCasC&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">defaultConfig&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">configScripts&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># Credential 설정&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">credentials-config&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">|&lt;/span>&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> credentials:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> system:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> domainCredentials:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> - credentials:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> # GitHub Token
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> - usernamePassword:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> scope: GLOBAL
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> id: &amp;#34;github-token&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> username: &amp;#34;${GITHUB_USERNAME}&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> password: &amp;#34;${GITHUB_TOKEN}&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> # GCP Service Account Key
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> - file:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> scope: GLOBAL
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> id: &amp;#34;gcp-sa-key&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> fileName: &amp;#34;gcp-sa-key.json&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> secretBytes: &amp;#34;${GCP_SA_KEY_BASE64}&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># Kubernetes Cloud 설정&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">k8s-cloud-config&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">|&lt;/span>&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> jenkins:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> clouds:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> - kubernetes:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> name: &amp;#34;kubernetes&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> serverUrl: &amp;#34;https://kubernetes.default&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> skipTlsVerify: true
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> namespace: &amp;#34;jenkins&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> jenkinsUrl: &amp;#34;http://jenkins.jenkins.svc.cluster.local:8080&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> jenkinsTunnel: &amp;#34;jenkins-agent.jenkins.svc.cluster.local:50000&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> containerCapStr: &amp;#34;10&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># Job 설정 (MultiBranch Pipeline)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">jobs-config&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">|&lt;/span>&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> jobs:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> - script: &amp;gt;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> multibranchPipelineJob(&amp;#39;backend&amp;#39;) {
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> branchSources {
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> git {
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> id(&amp;#39;backend&amp;#39;)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> remote(&amp;#39;https://github.com/your-organization/your-backend-repo.git&amp;#39;)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> credentialsId(&amp;#39;github-token&amp;#39;)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> }
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> }
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> orphanedItemStrategy {
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> discardOldItems {
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> numToKeep(20)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> }
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> }
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> }&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">persistence&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">enabled&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">size&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;10Gi&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">serviceAccount&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">create&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">jenkins&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">rbac&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">create&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">readSecrets&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Jenkins 설치&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">helm install jenkins jenkins/jenkins &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> -f jenkins-values.yaml &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> -n jenkins&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>2단계: Jenkinsfile 작성&lt;span class="hx:absolute hx:-mt-20" id="2단계-jenkinsfile-작성">&lt;/span>
&lt;a href="#2%eb%8b%a8%ea%b3%84-jenkinsfile-%ec%9e%91%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>각 서비스별로 독립된 Pod를 동적으로 생성하는 Jenkinsfile을 작성했습니다.&lt;/p>
&lt;ol>
&lt;li>Git 변경 사항 감지 → 변경된 서비스만 배포&lt;/li>
&lt;li>각 서비스별로 독립된 Pod 생성&lt;/li>
&lt;li>병렬 실행&lt;/li>
&lt;/ol>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt"> 10
&lt;/span>&lt;span class="lnt"> 11
&lt;/span>&lt;span class="lnt"> 12
&lt;/span>&lt;span class="lnt"> 13
&lt;/span>&lt;span class="lnt"> 14
&lt;/span>&lt;span class="lnt"> 15
&lt;/span>&lt;span class="lnt"> 16
&lt;/span>&lt;span class="lnt"> 17
&lt;/span>&lt;span class="lnt"> 18
&lt;/span>&lt;span class="lnt"> 19
&lt;/span>&lt;span class="lnt"> 20
&lt;/span>&lt;span class="lnt"> 21
&lt;/span>&lt;span class="lnt"> 22
&lt;/span>&lt;span class="lnt"> 23
&lt;/span>&lt;span class="lnt"> 24
&lt;/span>&lt;span class="lnt"> 25
&lt;/span>&lt;span class="lnt"> 26
&lt;/span>&lt;span class="lnt"> 27
&lt;/span>&lt;span class="lnt"> 28
&lt;/span>&lt;span class="lnt"> 29
&lt;/span>&lt;span class="lnt"> 30
&lt;/span>&lt;span class="lnt"> 31
&lt;/span>&lt;span class="lnt"> 32
&lt;/span>&lt;span class="lnt"> 33
&lt;/span>&lt;span class="lnt"> 34
&lt;/span>&lt;span class="lnt"> 35
&lt;/span>&lt;span class="lnt"> 36
&lt;/span>&lt;span class="lnt"> 37
&lt;/span>&lt;span class="lnt"> 38
&lt;/span>&lt;span class="lnt"> 39
&lt;/span>&lt;span class="lnt"> 40
&lt;/span>&lt;span class="lnt"> 41
&lt;/span>&lt;span class="lnt"> 42
&lt;/span>&lt;span class="lnt"> 43
&lt;/span>&lt;span class="lnt"> 44
&lt;/span>&lt;span class="lnt"> 45
&lt;/span>&lt;span class="lnt"> 46
&lt;/span>&lt;span class="lnt"> 47
&lt;/span>&lt;span class="lnt"> 48
&lt;/span>&lt;span class="lnt"> 49
&lt;/span>&lt;span class="lnt"> 50
&lt;/span>&lt;span class="lnt"> 51
&lt;/span>&lt;span class="lnt"> 52
&lt;/span>&lt;span class="lnt"> 53
&lt;/span>&lt;span class="lnt"> 54
&lt;/span>&lt;span class="lnt"> 55
&lt;/span>&lt;span class="lnt"> 56
&lt;/span>&lt;span class="lnt"> 57
&lt;/span>&lt;span class="lnt"> 58
&lt;/span>&lt;span class="lnt"> 59
&lt;/span>&lt;span class="lnt"> 60
&lt;/span>&lt;span class="lnt"> 61
&lt;/span>&lt;span class="lnt"> 62
&lt;/span>&lt;span class="lnt"> 63
&lt;/span>&lt;span class="lnt"> 64
&lt;/span>&lt;span class="lnt"> 65
&lt;/span>&lt;span class="lnt"> 66
&lt;/span>&lt;span class="lnt"> 67
&lt;/span>&lt;span class="lnt"> 68
&lt;/span>&lt;span class="lnt"> 69
&lt;/span>&lt;span class="lnt"> 70
&lt;/span>&lt;span class="lnt"> 71
&lt;/span>&lt;span class="lnt"> 72
&lt;/span>&lt;span class="lnt"> 73
&lt;/span>&lt;span class="lnt"> 74
&lt;/span>&lt;span class="lnt"> 75
&lt;/span>&lt;span class="lnt"> 76
&lt;/span>&lt;span class="lnt"> 77
&lt;/span>&lt;span class="lnt"> 78
&lt;/span>&lt;span class="lnt"> 79
&lt;/span>&lt;span class="lnt"> 80
&lt;/span>&lt;span class="lnt"> 81
&lt;/span>&lt;span class="lnt"> 82
&lt;/span>&lt;span class="lnt"> 83
&lt;/span>&lt;span class="lnt"> 84
&lt;/span>&lt;span class="lnt"> 85
&lt;/span>&lt;span class="lnt"> 86
&lt;/span>&lt;span class="lnt"> 87
&lt;/span>&lt;span class="lnt"> 88
&lt;/span>&lt;span class="lnt"> 89
&lt;/span>&lt;span class="lnt"> 90
&lt;/span>&lt;span class="lnt"> 91
&lt;/span>&lt;span class="lnt"> 92
&lt;/span>&lt;span class="lnt"> 93
&lt;/span>&lt;span class="lnt"> 94
&lt;/span>&lt;span class="lnt"> 95
&lt;/span>&lt;span class="lnt"> 96
&lt;/span>&lt;span class="lnt"> 97
&lt;/span>&lt;span class="lnt"> 98
&lt;/span>&lt;span class="lnt"> 99
&lt;/span>&lt;span class="lnt">100
&lt;/span>&lt;span class="lnt">101
&lt;/span>&lt;span class="lnt">102
&lt;/span>&lt;span class="lnt">103
&lt;/span>&lt;span class="lnt">104
&lt;/span>&lt;span class="lnt">105
&lt;/span>&lt;span class="lnt">106
&lt;/span>&lt;span class="lnt">107
&lt;/span>&lt;span class="lnt">108
&lt;/span>&lt;span class="lnt">109
&lt;/span>&lt;span class="lnt">110
&lt;/span>&lt;span class="lnt">111
&lt;/span>&lt;span class="lnt">112
&lt;/span>&lt;span class="lnt">113
&lt;/span>&lt;span class="lnt">114
&lt;/span>&lt;span class="lnt">115
&lt;/span>&lt;span class="lnt">116
&lt;/span>&lt;span class="lnt">117
&lt;/span>&lt;span class="lnt">118
&lt;/span>&lt;span class="lnt">119
&lt;/span>&lt;span class="lnt">120
&lt;/span>&lt;span class="lnt">121
&lt;/span>&lt;span class="lnt">122
&lt;/span>&lt;span class="lnt">123
&lt;/span>&lt;span class="lnt">124
&lt;/span>&lt;span class="lnt">125
&lt;/span>&lt;span class="lnt">126
&lt;/span>&lt;span class="lnt">127
&lt;/span>&lt;span class="lnt">128
&lt;/span>&lt;span class="lnt">129
&lt;/span>&lt;span class="lnt">130
&lt;/span>&lt;span class="lnt">131
&lt;/span>&lt;span class="lnt">132
&lt;/span>&lt;span class="lnt">133
&lt;/span>&lt;span class="lnt">134
&lt;/span>&lt;span class="lnt">135
&lt;/span>&lt;span class="lnt">136
&lt;/span>&lt;span class="lnt">137
&lt;/span>&lt;span class="lnt">138
&lt;/span>&lt;span class="lnt">139
&lt;/span>&lt;span class="lnt">140
&lt;/span>&lt;span class="lnt">141
&lt;/span>&lt;span class="lnt">142
&lt;/span>&lt;span class="lnt">143
&lt;/span>&lt;span class="lnt">144
&lt;/span>&lt;span class="lnt">145
&lt;/span>&lt;span class="lnt">146
&lt;/span>&lt;span class="lnt">147
&lt;/span>&lt;span class="lnt">148
&lt;/span>&lt;span class="lnt">149
&lt;/span>&lt;span class="lnt">150
&lt;/span>&lt;span class="lnt">151
&lt;/span>&lt;span class="lnt">152
&lt;/span>&lt;span class="lnt">153
&lt;/span>&lt;span class="lnt">154
&lt;/span>&lt;span class="lnt">155
&lt;/span>&lt;span class="lnt">156
&lt;/span>&lt;span class="lnt">157
&lt;/span>&lt;span class="lnt">158
&lt;/span>&lt;span class="lnt">159
&lt;/span>&lt;span class="lnt">160
&lt;/span>&lt;span class="lnt">161
&lt;/span>&lt;span class="lnt">162
&lt;/span>&lt;span class="lnt">163
&lt;/span>&lt;span class="lnt">164
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-groovy" data-lang="groovy">&lt;span class="line">&lt;span class="cl">&lt;span class="n">pipeline&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">agent&lt;/span> &lt;span class="n">none&lt;/span> &lt;span class="c1">// 마스터 노드에서 가볍게 시작
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">parameters&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">booleanParam&lt;/span>&lt;span class="o">(&lt;/span>&lt;span class="nl">name:&lt;/span> &lt;span class="s1">&amp;#39;agent-service&amp;#39;&lt;/span>&lt;span class="o">,&lt;/span> &lt;span class="nl">defaultValue:&lt;/span> &lt;span class="kc">false&lt;/span>&lt;span class="o">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">booleanParam&lt;/span>&lt;span class="o">(&lt;/span>&lt;span class="nl">name:&lt;/span> &lt;span class="s1">&amp;#39;community-service&amp;#39;&lt;/span>&lt;span class="o">,&lt;/span> &lt;span class="nl">defaultValue:&lt;/span> &lt;span class="kc">false&lt;/span>&lt;span class="o">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">...&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">environment&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">GCP_REGION&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s2">&amp;#34;REGION-docker.pkg.dev&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">GCP_PROJECT&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s2">&amp;#34;your-gcp-project&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">MANIFEST_REPO&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s2">&amp;#34;your-organization/manifest-repo&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">stages&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">stage&lt;/span>&lt;span class="o">(&lt;/span>&lt;span class="s1">&amp;#39;Checkout &amp;amp; Plan&amp;#39;&lt;/span>&lt;span class="o">)&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">agent&lt;/span> &lt;span class="n">any&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">steps&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">checkout&lt;/span> &lt;span class="n">scm&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">script&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// Git 변경 사항 감지
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="kt">def&lt;/span> &lt;span class="n">changedFiles&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">sh&lt;/span>&lt;span class="o">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nl">script:&lt;/span> &lt;span class="s2">&amp;#34;git diff --name-only HEAD^ HEAD&amp;#34;&lt;/span>&lt;span class="o">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nl">returnStdout:&lt;/span> &lt;span class="kc">true&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">).&lt;/span>&lt;span class="na">trim&lt;/span>&lt;span class="o">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kt">def&lt;/span> &lt;span class="n">services&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="o">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s1">&amp;#39;agent-service&amp;#39;&lt;/span>&lt;span class="o">,&lt;/span> &lt;span class="s1">&amp;#39;community-service&amp;#39;&lt;/span>&lt;span class="o">,&lt;/span> &lt;span class="o">...&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kt">def&lt;/span> &lt;span class="n">deployments&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="o">[:]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// Pod Template YAML 정의
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="kt">def&lt;/span> &lt;span class="n">podYaml&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">apiVersion: v1
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">kind: Pod
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">spec:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> nodeSelector:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> node-pool: jenkins-agent
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> tolerations:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> - key: &amp;#34;node-pool&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> operator: &amp;#34;Equal&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> value: &amp;#34;jenkins-agent&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> effect: &amp;#34;NoSchedule&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> containers:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> - name: gradle
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> image: gradle:8.5-jdk17
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> command:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> - cat
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> tty: true
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> resources:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> limits:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> memory: &amp;#34;4Gi&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> cpu: &amp;#34;1.5&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> requests:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> memory: &amp;#34;2Gi&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> cpu: &amp;#34;1000m&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> - name: dind
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> image: docker:24.0.7-dind
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> securityContext:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> privileged: true
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> env:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> - name: DOCKER_TLS_CERTDIR
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> value: &amp;#34;&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> - name: utils
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> image: bitnami/git:latest
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> command:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> - cat
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> tty: true
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 배포할 서비스 결정 및 병렬 실행
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">services&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">each&lt;/span> &lt;span class="o">{&lt;/span> &lt;span class="n">serviceName&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kt">def&lt;/span> &lt;span class="n">isManualSelected&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">params&lt;/span>&lt;span class="o">[&lt;/span>&lt;span class="n">serviceName&lt;/span>&lt;span class="o">]&lt;/span> &lt;span class="o">==&lt;/span> &lt;span class="kc">true&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kt">def&lt;/span> &lt;span class="n">isForceAll&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">params&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">FORCE_DEPLOY_ALL&lt;/span> &lt;span class="o">==&lt;/span> &lt;span class="kc">true&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kt">def&lt;/span> &lt;span class="n">isGitChanged&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="o">!&lt;/span>&lt;span class="n">params&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">IGNORE_GIT_CHANGES&lt;/span> &lt;span class="o">&amp;amp;&amp;amp;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">changedFiles&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">contains&lt;/span>&lt;span class="o">(&lt;/span>&lt;span class="s2">&amp;#34;${serviceName}/&amp;#34;&lt;/span>&lt;span class="o">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kt">def&lt;/span> &lt;span class="n">isCommonChanged&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="o">!&lt;/span>&lt;span class="n">params&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">IGNORE_GIT_CHANGES&lt;/span> &lt;span class="o">&amp;amp;&amp;amp;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">changedFiles&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">contains&lt;/span>&lt;span class="o">(&lt;/span>&lt;span class="s2">&amp;#34;common/&amp;#34;&lt;/span>&lt;span class="o">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="o">(&lt;/span>&lt;span class="n">isManualSelected&lt;/span> &lt;span class="o">||&lt;/span> &lt;span class="n">isForceAll&lt;/span> &lt;span class="o">||&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">isGitChanged&lt;/span> &lt;span class="o">||&lt;/span> &lt;span class="n">isCommonChanged&lt;/span>&lt;span class="o">)&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 각 서비스별로 독립된 Pod 생성 및 실행
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">deployments&lt;/span>&lt;span class="o">[&lt;/span>&lt;span class="n">serviceName&lt;/span>&lt;span class="o">]&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">podTemplate&lt;/span>&lt;span class="o">(&lt;/span>&lt;span class="nl">yaml:&lt;/span> &lt;span class="n">podYaml&lt;/span>&lt;span class="o">)&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">node&lt;/span>&lt;span class="o">(&lt;/span>&lt;span class="n">POD_LABEL&lt;/span>&lt;span class="o">)&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">stage&lt;/span>&lt;span class="o">(&lt;/span>&lt;span class="s2">&amp;#34;Deploy ${serviceName}&amp;#34;&lt;/span>&lt;span class="o">)&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">checkout&lt;/span> &lt;span class="n">scm&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// Gradle Build
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">container&lt;/span>&lt;span class="o">(&lt;/span>&lt;span class="s1">&amp;#39;gradle&amp;#39;&lt;/span>&lt;span class="o">)&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">sh&lt;/span> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> ./gradlew :${serviceName}:bootJar \
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> -Dorg.gradle.jvmargs=&amp;#39;-Xmx3072m -XX:MaxMetaspaceSize=512m&amp;#39;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> &amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// Docker Build &amp;amp; Push
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">container&lt;/span>&lt;span class="o">(&lt;/span>&lt;span class="s1">&amp;#39;dind&amp;#39;&lt;/span>&lt;span class="o">)&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">withCredentials&lt;/span>&lt;span class="o">([&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">file&lt;/span>&lt;span class="o">(&lt;/span>&lt;span class="nl">credentialsId:&lt;/span> &lt;span class="s1">&amp;#39;gcp-sa-key&amp;#39;&lt;/span>&lt;span class="o">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nl">variable:&lt;/span> &lt;span class="s1">&amp;#39;GCP_CREDENTIALS&amp;#39;&lt;/span>&lt;span class="o">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">])&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kt">def&lt;/span> &lt;span class="n">fullImageName&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s2">&amp;#34;${env.GCP_REGION}/${env.GCP_PROJECT}/${serviceName}:${env.GIT_COMMIT}&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">sh&lt;/span> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> cat \$GCP_CREDENTIALS &amp;gt; /tmp/gcp-key.json
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> cat /tmp/gcp-key.json | docker login \
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> -u _json_key --password-stdin \
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> https://${env.GCP_REGION}
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> docker build -t ${fullImageName} ./${serviceName}
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> docker push ${fullImageName}
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> &amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// Manifest Update (GitOps)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">container&lt;/span>&lt;span class="o">(&lt;/span>&lt;span class="s1">&amp;#39;utils&amp;#39;&lt;/span>&lt;span class="o">)&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">withCredentials&lt;/span>&lt;span class="o">([&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">usernamePassword&lt;/span>&lt;span class="o">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nl">credentialsId:&lt;/span> &lt;span class="s1">&amp;#39;github-token&amp;#39;&lt;/span>&lt;span class="o">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nl">usernameVariable:&lt;/span> &lt;span class="s1">&amp;#39;GH_USER&amp;#39;&lt;/span>&lt;span class="o">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nl">passwordVariable:&lt;/span> &lt;span class="s1">&amp;#39;GH_TOKEN&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">])&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">sh&lt;/span> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> curl -L https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -o /usr/bin/yq
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> chmod +x /usr/bin/yq
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> git clone https://\${GH_TOKEN}@github.com/${env.MANIFEST_REPO}.git manifest-repo
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> cd manifest-repo
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> # yq로 이미지 태그 업데이트
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> export NEW_IMAGE=&amp;#34;${env.GCP_REGION}/${env.GCP_PROJECT}/${serviceName}:${env.GIT_COMMIT}&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> yq e -i &amp;#39;.spec.template.spec.containers[0].image = env(NEW_IMAGE)&amp;#39; \${serviceName}/deployment.yaml
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> git config user.name &amp;#34;Jenkins Pipeline&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> git config user.email &amp;#34;jenkins@example.com&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> git add \${serviceName}/deployment.yaml
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> git commit -m &amp;#34;Update ${serviceName} image tag to ${env.GIT_COMMIT}&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> git push origin main
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2"> &amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 병렬 실행
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">if&lt;/span> &lt;span class="o">(&lt;/span>&lt;span class="n">deployments&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">size&lt;/span>&lt;span class="o">()&lt;/span> &lt;span class="o">&amp;gt;&lt;/span> &lt;span class="mi">0&lt;/span>&lt;span class="o">)&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">parallel&lt;/span> &lt;span class="n">deployments&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span> &lt;span class="k">else&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">echo&lt;/span> &lt;span class="s2">&amp;#34;No services to deploy.&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>핵심 포인트 설명&lt;span class="hx:absolute hx:-mt-20" id="핵심-포인트-설명">&lt;/span>
&lt;a href="#%ed%95%b5%ec%8b%ac-%ed%8f%ac%ec%9d%b8%ed%8a%b8-%ec%84%a4%eb%aa%85" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;h4>1. 동적 Pod 프로비저닝&lt;span class="hx:absolute hx:-mt-20" id="1-동적-pod-프로비저닝">&lt;/span>
&lt;a href="#1-%eb%8f%99%ec%a0%81-pod-%ed%94%84%eb%a1%9c%eb%b9%84%ec%a0%80%eb%8b%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-groovy" data-lang="groovy">&lt;span class="line">&lt;span class="cl">&lt;span class="n">podTemplate&lt;/span>&lt;span class="o">(&lt;/span>&lt;span class="nl">yaml:&lt;/span> &lt;span class="n">podYaml&lt;/span>&lt;span class="o">)&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">node&lt;/span>&lt;span class="o">(&lt;/span>&lt;span class="n">POD_LABEL&lt;/span>&lt;span class="o">)&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 파이프라인 실행
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>동작 방식:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>파이프라인 실행 시 Jenkins가 Kubernetes API를 호출해 Pod를 생성합니다.&lt;/li>
&lt;li>파이프라인 완료 후 Pod는 자동 삭제됩니다.&lt;/li>
&lt;li>이렇게 되면 Self-hosted Runner처럼 항상 떠 있을 필요도 없습니다.&lt;/li>
&lt;/ul>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yml" data-lang="yml">&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">nodeSelector&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">node-pool&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">jenkins-agent&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">tolerations&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">key&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;node-pool&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">operator&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;Equal&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">value&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;jenkins-agent&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">effect&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;NoSchedule&amp;#34;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>위 설정 덕분에 Jenkins Agent Pod가 Jenkins 전용 노드 풀에만 스케줄링 됩니다. 위에서 언급했듯 해당 노드풀을 오토스케일링 처리해두고 최소 갯수를 0으로 설정해두었기 때문에 Jenkins가 사용되지 않을 때는 노드가 0개가 되어 비용이 발생하지 않게 운영할 수 있습니다.&lt;/p>
&lt;p>&lt;strong>장점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>리소스 절약 (필요할 때만 사용)&lt;/li>
&lt;li>환경 일관성 (매번 새 Pod로 시작)&lt;/li>
&lt;li>Macbook에 부담 전혀 없음&lt;/li>
&lt;li>노드 풀 오토스케일링으로 비용 절감&lt;/li>
&lt;/ul>
&lt;h4>2. 멀티 컨테이너 구성&lt;span class="hx:absolute hx:-mt-20" id="2-멀티-컨테이너-구성">&lt;/span>
&lt;a href="#2-%eb%a9%80%ed%8b%b0-%ec%bb%a8%ed%85%8c%ec%9d%b4%eb%84%88-%ea%b5%ac%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">containers&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">gradle &lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># Gradle 빌드용&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">dind &lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># Docker 빌드용 (Docker in Docker)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">utils &lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># Git, yq 등 유틸리티용&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>왜 멀티 컨테이너?&lt;/strong>&lt;/p>
&lt;p>각 단계에서 필요한 환경이 다릅니다.&lt;/p>
&lt;ul>
&lt;li>Gradle 빌드: JDK 17 + Gradle&lt;/li>
&lt;li>Docker 빌드: Docker Daemon&lt;/li>
&lt;li>Manifest 업데이트: Git + yq&lt;/li>
&lt;/ul>
&lt;p>하나의 컨테이너에 전부 넣으면 이미지가 비대해지고 관리가 어렵습니다.&lt;/p>
&lt;p>멀티 컨테이너로 분리하면&lt;/p>
&lt;ul>
&lt;li>각 컨테이너는 필요한 도구만 포함&lt;/li>
&lt;li>이미지 재사용 가능 (공식 이미지 활용)&lt;/li>
&lt;li>관심사 분리&lt;/li>
&lt;/ul>
&lt;h4>3. Git 변경 감지 자동 배포&lt;span class="hx:absolute hx:-mt-20" id="3-git-변경-감지-자동-배포">&lt;/span>
&lt;a href="#3-git-%eb%b3%80%ea%b2%bd-%ea%b0%90%ec%a7%80-%ec%9e%90%eb%8f%99-%eb%b0%b0%ed%8f%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-groovy" data-lang="groovy">&lt;span class="line">&lt;span class="cl">&lt;span class="kt">def&lt;/span> &lt;span class="n">isGitChanged&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">changedFiles&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">contains&lt;/span>&lt;span class="o">(&lt;/span>&lt;span class="s2">&amp;#34;${serviceName}/&amp;#34;&lt;/span>&lt;span class="o">)&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>동작 방식:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;code>git diff --name-only HEAD^ HEAD&lt;/code>로 변경된 파일 목록 추출&lt;/li>
&lt;li>각 서비스 디렉토리 확인&lt;/li>
&lt;li>변경된 서비스만 배포 대상에 포함&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>장점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>불필요한 빌드 방지&lt;/li>
&lt;li>시간 절약&lt;/li>
&lt;li>리소스 절약&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>예시:&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>변경된 파일:
- user-service/src/main/java/UserController.java
- common/src/main/java/CommonUtil.java
배포 대상:
- user-service (직접 변경)
- 모든 서비스 (common 변경 시)&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h4>4. 병렬 실행&lt;span class="hx:absolute hx:-mt-20" id="4-병렬-실행">&lt;/span>
&lt;a href="#4-%eb%b3%91%eb%a0%ac-%ec%8b%a4%ed%96%89" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-groovy" data-lang="groovy">&lt;span class="line">&lt;span class="cl">&lt;span class="n">parallel&lt;/span> &lt;span class="n">deployments&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>동작 방식:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>배포할 서비스들을 Map에 저장&lt;/li>
&lt;li>&lt;code>parallel&lt;/code>로 동시 실행&lt;/li>
&lt;li>각 서비스별로 독립된 Pod 생성&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>효과:&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>Self-hosted Runner (순차 실행):
user-service: 5분
chat-service: 5분
match-service: 5분
총: 15분
Jenkins (병렬 실행):
user-service: 5분
chat-service: 5분 } 동시 실행
match-service: 5분
총: 5분&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;hr>
&lt;h2>결과&lt;span class="hx:absolute hx:-mt-20" id="결과">&lt;/span>
&lt;a href="#%ea%b2%b0%ea%b3%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>위와 같이 구성한 덕분에 저희는 다음과 같은 개선을 얻을 수 있었습니다.&lt;/p>
&lt;h3>Before: Self-hosted Runner&lt;span class="hx:absolute hx:-mt-20" id="before-self-hosted-runner">&lt;/span>
&lt;a href="#before-self-hosted-runner" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>문제점&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>팀원 Macbook 발열로 개발 작업 방해&lt;/li>
&lt;li>동시 실행 안 돼서 대기 시간 증가 (15분 → 5분)&lt;/li>
&lt;li>Runner 관리 부담 (환경 일관성, 상태 관리)&lt;/li>
&lt;li>서비스 증가 시 확장성 한계&lt;/li>
&lt;/ul>
&lt;h3>After: Jenkins on Kubernetes&lt;span class="hx:absolute hx:-mt-20" id="after-jenkins-on-kubernetes">&lt;/span>
&lt;a href="#after-jenkins-on-kubernetes" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>개선사항&lt;/strong>&lt;/p>
&lt;p>&lt;strong>1. 개발자 경험(DX) 개선&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Macbook에 부담 전혀 없음&lt;/li>
&lt;li>CI/CD 돌아가는 동안에도 개발자 영향도 없음&lt;/li>
&lt;li>팀원들 만족도 상승&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>2. 배포 시간 단축&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>동시 실행으로 대기 시간 없음&lt;/li>
&lt;li>여러 서비스 동시 배포 가능&lt;/li>
&lt;li>전체 배포 시간 &lt;strong>단축&lt;/strong>&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>3. 비용 효율성&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>GitHub Actions 과금 없음&lt;/li>
&lt;li>Kubernetes 클러스터 활용으로 추가 인프라 비용 최소화&lt;/li>
&lt;li>동적 Pod 생성으로 리소스 낭비 방지&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>4. 확장성&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>서비스 추가 시 Jenkinsfile 파라미터만 추가&lt;/li>
&lt;li>자동 스케일링&lt;/li>
&lt;li>MSA 환경에 적합&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>5. 유지보수성&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Jenkinsfile로 파이프라인 코드화&lt;/li>
&lt;li>GitOps 패턴 적용 (Manifest 자동 업데이트)&lt;/li>
&lt;li>중앙집중식 관리&lt;/li>
&lt;li>환경 일관성 (매번 새 Pod로 시작)&lt;/li>
&lt;/ul>
&lt;h3>하지만 새로운 트레이드오프도 생겼습니다&lt;span class="hx:absolute hx:-mt-20" id="하지만-새로운-트레이드오프도-생겼습니다">&lt;/span>
&lt;a href="#%ed%95%98%ec%a7%80%eb%a7%8c-%ec%83%88%eb%a1%9c%ec%9a%b4-%ed%8a%b8%eb%a0%88%ec%9d%b4%eb%93%9c%ec%98%a4%ed%94%84%eb%8f%84-%ec%83%9d%ea%b2%bc%ec%8a%b5%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>물론 Jenkins on Kubernetes도 완벽한 해결책은 아니라고 생각합니다.&lt;/p>
&lt;p>&lt;strong>1. Cold Start 문제&lt;/strong>&lt;/p>
&lt;p>동적 Pod 프로비저닝의 가장 큰 단점이라고 생각합니다. 아무래도 Pod를 새로 생성하는 데 시간이 걸리기 때문입니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>GitHub Actions (Hosted Runner): 즉시 시작
Self-hosted Runner: 즉시 시작 (이미 떠 있음)
Jenkins Pod 프로비저닝: 30초~1분 대기
- Pod 스케줄링: 5~10초
- 컨테이너 이미지 pull: 20~40초 (캐시 없을 시)
- 컨테이너 시작: 5초&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>특히 처음 빌드하거나 한동안 빌드를 안 했을 때, 이미지 캐시가 없으면 더 오래 걸렸습니다.&lt;/p>
&lt;p>&lt;strong>해결 방법:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Node에 이미지 미리 pull 해두기 (ImagePullPolicy: IfNotPresent)&lt;/li>
&lt;li>자주 사용하는 이미지는 DaemonSet으로 미리 캐싱&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>2. Jenkins 관리 복잡도 증가&lt;/strong>&lt;/p>
&lt;p>또 한가지 큰 단점으로는 GitHub Actions는 관리할 서버가 없지만, Jenkins는 별도로 관리해야 한다는 점입니다.&lt;/p>
&lt;ul>
&lt;li>Jenkins Controller Pod 관리 필요&lt;/li>
&lt;li>플러그인 버전 관리&lt;/li>
&lt;li>JCasC 설정 관리&lt;/li>
&lt;li>Jenkins 업그레이드 시 호환성 이슈&lt;/li>
&lt;/ul>
&lt;p>한 번은 Jenkins 플러그인 업데이트 후 Kubernetes Plugin과 호환성 문제로 빌드가 안 되는 일도 있었습니다.&lt;/p>
&lt;p>&lt;strong>3. GitHub Actions에 비해 높은 학습 곡선&lt;/strong>&lt;/p>
&lt;p>아무래도 위와 연관된 부분인데, Jenkins는 GitHub Actions에 비해 학습 곡선이 더 가파르다고 생각합니다.
Github Actions는 상당히 직관적인 편인데 Jenkins는 Groovy 문법과 Jenkinsfile DSL을 익혀야 하기 때문에 그리고 Jenkins의 아키텍처를 이해해야 하기때문에 러닝커브가 좀 더 높을 수 밖에 없다고 생각합니다.&lt;/p>
&lt;p>게다가 Kubernetes와 통합하는 부분도 추가로 익혀야 하기 때문에 신규 팀원분이 합류하신다면 적응하는 데 시간이 좀 더 걸릴 것 같습니다.
지금은 구성도 제가하고 관리도 제가 하고 있기 때문에 큰 문제는 없지만, 앞으로 팀원이 늘어나고 관리 주체가 분산된다면 이 부분도 신경써야 할 것 같습니다.&lt;/p>
&lt;p>&lt;strong>4. 초기 설정 복잡도&lt;/strong>&lt;/p>
&lt;p>이것 역시 관리 복잡도와 연관된 부분인데, Jenkins on Kubernetes는 초기 설정이 GitHub Actions에 비해 훨씬 복잡합니다. Github Actions는 그냥 YAML 파일 하나 작성하면 끝이지만, Jenkins on Kubernetes는 여러 단계가 필요합니다.&lt;/p>
&lt;p>GitHub Actions:&lt;/p>
&lt;ul>
&lt;li>Repository에 .github/workflows/ 폴더 만들고 YAML 파일 작성하면 끝&lt;/li>
&lt;/ul>
&lt;p>Jenkins on Kubernetes:&lt;/p>
&lt;ul>
&lt;li>Helm Chart 설정&lt;/li>
&lt;li>Kubernetes Secret 관리&lt;/li>
&lt;li>Credential 설정 (JCasC)&lt;/li>
&lt;li>Kubernetes Cloud 연동 설정&lt;/li>
&lt;li>Jenkinsfile 작성&lt;/li>
&lt;/ul>
&lt;p>초기 구축에 약 2~3일 정도 소요된 것 같습니다. 트러블 슈팅을 꽤 하긴 했던 것 같습니다.&lt;/p>
&lt;p>&lt;strong>5. UI/UX&lt;/strong>&lt;/p>
&lt;p>솔직히 GitHub Actions의 UI/UX가 더 직관적이고 깔끔 한것 같습니다. Jenkins의 학습곡선가 높은 부분도 UI/UX가 직관적이지 못한 부분이 어느정도 기여하는것 같습니다. (이건 제 개인적인 견해 입니다.)&lt;/p>
&lt;ul>
&lt;li>GitHub Actions: PR과 통합, 로그 보기 편함, 실시간 업데이트&lt;/li>
&lt;li>Jenkins: Blue Ocean 써도 GitHub Actions보단 덜 직관적&lt;/li>
&lt;/ul>
&lt;h3>GitHub Actions vs Jenkins: 언제 무엇을 선택해야 할까?&lt;span class="hx:absolute hx:-mt-20" id="github-actions-vs-jenkins-언제-무엇을-선택해야-할까">&lt;/span>
&lt;a href="#github-actions-vs-jenkins-%ec%96%b8%ec%a0%9c-%eb%ac%b4%ec%97%87%ec%9d%84-%ec%84%a0%ed%83%9d%ed%95%b4%ec%95%bc-%ed%95%a0%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>사실 언제나 생각하는 거지만 도구에는 정답이 없다고 생각합니다. 언제든 상황에 따라 달라질 수 있고 각 도구마다 장단점이 있기 때문입니다.
제 경험을 토대로 두 도구를 언제 선택하는게 나을 것 같은지를 정리해보자면&lt;/p>
&lt;p>&lt;strong>GitHub Actions를 선택하는 게 더 낫다고 생각이 드는 경우&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>팀 규모가 작고 (5명 이하)&lt;/li>
&lt;li>서비스 개수가 적고 (5개 이하)&lt;/li>
&lt;li>월 배포 횟수가 적고 (2000분 이하)&lt;/li>
&lt;li>빠르게 CI/CD 구축하고 싶고&lt;/li>
&lt;li>관리 부담을 최소화하고 싶을 때&lt;/li>
&lt;/ul>
&lt;p>이럴때는 Github Actions로도 충분히 해결이 가능하고 관리 부담도 적기 때문에 Github Actions를 선택하는게 더 낫다는 생각이 듭니다.&lt;/p>
&lt;p>&lt;strong>Jenkins on Kubernetes를 선택하는 게 더 낫다고 생각이 드는 경우&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>MSA 환경에서 서비스가 많고 (10개 이상)&lt;/li>
&lt;li>배포가 빈번하고 (월 100회 이상)&lt;/li>
&lt;li>Kubernetes 클러스터가 이미 있고&lt;/li>
&lt;li>복잡한 빌드 로직이 필요하고&lt;/li>
&lt;li>비용을 최소화하고 싶을 때&lt;/li>
&lt;/ul>
&lt;p>이럴 때는 Jenkins on Kubernetes가 더 나은 선택이 될 수 있다고 생각합니다. 물론 러닝커브와 운영 부담을 고려해야겠지만요.&lt;/p>
&lt;p>&lt;strong>Self-hosted Runner를 선택하는 게 나은 경우:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>임시 방편으로 빠르게 적용하고 싶을 때&lt;/li>
&lt;li>GitHub Actions 워크플로우를 그대로 유지하고 싶을 때&lt;/li>
&lt;li>단, 서비스가 많아지면 결국 다른 선택을 고려해야 함&lt;/li>
&lt;/ul>
&lt;p>임시방편으로는 나쁘지 않다고 생각합니다. 개발자 경험이 많이 나빠지지 않는 선에서 빠르게 적용할 수 있기 때문입니다. 다만 장기적으로는 결국 다른 선택을 고려해야 할 것 같습니다. (물론 꼭 Self-hosted Runner라고 개발자 노트북에 돌리는게 아니라 별도의 서버에 Self-hosted Runner를 구축하는 방법도 있긴 합니다.)&lt;/p>
&lt;hr>
&lt;h2>배운 점&lt;span class="hx:absolute hx:-mt-20" id="배운-점">&lt;/span>
&lt;a href="#%eb%b0%b0%ec%9a%b4-%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>1. 모든 선택엔 트레이드오프가 있다&lt;span class="hx:absolute hx:-mt-20" id="1-모든-선택엔-트레이드오프가-있다">&lt;/span>
&lt;a href="#1-%eb%aa%a8%eb%93%a0-%ec%84%a0%ed%83%9d%ec%97%94-%ed%8a%b8%eb%a0%88%ec%9d%b4%eb%93%9c%ec%98%a4%ed%94%84%ea%b0%80-%ec%9e%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Self-hosted Runner를 도입할 때는 그게 &lt;strong>당시엔 최선&lt;/strong>이었다고 생각합니다.&lt;/p>
&lt;ul>
&lt;li>시간적 여유가 없었고&lt;/li>
&lt;li>기존 파이프라인을 유지할 수 있었고&lt;/li>
&lt;li>비용 문제도 해결됐으니까요&lt;/li>
&lt;/ul>
&lt;p>Jenkins on Kubernetes로 마이그레이션했을 때도&lt;/p>
&lt;ul>
&lt;li>Macbook 발열 문제는 해결됐지만&lt;/li>
&lt;li>Cold start 지연 시간이 생겼고&lt;/li>
&lt;li>관리 복잡도가 증가했습니다&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>완벽한 CI/CD, 완벽한 도구는 없는 것 같습니다. 각 선택마다 장단점이 있고, 현재 상황에서 가장 중요한 게 무엇인지 파악해서 선택해야 한다는걸 다시한번 느꼈습니다.&lt;/strong>&lt;/p>
&lt;h3>2. 비용 최적화는 단순히 돈만의 문제가 아니다&lt;span class="hx:absolute hx:-mt-20" id="2-비용-최적화는-단순히-돈만의-문제가-아니다">&lt;/span>
&lt;a href="#2-%eb%b9%84%ec%9a%a9-%ec%b5%9c%ec%a0%81%ed%99%94%eb%8a%94-%eb%8b%a8%ec%88%9c%ed%9e%88-%eb%8f%88%eb%a7%8c%ec%9d%98-%eb%ac%b8%ec%a0%9c%ea%b0%80-%ec%95%84%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>처음엔 GitHub Actions 무료 사용량 문제로 시작했지만, 결국 &lt;strong>개발자 경험(DX)&lt;/strong> 문제로 귀결됐습니다.&lt;/p>
&lt;p>Self-hosted Runner가 Macbook에서 돌아가면서 발열과 성능 저하를 일으켰고, 이게 개발 생산성에 직접적인 영향을 미쳤습니다.&lt;/p>
&lt;p>&lt;strong>진짜 비용은 인프라 비용이 아니라 개발자의 시간일 수 있겠다 싶습니다.&lt;/strong>&lt;/p>
&lt;h3>3. Kubernetes는 단순히 오케스트레이션 도구가 아니다&lt;span class="hx:absolute hx:-mt-20" id="3-kubernetes는-단순히-오케스트레이션-도구가-아니다">&lt;/span>
&lt;a href="#3-kubernetes%eb%8a%94-%eb%8b%a8%ec%88%9c%ed%9e%88-%ec%98%a4%ec%bc%80%ec%8a%a4%ed%8a%b8%eb%a0%88%ec%9d%b4%ec%85%98-%eb%8f%84%ea%b5%ac%ea%b0%80-%ec%95%84%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Kubernetes의 동적 Pod 프로비저닝을 활용하니, CI/CD 파이프라인의 리소스 효율성이 크게 개선됐습니다.&lt;/p>
&lt;p>필요할 때만 Pod를 생성하고 완료 후 삭제하는 패턴은, Self-hosted Runner처럼 항상 떠 있는 방식보다 훨씬 효율적이었습니다.&lt;/p>
&lt;p>&lt;strong>Kubernetes는 서비스 배포뿐 아니라 CI/CD 인프라로도 강력하다고 느꼈습니다.&lt;/strong>&lt;/p>
&lt;h3>4. 문제 해결은 단계적으로&lt;span class="hx:absolute hx:-mt-20" id="4-문제-해결은-단계적으로">&lt;/span>
&lt;a href="#4-%eb%ac%b8%ec%a0%9c-%ed%95%b4%ea%b2%b0%ec%9d%80-%eb%8b%a8%ea%b3%84%ec%a0%81%ec%9c%bc%eb%a1%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>1단계: GitHub Actions 무료 사용량 부족
→ Self-hosted Runner 도입
2단계: Self-hosted Runner 성능 문제
→ Jenkins 마이그레이션&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>각 단계에서 겪은 문제를 해결하면서, 점진적으로 더 나은 방향으로 발전할 수 있었습니다.&lt;/p>
&lt;p>&lt;strong>한 번에 완벽한 해결책을 찾으려 하지 말고, 지금 당장 할수있는 방법중 가장 최선의 선택을 하기 위해 노력하며 점진적으로 개선해나가는 게 중요하다고 느꼈습니다.&lt;/strong>&lt;/p>
&lt;hr>
&lt;h2>마치며&lt;span class="hx:absolute hx:-mt-20" id="마치며">&lt;/span>
&lt;a href="#%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>CI/CD는 한 번 구성하면 끝이 아니더라구요.&lt;/p>
&lt;p>팀의 규모, 서비스의 개수, 비용, 성능 등 여러 요소를 고려해서 지속적으로 개선해나가야 한다고 느꼈습니다.&lt;/p>
&lt;p>저희는 &lt;strong>GitHub Actions → Self-hosted Runner → Jenkins on Kubernetes&lt;/strong>로 진화했고, 현재는 안정적으로 운영 중 이라고 생각합니다. ( 제 개인적인 견해로는 말이죠 ㅎ.. )&lt;/p>
&lt;p>물론 이게 완벽한 해결책은 아닐 수 있다 싶습니다. 시간이 지나면 또 다른 문제가 생길 수 있으니까요.&lt;/p>
&lt;p>&lt;strong>그렇게 된다면 또 그때 다시금 고민하고 그때의 최선을 찾아 개선해나가야겠죠.&lt;/strong>&lt;/p>
&lt;p>이 글이 비슷한 고민을 하고 계신 분들께 이 글이 도움이 되길 바랍니다. 긴글 읽어주셔서 감사합니다.&lt;/p>
&lt;hr>
&lt;h2>Reference&lt;span class="hx:absolute hx:-mt-20" id="reference">&lt;/span>
&lt;a href="#reference" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;ul>
&lt;li>&lt;a href="https://docs.github.com/en/billing/concepts/product-billing/github-actions"target="_blank" rel="noopener">GitHub Actions billing - GitHub Docs&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners"target="_blank" rel="noopener">Self-hosted runners - GitHub Docs&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://plugins.jenkins.io/kubernetes/"target="_blank" rel="noopener">Jenkins Kubernetes Plugin - Official Documentation&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/jenkinsci/kubernetes-plugin"target="_blank" rel="noopener">GitHub - jenkinsci/kubernetes-plugin&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://dev.to/alex_aslam/jenkins-on-kubernetes-dynamic-agents-effortless-scalability-for-modern-cicd-2ff3"target="_blank" rel="noopener">Jenkins on Kubernetes: Dynamic Agents &amp;amp; Effortless Scalability&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://devopscube.com/jenkins-build-agents-kubernetes/"target="_blank" rel="noopener">How to Setup Jenkins Build Agents on Kubernetes Pods&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>Certified Kubernetes Administrator (CKA) 합격 및 취득 후기</title><link>https://jeongil.dev/ko/blog/reflection/certified-kubernetes-administrator/</link><pubDate>Mon, 01 Dec 2025 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/reflection/certified-kubernetes-administrator/</guid><description>
&lt;h2>들어가며&lt;span class="hx:absolute hx:-mt-20" id="들어가며">&lt;/span>
&lt;a href="#%eb%93%a4%ec%96%b4%ea%b0%80%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>안녕하세요. 저는 프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 3년차 백엔드 개발자 정정일입니다.&lt;/p>
&lt;p>현대 웹 서버 배포에서 컨테이너화의 중요성이 점점 커지는 것 같습니다.&lt;/p>
&lt;p>과거에는 가상머신 혹은 온프라미스 서버에 직접 톰캣 같은 웹서버를 직접 설치 하고 운영하는 경우가 많았지만, 컨테이너가 등장하면서 많은 기업들이 컨테이너를 통해 배포를 하기 시작한 것 같습니다.&lt;/p>
&lt;p>웹 서버를 직접 설치하고 운영할땐 불편한게 한두개가 아니죠 ㅎㅎ.. 아무래도 컨테이너는 가볍고 빠르게 배포할 수 있으며, 일관된 환경을 제공한다는 점에서 매우 매력적이라고 생각합니다.&lt;/p>
&lt;p>이렇게 많은 기업들이 컨테이너를 통해 배포하기 시작하면서 컨테이너를 잘 관리하기 위한 컨테이너 오케스트레이션 툴의 필요성이 대두되었고, 그 중 가장 널리 사용되는 도구 중 하나가 바로 &lt;strong>Kubernetes&lt;/strong>인 것 같습니다.&lt;/p>
&lt;p>저 역시 Kubernetes를 구축,배포 및 운영하는 과정에서 Kubernetes에 대해 좀더 알고 싶어져, 이번에 관련 자격증인 &lt;strong>Certified Kubernetes Administrator (CKA)&lt;/strong> 를 취득하게 됐는데, 이 자격증에 대한 후기에 대해 공유드리고자 합니다.&lt;/p>
&lt;h2>쿠버네티스와의 인연&lt;span class="hx:absolute hx:-mt-20" id="쿠버네티스와의-인연">&lt;/span>
&lt;a href="#%ec%bf%a0%eb%b2%84%eb%84%a4%ed%8b%b0%ec%8a%a4%ec%99%80%ec%9d%98-%ec%9d%b8%ec%97%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>&amp;ldquo;왜 CKA 자격증을 취득했나요?&amp;ldquo;라고 누군가 제게 여쭤보신다면 저와 쿠버네티스의 인연부터 설명드려야 할 것 같습니다.&lt;/p>
&lt;p>제가 이전 회사에서 근무할 때, 회사의 인프라는 이미 쿠버네티스 기반으로 운영되고 있었습니다. 당시 저는 백엔드 개발자로서 애플리케이션 개발에 집중하고 있었고, 인프라과 관련된 작업들은 회사의 유일한 DevOps분께서 모두 담당하고 계셨습니다.&lt;/p>
&lt;p>저는 이미 구축되어 있는 Jenkins, ArgoCD, ELK, Prometheus, Grafana 등의 도구들을 사용하여 모니터링 및 배포를 진행했지만, 인프라가 어떻게 구성되어 있는지, 어떤 기술들인지, 쿠버네티스가 어떻게 동작하는지에 대해서는 제대로 알지 못했습니다.&lt;/p>
&lt;p>그러던 중 DevOps 분께서 이직을 하시게 되었고, 이직을 하시기 한달전에 &amp;ldquo;인수인계 받을 DevOps 한명을 새로 뽑으면 1달 인수인계 해주고 가겠다&amp;rdquo; 라고 사측에 제안하셨지만 회사는 신규채용을 할 수 없는 상황이였습니다.&lt;/p>
&lt;p>DevOps 분께서는 그럼 인수인계 문서만 남기고 가시겠다고 하셨지만 저는 그 문서만으로는 부족하다고 생각했습니다. 신규 DevOps분께서 언제 채용될지 모르는 상황이였고, 그 사이에 인프라에 문제가 생기면 누군가가 해결해야 한다고 생각했기 때문입니다.&lt;/p>
&lt;p>그래서 저는 DevOps분을 따로 찾아뵙고 조심스럽게 부탁드렸습니다.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;혹시 실례가 안된다면 제게 회사 인프라에 대해 조금만 알려주실 수 있으실까요..? DevOps가 공백인 기간에 혹시라도 서버에 문제가 생기면 누군가는 해결해야 할 텐데&amp;hellip; 번거로우시겠지만 조금만 알려주신다면 제가 부족한 지식으로라도 어떻게든 버텨보겠습니다.&amp;rdquo;&lt;/p>
&lt;/blockquote>
&lt;p>당시 그런 저를 좋게 봐주셨는지 DevOps분께서 1개월간 멘토링 및 인수인계를 제게 해주셨고, 덕분에 &lt;strong>쿠버네티스, AWS EKS, Jenkins, ArgoCD, ELK&lt;/strong> 등의 DevOps 및 인프라 관련 지식을 쌓을 수 있었습니다. 이후 7개월 정도 다음 DevOps분께서 채용되시기 전까지 혼자 인프라를 운영을 했었거든요.&lt;/p>
&lt;blockquote>
&lt;p>사실 1개월 멘토링으로 다 습득할 수 있는 양은 아니었기 때문에 던져주시는 인프라 관련 키워드를 노트에 다 받아적어 하나하나 찾아보며 공부했던 기억이 있네요&amp;hellip; ㅎ..&lt;/p>
&lt;/blockquote>
&lt;p>지금 돌이켜보면 정말 무모한 도전이었던 것 같습니다&amp;hellip; 그 7개월 사이에 어떻게든 해결한 몇번의 장애도 있었고, 제가 해결하지 못해 이직한 DevOps분께 사적으로 연락드려 SOS를 요청했던 적도 있었거든요.&lt;/p>
&lt;p>그치만 덕분에 정말 많이 배울 수 있어 제 인생에 있어 하나의 큰 행운이였던 것 같습니다. 그 전까진 많은 회사에서 그렇겠지만 인프라 접근 권한 자체가 없었거든요.&lt;/p>
&lt;h2>내 손으로 쿠버네티스 구축하기&lt;span class="hx:absolute hx:-mt-20" id="내-손으로-쿠버네티스-구축하기">&lt;/span>
&lt;a href="#%eb%82%b4-%ec%86%90%ec%9c%bc%eb%a1%9c-%ec%bf%a0%eb%b2%84%eb%84%a4%ed%8b%b0%ec%8a%a4-%ea%b5%ac%ec%b6%95%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이후 저는 현재 회사에 이직을 하게 되었고, 현재 회사는 제가 처음 팀에 합류 했을때는 단일 인스턴스에 모든 MSA 웹서버가 배포, 운영되는 모놀리식 아키텍처 환경이였습니다.&lt;/p>
&lt;p>이렇게만 들으시면 &amp;ldquo;엥 MSA를 단일 인스턴스에?&amp;rdquo; 라고 의아해 하실 수 있는데, 아무래도 회사는 스타트업이였고, 비용 절감을 위해 그런 구조를 택한 것 같았습니다.&lt;/p>
&lt;p>하지만 GCP에서 스타트업에게 1년간 크레딧을 지원해주는 프로그램에 선정되면서, 저는 회사에 GCP로 인프라를 이전하고 쿠버네티스를 도입할 것을 제안했습니다.&lt;/p>
&lt;p>다행히도 회사에서도 긍정적으로 검토해주셔서 쿠버네티스 운영 경험이 있던 제가 쿠버네티스를 구축하고 설계하는 업무를 맡게 됐습니다.&lt;/p>
&lt;p>어찌저찌 GKE 기반의 Managed 쿠버네티스를 구성하고 무중단으로 마이그레이션까지 성공적으로 완료하게 됐습니다. 쿠버네티스를 구축하는 과정에 대해 정리한 글은 다음 글을 참고해주세요. &lt;a href="https://jeongil.dev/ko/blog/infrastructure/docker-compose-to-k8s/">&lt;strong>개발 서버도 없던 팀이 GitOps를 갖추기까지: 맨땅에서 시작한 쿠버네티스 도입기&lt;/strong>&lt;/a>&lt;/p>
&lt;h2>그래서 CKA는 왜?&lt;span class="hx:absolute hx:-mt-20" id="그래서-cka는-왜">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%9e%98%ec%84%9c-cka%eb%8a%94-%ec%99%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>사설이 길어졌는데, 다시 본론으로 돌아와서 제가 CKA 자격증을 취득하게 된 계기에 대해 말씀드리자면,&lt;/p>
&lt;p>쿠버네티스를 운영하고 구축하는 과정에서 저는 제가 제대로 알고 있는지 검증하고 싶다는 생각이 들었습니다. 또 검증하는 과정에서 쿠버네티스에 대해 더 깊이있게 공부할 수 있을 것 같다는 생각도 들었고요.&lt;/p>
&lt;p>그래서 쿠버네티스 관련 자격증을 찾아보게 되었고, 그 중 가장 널리 알려져 있고 공신력 있는 자격증이 바로 &lt;strong>Certified Kubernetes Administrator (CKA)&lt;/strong> 라는 것을 알게 되었습니다.&lt;/p>
&lt;p>알아본 이후로 고민은 길지 않았습니다. 블랙프라이데이 할인 기간을 틈타 CKA 자격증을 도전하게 되었습니다.&lt;/p>
&lt;p>CKA는 가격이 비싼 편인데 2025년 2월 전까진 395달러로 한화 약 50만원이 넘는 금액이였는데 2월 4일 이후로 445달러로 인상돼 한화 약 60만원이 넘는 엄청난 가격이 됐습니다.&lt;/p>
&lt;p>가격이 정말 만만치 않은데 CKA를 응시하실 생각이 있는 분들은 꼭 블랙프라이데이나 바우처가 있는 상태에서 응시하시길 추천드립니다. 한번 결제해두면 1년 내에 원하실때 응시하면 되고 한번 불합격한다 하더라도 1번의 재시험 응시가 가능하기 때문에 세일할때 결제해두고 공부하신 후에 응시하시는게 좋으실 것 같습니다.&lt;/p>
&lt;p>저는 블랙프라이데이 기간에 50% 할인 받아 결제하여 저는 절반 가격에 응시할 수 있었습니다. 물론 절반 가격도 만만치 않은것도 맞습니다. 또 합격 후에도 2년 마다 갱신을 위해 재응시를 해야 한다는 점도 고려해야 합니다.&lt;/p>
&lt;h2>시험 응시 및 준비&lt;span class="hx:absolute hx:-mt-20" id="시험-응시-및-준비">&lt;/span>
&lt;a href="#%ec%8b%9c%ed%97%98-%ec%9d%91%ec%8b%9c-%eb%b0%8f-%ec%a4%80%eb%b9%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>CKA 시험은 온라인으로 응시할 수 있으며, 시험 시간은 2시간입니다. 문제는 핸즈온으로 제공되며, 각 문제는 특정 작업을 수행하는 데 필요한 명령어를 입력해야 합니다. 예를 들어, 특정 네임스페이스에 배포된 애플리케이션의 로그를 확인하거나, 특정 리소스를 생성하거나 삭제하는 등의 작업이 포함됩니다.&lt;/p>
&lt;p>시험 준비를 위해 저는 다음과 같은 자료들을 활용했습니다. 사실 시험 문제나 준비 방법은 다른 분들 게시글의 잘 정리된 글들이 많기 때문에 저는 제가 활용한 자료들 위주로만 공유드리겠습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://udemy.com/course/certified-kubernetes-administrator-with-practice-tests"target="_blank" rel="noopener">Udemy: Certified Kubernetes Administrator with Practice Tests&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;ul>
&lt;li>너무 유명한 뭄샤드 강의 입니다. 뭄샤드님 강의는 정말 유명해서 이미 많은 분들이 수강하셨을 것 같아 저는 따로 후기를 남기진 않겠습니다. 다만 강의가 워낙 잘 만들어져 있어 CKA 준비하시는 분들께 강력 추천드립니다.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>&lt;a href="https://sunrise-min.tistory.com/entry/2025-CKA-%EC%8B%9C%ED%97%98-%EC%A4%80%EB%B9%84-%ED%95%B5%EC%8B%AC-%EC%9A%94%EC%95%BD"target="_blank" rel="noopener">2025 CKA 시험 준비 핵심 요약 - by 내기록&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;ul>
&lt;li>2025년 부터 CKA 유형이 변경됐는데 이에 맞춰 잘 정리된 글입니다.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>&lt;a href="https://hyunlulu.tistory.com/entry/CKA-CKA-exam-2025-question-%EB%AC%B8%EC%A0%9C%ED%92%80%EC%9D%B4-%EC%A0%95%EB%A6%AC"target="_blank" rel="noopener">[CKA] CKA Exam 2025 문제풀이 정리 1 - hyunlulu&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;ul>
&lt;li>문제 풀이 정리 글입니다. 문제 유형을 파악하는데 도움이 많이 됐습니다. 2편도 있으니 같이 참고하시면 좋을 것 같습니다.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;p>시험 준비 기간은 약 한 달 정도 걸렸습니다. 쿠버네티스 지식이 어느정도 있던 상태였지만, 업무로 인해 공부에 많은 시간을 투자하지 못해 생각보다 오래 걸렸던 것 같습니다. 만약 쿠버네티스에 대해 아예 모르는 상태에서 준비하신다면 2~3달 정도는 잡으시는게 좋을 것 같습니다.&lt;/p>
&lt;h2>시험 결과 및 솔직한 후기&lt;span class="hx:absolute hx:-mt-20" id="시험-결과-및-솔직한-후기">&lt;/span>
&lt;a href="#%ec%8b%9c%ed%97%98-%ea%b2%b0%ea%b3%bc-%eb%b0%8f-%ec%86%94%ec%a7%81%ed%95%9c-%ed%9b%84%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/qk0up2fv3zd3m887zh3r4/cka-result.png?rlkey=svogl1ge9tesbqqi7lt41caem&amp;amp;st=nrcmpmw0&amp;amp;raw=1" alt="cka-result" loading="lazy" />&lt;/p>
&lt;p>결과부터 말씀드리면 합격선 66점에 &lt;strong>76점으로 합격&lt;/strong>했습니다.&lt;/p>
&lt;p>솔직히 더 높은 점수를 받을 줄 알았는데 생각보다 점수가 낮게 나왔습니다. 시험 보고 나서 한동안 왜 이렇게 점수가 낮았을까 생각해봤는데, 돌이켜보니 이유가 명확했습니다.&lt;/p>
&lt;p>&lt;strong>제가 실무에서 다뤘던 쿠버네티스는 사실 절반만 알고 있었던 거더라구요.&lt;/strong>&lt;/p>
&lt;p>이전 회사에서는 AWS EKS, 현재 회사에서는 GKE를 사용했는데, 이런 Managed Kubernetes 환경에서는 &lt;strong>Control Plane을 직접 건드릴 일이 거의 없습니다.&lt;/strong> Google이나 AWS가 알아서 관리해주거든요.&lt;/p>
&lt;p>그래서 제가 실무에서 주로 다뤘던 건&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Application 레벨&lt;/strong>: Deployment, Pod, Service, Ingress, ConfigMap, Secret 등&lt;/li>
&lt;li>애플리케이션 배포, 스케일링, 로그 확인, 간단한 트러블슈팅&lt;/li>
&lt;/ul>
&lt;p>반면 CKA 시험에서 요구하는 건&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Infrastructure 레벨&lt;/strong>: ETCD 백업/복구, Control Plane 컴포넌트 이해, Static Pod, 노드 관리, CNI(Calico 등) 네트워킹 등&lt;/li>
&lt;li>클러스터 자체를 구축하고 관리하는 능력&lt;/li>
&lt;/ul>
&lt;p>시험 보면서 느낀 건, &lt;strong>&amp;ldquo;아 나는 쿠버네티스 위에서 애플리케이션 돌리는 건 익숙한데, 쿠버네티스 자체를 관리하는 건 제대로 몰랐구나&amp;rdquo;&lt;/strong> 였습니다.&lt;/p>
&lt;p>예를 들면&lt;/p>
&lt;ul>
&lt;li>ETCD 백업/복구: 실무에서 해본 적 없음 (Managed 서비스니까)&lt;/li>
&lt;li>Static Pod: 개념만 알고 로그 확인 정도만 해봤음&lt;/li>
&lt;li>Control Plane 컴포넌트 트러블슈팅: apiserver, scheduler, controller-manager 건들일 일 없음&lt;/li>
&lt;li>CNI 네트워크 설정: 그냥 GKE가 알아서 해줬음&lt;/li>
&lt;/ul>
&lt;p>Mock Exam에서 점수가 높았던 건 반복해서 풀다보니 패턴에 익숙해진 거였고, 실전에서는 이런 &amp;ldquo;몰랐던 영역&amp;quot;들이 나오니까 당황했던 것 같습니다.&lt;/p>
&lt;p>그래도 &lt;strong>이 과정이 정말 값졌습니다.&lt;/strong>&lt;/p>
&lt;p>CKA 준비하면서 처음으로 쿠버네티스를 &amp;ldquo;전체적으로&amp;rdquo; 이해하게 됐거든요. Managed 서비스만 쓰면 편하긴 한데, 내부 동작 원리를 모르고 쓰는 거라 한계가 있더라구요.&lt;/p>
&lt;p>시험 준비하면서:&lt;/p>
&lt;ul>
&lt;li>&amp;ldquo;아 kubelet이 이렇게 동작하는구나&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;Control Plane 컴포넌트들이 이렇게 통신하는구나&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;ETCD가 이렇게 중요한 역할을 하는구나&amp;rdquo;&lt;/li>
&lt;/ul>
&lt;p>이런 걸 알게 됐고, 이제는 장애가 생겨도 어디서부터 봐야 할지 감이 잡히는 것 같습니다.&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/qcdxgfokoqygxhycvmxy9/cka-percent.png?rlkey=i8klrn347rv7usgbltmpyfloh&amp;amp;st=3ffx8m2n&amp;amp;raw=1" alt="cka-percent" loading="lazy" />&lt;/p>
&lt;p>시험 출제 비중이 위와 같은데, 특히 &lt;strong>Troubleshooting 파트&lt;/strong>가 제일 좋았습니다. 문제를 해결하려면 쿠버네티스 내부 동작 원리를 알아야 하거든요.&lt;/p>
&lt;p>그래서 시험이 끝난 후에도 &amp;ldquo;아 이 부분은 왜 이렇게 되는거지?&amp;rdquo; 하면서 찾아보게 되고, 앞으로도 더 공부하고 싶은 욕구가 생기더라구요.&lt;/p>
&lt;p>CKA가 단순히 자격증이 아니라, &lt;strong>쿠버네티스를 제대로 이해하기 위한 계기&lt;/strong>가 되었다고 생각합니다.&lt;/p>
&lt;h2>그래서 CKA 추천 하나요?&lt;span class="hx:absolute hx:-mt-20" id="그래서-cka-추천-하나요">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%9e%98%ec%84%9c-cka-%ec%b6%94%ec%b2%9c-%ed%95%98%eb%82%98%ec%9a%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>&lt;strong>저는 개인적으로 CKA 자격증 취득을 추천&lt;/strong>드립니다.&lt;/p>
&lt;p>특히 저처럼 &lt;strong>Managed Kubernetes만 써보신 분들께 강력 추천&lt;/strong>합니다. 실무에서 애플리케이션 배포는 잘하는데, 쿠버네티스 내부는 잘 모르는 분들이라면 CKA 준비하면서 정말 많이 배우실 겁니다.&lt;/p>
&lt;p>CKA의 가치는 &amp;ldquo;자격증&amp;quot;이 아니라 &lt;strong>시험을 준비하는 과정에서 안 다뤄봤던 영역까지 공부하게 된다&lt;/strong>는 점인 것 같습니다.&lt;/p>
&lt;p>시험이 핸즈온으로 진행되기 때문에 단순히 이론만 외우는 게 아니라 직접 터미널에서 명령어 치면서 익히게 되는데, 이게 실제로 공부에 도움이 많이 되는 것 같습니다.&lt;/p>
&lt;p>이제까지 자격증들은 대부분 암기식으로 Dump문제를 외우는 경우들이 많아 사실 &amp;ldquo;취득했다&amp;rdquo; 라는 사실 자체에 의미를 두는 경우가 많았던 것 같습니다. 하지만 CKA는 준비 과정 자체가 학습이 되더라구요.&lt;/p>
&lt;p>사실 &lt;strong>CKA가 채용시장에서 높은 가치를 지니는 자격증인지는 잘 모르겠습니다.&lt;/strong> 아직 CKA를 가지고 이직을 시도해본적은 없어서요. 또 있는 상태로 이직을 시도한다 하더라도 그렇게 높게 평가받는 자격증은 아닐 것 같습니다.&lt;/p>
&lt;p>다만 쿠버네티스를 제대로 공부하고 싶으신 분들, 특히 Managed 환경만 써보신 분들께는 &lt;strong>CKA 준비 과정 자체를 추천&lt;/strong>드리고 싶습니다.&lt;/p>
&lt;h2>시험 준비 팁&lt;span class="hx:absolute hx:-mt-20" id="시험-준비-팁">&lt;/span>
&lt;a href="#%ec%8b%9c%ed%97%98-%ec%a4%80%eb%b9%84-%ed%8c%81" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>설령 CKA의 자격증 자체보다 CKA의 응시과정이 더 값진 것 같다는 말씀을 드리긴 했지만, 그래도 비싼 돈 주고 응시하는데 이왕이면 자격증도 따는게 당연히 좋겠죠? ㅎㅎ&lt;/p>
&lt;p>그런 의미에서 시험을 준비하실 분들에게 몇가지 팁을 드리자면 첫번째로는 &lt;strong>단순히 외우는 게 아니라 쿠버네티스를 제대로 이해하는 방향으로 공부&lt;/strong>하시는게 좋을 것 같습니다. 예를 들면 &amp;ldquo;Kubelet의 역할은 무엇인가?&amp;rdquo;, &amp;ldquo;etcd는 무엇인가?&amp;rdquo; 같은 개념적인 질문들에 대해 머리 속에서 제대로 답할 수 있어야 합니다.&lt;/p>
&lt;p>또 &amp;ldquo;Static Pod는 누가 관리하는가?&amp;rdquo;, &amp;ldquo;Ingress와 Service의 차이는 무엇인가?&amp;rdquo;, &amp;ldquo;PVC와 PV는 각각 무엇인가&amp;rdquo; 같은 질문들에 대해서도 스스로 명확히 답할 수 있어야 합니다.&lt;/p>
&lt;p>두번째 팁으로는 &lt;strong>Udemy 강의에 있는 Mock Exam들과 Lightning Lab을 꼭 여러번 풀어보시길 추천&lt;/strong>드립니다. 문제 유형이 굉장히 비슷하고 강의에 각 문제에 대한 풀이도 있기 때문에 내가 어떤 부분을 알고 모르는지 파악하는데 도움이 많이 됩니다.&lt;/p>
&lt;p>저는 Lightning Lab을 3번 Mock Exam을 각각 4번씩 풀어봤던 것 같습니다. 시험보기 직전에도 전부 한번 더 풀어봤구요.&lt;/p>
&lt;p>다만 &lt;strong>Mock Exam 점수가 높다고 방심하지 마세요.&lt;/strong> 저처럼 패턴에 익숙해져서 점수가 높게 나올 수 있거든요. 실전에서는 변형된 문제나 처음 보는 상황이 나올 수 있으니, 문제를 푸는 것보다 &lt;strong>&amp;ldquo;왜 이렇게 푸는지&amp;rdquo;&lt;/strong> 이해하는 게 중요합니다.&lt;/p>
&lt;p>CKA를 결제하면 killer.sh 라는 시험 환경과 비슷한 환경에서 시뮬레이션 테스트를 할 수 있는 곳에 접근할 수 있는 권한이 2번 주어지는데, 문제 난이도가 시험보다 훨씬 어렵기 때문에 시험 보기 전에 꼭 한번씩 풀어보시길 추천드립니다.&lt;/p>
&lt;p>문제를 풀기보다는 시험 환경에 익숙해지는 용도로 푸시는게 좋을 것 같습니다. 시험환경은 Mock Exam보다 훨씬 불편하거든요.&lt;/p>
&lt;p>그리고 세번째로는 시험 보시기전에 위에 정리해드렸던 블로그들의 기출문제를 한번씩 보시는 걸 꼭 추천드립니다. 문제 유형이 비슷하기 때문에 기출문제를 통해 어떤 유형의 문제가 나오는지 파악하는게 도움이 많이 됩니다.&lt;/p>
&lt;h2>마치며&lt;span class="hx:absolute hx:-mt-20" id="마치며">&lt;/span>
&lt;a href="#%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이상으로 Certified Kubernetes Administrator (CKA) 자격증 취득 후기를 공유드렸습니다.&lt;/p>
&lt;p>76점이라는 점수가 높은 편은 아니지만, 이 과정을 통해 제가 몰랐던 쿠버네티스의 절반을 배울 수 있었습니다. Managed Kubernetes만 쓰면서 &amp;ldquo;나는 쿠버네티스 안다&amp;quot;고 생각했는데, 사실 Application 레벨만 알고 Infrastructure 레벨은 몰랐더라구요.&lt;/p>
&lt;p>CKA 준비하면서 쿠버네티스를 &amp;ldquo;전체적으로&amp;rdquo; 이해하게 됐고, 이제는 장애가 생겨도 어디서부터 봐야 할지 감이 잡힙니다.&lt;/p>
&lt;p>쿠버네티스에 대해 더 깊이있게 공부하고 싶으신 분들, 특히 Managed 환경만 써보신 분들이라면 CKA 자격증 취득을 추천드립니다. 다만 가격이 비싼 편이기 때문에 블랙프라이데이 기간이나 바우처가 있는 상태에서 응시하시는걸 추천드립니다.&lt;/p>
&lt;p>앞으로도 쿠버네티스 관련해서 더 깊이있게 공부하고, 관련된 글도 계속 작성해보도록 하겠습니다. 긴 글 읽어주셔서 감사합니다!&lt;/p>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/j3zovsvpuz7d60wok1rz2/jeongil-jeong-4e19e861-4428-4d91-8ab1-fd0beda3aaed-certificate.jpg?rlkey=qta1xivk3ygsf0v2egp7slulo&amp;amp;st=kjr6kgqx&amp;amp;raw=1" alt="cka-certificate" loading="lazy" />&lt;/p></description></item><item><title>검색엔진 Manticore Search란? 구성 및 설정, 실무 적용기</title><link>https://jeongil.dev/ko/blog/infrastructure/manticore-search-introduction/</link><pubDate>Tue, 25 Nov 2025 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/infrastructure/manticore-search-introduction/</guid><description>
&lt;p>안녕하세요. 프롭테크 플랫폼에서 백엔드 개발자로 일하고 있는 정정일입니다.&lt;/p>
&lt;p>&amp;ldquo;검색 기능이 필요해요.&amp;rdquo; 이 말을 들었을 때, 많은 개발자 분들의 머릿속에는 아마 하나의 이름이 떠오르셨을 것 같습니다. 바로 &lt;strong>Elasticsearch&lt;/strong>입니다. 막강한 기능과 풍부한 생태계 덕분에 업계 표준처럼 여겨지기도 하는 것 같습니다.&lt;/p>
&lt;p>하지만 Elasticsearch가 항상 정답은 아니라고 생각합니다. 물론 너무 당연한 말이라 느끼실 수 있지만 모든 기술은 상황과 환경에 따라 적절히 선택해야하죠. 그런점에서 저희의 고민은 &amp;ldquo;검색 기능 하나 추가하자고 Kibana까지 설정하고, Java 힙 메모리와 사투를 벌여야 할까?&amp;rdquo; 였습니다. 특히 리소스가 제한적인 환경이라면 Elasticsearch의 높은 리소스 요구량과 복잡성은 상당한 부담이 될 수 있다고 생각했습니다.&lt;/p>
&lt;p>저희는 이 고민의 끝에서 &lt;strong>Manticore Search&lt;/strong>라는 검색엔진 오픈소스를 발견했습니다. 이 글은 검색엔진으로 Manticore Search를 선택하고, 실제 프로덕션 환경에 적용하며 겪었던 현실적인 고민과 경험, 그리고 기술적인 선택의 과정을 담은 기록입니다.&lt;/p>
&lt;h2>Manticore Search?&lt;span class="hx:absolute hx:-mt-20" id="manticore-search">&lt;/span>
&lt;a href="#manticore-search" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>Manticore Search는 C++로 작성된 고성능 오픈소스 전문 검색(Full-text Search) 엔진입니다. 하지만 완전히 새로운 프로젝트는 아니라는 점이 흥미로웠습니다.&lt;/p>
&lt;p>그 뿌리는 2000년대 초반, MySQL과 함께 가볍고 빠른 성능으로 인기를 끌었던 &lt;strong>Sphinx Search&lt;/strong>에 있었습니다. 2016년, Sphinx의 개발이 사실상 중단되자 핵심 개발팀 대부분이 나와 2017년에 프로젝트를 Fork 하여 Manticore Search를 탄생시켰습니다.&lt;/p>
&lt;p>흥미로운 점은 그 후 Sphinx가 클로즈드 소스로 전환된 반면, Manticore Search는 100% 오픈소스를 유지하며 훨씬 더 활발하게 발전하고 있다는 점이었습니다. (&lt;a href="https://manticoresearch.com/blog/manticore-search-3-years-after-forking-from-sphinx/"target="_blank" rel="noopener">&lt;em>Manticore Search: 3 years after forking from Sphinx&lt;/em>&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>)&lt;/p>
&lt;h2>저희가 Manticore Search를 선택한 현실적인 이유&lt;span class="hx:absolute hx:-mt-20" id="저희가-manticore-search를-선택한-현실적인-이유">&lt;/span>
&lt;a href="#%ec%a0%80%ed%9d%ac%ea%b0%80-manticore-search%eb%a5%bc-%ec%84%a0%ed%83%9d%ed%95%9c-%ed%98%84%ec%8b%a4%ec%a0%81%ec%9d%b8-%ec%9d%b4%ec%9c%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>저는 개인적으로 기술 선택은 언제나 트레이드오프의 연속이라고 생각합니다. 저희 팀이 Manticore Search를 선택하기까지의 과정은 다음과 같았습니다.&lt;/p>
&lt;h3>1. 현실적인 제약: 서버 비용 리소스&lt;span class="hx:absolute hx:-mt-20" id="1-현실적인-제약-서버-비용-리소스">&lt;/span>
&lt;a href="#1-%ed%98%84%ec%8b%a4%ec%a0%81%ec%9d%b8-%ec%a0%9c%ec%95%bd-%ec%84%9c%eb%b2%84-%eb%b9%84%ec%9a%a9-%eb%a6%ac%ec%86%8c%ec%8a%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>가장 큰 이유는 &lt;strong>비용&lt;/strong> 문제였습니다. 현실적인 이유 하면 빠질 수 없는 가장 대표적인 이유중 하나죠.&lt;/p>
&lt;p>Elasticsearch는 Java 기반으로, 운영 환경에서는 최소 8GB RAM, 2vCPU 이상이 권장됩니다. 저희 서비스 규모에 비해 과한 리소스였고, 이는 곧바로 인프라 비용 부담으로 이어질거라 예상되었습니다.&lt;/p>
&lt;p>반면 C++로 작성된 Manticore Search는 &lt;strong>빈 인스턴스 기준 약 40MB의 RSS&lt;/strong>만 사용하는 놀라운 효율성을 보여준다는 문서를 읽었습니다. 물론 권장사양은 그보다 더 높은 사양을 요구하겠지만 리소스를 덜 잡아먹는 다는 점은 확실해 보였습니다.&lt;/p>
&lt;p>현재 저희는 쿠버네티스 환경에서 &lt;code>requests: cpu: 200m, memory: 512Mi&lt;/code> 정도의 스펙으로 Manticore-search를 안정적으로 운영하고 있습니다.&lt;/p>
&lt;p>&lt;code>Cpu: 2vCPU, Memory: 8GB RAM&lt;/code>, &lt;code>Cpu: 200m, Memory: 512Mi&lt;/code> 이 차이는 스타트업이나 중소규모 프로젝트처럼 소규모의 팀에게는 무시할 수 없는 수준이라고 생각합니다.&lt;/p>
&lt;h3>2. 성능: 가벼움이 곧 빠름으로 이어질까?&lt;span class="hx:absolute hx:-mt-20" id="2-성능-가벼움이-곧-빠름으로-이어질까">&lt;/span>
&lt;a href="#2-%ec%84%b1%eb%8a%a5-%ea%b0%80%eb%b2%bc%ec%9b%80%ec%9d%b4-%ea%b3%a7-%eb%b9%a0%eb%a6%84%ec%9c%bc%eb%a1%9c-%ec%9d%b4%ec%96%b4%ec%a7%88%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>비용만큼이나 중요했던 것은 &lt;strong>성능&lt;/strong>이었습니다. Manticore Search 측에서 공개한 최신 벤치마크에 따르면, 특히 로그 분석 같은 시나리오에서 Elasticsearch보다 &lt;strong>수 배에서 수십 배&lt;/strong> 빠르다고 주장하고 있습니다. (&lt;a href="https://manticoresearch.com/comparison/vs-elasticsearch/"target="_blank" rel="noopener">&lt;em>Manticore Search vs Elasticsearch&lt;/em>&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>)&lt;/p>
&lt;p>물론 벤치마크는 이상적인 환경에서의 결과일 뿐이라고 생각합니다. 그리고 아무래도 Manticore Search측에서 공개한 만큼 보다 긍정적인 결과가 나올 수밖에 없다는 점도 감안해야 한다고 생각합니다.&lt;/p>
&lt;p>하지만 저희는 C++로 작성되어 JVM의 가비지 컬렉션(GC) 같은 오버헤드 없이 시스템 리소스를 직접적으로 사용하는 Manticore의 아키텍처가 &amp;lsquo;예측 가능하고 꾸준한 성능&amp;rsquo;을 제공해줄 것이라 기대했습니다.&lt;/p>
&lt;h3>3. 개발 생산성: SQL과 HTTP&lt;span class="hx:absolute hx:-mt-20" id="3-개발-생산성-sql과-http">&lt;/span>
&lt;a href="#3-%ea%b0%9c%eb%b0%9c-%ec%83%9d%ec%82%b0%ec%84%b1-sql%ea%b3%bc-http" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Manticore Search의 큰 매력 중 하나는 &lt;strong>SQL을 네이티브로 지원&lt;/strong>한다는 점이었습니다. MySQL 프로토콜과 호환되어 기존에 사용하던 MySQL 클라이언트로 바로 접속하고, 익숙한 SQL로 검색 쿼리를 작성할 수 있었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- Elasticsearch의 JSON DSL 대신 이런 SQL을 사용할 수 있습니다.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">poi&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">MATCH&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;강남역&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/zqywde80vp8pkzuewyz2c/manticore-sql-example.png?rlkey=p97zv65ncxpq4059mllw8u8w7&amp;amp;st=bvjclmbw&amp;amp;raw=1" alt="manticore-sql" loading="lazy" />&lt;/p>
&lt;p>뿐만 아니라, 현대적인 웹 서비스 아키텍처에 필수적인 &lt;strong>HTTP JSON API&lt;/strong>도 기본적으로 지원합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># curl을 이용한 HTTP API 검색 요청 예시&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">curl -X POST &lt;span class="s1">&amp;#39;http://127.0.0.1:9308/search&amp;#39;&lt;/span> -H &lt;span class="s1">&amp;#39;Content-Type: application/json&amp;#39;&lt;/span> -d &lt;span class="s1">&amp;#39;{
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s1"> &amp;#34;index&amp;#34;: &amp;#34;poi&amp;#34;,
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s1"> &amp;#34;query&amp;#34;: {
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s1"> &amp;#34;match&amp;#34;: { &amp;#34;name&amp;#34;: &amp;#34;강남역&amp;#34; }
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s1"> }
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s1">}&amp;#39;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;img src="https://www.dropbox.com/scl/fi/scanv3bz1eb7bap1avr41/manticore-http-example.png?rlkey=x01gm289tn0uris9xyf3w9a07&amp;amp;st=603zekxv&amp;amp;raw=1" alt="manticore-http" loading="lazy" />&lt;/p>
&lt;h2>다른 검색 엔진과의 비교: 왜 Manticore였나?&lt;span class="hx:absolute hx:-mt-20" id="다른-검색-엔진과의-비교-왜-manticore였나">&lt;/span>
&lt;a href="#%eb%8b%a4%eb%a5%b8-%ea%b2%80%ec%83%89-%ec%97%94%ec%a7%84%ea%b3%bc%ec%9d%98-%eb%b9%84%ea%b5%90-%ec%99%9c-manticore%ec%98%80%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>Elasticsearch 외에도 저희는 &lt;strong>Meilisearch&lt;/strong>, &lt;strong>Typesense&lt;/strong> 같은 다른 경량 검색 엔진들도 함께 검토했습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th style="text-align: left">항목&lt;/th>
&lt;th style="text-align: left">Manticore Search&lt;/th>
&lt;th style="text-align: left">Meilisearch&lt;/th>
&lt;th style="text-align: left">Typesense&lt;/th>
&lt;th style="text-align: left">Elasticsearch&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td style="text-align: left">&lt;strong>개발 언어&lt;/strong>&lt;/td>
&lt;td style="text-align: left">C++&lt;/td>
&lt;td style="text-align: left">Rust&lt;/td>
&lt;td style="text-align: left">C++&lt;/td>
&lt;td style="text-align: left">Java&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align: left">&lt;strong>데이터 동기화&lt;/strong>&lt;/td>
&lt;td style="text-align: left">&lt;strong>Pull&lt;/strong> (DB → 검색엔진)&lt;/td>
&lt;td style="text-align: left">&lt;strong>Push&lt;/strong> (App → 검색엔진)&lt;/td>
&lt;td style="text-align: left">&lt;strong>Push&lt;/strong> (App → 검색엔진)&lt;/td>
&lt;td style="text-align: left">&lt;strong>Push&lt;/strong> (App/Logstash → 검색엔진)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align: left">&lt;strong>장점&lt;/strong>&lt;/td>
&lt;td style="text-align: left">SQL 네이티브, 낮은 리소스&lt;/td>
&lt;td style="text-align: left">쉬운 사용성, 빠른 개발&lt;/td>
&lt;td style="text-align: left">빠른 검색 속도(In-Memory)&lt;/td>
&lt;td style="text-align: left">풍부한 생태계, 분석 기능&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="text-align: left">&lt;strong>단점&lt;/strong>&lt;/td>
&lt;td style="text-align: left">작은 생태계, 국내 인지도&lt;/td>
&lt;td style="text-align: left">대규모 데이터 처리 한계&lt;/td>
&lt;td style="text-align: left">데이터 크기가 RAM에 제한&lt;/td>
&lt;td style="text-align: left">높은 리소스, 복잡성&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Elasticsearch, Meilisearch, Typesense는 모두 어플리케이션에서 API를 호출하여 데이터를 &lt;strong>Push&lt;/strong>하는 방식에 최적화되어 있다고 알고있습니다.&lt;/p>
&lt;p>반면, 저희가 사용한 Manticore의 &lt;code>Plain&lt;/code> 인덱스는 &lt;code>indexer&lt;/code>가 주기적으로 DB에서 데이터를 &lt;strong>Pull&lt;/strong>하여 인덱스를 재생성하는 방식에 더 특화되어 있었습니다.&lt;/p>
&lt;p>저희의 요구사항은 &lt;strong>&amp;lsquo;운영 DB의 특정 테이블들이 변경되면, 검색 엔진에도 주기적으로 반영되는&amp;rsquo;&lt;/strong> 것이었습니다. 이 경우 Push 모델을 사용하려면 DB 변경을 감지하고 API를 호출하는 별도의 동기화 로직을 어플리케이션에 구현해야 합니다. ( 에필로그에서 다루지만 Elasticsearch로 마이그레이션 하면서 Spring Batch로 이 로직을 구현했습니다. )&lt;/p>
&lt;p>반면 Manticore의 Pull 모델은 이 과정을 검색 엔진의 책임으로 위임하여 어플리케이션 로직을 단순하게 유지할 수 있다는 점에서 저희에게 더 적합하다고 판단했습니다.&lt;/p>
&lt;p>아래는 두 데이터 동기화 방식의 차이를 다이어그램으로 나타낸 것입니다.&lt;/p>
&lt;h4>Push Model&lt;span class="hx:absolute hx:-mt-20" id="push-model">&lt;/span>
&lt;a href="#push-model" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;blockquote>
&lt;p>&lt;code>Push&lt;/code> 모델에서는 데이터 동기화의 책임이 &lt;strong>어플리케이션&lt;/strong>에 있습니다. 어플리케이션이 DB 변경을 감지하고, 검색 엔진의 API를 호출하여 데이터를 밀어넣어줘야 합니다.
예를 들면 Spring Batch 와 같은 서비스로 구현할 수 있겠죠.&lt;/p>
&lt;/blockquote>
&lt;pre class="mermaid hx:mt-6">
graph LR;
DB[(Database)] -- &amp;#34;1. Data Changed&amp;#34; --&amp;gt; App{&amp;#34;Application&amp;lt;br/&amp;gt;with Sync Logic&amp;#34;};
App -- &amp;#34;2. Push Data&amp;#34; --&amp;gt; SE[&amp;#34;Search Engine&amp;lt;br/&amp;gt;(ex. ElasticSearch)&amp;#34;];
&lt;/pre>&lt;h4>Pull Model&lt;span class="hx:absolute hx:-mt-20" id="pull-model">&lt;/span>
&lt;a href="#pull-model" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;blockquote>
&lt;p>&lt;code>Pull&lt;/code> 모델에서는 데이터 동기화의 책임이 &lt;strong>검색 엔진&lt;/strong>에 있습니다. 어플리케이션은 검색 요청만 담당하고, Manticore Search의 &lt;code>Indexer&lt;/code>가 주기적으로 DB에서 데이터를 가져와(Pull) 인덱스를 최신 상태로 유지합니다.&lt;/p>
&lt;/blockquote>
&lt;pre class="mermaid hx:mt-6">
graph LR;
DB[(Database)];
App{&amp;#34;Application&amp;lt;br/&amp;gt;(Search Only)&amp;#34;} -- &amp;#34;Search Query&amp;#34; --&amp;gt; MS[&amp;#34;Manticore Search&amp;#34;];
MS -- &amp;#34;Pulls Data Periodically&amp;#34; --&amp;gt; DB;
&lt;/pre>&lt;h2>실전 배포 및 인덱싱 자동화&lt;span class="hx:absolute hx:-mt-20" id="실전-배포-및-인덱싱-자동화">&lt;/span>
&lt;a href="#%ec%8b%a4%ec%a0%84-%eb%b0%b0%ed%8f%ac-%eb%b0%8f-%ec%9d%b8%eb%8d%b1%ec%8b%b1-%ec%9e%90%eb%8f%99%ed%99%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이제 실제 운영 환경에서 Manticore Search를 어떻게 배포하고 인덱싱을 자동화했는지, &lt;strong>Docker Compose&lt;/strong>를 사용한 방법과 &lt;strong>Kubernetes&lt;/strong>를 사용한 두 가지 방법을 공유하려 합니다.&lt;/p>
&lt;h3>방법 1: Docker Compose로 개발 환경 구성하기&lt;span class="hx:absolute hx:-mt-20" id="방법-1-docker-compose로-개발-환경-구성하기">&lt;/span>
&lt;a href="#%eb%b0%a9%eb%b2%95-1-docker-compose%eb%a1%9c-%ea%b0%9c%eb%b0%9c-%ed%99%98%ea%b2%bd-%ea%b5%ac%ec%84%b1%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>로컬 개발 환경이나 단일 서버 배포 시에는 Docker Compose를 사용하는 것이 매우 간편합니다. 저희가 실제 사용했던 구성을 단순화한 예시입니다.&lt;/p>
&lt;h4>1. &lt;code>docker-compose.yml&lt;/code>&lt;span class="hx:absolute hx:-mt-20" id="1-docker-composeyml">&lt;/span>
&lt;a href="#1-docker-composeyml" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div class="hextra-code-filename not-prose" dir="auto">docker-compose.yml&lt;/div>&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">version&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;3.8&amp;#39;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">services&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">manticore&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">build&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">context&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">dockerfile&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">Dockerfile.manticore&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">container_name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">manticore&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">restart&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">unless-stopped&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">ports&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="s2">&amp;#34;9306:9306&amp;#34;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># MySQL protocol&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="s2">&amp;#34;9308:9308&amp;#34;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># HTTP API&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">volumes&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># 데이터, 설정, 로그를 호스트와 공유하여 영속성 확보&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">./manticore-data:/var/lib/manticore&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">./manticore.conf:/etc/manticoresearch/manticore.conf&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">./manticore-logs:/var/log/manticore&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># 대규모 검색 환경에서 파일 디스크립터 한계를 늘려 성능 문제 방지&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">ulimits&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">nofile&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">soft&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">65536&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">hard&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">65536&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-8">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div class="hextra-code-filename not-prose" dir="auto">manticore.conf&lt;/div>&lt;div>&lt;pre>&lt;code># 1. searchd 데몬 기본 설정
searchd {
listen = 9306:mysql41 # MySQL 프로토콜
listen = 9308:http # HTTP API 포트
pid_file = /var/run/manticore/searchd.pid
log = /var/log/manticore/searchd.log
query_log = /var/log/manticore/query.log
}
# 2. 데이터 소스(Source) 설정 예시
source poi_src
{
type = mysql
sql_host = YOUR_DB_HOST
sql_user = YOUR_DB_USER
sql_pass = YOUR_DB_PASSWORD
sql_db = YOUR_DB_NAME
sql_query = \
SELECT station_id AS id, station_name, line_name \
FROM station_table_example
sql_attr_string = line_name
}
# 3. 인덱스(Index) 설정 예시
index poi {
source = poi_src
path = /var/lib/manticore/poi
# --- 한글 검색을 위한 핵심 설정 ---
charset_table = 0..9, A..Z-&amp;gt;a..z, a..z
infix_fields = station_name
min_infix_len = 2
ngram_len = 2
ngram_chars = U&amp;#43;AC00..U&amp;#43;D7AF, U&amp;#43;1100..U&amp;#43;11FF, U&amp;#43;3130..U&amp;#43;318F
}&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-8">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h4>2. &lt;code>Dockerfile.manticore&lt;/code> &amp;amp; &lt;code>start.sh&lt;/code>&lt;span class="hx:absolute hx:-mt-20" id="2-dockerfilemanticore--startsh">&lt;/span>
&lt;a href="#2-dockerfilemanticore--startsh" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>Manticore 컨테이너 내에서 &lt;code>cron&lt;/code>을 설정하여 인덱싱을 자동화합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div class="hextra-code-filename not-prose" dir="auto">Dockerfile&lt;/div>&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-dockerfile" data-lang="dockerfile">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># Dockerfile.manticore&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="s"> manticoresearch/manticore:latest&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="c"># cron 설치 및 로그 파일 생성&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="k">RUN&lt;/span> apt-get update &lt;span class="o">&amp;amp;&amp;amp;&lt;/span> apt-get install -y cron &lt;span class="o">&amp;amp;&amp;amp;&lt;/span> &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> touch /var/log/manticore/cron.log&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="c"># cron 작업 설정 (매시간 인덱스 갱신)&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="k">RUN&lt;/span> &lt;span class="nb">echo&lt;/span> &lt;span class="s2">&amp;#34;0 * * * * indexer poi --config /etc/manticoresearch/manticore.conf --rotate &amp;gt;&amp;gt; /var/log/manticore/cron.log 2&amp;gt;&amp;amp;1 &amp;amp;&amp;amp; mysql -h 127.0.0.1 -P9306 -e \&amp;#34;RELOAD INDEXES;\&amp;#34; &amp;gt;&amp;gt; /var/log/manticore/cron.log 2&amp;gt;&amp;amp;1&amp;#34;&lt;/span> &amp;gt; /etc/cron.d/manticore-indexer&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="k">RUN&lt;/span> chmod &lt;span class="m">0644&lt;/span> /etc/cron.d/manticore-indexer&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="k">RUN&lt;/span> crontab /etc/cron.d/manticore-indexer&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="c"># 시작 스크립트 복사 및 권한 부여&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="k">COPY&lt;/span> start.sh /start.sh&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="k">RUN&lt;/span> chmod +x /start.sh&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="k">CMD&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;/start.sh&amp;#34;&lt;/span>&lt;span class="p">]&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-8">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div class="hextra-code-filename not-prose" dir="auto">start.sh&lt;/div>&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;span class="lnt">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># start.sh&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">#!/bin/bash&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">set&lt;/span> -e
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># cron 서비스 시작&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">service cron start
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Manticore를 포어그라운드로 실행&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">exec&lt;/span> searchd --nodetach&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-8">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 방식은 모든 인프라 설정을 코드(IaC)로 관리하고, &lt;code>docker-compose up&lt;/code> 명령어 하나로 동일한 개발 환경을 쉽게 구축할 수 있다는 장점이 있다고 생각했습니다.&lt;/p>
&lt;hr>
&lt;h3>방법 2: Kubernetes로 프로덕션 환경 배포하기&lt;span class="hx:absolute hx:-mt-20" id="방법-2-kubernetes로-프로덕션-환경-배포하기">&lt;/span>
&lt;a href="#%eb%b0%a9%eb%b2%95-2-kubernetes%eb%a1%9c-%ed%94%84%eb%a1%9c%eb%8d%95%ec%85%98-%ed%99%98%ea%b2%bd-%eb%b0%b0%ed%8f%ac%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>저희의 실제 프로덕션 환경 구성 방식입니다. 인덱싱 자동화의 책임을 Kubernetes의 &lt;code>CronJob&lt;/code> 리소스가 아닌 &lt;strong>Manticore 컨테이너 자체&lt;/strong>에 부여했습니다. 배포와 관련된 모든 책임을 하나의 &lt;code>Deployment&lt;/code>로 통일하여 관리를 더 쉽게 하기 위함이었습니다.&lt;/p>
&lt;h4>1. &lt;code>manticore.conf&lt;/code> (ConfigMap 예시)&lt;span class="hx:absolute hx:-mt-20" id="1-manticoreconf-configmap-예시">&lt;/span>
&lt;a href="#1-manticoreconf-configmap-%ec%98%88%ec%8b%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>블로그 예시에 맞게 &lt;strong>하나의 소스와 하나의 인덱스&lt;/strong>로 간결하게 구성했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div class="hextra-code-filename not-prose" dir="auto">configmap.yaml&lt;/div>&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">apiVersion&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">v1&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">kind&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">ConfigMap&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">metadata&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">manticore-search-config&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">data&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">manticore.conf&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">|&lt;/span>&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> # 1. searchd 데몬 기본 설정
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> searchd {
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> listen = 9306:mysql41 # MySQL 프로토콜
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> listen = 9308:http # HTTP API 포트
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> pid_file = /var/run/manticore/searchd.pid
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> log = /var/log/manticore/searchd.log
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> query_log = /var/log/manticore/query.log
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> }
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> # 2. 데이터 소스(Source) 설정 예시
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> source poi_src
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> {
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> type = mysql
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> sql_host = YOUR_DB_HOST
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> sql_user = YOUR_DB_USER
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> sql_pass = YOUR_DB_PASSWORD
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> sql_db = YOUR_DB_NAME
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> sql_query = \
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> SELECT station_id AS id, station_name, line_name \
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> FROM station_table_example
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> sql_attr_string = line_name
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> }
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> # 3. 인덱스(Index) 설정 예시
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> index poi {
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> source = poi_src
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> path = /var/lib/manticore/poi
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> # --- 한글 검색을 위한 핵심 설정 ---
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> charset_table = 0..9, A..Z-&amp;gt;a..z, a..z
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> infix_fields = station_name
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> min_infix_len = 2
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> ngram_len = 2
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> ngram_chars = U+AC00..U+D7AF, U+1100..U+11FF, U+3130..U+318F
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> }&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-8">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h4>2. &lt;code>Dockerfile&lt;/code> 과 &lt;code>start.sh&lt;/code>&lt;span class="hx:absolute hx:-mt-20" id="2-dockerfile-과-startsh">&lt;/span>
&lt;a href="#2-dockerfile-%ea%b3%bc-startsh" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>Kubernetes 환경에서도 Docker Compose 방식과 유사한 &lt;code>Dockerfile&lt;/code>과 &lt;code>start.sh&lt;/code>를 사용하여, 컨테이너가 자체적으로 인덱싱 스케줄링을 담당하도록 이미지를 빌드합니다. &lt;code>start.sh&lt;/code>에 &lt;strong>초기 인덱싱 로직&lt;/strong>을 추가해줬습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div class="hextra-code-filename not-prose" dir="auto">Dockerfile&lt;/div>&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-dockerfile" data-lang="dockerfile">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># Dockerfile&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="s"> manticoresearch/manticore:latest&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="c"># cron, flock(util-linux) 설치&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="k">RUN&lt;/span> apt-get update &lt;span class="o">&amp;amp;&amp;amp;&lt;/span> apt-get install -y cron util-linux&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="c"># cron 작업 설정 (로그 포함 및 중복 실행 방지)&lt;/span>&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="k">RUN&lt;/span> &lt;span class="nb">echo&lt;/span> &lt;span class="s2">&amp;#34;0 * * * * /usr/bin/flock -n /var/run/manticore-indexer.lock /bin/bash -c &amp;#39;...&amp;#39; &amp;#34;&lt;/span> &amp;gt; /etc/cron.d/manticore-indexer&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="k">COPY&lt;/span> start.sh /start.sh&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="k">RUN&lt;/span> chmod +x /start.sh&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="err">&lt;/span>&lt;span class="k">CMD&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;/start.sh&amp;#34;&lt;/span>&lt;span class="p">]&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-8">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div class="hextra-code-filename not-prose" dir="auto">start.sh&lt;/div>&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># start.sh (개선된 버전)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">#!/bin/bash&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">set&lt;/span> -e
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">service cron start
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Pod가 처음 생성될 때 인덱스 파일이 없다면 초기 인덱싱 실행 (Cold Start 문제 해결)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">if&lt;/span> &lt;span class="o">[&lt;/span> ! -f /var/lib/manticore/poi.sph &lt;span class="o">]&lt;/span>&lt;span class="p">;&lt;/span> &lt;span class="k">then&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nb">echo&lt;/span> &lt;span class="s2">&amp;#34;No existing index found. Running initial indexing...&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> indexer poi --config /etc/manticoresearch/manticore.conf
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">fi&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">exec&lt;/span> searchd --nodetach&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-8">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h4>3. &lt;code>Deployment.yaml&lt;/code>&lt;span class="hx:absolute hx:-mt-20" id="3-deploymentyaml">&lt;/span>
&lt;a href="#3-deploymentyaml" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div class="hextra-code-filename not-prose" dir="auto">deployment.yaml&lt;/div>&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">apiVersion&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">apps/v1&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">kind&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">Deployment&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">metadata&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">manticore-search-prod&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">spec&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">replicas&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">2&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">template&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">spec&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># 컨테이너 시작 전, 볼륨의 소유권을 Manticore 프로세스(uid 999)에 부여&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">initContainers&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">init-permissions&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">image&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">busybox:1.36&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">command&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;sh&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;-c&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;chown -R 999:999 /var/lib/manticore&amp;#34;&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">volumeMounts&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">manticore-data&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">mountPath&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">/var/lib/manticore&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">containers&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">manticore-search&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">image&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">YOUR_CUSTOM_MANTICORE_IMAGE:TAG&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">ports&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">containerPort&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">9306&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">containerPort&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">9308&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">volumeMounts&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">manticore-data&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">mountPath&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">/var/lib/manticore&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">manticore-search-config&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">mountPath&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">/etc/manticoresearch/manticore.conf&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">subPath&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">manticore.conf&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">resources&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">requests&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">cpu&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">200m&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">memory&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">512Mi&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">limits&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">cpu&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">500m&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">memory&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">1Gi&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># Liveness: 컨테이너가 응답하지 않으면 재시작&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">livenessProbe&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">tcpSocket&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>{&lt;span class="w"> &lt;/span>&lt;span class="nt">port&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">9306&lt;/span>&lt;span class="w"> &lt;/span>}&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">initialDelaySeconds&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">30&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># Readiness: 프로브 성공 전까지 서비스 트래픽을 받지 않음&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">readinessProbe&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">tcpSocket&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>{&lt;span class="w"> &lt;/span>&lt;span class="nt">port&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">9306&lt;/span>&lt;span class="w"> &lt;/span>}&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">initialDelaySeconds&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">10&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-8">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h2>한글 검색, 삽질의 기록&lt;span class="hx:absolute hx:-mt-20" id="한글-검색-삽질의-기록">&lt;/span>
&lt;a href="#%ed%95%9c%ea%b8%80-%ea%b2%80%ec%83%89-%ec%82%bd%ec%a7%88%ec%9d%98-%ea%b8%b0%eb%a1%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>한글 토큰화 과정에서 저희는 &lt;code>ngram_len&lt;/code> 값을 두고 고민했습니다. 공식 문서에서는 &lt;code>ngram_len=1&lt;/code>을 권장하는 경우가 많았지만, 저희 데이터셋의 특성과 주요 검색어들을 분석했을 때, &amp;lsquo;강남&amp;rsquo;, &amp;lsquo;서초&amp;rsquo; 처럼 두 글자 단위의 검색이 더 자연스럽고 정확도가 높다고 판단했습니다. 그래서 최종적으로 &lt;strong>&lt;code>ngram_len=2&lt;/code>&lt;/strong> (2글자씩 자르기)로 결정했습니다.&lt;/p>
&lt;p>정해진 답을 따르기보다는, 실제 데이터와 유저의 검색 패턴을 분석하여 우리 서비스에 맞는 설정을 찾아가는 과정이 중요하다고 생각합니다.&lt;/p>
&lt;h2>우리가 겪었던 문제들&lt;span class="hx:absolute hx:-mt-20" id="우리가-겪었던-문제들">&lt;/span>
&lt;a href="#%ec%9a%b0%eb%a6%ac%ea%b0%80-%ea%b2%aa%ec%97%88%eb%8d%98-%eb%ac%b8%ec%a0%9c%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;ol>
&lt;li>&lt;strong>초기 인덱싱 속도 저하&lt;/strong>: 원인은 &lt;strong>Source DB의 &lt;code>sql_query&lt;/code> 성능 문제&lt;/strong>였습니다. 쿼리를 튜닝하고 인덱스를 추가하여 해결했습니다.&lt;/li>
&lt;li>&lt;strong>Kibana의 부재&lt;/strong>: Grafana 연동 등을 고려하고 있지만, 아직 만족스러운 시각화/모니터링 해결책을 찾지는 못했습니다.&lt;/li>
&lt;li>&lt;strong>한글+영문/숫자 혼용 검색&lt;/strong>: &lt;code>charset_table&lt;/code>에 영문과 숫자를 포함시켜 해결했습니다.&lt;/li>
&lt;/ol>
&lt;h2>제가 느낀 Manticore Search의 장단점&lt;span class="hx:absolute hx:-mt-20" id="제가-느낀-manticore-search의-장단점">&lt;/span>
&lt;a href="#%ec%a0%9c%ea%b0%80-%eb%8a%90%eb%82%80-manticore-search%ec%9d%98-%ec%9e%a5%eb%8b%a8%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>장점&lt;span class="hx:absolute hx:-mt-20" id="장점">&lt;/span>
&lt;a href="#%ec%9e%a5%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;strong>가벼운 리소스 사용량&lt;/strong>: 적은 메모리와 CPU로도 충분히 운영이 가능했습니다.&lt;/li>
&lt;li>&lt;strong>Pull 인덱싱 모델&lt;/strong>: 별도 시스템을 구축할 필요 없이 인덱싱 자동화가 가능하다는 점에서 구성하기 매우 편리했습니다.&lt;/li>
&lt;li>&lt;strong>빠른 검색 성능&lt;/strong>: 벤치마크 결과뿐만 아니라 실제 운영 환경에서도 만족스러운 검색 속도를 경험했습니다.&lt;/li>
&lt;li>&lt;strong>한글 검색 지원&lt;/strong>: 공식 문서의 도움으로 한글 토큰화 설정을 비교적 쉽게 적용할 수 있었습니다.&lt;/li>
&lt;/ul>
&lt;h3>단점&lt;span class="hx:absolute hx:-mt-20" id="단점">&lt;/span>
&lt;a href="#%eb%8b%a8%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;strong>작은 생태계&lt;/strong>: Elasticsearch에 비해 커뮤니티와 자료가 적어, 문제 해결에 시간이 더 걸리는 경우가 있다고 느껴졌습니다.&lt;/li>
&lt;li>&lt;strong>제한된 고급 기능&lt;/strong>: 복잡한 분석 기능이나 임베딩 검색 등에 대한 지원이 부족하다고 느껴졌습니다. 물론 있는 기능들도 있지만 레퍼런스가 적어 리스크를 감수해야 했습니다. (에필로그에서 다루겠지만, 결국 저희는 RAG 시스템 구축을 위해 Elasticsearch로 이전하게 되었습니다.)&lt;/li>
&lt;li>&lt;strong>모니터링 도구 부족&lt;/strong>: Kibana와 같은 시각화 도구가 없어, 로그 분석과 모니터링에 어려움이 있었습니다.&lt;/li>
&lt;/ul>
&lt;h2>결론: 문제에 맞는 도구를 선택하는 여정&lt;span class="hx:absolute hx:-mt-20" id="결론-문제에-맞는-도구를-선택하는-여정">&lt;/span>
&lt;a href="#%ea%b2%b0%eb%a1%a0-%eb%ac%b8%ec%a0%9c%ec%97%90-%eb%a7%9e%eb%8a%94-%eb%8f%84%ea%b5%ac%eb%a5%bc-%ec%84%a0%ed%83%9d%ed%95%98%eb%8a%94-%ec%97%ac%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>저희 팀은 비용과 복잡성이라는 현실적인 문제에서 출발해, Manticore Search라는 비교적 훌륭한 대안을 찾았다 생각합니다.&lt;/p>
&lt;p>Elasticsearch가 제공하는 모든 기능이 필요하지 않다면, Manticore Search는 훨씬 적은 비용과 노력으로 훌륭한 검색 기능을 구현할 수 있는 방법이 될 수 있다고 생각합니다.&lt;/p>
&lt;p>국내에 Manticore Search 관련 레퍼런스가 많지 않아 이 글이 도입을 고려하시는 분들께 조금이나마 도움이 됐으면 합니다. 궁금한 점이나 잘못된 내용이 있다면 편하게 댓글 남겨주세요!&lt;/p>
&lt;h2>에필로그: Elasticsearch의 품으로&lt;span class="hx:absolute hx:-mt-20" id="에필로그-elasticsearch의-품으로">&lt;/span>
&lt;a href="#%ec%97%90%ed%95%84%eb%a1%9c%ea%b7%b8-elasticsearch%ec%9d%98-%ed%92%88%ec%9c%bc%eb%a1%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이 글을 작성한 시점 이후, 저희 팀의 기술 스택에는 또 한 번의 변화가 있었습니다. 저희는 결국 Elasticsearch를 선택하게 됐습니다. Manticore Search에 만족하며 사용하고 있었지만, &lt;strong>RAG(Retrieval-Augmented Generation) 시스템을 새롭게 구축&lt;/strong>하는 과정에서 기술적인 요구사항이 달라졌기 때문입니다.&lt;/p>
&lt;p>RAG 시스템의 핵심인 임베딩 벡터 검색과 앞으로의 확장성 측면에서, Elasticsearch가 제공하는 풍부한 기능과 생태계가 더 유리하다고 판단했습니다.&lt;/p>
&lt;p>그러나 지금도 여전히 &lt;strong>&amp;lsquo;가볍고 빠른 검색&amp;rsquo;&lt;/strong> 만이 목적이고 &lt;code>Pull&lt;/code> 방식의 인덱싱을 지원하는 툴을 찾고 계시다면 Manticore Search는 훌륭한 선택지가 될 수 있다고 생각합니다.&lt;/p>
&lt;p>Elasticsearch는 저희의 새로운 요구사항이였던 &amp;lsquo;복잡하고 다양한 검색 지원 (ex. 임베딩 기반 유사도 검색 및 여러 파라미터 검색)&amp;lsquo;이라는 문제에 대해서는 더 나은 도구가 되지 않나 싶습니다. ( 이 과정에서 인덱싱은 위에서 언급한대로 spring batch를 통해 구현했습니다. )&lt;/p>
&lt;p>Manticore Search에서 Elasticsearch로 이전하며 겪었던 경험과 RAG 시스템 구축에 대한 이야기는 다음 기회에 다른 글에서 자세히 다뤄보도록 하겠습니다.&lt;/p>
&lt;h2>Reference&lt;span class="hx:absolute hx:-mt-20" id="reference">&lt;/span>
&lt;a href="#reference" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;ul>
&lt;li>&lt;a href="https://manticoresearch.com/"target="_blank" rel="noopener">Manticore Search 공식 사이트&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/manticoresoftware/manticoresearch"target="_blank" rel="noopener">Manticore Search GitHub&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://manticoresearch.com/comparison/vs-elasticsearch/"target="_blank" rel="noopener">Manticore Search vs Elasticsearch 비교&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://manual.manticoresearch.com/Creating_a_table/NLP_and_tokenization/Data_tokenization"target="_blank" rel="noopener">Manticore Search Manual - NLP and tokenization&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://db-benchmarks.com"target="_blank" rel="noopener">db-benchmarks.com - Independent Database Benchmarks&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>배포만 하면 느려지는 API, JVM Cold Start 문제 85% 개선하기</title><link>https://jeongil.dev/ko/blog/backend/performance/k8s-jvm-warm-up/</link><pubDate>Tue, 18 Nov 2025 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/backend/performance/k8s-jvm-warm-up/</guid><description>
&lt;h2>들어가며&lt;span class="hx:absolute hx:-mt-20" id="들어가며">&lt;/span>
&lt;a href="#%eb%93%a4%ec%96%b4%ea%b0%80%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>최근 저희 팀은 Docker Compose 기반의 운영 환경을 쿠버네티스로 전환했습니다.
확장성, 자동화, 무중단 배포 등 MSA 환경에서 필요한 기능들을 제대로 활용하기 위한 선택이었죠.&lt;/p>
&lt;blockquote>
&lt;p>관련 글: &lt;a href="https://jeongil.dev/ko/blog/infrastructure/docker-compose-to-k8s/">개발 서버도 없던 팀이 GitOps를 갖추기까지: 맨땅에서 시작한 쿠버네티스 도입기&lt;/a>&lt;/p>
&lt;/blockquote>
&lt;p>전환 후 메트릭을 살펴보다가, 묘한 패턴을 발견했습니다.
배포 직후 몇 분간 첫 API 요청이 유독 느리다는 거였죠. 평소엔 &lt;code>100~200ms&lt;/code>인 응답이 배포 직후엔 &lt;code>1.2~1.4&lt;/code>초씩 걸리는 상황이었습니다. 😱&lt;/p>
&lt;p>&amp;ldquo;배포만 하면 느려지네?&amp;rdquo;&lt;/p>
&lt;p>처음엔 배포 과정의 문제인가 싶었는데, 시간이 지나면 자연스럽게 빨라지는 걸 보고 확신했습니다. &lt;strong>JVM Cold Start 문제&lt;/strong>였습니다.&lt;/p>
&lt;p>이 글은 Kubernetes의 &lt;code>startupProbe&lt;/code>와 JVM Warm-up을 &lt;strong>저희 서비스에 적용한 과정&lt;/strong>을 기록하고 공유하려 합니다.&lt;/p>
&lt;h2>문제: 배포 직후 첫 요청이 너무 느리다&lt;span class="hx:absolute hx:-mt-20" id="문제-배포-직후-첫-요청이-너무-느리다">&lt;/span>
&lt;a href="#%eb%ac%b8%ec%a0%9c-%eb%b0%b0%ed%8f%ac-%ec%a7%81%ed%9b%84-%ec%b2%ab-%ec%9a%94%ec%b2%ad%ec%9d%b4-%eb%84%88%eb%ac%b4-%eb%8a%90%eb%a6%ac%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>증상&lt;span class="hx:absolute hx:-mt-20" id="증상">&lt;/span>
&lt;a href="#%ec%a6%9d%ec%83%81" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>저희 회사 서비스는 MSA로 구성되어 있고, 각 서비스가 Spring Boot + Kotlin으로 작성되어 있습니다. 배포는 쿠버네티스 위에서 이루어지고있고
배포 직후 다음과 같은 현상이 반복되었습니다.&lt;/p>
&lt;ul>
&lt;li>첫 요청 API: &lt;strong>1.19~1.39s&lt;/strong> (1,190~1,390ms)&lt;/li>
&lt;li>두 번째 요청부터: &lt;strong>100~200ms&lt;/strong>&lt;/li>
&lt;/ul>
&lt;p>약 7~14배 차이였습니다. 😭&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/076ba38e-d0d8-476f-8a2b-99a030a43099/image.jpg" alt="" loading="lazy" />&lt;/p>
&lt;blockquote>
&lt;p>&lt;em>배포 직후 첫 요청 테스트 응답 시간 - 1,000ms~1,300ms&lt;/em>&lt;/p>
&lt;/blockquote>
&lt;h3>원인 분석&lt;span class="hx:absolute hx:-mt-20" id="원인-분석">&lt;/span>
&lt;a href="#%ec%9b%90%ec%9d%b8-%eb%b6%84%ec%84%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>JVM 기반 애플리케이션의 숙명이라고 할 수 있는 &lt;strong>JIT(Just In Time) 컴파일러&lt;/strong>의 특성 때문이었습니다.&lt;/p>
&lt;p>JVM은 처음 코드를 실행할 때 &lt;strong>인터프리터 모드&lt;/strong>로 동작합니다. 자주 사용되는 코드(Hot Spot)를 찾아내면 그제서야 &lt;strong>네이티브 코드로 최적화&lt;/strong>하는 구조죠. 즉, 첫 요청은 희생양이 되는 겁니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>단계&lt;/th>
&lt;th>실행 방식&lt;/th>
&lt;th>속도&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Cold Start (첫 실행)&lt;/td>
&lt;td>인터프리터 모드&lt;/td>
&lt;td>느림&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Warm-up 완료&lt;/td>
&lt;td>JIT 최적화 완료&lt;/td>
&lt;td>빠름&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>여기에 Kubernetes 환경의 특성이 더해집니다:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Pod는 언제든 재시작&lt;/strong>됩니다 (배포, 스케일링, 장애)&lt;/li>
&lt;li>&lt;strong>매번 새로운 JVM&lt;/strong>이 Cold Start 상태로 시작&lt;/li>
&lt;li>&lt;strong>첫번째 사용자 요청이 Warm-up 희생양&lt;/strong>이 됨&lt;/li>
&lt;/ol>
&lt;p>&amp;ldquo;이거 그냥 놔둘 수 없다&amp;quot;는 생각이 들었습니다.&lt;/p>
&lt;h2>기존에는 왜 문제가 안 됐을까?&lt;span class="hx:absolute hx:-mt-20" id="기존에는-왜-문제가-안-됐을까">&lt;/span>
&lt;a href="#%ea%b8%b0%ec%a1%b4%ec%97%90%eb%8a%94-%ec%99%9c-%eb%ac%b8%ec%a0%9c%ea%b0%80-%ec%95%88-%eb%90%90%ec%9d%84%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>사실 이 문제는 새로운 게 아니었습니다. Docker Compose로 운영할 때도 Cold Start는 있었죠.
하지만 컨테이너가 한 번 뜨면 오래 살아있었기 때문에, 배포 시에만 잠깐 문제가 됐을 뿐입니다.&lt;/p>
&lt;p>쿠버네티스는 다릅니다.&lt;/p>
&lt;p>Kubernetes는 Pod를 &lt;strong>&amp;ldquo;Cattle, not Pets&amp;rdquo;&lt;/strong> 로 대합니다. 언제든 죽일 수 있고, 죽을 수 있는 존재로 보는 거죠.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Rolling Update&lt;/strong>: 배포 시 새 Pod가 계속 생성됨&lt;/li>
&lt;li>&lt;strong>Auto Scaling&lt;/strong>: 부하에 따라 Pod가 늘었다 줄었다 함&lt;/li>
&lt;li>&lt;strong>Node 재시작&lt;/strong>: 인프라 이슈로 Pod가 재배치됨&lt;/li>
&lt;/ul>
&lt;p>즉, &lt;strong>Pod가 재생성되는 빈도가 훨씬 높아졌고&lt;/strong>, 그만큼 &lt;strong>사용자가 Cold Start 상태의 Pod에 요청을 보낼 확률도 높아진 겁니다&lt;/strong>.&lt;/p>
&lt;h2>해결 방법을 찾아서&lt;span class="hx:absolute hx:-mt-20" id="해결-방법을-찾아서">&lt;/span>
&lt;a href="#%ed%95%b4%ea%b2%b0-%eb%b0%a9%eb%b2%95%ec%9d%84-%ec%b0%be%ec%95%84%ec%84%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>&amp;ldquo;이거 우리만 겪는 문제는 아닐 텐데&amp;hellip;&amp;rdquo;&lt;/p>
&lt;p>검색을 시작했습니다. 역시나 많은 회사에서 이미 비슷한 문제를 겪고 해결했더라고요.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>OLX&lt;/strong>는 CPU 리소스를 동적으로 조정하는 방법을 공유했고&lt;/li>
&lt;li>&lt;strong>BlaBlaCar&lt;/strong>는 startupProbe + Warm-up 엔드포인트 패턴을 사용했고&lt;/li>
&lt;li>국내 기술 블로그에서도 실제 적용 사례를 찾을 수 있었습니다&lt;/li>
&lt;/ul>
&lt;p>&amp;ldquo;이게 표준 패턴이구나. 우리도 적용해보자&amp;rdquo;&lt;/p>
&lt;h2>해결 과정: startupProbe + JVM Warm-up&lt;span class="hx:absolute hx:-mt-20" id="해결-과정-startupprobe--jvm-warm-up">&lt;/span>
&lt;a href="#%ed%95%b4%ea%b2%b0-%ea%b3%bc%ec%a0%95-startupprobe--jvm-warm-up" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>전략&lt;span class="hx:absolute hx:-mt-20" id="전략">&lt;/span>
&lt;a href="#%ec%a0%84%eb%9e%b5" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>핵심 아이디어는 두 가지입니다:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Warm-up 실행&lt;/strong>: &amp;ldquo;사용자가 요청하기 전에 우리가 먼저 요청해서 JVM을 깨워놓자&amp;rdquo;&lt;/li>
&lt;li>&lt;strong>Warm-up 대기&lt;/strong>: &amp;ldquo;Kubernetes가 warm-up 완료를 기다리도록 &lt;code>startupProbe&lt;/code>를 설정하자&amp;rdquo;&lt;/li>
&lt;/ol>
&lt;p>startupProbe는 warm-up을 &lt;strong>실행하는 게 아니라&lt;/strong>, warm-up &lt;strong>완료를 확인하고 기다리는&lt;/strong> 역할을 합니다.&lt;/p>
&lt;h3>1단계: Kubernetes Probe 이해하기&lt;span class="hx:absolute hx:-mt-20" id="1단계-kubernetes-probe-이해하기">&lt;/span>
&lt;a href="#1%eb%8b%a8%ea%b3%84-kubernetes-probe-%ec%9d%b4%ed%95%b4%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Kubernetes에는 3가지 Probe가 있습니다:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Probe&lt;/th>
&lt;th>용도&lt;/th>
&lt;th>실패 시 동작&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>livenessProbe&lt;/strong>&lt;/td>
&lt;td>컨테이너가 살아있는지 확인&lt;/td>
&lt;td>Pod 재시작&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>readinessProbe&lt;/strong>&lt;/td>
&lt;td>트래픽을 받을 준비가 됐는지 확인&lt;/td>
&lt;td>Service에서 제외&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>startupProbe&lt;/strong>&lt;/td>
&lt;td>애플리케이션이 시작됐는지 확인&lt;/td>
&lt;td>성공할 때까지 다른 Probe 비활성화&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>우리가 필요한 건 &lt;strong>startupProbe&lt;/strong>입니다.&lt;/p>
&lt;p>&lt;strong>왜 startupProbe가 필요한가?&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>warm-up이 오래 걸리면(예: 1~2분) livenessProbe가 먼저 실패해서 Pod를 재시작시킬 수 있음&lt;/li>
&lt;li>startupProbe가 &lt;strong>성공할 때까지&lt;/strong> &lt;code>readinessProbe&lt;/code>와 &lt;code>livenessProbe&lt;/code>가 비활성화됨&lt;/li>
&lt;li>따라서 warm-up 시간을 안전하게 확보할 수 있음&lt;/li>
&lt;/ul>
&lt;h3>2단계: Warm-up 구현&lt;span class="hx:absolute hx:-mt-20" id="2단계-warm-up-구현">&lt;/span>
&lt;a href="#2%eb%8b%a8%ea%b3%84-warm-up-%ea%b5%ac%ed%98%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>여러 레퍼런스를 참고해 다음과 같이 구현했습니다.&lt;/p>
&lt;h4>(1) WarmupHealthIndicator 생성&lt;span class="hx:absolute hx:-mt-20" id="1-warmuphealthindicator-생성">&lt;/span>
&lt;a href="#1-warmuphealthindicator-%ec%83%9d%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>Spring Actuator와 통합되는 Health Indicator를 만듭니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Component&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">WarmupHealthIndicator&lt;/span> &lt;span class="p">:&lt;/span> &lt;span class="n">HealthIndicator&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">private&lt;/span> &lt;span class="k">val&lt;/span> &lt;span class="py">warmedUp&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">AtomicBoolean&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">false&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">override&lt;/span> &lt;span class="k">fun&lt;/span> &lt;span class="nf">health&lt;/span>&lt;span class="p">():&lt;/span> &lt;span class="n">Health&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">warmedUp&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">get&lt;/span>&lt;span class="p">())&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nc">Health&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">up&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="n">build&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span> &lt;span class="k">else&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nc">Health&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">down&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="n">withDetail&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;reason&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;warmup in progress&amp;#34;&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="n">build&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">fun&lt;/span> &lt;span class="nf">complete&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">warmedUp&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">set&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">true&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h4>(2) Warmup 로직 구현&lt;span class="hx:absolute hx:-mt-20" id="2-warmup-로직-구현">&lt;/span>
&lt;a href="#2-warmup-%eb%a1%9c%ec%a7%81-%ea%b5%ac%ed%98%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>애플리케이션 시작 시 자동으로 실행되도록 &lt;code>ContextRefreshedEvent&lt;/code>를 사용합니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;span class="lnt">45
&lt;/span>&lt;span class="lnt">46
&lt;/span>&lt;span class="lnt">47
&lt;/span>&lt;span class="lnt">48
&lt;/span>&lt;span class="lnt">49
&lt;/span>&lt;span class="lnt">50
&lt;/span>&lt;span class="lnt">51
&lt;/span>&lt;span class="lnt">52
&lt;/span>&lt;span class="lnt">53
&lt;/span>&lt;span class="lnt">54
&lt;/span>&lt;span class="lnt">55
&lt;/span>&lt;span class="lnt">56
&lt;/span>&lt;span class="lnt">57
&lt;/span>&lt;span class="lnt">58
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Component&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">WarmupRunner&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">private&lt;/span> &lt;span class="k">val&lt;/span> &lt;span class="py">warmupHealthIndicator&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">WarmupHealthIndicator&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">private&lt;/span> &lt;span class="k">val&lt;/span> &lt;span class="py">restTemplate&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">RestTemplate&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">)&lt;/span> &lt;span class="p">:&lt;/span> &lt;span class="n">ApplicationListener&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">ContextRefreshedEvent&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">private&lt;/span> &lt;span class="k">val&lt;/span> &lt;span class="py">logger&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="nc">LoggerFactory&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">getLogger&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">javaClass&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">private&lt;/span> &lt;span class="k">val&lt;/span> &lt;span class="py">executed&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">AtomicBoolean&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">false&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">override&lt;/span> &lt;span class="k">fun&lt;/span> &lt;span class="nf">onApplicationEvent&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">ContextRefreshedEvent&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 한 번만 실행되도록 보장
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">if&lt;/span> &lt;span class="p">(!&lt;/span>&lt;span class="n">executed&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">compareAndSet&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">false&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="k">true&lt;/span>&lt;span class="p">))&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">logger&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">info&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;Starting JVM warm-up...&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">val&lt;/span> &lt;span class="py">warmupRequests&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="n">listOf&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;/api/v1/users/profile&amp;#34;&lt;/span> &lt;span class="n">to&lt;/span> &lt;span class="nc">HttpMethod&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">GET&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;/api/v1/auth/validate&amp;#34;&lt;/span> &lt;span class="n">to&lt;/span> &lt;span class="nc">HttpMethod&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">POST&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;/api/v1/buildings/search&amp;#34;&lt;/span> &lt;span class="n">to&lt;/span> &lt;span class="nc">HttpMethod&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">POST&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;/api/v1/communities/popular&amp;#34;&lt;/span> &lt;span class="n">to&lt;/span> &lt;span class="nc">HttpMethod&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">GET&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">warmupRequests&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">forEach&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">path&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">method&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">repeat&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="m">10&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">try&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">when&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">method&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nc">HttpMethod&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">GET&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="n">restTemplate&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">getForEntity&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;http://localhost:8080&lt;/span>&lt;span class="si">$path&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">String&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="k">class&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">java&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nc">HttpMethod&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">POST&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="n">restTemplate&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">postForEntity&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;http://localhost:8080&lt;/span>&lt;span class="si">$path&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">createDummyRequest&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">path&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">String&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="k">class&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">java&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">else&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="p">{}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span> &lt;span class="k">catch&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">Exception&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// Warm-up 중 에러는 무시 (목적은 코드 실행이므로)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">logger&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">debug&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;Warm-up request failed (expected): &lt;/span>&lt;span class="si">${e.message}&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">warmupHealthIndicator&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">complete&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">logger&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">info&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;JVM warm-up completed!&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">private&lt;/span> &lt;span class="k">fun&lt;/span> &lt;span class="nf">createDummyRequest&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">path&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">String&lt;/span>&lt;span class="p">):&lt;/span> &lt;span class="n">Any&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="k">when&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">path&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">contains&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;auth&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="n">mapOf&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;token&amp;#34;&lt;/span> &lt;span class="n">to&lt;/span> &lt;span class="s2">&amp;#34;dummy&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">path&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">contains&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;search&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="n">mapOf&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;keyword&amp;#34;&lt;/span> &lt;span class="n">to&lt;/span> &lt;span class="s2">&amp;#34;테스트&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">else&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="n">emptyMap&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">Any&lt;/span>&lt;span class="p">&amp;gt;()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h4>(3) application.yml 설정&lt;span class="hx:absolute hx:-mt-20" id="3-applicationyml-설정">&lt;/span>
&lt;a href="#3-applicationyml-%ec%84%a4%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">management&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">endpoint&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">health&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">probes&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">enabled&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">group&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">readiness&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">include&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">warmup &lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># warmup을 readiness에 포함&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">liveness&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">exclude&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">warmup &lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># liveness에서는 제외&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>핵심 포인트&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>&lt;code>ContextRefreshedEvent&lt;/code>: HTTP 포트 오픈 전에 실행되어 warm-up 중 요청 유입 방지&lt;/li>
&lt;li>&lt;code>AtomicBoolean&lt;/code>: 동시성 제어로 중복 실행 방지&lt;/li>
&lt;li>&lt;code>HealthIndicator&lt;/code>: Kubernetes probe와 자연스럽게 통합&lt;/li>
&lt;li>&lt;strong>readiness에만 포함&lt;/strong>: warm-up 완료 전까지 트래픽 차단&lt;/li>
&lt;/ul>
&lt;h3>3단계: Kubernetes Probe 설정&lt;span class="hx:absolute hx:-mt-20" id="3단계-kubernetes-probe-설정">&lt;/span>
&lt;a href="#3%eb%8b%a8%ea%b3%84-kubernetes-probe-%ec%84%a4%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>중요: startupProbe는 필수입니다!&lt;/strong>&lt;/p>
&lt;p>warm-up이 오래 걸릴 경우 livenessProbe가 Pod를 재시작시킬 수 있기 때문에, startupProbe로 warm-up 완료를 기다려야 합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;span class="lnt">45
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">apiVersion&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">apps/v1&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">kind&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">Deployment&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">metadata&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">user-service&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">spec&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">template&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">spec&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">containers&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">user-service&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">image&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">example/user-service:latest&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">ports&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">containerPort&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">8080&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># startupProbe: warm-up 완료될 때까지 대기&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">startupProbe&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">httpGet&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">path&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">/actuator/health/readiness&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">port&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">8080&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">initialDelaySeconds&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">10&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">periodSeconds&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">5&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">failureThreshold&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">24&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># 최대 2분 (5초 × 24번)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># readinessProbe: startupProbe 성공 후 활성화&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">readinessProbe&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">httpGet&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">path&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">/actuator/health/readiness&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">port&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">8080&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">periodSeconds&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">5&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">failureThreshold&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">3&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># livenessProbe: startupProbe 성공 후 활성화&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">livenessProbe&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">httpGet&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">path&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">/actuator/health/liveness&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">port&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">8080&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">periodSeconds&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">10&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">failureThreshold&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">3&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">resources&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">requests&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">cpu&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">500m&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">memory&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">1Gi&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">limits&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">cpu&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">1800m &lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># Warm-up 시 CPU를 충분히 사용하도록&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">memory&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">2Gi&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>설정 의도&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>startupProbe&lt;/strong>: warm-up 완료를 기다리며, 완료될 때까지 다른 probe 비활성화&lt;/li>
&lt;li>&lt;code>/actuator/health/readiness&lt;/code>: warmup HealthIndicator 포함하여 warm-up 완료 전까지 DOWN 반환&lt;/li>
&lt;li>&lt;code>failureThreshold: 24&lt;/code>: 최대 2분 동안 warm-up 시간 보장&lt;/li>
&lt;li>&lt;strong>liveness에서 warmup 제외&lt;/strong>: warm-up이 길어져도 Pod 재시작 방지&lt;/li>
&lt;li>CPU &lt;code>limits: 1800m&lt;/code>: Warm-up 중 충분한 CPU 제공&lt;/li>
&lt;/ul>
&lt;h3>전체 동작 흐름&lt;span class="hx:absolute hx:-mt-20" id="전체-동작-흐름">&lt;/span>
&lt;a href="#%ec%a0%84%ec%b2%b4-%eb%8f%99%ec%9e%91-%ed%9d%90%eb%a6%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>위 설정들이 어떻게 협력하는지 전체 흐름을 살펴보겠습니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>1. Pod 시작
↓
2. Spring Boot 애플리케이션 시작
↓
3. ContextRefreshedEvent 발생
→ WarmupRunner가 warm-up 실행 시작
→ WarmupHealthIndicator는 DOWN 상태 유지
↓
4. Warm-up 진행 중...
→ 주요 API들을 10번씩 반복 호출
→ JIT 컴파일러가 코드 최적화
→ startupProbe가 5초마다 /actuator/health/readiness 체크
→ DOWN이므로 계속 대기 (최대 24번)
↓
5. Warm-up 완료
→ WarmupHealthIndicator.complete() 호출
→ WarmupHealthIndicator가 UP으로 변경
↓
6. startupProbe 성공
→ /actuator/health/readiness가 UP 반환
→ startupProbe 성공
↓
7. readinessProbe, livenessProbe 활성화
→ readinessProbe가 Service에 Pod 등록
↓
8. 트래픽 수신 시작
→ 이미 warm-up 완료된 상태로 요청 처리&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>핵심 포인트&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Warm-up 실행&lt;/strong>: &lt;code>ContextRefreshedEvent&lt;/code> 리스너가 담당&lt;/li>
&lt;li>&lt;strong>Warm-up 대기&lt;/strong>: &lt;code>startupProbe&lt;/code>가 담당&lt;/li>
&lt;li>startupProbe는 warm-up을 &lt;strong>실행하지 않고&lt;/strong>, warm-up &lt;strong>완료를 기다릴 뿐&lt;/strong>입니다&lt;/li>
&lt;/ul>
&lt;h3>4단계: CPU 리소스 최적화&lt;span class="hx:absolute hx:-mt-20" id="4단계-cpu-리소스-최적화">&lt;/span>
&lt;a href="#4%eb%8b%a8%ea%b3%84-cpu-%eb%a6%ac%ec%86%8c%ec%8a%a4-%ec%b5%9c%ec%a0%81%ed%99%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>여기서 중요한 발견이 있었습니다. 처음엔 CPU limit을 &lt;code>1000m&lt;/code>으로 설정했는데, Warm-up이 제대로 안 되더라고요.&lt;/p>
&lt;p>알고 보니 &lt;strong>JVM Warm-up 중에는 평소보다 3배 정도의 CPU&lt;/strong>가 필요했습니다. JIT 컴파일러가 코드를 최적화하면서 CPU를 많이 사용하거든요.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">resources&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">requests&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">cpu&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">500m &lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># 평상시 사용량&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">limits&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">cpu&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">1800m &lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># Warm-up 시를 고려한 넉넉한 설정&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>Kubernetes의 CGroup CPU Throttling 때문에 limit에 걸리면 Warm-up이 느려집니다. 그래서 &lt;strong>Warm-up 중엔 충분한 CPU를 보장&lt;/strong>하고, 평상시엔 &lt;code>requests&lt;/code>로 최소 리소스만 예약하도록 했습니다.&lt;/p>
&lt;h2>결과: 85% 개선&lt;span class="hx:absolute hx:-mt-20" id="결과-85-개선">&lt;/span>
&lt;a href="#%ea%b2%b0%ea%b3%bc-85-%ea%b0%9c%ec%84%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/a3e38702-1050-4404-b04f-a6b4bf1e63aa/image.png" alt="" loading="lazy" />&lt;/p>
&lt;blockquote>
&lt;p>&lt;em>Warm-up 적용 후 첫 요청 응답 시간 - 평균 150~230ms&lt;/em>&lt;/p>
&lt;/blockquote>
&lt;h3>Before (Cold Start)&lt;span class="hx:absolute hx:-mt-20" id="before-cold-start">&lt;/span>
&lt;a href="#before-cold-start" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>첫 요청 API: &lt;strong>1,190~1,390ms&lt;/strong>&lt;/li>
&lt;li>두 번째 요청: &lt;strong>100~200ms&lt;/strong>&lt;/li>
&lt;li>사용자 체감 불편함: 높음&lt;/li>
&lt;/ul>
&lt;h3>After (Warm-up 적용)&lt;span class="hx:absolute hx:-mt-20" id="after-warm-up-적용">&lt;/span>
&lt;a href="#after-warm-up-%ec%a0%81%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>첫 요청 API: &lt;strong>150~230ms&lt;/strong>&lt;/li>
&lt;li>두 번째 요청: &lt;strong>100~200ms&lt;/strong>&lt;/li>
&lt;li>사용자 체감 불편함: 없음&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>약 85% 개선&lt;/strong>되었고, 무엇보다 &lt;strong>첫 요청과 이후 요청의 차이가 대폭 줄어들었습니다&lt;/strong>.&lt;/p>
&lt;h3>긍정적 효과&lt;span class="hx:absolute hx:-mt-20" id="긍정적-효과">&lt;/span>
&lt;a href="#%ea%b8%8d%ec%a0%95%ec%a0%81-%ed%9a%a8%ea%b3%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ol>
&lt;li>&lt;strong>Auto Scaling 안정화&lt;/strong>: 새 Pod가 바로 트래픽을 처리할 수 있어서 스케일링이 부드러워짐&lt;/li>
&lt;li>&lt;strong>사용자 이탈 감소&lt;/strong>: 배포 시간대에 첫 페이지 로딩이 느려서 이탈하던 사용자들이 줄어듬&lt;/li>
&lt;/ol>
&lt;h2>적용 시 주의사항&lt;span class="hx:absolute hx:-mt-20" id="적용-시-주의사항">&lt;/span>
&lt;a href="#%ec%a0%81%ec%9a%a9-%ec%8b%9c-%ec%a3%bc%ec%9d%98%ec%82%ac%ed%95%ad" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>다른 회사들의 적용 사례를 보면 다음과 같은 점들을 주의해야 합니다.&lt;/p>
&lt;h3>1. 배포 시간 증가&lt;span class="hx:absolute hx:-mt-20" id="1-배포-시간-증가">&lt;/span>
&lt;a href="#1-%eb%b0%b0%ed%8f%ac-%ec%8b%9c%ea%b0%84-%ec%a6%9d%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>문제&lt;/strong>: Warm-up 때문에 Pod가 Ready 상태가 되는 시간이 늘어날 수 있습니다.&lt;/p>
&lt;p>&lt;strong>해결&lt;/strong>: Rolling Update 전략을 조정하면 됩니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">spec&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">strategy&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">type&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">RollingUpdate&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">rollingUpdate&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">maxSurge&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">1&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># 한 번에 1개씩만 새 Pod 생성&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">maxUnavailable&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">0&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># 기존 Pod는 새 Pod가 Ready될 때까지 유지&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이렇게 하면 배포는 조금 느려지지만, &lt;strong>무중단 배포가 보장&lt;/strong>됩니다.&lt;/p>
&lt;h3>2. 외부 API Warm-up&lt;span class="hx:absolute hx:-mt-20" id="2-외부-api-warm-up">&lt;/span>
&lt;a href="#2-%ec%99%b8%eb%b6%80-api-warm-up" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>문제&lt;/strong>: 외부 API를 Warm-up에 포함시키면 &lt;strong>외부 시스템에 불필요한 부하를 전파&lt;/strong>하게 됩니다.&lt;/p>
&lt;p>&lt;strong>해결&lt;/strong>: Warm-up은 &lt;strong>내부 API 또는 더미 데이터 처리 로직&lt;/strong>으로만 제한하는 게 좋습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;span class="lnt">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// ❌ 나쁜 예
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="n">repeat&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="m">10&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">externalApiClient&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">sendNotification&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="o">..&lt;/span>&lt;span class="p">.)&lt;/span> &lt;span class="c1">// 외부 시스템 부하!
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// ✅ 좋은 예
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="n">repeat&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="m">10&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">notificationService&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">validateRequest&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">dummyRequest&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="c1">// 내부 로직만 실행
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>3. DB 커넥션 이슈&lt;span class="hx:absolute hx:-mt-20" id="3-db-커넥션-이슈">&lt;/span>
&lt;a href="#3-db-%ec%bb%a4%eb%84%a5%ec%85%98-%ec%9d%b4%ec%8a%88" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>문제&lt;/strong>: Warm-up 중 DB 조회 API를 호출하면 커넥션 풀이 고갈될 수 있습니다.&lt;/p>
&lt;p>&lt;strong>해결&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>DB 조회가 필요한 API는 &lt;strong>모킹&lt;/strong>하거나&lt;/li>
&lt;li>커넥션 풀 크기를 조정하면 됩니다&lt;/li>
&lt;/ul>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">spring&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">datasource&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">hikari&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">maximum-pool-size&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">20&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># 기존 10 → 20으로 증가&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h2>배운 점&lt;span class="hx:absolute hx:-mt-20" id="배운-점">&lt;/span>
&lt;a href="#%eb%b0%b0%ec%9a%b4-%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>1. JVM 특성을 이해하는 게 중요하다&lt;span class="hx:absolute hx:-mt-20" id="1-jvm-특성을-이해하는-게-중요하다">&lt;/span>
&lt;a href="#1-jvm-%ed%8a%b9%ec%84%b1%ec%9d%84-%ec%9d%b4%ed%95%b4%ed%95%98%eb%8a%94-%ea%b2%8c-%ec%a4%91%ec%9a%94%ed%95%98%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Java/Kotlin을 쓴다고 해서 JVM을 모르고 넘어가면, 이런 성능 문제를 해결할 수 없습니다. JIT 컴파일러, GC, 클래스 로딩 등 &lt;strong>JVM 내부 동작 원리&lt;/strong>를 이해하는 게 중요하다는 걸 다시 느꼈습니다.&lt;/p>
&lt;h3>2. Kubernetes Probe는 단순한 Health Check가 아니다&lt;span class="hx:absolute hx:-mt-20" id="2-kubernetes-probe는-단순한-health-check가-아니다">&lt;/span>
&lt;a href="#2-kubernetes-probe%eb%8a%94-%eb%8b%a8%ec%88%9c%ed%95%9c-health-check%ea%b0%80-%ec%95%84%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Kubernetes의 3가지 Probe를 &lt;strong>상황에 맞게 전략적으로 활용&lt;/strong>하는 게 중요합니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>상황&lt;/th>
&lt;th>적합한 Probe&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>느린 시작 (JVM Warm-up)&lt;/td>
&lt;td>startupProbe&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>트래픽 수신 준비 확인&lt;/td>
&lt;td>readinessProbe&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>프로세스 살아있는지 확인&lt;/td>
&lt;td>livenessProbe&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3>3. 리소스는 여유있게, 하지만 낭비하지 말고&lt;span class="hx:absolute hx:-mt-20" id="3-리소스는-여유있게-하지만-낭비하지-말고">&lt;/span>
&lt;a href="#3-%eb%a6%ac%ec%86%8c%ec%8a%a4%eb%8a%94-%ec%97%ac%ec%9c%a0%ec%9e%88%ea%b2%8c-%ed%95%98%ec%a7%80%eb%a7%8c-%eb%82%ad%eb%b9%84%ed%95%98%ec%a7%80-%eb%a7%90%ea%b3%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>CPU &lt;code>requests&lt;/code>와 &lt;code>limits&lt;/code>의 차이를 이해하고 활용하는 게 중요합니다.&lt;/p>
&lt;ul>
&lt;li>&lt;code>requests&lt;/code>: 평상시 필요한 최소 리소스 (스케줄링 기준)&lt;/li>
&lt;li>&lt;code>limits&lt;/code>: 최대 사용 가능한 리소스 (Throttling 기준)&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Warm-up처럼 일시적으로 많은 리소스가 필요한 경우&lt;/strong>, &lt;code>limits&lt;/code>를 넉넉하게 설정하되 &lt;code>requests&lt;/code>는 평상시 사용량에 맞추는 게 효율적입니다.&lt;/p>
&lt;h3>4. 모니터링이 모든 것의 시작이다&lt;span class="hx:absolute hx:-mt-20" id="4-모니터링이-모든-것의-시작이다">&lt;/span>
&lt;a href="#4-%eb%aa%a8%eb%8b%88%ed%84%b0%eb%a7%81%ec%9d%b4-%eb%aa%a8%eb%93%a0-%ea%b2%83%ec%9d%98-%ec%8b%9c%ec%9e%91%ec%9d%b4%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이 문제를 발견한 것도, 개선을 확인한 것도 모두 &lt;strong>메트릭 덕분&lt;/strong>이었습니다. Prometheus + Grafana로 API 응답 시간을 모니터링하지 않았다면, 아마 이 문제를 모르고 넘어갔을 겁니다.&lt;/p>
&lt;blockquote>
&lt;p>참고:
&lt;a href="https://engineering.linecorp.com/ko/blog/apply-warm-up-in-spring-boot-and-kubernetes/"target="_blank" rel="noopener">Spring Boot + Kubernetes 기반에서 웜업 적용하기 - LINE Engineering&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://tech.olx.com/improving-jvm-warm-up-on-kubernetes-1b27dd8ecd58"target="_blank" rel="noopener">Improving JVM Warm-up on Kubernetes - OLX Engineering&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://kubernetes.io/docs/concepts/configuration/liveness-readiness-startup-probes/"target="_blank" rel="noopener">Kubernetes 공식 문서 - Liveness, Readiness, Startup Probes&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p>
&lt;/blockquote>
&lt;h2>마치며&lt;span class="hx:absolute hx:-mt-20" id="마치며">&lt;/span>
&lt;a href="#%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>JVM Cold Start 문제는 쿠버네티스 환경에서 피할 수 없는 숙제입니다. 하지만 &lt;code>startupProbe&lt;/code>와 JVM Warm-up을 적절히 활용하면, &lt;strong>사용자 경험을 해치지 않으면서도 컨테이너 오케스트레이션의 장점을 누릴 수 있습니다&lt;/strong>.&lt;/p>
&lt;p>이 글이 비슷한 문제를 겪고 있는 분들께 도움이 되길 바랍니다. 😊&lt;/p></description></item><item><title>나는 미래를 받아들였는가? - 개발자 AI 코딩 툴과 협업하는 법</title><link>https://jeongil.dev/ko/blog/trends/ai-agent-co-work/</link><pubDate>Sat, 25 Oct 2025 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/trends/ai-agent-co-work/</guid><description>
&lt;p>안녕하세요. 프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 3년차 백엔드 개발자 정정일입니다.&lt;/p>
&lt;p>요즘 개발자들 사이에서 AI 코딩 툴의 비중이 점점 커져가고 있습니다.&lt;/p>
&lt;p>GitHub Copilot, ChatGPT, Claude Code&amp;hellip; 이미 많은 개발자들이 사용하고 있고, &amp;ldquo;AI 없이 개발하면 뒤처진다&amp;quot;는 말까지 나오고 있죠.&lt;/p>
&lt;p>저도 AI 코딩 어시스턴트를 사용한 지 벌써 몇 달이 지났습니다. 처음엔 신기했습니다. &amp;ldquo;와, 이제 AI가 코드도 짜주네!&amp;rdquo;&lt;/p>
&lt;p>하지만 시간이 지나면서 이런 생각이 들었습니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;나는 이 도구를 제대로 쓰고 있는 걸까?&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>단순 반복 작업만 시키고, 중요한 건 여전히 제가 직접 하고 있었습니다. AI가 작성한 코드를 온전히 믿지 못해 검증하는 과정을 거쳐야하기 때문에, &amp;ldquo;차라리 간단한 일만 시키는 게 낫지 않을까?&amp;rdquo; 하는 생각에 어느정도 거리를 두고 활용하고 있었습니다.&lt;/p>
&lt;p>그러던 어느 날, 별 생각 없이 어떤 책을 읽다가 머리를 쌔게 맞은 문장을 만났습니다.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;미래는 이미 와 있다. 다만, 모두에게 균등하게 온 것은 아니다&amp;rdquo;
- 윌리엄 깁슨&lt;/p>
&lt;/blockquote>
&lt;p>이 문장을 읽는 순간, AI 코딩 툴이라는 &amp;ldquo;미래&amp;quot;를 마주하고도 막연한 불안감 때문에 제대로 활용해볼 생각도 못하고 있는 제 모습을 돌아보게 됐습니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;아, 나는 미래를 받아들이지 못하고 있었구나.&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>이 글은 제가 AI 코딩 툴을 제대로 활용하기 위해 겪었던 시행착오들을 공유하고자 합니다. 토큰 효율 50-92% 개선, TDD와 AI의 결합, 그리고 직접 겪으며 깨달은 &amp;ldquo;AI와 협업하는 법&amp;quot;에 대한 이야기입니다.&lt;/p>
&lt;hr>
&lt;h2>제한적으로만 사용하고 있던 AI&lt;span class="hx:absolute hx:-mt-20" id="제한적으로만-사용하고-있던-ai">&lt;/span>
&lt;a href="#%ec%a0%9c%ed%95%9c%ec%a0%81%ec%9c%bc%eb%a1%9c%eb%a7%8c-%ec%82%ac%ec%9a%a9%ed%95%98%ea%b3%a0-%ec%9e%88%eb%8d%98-ai" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>제가 그동안 구체적으로 어떻게 개발에서 AI를 활용하고 있었는지 돌이켜보니&lt;/p>
&lt;ul>
&lt;li>파라미터 타입 일괄 변경&lt;/li>
&lt;li>테스트 코드 작성&lt;/li>
&lt;li>간단한 함수 리팩토링&lt;/li>
&lt;li>내가 작성한 코드에 대한 코드 리뷰&lt;/li>
&lt;/ul>
&lt;p>이런 &lt;strong>단순하지만 하기 귀찮은 작업&lt;/strong>들 혹은 내가 놓친부분은 없는지 확인을 보통 시키고 있었습니다.&lt;/p>
&lt;p>핵심 비즈니스 로직, 복잡한 API등과 같은 작업은 여전히 제가 직접 하고 있었습니다.&lt;/p>
&lt;p>왜 그랬을까요? 사실 생각해보면 당연합니다. &lt;strong>&amp;ldquo;너무 신뢰하면 안 될 것 같아서&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>&amp;ldquo;AI가 작성한 코드를 제대로 검증하려면 매번 꼼꼼히 봐야 하는데, 내가 놓치는 경우들이 있을 수 있지 않을까?&amp;rdquo;
&amp;ldquo;너무 AI에게 의존하다보면 내 실력이 떨어지는 건 아닐까?&amp;rdquo;
“AI가 관리하는 컨텍스트가 너무 많아져 내 이해 범위를 넘어서는 내가 이해하고 있지 않은 코드들이 쌓이진 않을까?“&lt;/p>
&lt;p>이런 막연한 불안감 때문에 어느정도 거리를 두고 있었던 것 같습니다.&lt;/p>
&lt;hr>
&lt;h2>그제서야 떠오른 토비(Toby)님의 말씀&lt;span class="hx:absolute hx:-mt-20" id="그제서야-떠오른-토비toby님의-말씀">&lt;/span>
&lt;a href="#%ea%b7%b8%ec%a0%9c%ec%84%9c%ec%95%bc-%eb%96%a0%ec%98%a4%eb%a5%b8-%ed%86%a0%eb%b9%84toby%eb%8b%98%ec%9d%98-%eb%a7%90%ec%94%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>&amp;ldquo;미래는 이미 와 있다. 다만, 모두에게 균등하게 온 것은 아니다&amp;rdquo; 라는 문구를 책에서 읽는 순간 참 스스로를 돌이켜보게 됐습니다.&lt;/p>
&lt;p>흔히들 개발자가 AI에 일부 대체될거라고들 많이 말씀 하십니다. 저 또한 그런 생각을 하고 있구요. 누구나 어렵지 않게 그릴 수 있는 미래입니다. 생각해보면 미래도 아니네요. AI에 등장 이후로 개발자 채용시장이 어느정도 차가워졌다는 걸 개발자분들은 몸소 체감하실겁니다.&lt;/p>
&lt;p>또 누군가는 &lt;strong>&amp;ldquo;개발자는 AI에게 대체되는 것이 아니라 AI를 잘활용하는 개발자에게 대체될 것 이다&amp;rdquo;&lt;/strong> 라고도 말씀 하셨습니다.&lt;/p>
&lt;p>물론 미래는 확신할 수 없지만 아주 높은 확률로 AI를 잘 활용하는 능력은 개발자의 중요한 역량중 하나가 될 것이라 생각합니다. 1명의 개발자가 AI와 협업하여 10명의 개발자보다 더 많은 일을 해낼 수 있는 시대가 올지도 모릅니다.&lt;/p>
&lt;p>아니죠, 올지도 모른다는 잘못된 표현인 것 같고 확실히 오고 있습니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;그런데 왜 나는 그 미래를 지금 내것으로 만들지 못하고 있었지?&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>이런 생각에 머리를 한대 크게 맞은 것 같았습니다.&lt;/p>
&lt;p>그리고 얼마 전 2025년 7월에 참관했던 토비님 밋업 &lt;a href="https://jeongil.dev/ko/blog/reflection/how-to-live-as-a-developer-in-the-ai-era/">&amp;ldquo;31년차 개발자가 전하는 AI시대, 개발자로 살아가는 법&amp;rdquo;&lt;/a>의 내용이 다시 떠올랐습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>개발자는 더 이상 고정된 직능이 아니라 AI와 함께 계속 새롭게 정의될 유동적인 개념이 될 것&lt;/strong>&lt;/li>
&lt;li>&lt;strong>AI와 협업하는 능력이 개발자의 핵심 역량이 될 것&lt;/strong>&lt;/li>
&lt;li>&lt;strong>앞으로 효율적인 개발자는 작업의 성격과 복잡성에 따라 AI와의 협업 모델을 유연하게 전환할 수 있는 &amp;lsquo;모드 전환자(Mode Switchers)&amp;rsquo;&lt;/strong>&lt;/li>
&lt;/ul>
&lt;p>당시에는 그냥 &amp;ldquo;그렇구나&amp;rdquo; 하고 들었지만, 정작 저는 여전히 AI를 제한적으로만 사용하고 있었습니다.&lt;/p>
&lt;p>그 문장을 읽고 나서야, 토비님 말씀이 진짜로 와닿았습니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;아, 나는 미래를 손에 쥐고도 제대로 쓰지 못하고 있었구나.&amp;rdquo;&lt;/strong>&lt;/p>
&lt;hr>
&lt;h2>결심: 제대로 협업해보자&lt;span class="hx:absolute hx:-mt-20" id="결심-제대로-협업해보자">&lt;/span>
&lt;a href="#%ea%b2%b0%ec%8b%ac-%ec%a0%9c%eb%8c%80%eb%a1%9c-%ed%98%91%ec%97%85%ed%95%b4%eb%b3%b4%ec%9e%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>그래서 결심했습니다.&lt;/p>
&lt;p>&lt;strong>사이드 프로젝트를 진행하면서 AI와 제대로 협업하는 법을 배워보자!&lt;/strong>&lt;/p>
&lt;p>평소 관심있던 사이드 프로젝트 아이디어가 있었습니다.
다만 귀찮은 마음에 미뤄두고 있었는데, 이참에 AI와 협업하면서 진행해보기로 했습니다.&lt;/p>
&lt;p>처음에는 간단한 규칙만 새워두고 시작했습니다. 기획서를 작성하고 해당 기획서에 대한 요구사항을 분석하여 Issue로 정리하는 것부터 AI와 협업했습니다.
이미 Claude code가 github cli를 사용할 수 있었기에, Issue 작성도 AI에게 맡겼습니다. 다만 정확하지 않은 분석은 제가 직접 수정해주었습니다.&lt;/p>
&lt;p>만들어진 이슈를 바탕으로 Claude Code와 함께 개발을 시작했습니다.&lt;/p>
&lt;p>AI에게 특정 이슈를 맡기고 구현을 같이 협업하기 시작했습니다. 하다보니 신기한 일이 생겼습니다. AI가 코드를 작성하는 중간중간에 제가 &lt;strong>자연스럽게 끼어들게&lt;/strong> 되더라고요.&lt;/p>
&lt;h3>&amp;ldquo;어라? 그거 그렇게 하면 안되는데?&amp;rdquo;&lt;span class="hx:absolute hx:-mt-20" id="어라-그거-그렇게-하면-안되는데">&lt;/span>
&lt;a href="#%ec%96%b4%eb%9d%bc-%ea%b7%b8%ea%b1%b0-%ea%b7%b8%eb%a0%87%ea%b2%8c-%ed%95%98%eb%a9%b4-%ec%95%88%eb%90%98%eb%8a%94%eb%8d%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>예를 들어 이런 경우 였습니다. Claude에게 특정 기능을 맡기고 API를 구현하던 중이었습니다.&lt;/p>
&lt;p>Claude가 Service 레이어에서 바로 JOOQ 쿼리를 작성하고 있었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Service&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">UserService&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">private&lt;/span> &lt;span class="k">val&lt;/span> &lt;span class="py">dslContext&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">DSLContext&lt;/span> &lt;span class="c1">// 어?
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">fun&lt;/span> &lt;span class="nf">getUsers&lt;/span>&lt;span class="p">():&lt;/span> &lt;span class="n">List&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">User&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">dslContext&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">select&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nc">USER&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">ID&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nc">USER&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">EMAIL&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">.&lt;/span>&lt;span class="n">from&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">USER&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">.&lt;/span>&lt;span class="n">fetch&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="c1">// Service에서 직접 쿼리를?
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&amp;ldquo;잠깐, Service에서 직접 쿼리를 날리면 안 되지. 설계에 부합하지 않는데. 쿼리는 Repository레이어에서 해야하잖아.&amp;rdquo;&lt;/p>
&lt;p>제 사이드 프로젝트는 MVC 계층 구조가 명확합니다. Service는 비즈니스 로직만, Repository가 데이터베이스 접근을 담당합니다.&lt;/p>
&lt;p>중간에 끼어들어 Claude에 수정을 요청하고 제가 다시 이 규칙을 말할 필요 없게 Claude가 볼 수 있도록 CLAUDE.md에 작성하게 됩니다.&lt;/p>
&lt;p>→ &lt;strong>CLAUDE.md에 추가&lt;/strong>: &amp;ldquo;Service는 Repository를 통해서만 데이터베이스에 접근&amp;rdquo;&lt;/p>
&lt;h3>&amp;ldquo;더 나은 방식이 있는데..&amp;rdquo;&lt;span class="hx:absolute hx:-mt-20" id="더-나은-방식이-있는데">&lt;/span>
&lt;a href="#%eb%8d%94-%eb%82%98%ec%9d%80-%eb%b0%a9%ec%8b%9d%ec%9d%b4-%ec%9e%88%eb%8a%94%eb%8d%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>사용자 인터랙션을 처리하는 코드를 작성하던 중이었습니다.&lt;/p>
&lt;p>AI가 작성한 코드:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Service&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">InteractionService&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">fun&lt;/span> &lt;span class="nf">recordLike&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">UUID&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">contentId&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">UUID&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 좋아요 기록
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">likeRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">save&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Like&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">contentId&lt;/span>&lt;span class="p">))&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 통계 업데이트
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">statisticsService&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">updateLikeCount&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">contentId&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="c1">// 동기로?
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 알림 발송
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">notificationService&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">sendLikeNotification&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">contentId&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="c1">// 이것도 동기로?
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&amp;ldquo;잠깐, 통계 업데이트랑 알림 발송은 비동기로 처리해야 더 나은 구조라고 생각하는데?&amp;rdquo;&lt;/p>
&lt;p>이렇게 말하면 Claude는 어떤 대답을 했을까요?&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;아, 맞는 말씀입니다! 메인 트랜잭션과 독립적인 작업들은 비동기로 처리하는 것이 좋습니다. 코루틴을 사용하여 비동기 처리를 구현해보겠습니다.&amp;rdquo;&lt;/p>
&lt;/blockquote>
&lt;p>&amp;ldquo;음 코루틴도 괜찮긴 한데, 통계 업데이트나 알림 발송이 실패해도 좋아요 기록 자체는 성공해야 하잖아. TransactionalEventListener를 쓰면 메인 트랜잭션이 커밋된 후에 독립적으로 실행되니까, 알림이 실패해도 좋아요는 저장되고. 그리고 도메인 이벤트로 관심사도 명확하게 분리되고. Spring Event가 더 적합할 것 같은데?&amp;rdquo;&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;맞습니다! Spring Event를 사용하여 비동기 처리를 구현해보겠습니다.&amp;rdquo;&lt;/p>
&lt;/blockquote>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Service&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">InteractionService&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">fun&lt;/span> &lt;span class="nf">recordLike&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">UUID&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">contentId&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">UUID&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">likeRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">save&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Like&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">contentId&lt;/span>&lt;span class="p">))&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 이벤트 발행 (비동기)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">eventPublisher&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">publishEvent&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">LikeRecordedEvent&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">contentId&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Component&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">InteractionEventListener&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nd">@Async&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nd">@TransactionalEventListener&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">phase&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="nc">TransactionPhase&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">AFTER_COMMIT&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">fun&lt;/span> &lt;span class="nf">handleLikeRecorded&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">LikeRecordedEvent&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">statisticsService&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">updateLikeCount&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">contentId&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">notificationService&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">sendLikeNotification&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">event&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">event&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">contentId&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이렇게 되면 다시금 제가 CLAUDE.md에 규칙을 추가하게 됩니다.&lt;/p>
&lt;p>→ &lt;strong>CLAUDE.md에 추가&lt;/strong>: &amp;ldquo;메인 트랜잭션과 독립적인 작업은 Spring Event로 비동기 처리&amp;rdquo;&lt;/p>
&lt;h3>&amp;ldquo;잠깐! 그거 진짜 지우면 안 되는데?&amp;rdquo;&lt;span class="hx:absolute hx:-mt-20" id="잠깐-그거-진짜-지우면-안-되는데">&lt;/span>
&lt;a href="#%ec%9e%a0%ea%b9%90-%ea%b7%b8%ea%b1%b0-%ec%a7%84%ec%a7%9c-%ec%a7%80%ec%9a%b0%eb%a9%b4-%ec%95%88-%eb%90%98%eb%8a%94%eb%8d%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>사용자 삭제 기능을 구현할 때였습니다.&lt;/p>
&lt;p>Claude가 작성한 코드를 보니&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="k">fun&lt;/span> &lt;span class="nf">deleteUser&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">UUID&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">dslContext&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">.&lt;/span>&lt;span class="n">deleteFrom&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">USER&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">.&lt;/span>&lt;span class="k">where&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nc">USER&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nc">ID&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">eq&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="p">))&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">.&lt;/span>&lt;span class="n">execute&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="c1">// 진짜로 지우려고?!
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>&amp;ldquo;잠깐! 그거 물리적으로 지우면 안 되는데?&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>프로젝트는 &lt;strong>Soft Delete 규칙&lt;/strong>이 있습니다. 데이터는 물리적으로 지우지 않고, &lt;code>deletedAt&lt;/code>만 기록합니다.&lt;/p>
&lt;p>법적 이슈나 데이터 복구 때문에 실제로 DB에서 지워버리면 안 됩니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 올바른 방법
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">fun&lt;/span> &lt;span class="nf">deleteUser&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">UUID&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">dslContext&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">.&lt;/span>&lt;span class="n">update&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">USER&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">.&lt;/span>&lt;span class="k">set&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nc">USER&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">DELETED_AT&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nc">LocalDateTime&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">now&lt;/span>&lt;span class="p">())&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">.&lt;/span>&lt;span class="k">where&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nc">USER&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nc">ID&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">eq&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="p">))&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">.&lt;/span>&lt;span class="n">execute&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>다시금 제가 CLAUDE.md에 규칙을 추가하게 됩니다.&lt;/p>
&lt;p>→ &lt;strong>CLAUDE.md에 추가&lt;/strong>: &amp;ldquo;물리적 삭제 금지, Soft Delete만 허용. &lt;code>deletedAt&lt;/code> 필드 사용&amp;rdquo;&lt;/p>
&lt;p>이렇게 제 CLAUDE.md는 &lt;strong>피로 쓰인 규칙들로 점점 더 두꺼워져 갔습니다.&lt;/strong>&lt;/p>
&lt;hr>
&lt;h2>너무 방대해지는 CLAUDE.md&lt;span class="hx:absolute hx:-mt-20" id="너무-방대해지는-claudemd">&lt;/span>
&lt;a href="#%eb%84%88%eb%ac%b4-%eb%b0%a9%eb%8c%80%ed%95%b4%ec%a7%80%eb%8a%94-claudemd" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>제가 다시 말할필요 없도록 인터럽트할 때마다, CLAUDE.md에 규칙을 추가했습니다.
일종에 개발 컨벤션 문서처럼 돼가고 있었습니다.&lt;/p>
&lt;ul>
&lt;li>Repository 패턴 규칙&lt;/li>
&lt;li>Spring Event 비동기 처리 규칙&lt;/li>
&lt;li>Soft Delete 규칙&lt;/li>
&lt;li>SELECT asterisk 금지 규칙&lt;/li>
&lt;li>Audit Trail 필수 규칙&lt;/li>
&lt;li>KDoc 작성 규칙&lt;/li>
&lt;li>REST Docs 작성 규칙&lt;/li>
&lt;li>&amp;hellip;&lt;/li>
&lt;/ul>
&lt;p>규칙이 계속계속 쌓이다 보니, 어느새 &lt;strong>CLAUDE.md가 2,144줄&lt;/strong>이 되어있었습니다. 당연하게도 이는 곧 문제로 이어집니다.&lt;/p>
&lt;p>&lt;strong>CLAUDE.md 한 파일이 2,144줄, 약 40,000 토큰이 돼버린건데&lt;/strong>&lt;/p>
&lt;p>이러면 매번 Claude Code가 CLAUDE.md 2000줄이 넘는 규칙을 읽게 되니 컨텍스트가 금방 차버리고 중간에 내용을 까먹는 경우들도 발생하게 됩니다. 또 토큰양이 어마무시 하다보니 제 토큰 리밋을 순식간에 동나게 해버리더라구요.&lt;/p>
&lt;p>&lt;strong>API 하나 개발하는데 40,000 토큰&amp;hellip;&lt;/strong>, 게다가 추가적인 CLAUDE.md 뿐 아니라 실제 구현과정에서도 토큰을 사용할텐데 이건 너무 비효율적입니다. &amp;ldquo;어떻게하면 개선할 수 있을까?&amp;rdquo; 라는 생각이 당연히 들기 시작했습니다.&lt;/p>
&lt;hr>
&lt;h2>Skills: 필요한 컨텍스트만 불러오기&lt;span class="hx:absolute hx:-mt-20" id="skills-필요한-컨텍스트만-불러오기">&lt;/span>
&lt;a href="#skills-%ed%95%84%ec%9a%94%ed%95%9c-%ec%bb%a8%ed%85%8d%ec%8a%a4%ed%8a%b8%eb%a7%8c-%eb%b6%88%eb%9f%ac%ec%98%a4%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>고민하다보니 최근에 Claude Code에 &lt;strong>&lt;a href="https://www.anthropic.com/news/skills"target="_blank" rel="noopener">Skills&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/strong> 라는 기능이 추가된 걸 알게 됐습니다.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>Skills란?&lt;/strong>
Skills는 Claude Code가 특정 작업을 수행할 때 참고할 수 있는 모범 사례(best practices)와 지침을 담은 문서 모음입니다. 마치 전문가의 노하우가 정리된 가이드북 같은 역할을 합니다.&lt;/p>
&lt;/blockquote>
&lt;p>Claude Code는 작업을 시작하기 전에 관련된 Skill 문서를 자동으로 읽어서 참고합니다.&lt;/p>
&lt;p>작업별로 필요한 컨텍스트만 로드할 수 있고, 필요에 따라 직접 &lt;code>/skill [이름]&lt;/code> 명령어로 불러올 수 있습니다. 또 여러 개를 조합해서 쓸 수도 있다고 했습니다.&lt;/p>
&lt;p>보고 바로 &lt;strong>&amp;ldquo;이거다!&amp;rdquo;&lt;/strong> 싶었습니다.&lt;/p>
&lt;p>2,144줄의 거대한 CLAUDE.md를 &lt;strong>8개의 독립적인 Skill 파일&lt;/strong>로 분리했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>.claude/skills/
├── README.md # Skill 사용 가이드
├── quick-reference.md # 빠른 참조
├── core-principles.md # TDD, SOLID
├── mvc-layers.md # Controller/Service/Repository
├── testing-guide.md # 테스트 템플릿
├── api-design.md # REST API 설계
├── database-query.md # JOOQ, Soft Delete
├── code-style.md # 로깅, 네이밍
├── spring-event.md # Spring Event
└── pr-guide.md # PR 작성&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;code>.claude/skills/README.md&lt;/code>에 Claude가 Skill에 대해 빠르게 이해할 수 있도록 설명을 적어주고 각 스킬은 &lt;strong>500줄 이하&lt;/strong>로 유지했습니다.&lt;/p>
&lt;p>결과는 꽤나 놀라웠습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>작업 유형&lt;/th>
&lt;th>기존 CLAUDE.md&lt;/th>
&lt;th>Skill 사용&lt;/th>
&lt;th>절감&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>API 개발&lt;/td>
&lt;td>40,000 토큰&lt;/td>
&lt;td>17,500 토큰&lt;/td>
&lt;td>&lt;strong>56% ↓&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>테스트 작성&lt;/td>
&lt;td>40,000 토큰&lt;/td>
&lt;td>8,000 토큰&lt;/td>
&lt;td>&lt;strong>80% ↓&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>데이터베이스 쿼리&lt;/td>
&lt;td>40,000 토큰&lt;/td>
&lt;td>6,900 토큰&lt;/td>
&lt;td>&lt;strong>83% ↓&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>코드 리뷰&lt;/td>
&lt;td>40,000 토큰&lt;/td>
&lt;td>3,100 토큰&lt;/td>
&lt;td>&lt;strong>92% ↓&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>복잡한 기능 (Event 등)&lt;/td>
&lt;td>40,000 토큰&lt;/td>
&lt;td>19,900 토큰&lt;/td>
&lt;td>&lt;strong>50% ↓&lt;/strong>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>이제 API 하나 개발할 때는 &lt;code>/skill core-principles.md&lt;/code>,&lt;code>/skill mvc-layers&lt;/code>, &lt;code>/skill testing-guide&lt;/code>, &lt;code>/skill api-design&lt;/code> 이런 식으로 필요한 컨텍스트만 로드하고 시작할 수 있게 됐습니다.&lt;/p>
&lt;p>&lt;a href="https://github.com/12OneTwo12/upvy/tree/dev/upvy-backend/.claude/skills"target="_blank" rel="noopener">사이드 프로젝트 Skills 구성&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>을 보실 수 있게 남길테니 궁금하신 분들은 보셔도 좋을 것 같습니다.&lt;/p>
&lt;hr>
&lt;h2>Claude Code 검증을 자동화하다&lt;span class="hx:absolute hx:-mt-20" id="claude-code-검증을-자동화하다">&lt;/span>
&lt;a href="#claude-code-%ea%b2%80%ec%a6%9d%ec%9d%84-%ec%9e%90%eb%8f%99%ed%99%94%ed%95%98%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>그런데 한 가지 고민이 또 생겼습니다.&lt;/p>
&lt;p>AI가 코드를 작성하면, 제가 하나하나 검증해야 했습니다. 당연하게도 어떤 방식으로 코드를 작성 했는지 잘못된 부분은 없는지 확인하는 과정을 거쳐야했으니까요. AI가 작성한 코드더라도 최종적으로 제가 승인했다면 그 책임 역시 온전히 제가 져야합니다.&lt;/p>
&lt;p>실시간으로 인터럽트할 수 있다고 해도, 놓치는 부분이 있을 수 있었습니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;검증 부담을 자동화로 나눌 수 없을까?&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>방법은 어렵지 않게 떠올랐습니다. AI와의 협업이라지만 &lt;strong>다른 사람의 코드를 확인하고 검증하는 과정을 개발자들은 &amp;ldquo;코드 리뷰&amp;quot;라는 이름으로 이미 많이 해왔습니다.&lt;/strong>&lt;/p>
&lt;p>&lt;strong>“단지 대상이 AI가 됐을 뿐이죠.“&lt;/strong>&lt;/p>
&lt;p>개발자들이 이미 많이 하는 것들은 자동화 도구들이 많았습니다. 예를 들어 테스트 커버리지 측정, 정적 코드 분석과 같은 도구들이죠. 자연스레 제가 회사에서 다른 개발자분들과 협업할때도 사용하는 툴들을 도입하게 됐습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/31a4d4d1-959f-4cd3-bd9e-0d5d7a9f3b3e/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>&lt;strong>Jacoco&lt;/strong> - 테스트 커버리지&lt;/p>
&lt;ul>
&lt;li>AI가 작성한 코드에 테스트가 충분한지&lt;/li>
&lt;li>커버리지가 기준치 이상인지&lt;/li>
&lt;/ul>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/3d7ef9ae-6a08-40cc-99f7-a19152d6ccb3/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>&lt;strong>Detekt, reviewDog&lt;/strong> - 정적 코드 분석&lt;/p>
&lt;ul>
&lt;li>Kotlin 코드 스타일을 지키는지&lt;/li>
&lt;li>잠재적인 버그는 없는지&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>ArchUnit&lt;/strong> - 아키텍처 규칙 검증&lt;/p>
&lt;ul>
&lt;li>Controller는 Service만 의존하는지&lt;/li>
&lt;li>Service는 Repository만 의존하는지&lt;/li>
&lt;li>순환 참조는 없는지&lt;/li>
&lt;li>Soft Delete 규칙을 지키는지&lt;/li>
&lt;/ul>
&lt;p>이 도구들이 CI/CD에서 자동으로 돌아가고, &lt;strong>PR에 데코레이션으로 결과가 남습니다.&lt;/strong>&lt;/p>
&lt;p>예를 들어 Jacoco 테스트 커버리지가 부족하면 PR에 빨간 X가 뜨고, 충분하면 초록 사과가 뜹니다. 제가 직접 로컬에서 하나하나 검증할 필요도 없게 누구나 PR을 열면 바로 확인할 수 있도록 말이죠.&lt;/p>
&lt;p>그리고 한 가지를 더 추가했습니다.&lt;/p>
&lt;p>&lt;strong>Gemini Assistant를 PR 코드 리뷰어로 설정해두었습니다.&lt;/strong>&lt;/p>
&lt;p>Claude Code가 작성한 코드를 Gemini가 PR에서 리뷰하도록 말이죠.
&amp;ldquo;AI가 AI 코드를 리뷰한다고?&amp;rdquo; 싶으실 수 있는데, 실제로 효과가 꽤 컸습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/24ce66fa-7a1a-4872-9be6-64c01218d731/image.png" alt="" loading="lazy" />&lt;/p>
&lt;ul>
&lt;li>&amp;ldquo;이 함수는 null 체크가 필요해 보입니다&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;이 쿼리는 인덱스가 없어서 성능 이슈가 있을 수 있습니다&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;테스트 케이스가 부족합니다&amp;rdquo;&lt;/li>
&lt;/ul>
&lt;p>이런 피드백을 Claude Code에게 다시 전달하면, 코드를 개선해서 다시 작성하고 Commit한 후 Push합니다.&lt;/p>
&lt;p>&lt;strong>이게 실제로 효과가 있을까?&lt;/strong>&lt;/p>
&lt;p>놀랍게도 &lt;a href="https://arxiv.org/html/2312.13010v2"target="_blank" rel="noopener">AgentCoder 연구(2024)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에서 이를 검증하는 연구를 진행했습니다. Programmer agent가 작성한 코드를 Test executor agent가 검증하고 피드백을 주는 방식으로요.&lt;/p>
&lt;p>결과는 꽤나 놀라웠습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>HumanEval 벤치마크&lt;/strong>: 74.4% (1회) → &lt;strong>79.9% (5회 반복)&lt;/strong>&lt;/li>
&lt;li>&lt;strong>MBPP-ET 벤치마크&lt;/strong>: 80.3% → &lt;strong>89.1%&lt;/strong>&lt;/li>
&lt;/ul>
&lt;p>AI끼리 리뷰를 반복할수록 성능이 올라갔습니다.&lt;/p>
&lt;p>그리고 더 흥미로운 건, &lt;strong>단일 AI끼리의 협업보다 여러 AI의 협업이 훨씬 효과적&lt;/strong>이었다는 점입니다. AI가 생성한 코드를 다른 AI가 리뷰하고, 그 피드백을 다시 반영하는 &lt;strong>교차검증&lt;/strong>이 실제로 성능을 더욱 올렸습니다.&lt;/p>
&lt;ul>
&lt;li>Multi-agent 접근: &lt;strong>87.8%-89.9%&lt;/strong>&lt;/li>
&lt;li>Single agent: &lt;strong>61.0%-61.6%&lt;/strong>&lt;/li>
&lt;/ul>
&lt;p>그래서 저는 PR단위의 Gemini Assistant 코드리뷰를 도입했고, 이렇게 하니 &lt;strong>제 검증 부담이 확 줄었습니다.&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>Claude Code가 코드를 작성하고&lt;/li>
&lt;li>자동화 도구들(ArchUnit, Jacoco, Detekt)이 검증하고&lt;/li>
&lt;li>Gemini가 코드 리뷰하고&lt;/li>
&lt;li>저는 PR 데코레이션과 리뷰 코멘트를 보고 판단할 수 있게 됐습니다.&lt;/li>
&lt;/ol>
&lt;p>제가 &lt;strong>&lt;a href="https://github.com/12OneTwo12/upvy/pull/35"target="_blank" rel="noopener">실제로 두 AI와 함께 협업하는 PR&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/strong> 을 보시면 작업 과정의 이해가 좀더 용이하실 것 같습니다.&lt;/p>
&lt;p>이렇게 되니 AI에게 더 복잡한 작업도 맡길 수 있게 됐습니다.&lt;/p>
&lt;hr>
&lt;h2>직접 써보며 깨달은 것&lt;span class="hx:absolute hx:-mt-20" id="직접-써보며-깨달은-것">&lt;/span>
&lt;a href="#%ec%a7%81%ec%a0%91-%ec%8d%a8%eb%b3%b4%eb%a9%b0-%ea%b9%a8%eb%8b%ac%ec%9d%80-%ea%b2%83" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>돌이켜보면, 처음에는 막연한 불안감 때문에 AI를 제한적으로만 사용했습니다.&lt;/p>
&lt;ul>
&lt;li>&amp;ldquo;AI를 너무 신뢰하면 안 될 것 같아서&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;내가 AI에게 맡기기만 하고 아무것도 모르는 바보가 될까봐&amp;rdquo;&lt;/li>
&lt;/ul>
&lt;p>하지만 사이드 프로젝트에서 직접 AI와 협업하며 써보니, 역설적인 깨달음을 얻게됐습니다.&lt;/p>
&lt;p>&lt;strong>AI에게 더 많은 일을 맡기려면, 내가 더 잘 알아야 한다.&lt;/strong>&lt;/p>
&lt;p>위에서 언급했던 인터럽트 경험들처럼, AI가 코드를 작성하는 중간에 자연스럽게 끼어들 수 있었던 이유는 &lt;strong>제가 알고 있었기 때문&lt;/strong>입니다.&lt;/p>
&lt;p>만약 제가 몰랐다면 그냥 AI가 작성한 코드를 그대로 사용했을지도 모릅니다. 나중에 버그가 나거나, 코드 리뷰에서 지적받았을 수도 있겠죠.&lt;/p>
&lt;p>그렇게에 AI와의 협업에서 개발자의 아주 중요한 능력은 &lt;strong>&amp;ldquo;실시간으로 AI의 작업을 인터럽트할 수 있을 정도로 잘 아는 것&amp;rdquo;&lt;/strong> 이라는게 크게 느껴졌습니다.&lt;/p>
&lt;h3>TDD가 생각보다 중요하더라&lt;span class="hx:absolute hx:-mt-20" id="tdd가-생각보다-중요하더라">&lt;/span>
&lt;a href="#tdd%ea%b0%80-%ec%83%9d%ea%b0%81%eb%b3%b4%eb%8b%a4-%ec%a4%91%ec%9a%94%ed%95%98%eb%8d%94%eb%9d%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>프로젝트를 진행하면서 토비님이 강조하신 &lt;strong>&amp;ldquo;TDD를 하지 않으면 안 된다&amp;rdquo;&lt;/strong> 는 말을 직접 체감하기도 했습니다.&lt;/p>
&lt;p>테스트 코드를 먼저 작성하도록 하고 AI에게 구현을 맡기니, AI의 작업을 객관적으로 검증할 수 있더라고요.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>AI가 요구사항대로 테스트 작성 → AI가 코드 작성 → 테스트 실행 → 통과/실패 확인 → 실패시 분석 및 재작성&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>테스트는 일종의 안전망이자 검증 수단이었습니다. AI가 Goal에 도달했는지 확인하는 용도가 되기도 했고, AI에게 &amp;ldquo;정확히 무엇을 원하는지&amp;rdquo; 가장 명확하게 전달하는 수단인 것 같았습니다.&lt;/p>
&lt;p>리팩토링이나 기능을 추가할 때도 테스트가 있으니 기존 기능에 문제가 없는지 바로 확인할 수 있었습니다.&lt;/p>
&lt;p>그렇게 때문에 &lt;strong>TDD를 도입한 후, AI에게 더 복잡한 작업을 맡길 수 있게 됐습니다.&lt;/strong>&lt;/p>
&lt;p>시나리오 기반으로 테스트를 작성하라 요청하니 테스트 코드만으로도 &amp;ldquo;어떤 기능을 만들려고 하는구나&amp;rdquo;, &amp;ldquo;예외 처리가 부족한 부분이 있는 것 같은데?&amp;rdquo; 라는 판단도 가능했죠.&lt;/p>
&lt;h3>작업 특성에 따라 협업 모델 바꾸기&lt;span class="hx:absolute hx:-mt-20" id="작업-특성에-따라-협업-모델-바꾸기">&lt;/span>
&lt;a href="#%ec%9e%91%ec%97%85-%ed%8a%b9%ec%84%b1%ec%97%90-%eb%94%b0%eb%9d%bc-%ed%98%91%ec%97%85-%eb%aa%a8%eb%8d%b8-%eb%b0%94%ea%be%b8%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>또한 AI와 인간의 &lt;strong>세 가지 협업 모델&lt;/strong>을 실제로 적용해봤습니다.&lt;/p>
&lt;p>&lt;strong>AITL (AI-in-the-Loop):&lt;/strong> 아키텍처 설계나 핵심 비즈니스 로직은 제가 방향을 잡고, AI는 코드를 작성하도록 했습니다.&lt;/p>
&lt;p>&lt;strong>HITL (Human-in-the-Loop):&lt;/strong> API 엔드포인트 구현이나 테스트 코드 작성은 AI가 주도하되, 제가 코드 리뷰하며 검증했습니다. 가능하면 최대한 AI와의 협업을 하는 모든 순간에 &lt;strong>&amp;ldquo;딸깍딸깍 금지!&amp;rdquo;&lt;/strong> 를 실천하려고 했습니다. 무조건 수락하지 않고 질문했습니다.&lt;/p>
&lt;ul>
&lt;li>&amp;ldquo;왜 이렇게 작성했어?&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;다른 방법은 없어?&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;이 코드의 장단점은 뭐야?&amp;rdquo;&lt;/li>
&lt;/ul>
&lt;p>토비님이 &lt;strong>&amp;ldquo;딸깍딸깍 절대 하지말기&amp;rdquo;&lt;/strong> 를 강조하시며 하셨던 말씀중에 기억에 남는 말이 있는데&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;AI를 시니어 개발자라고 생각해봐라. &lt;strong>시니어 개발자가 옆에서 자세한 설명을 하면서 코드를 만드는 것을 도와주는데, 코드 입력만 하고 설명은 다 무시하는 주니어 개발자라고 생각해 보면 그 중요성을 알 수 있다&lt;/strong>&amp;rdquo;&lt;/p>
&lt;/blockquote>
&lt;p>실제로 저는 협업하는 거의 대부분의 과정에서 항상 Claude Code의 실행계획을 확인하고 질문, 반박, 재계획, 실행의 프로세스를 거쳤습니다. 이러면서 자연스레 작업의 방향성을 조정하고 이해할 수 있었습니다. 질문은 곧 학습의 기회이기도 했고 실행계획의 검증이 되기도 했습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/c7357b79-3592-4521-9b95-c79fc525849d/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>Claude Code의 실행계획을 보면 저희 개발자들과 생각 및 개발과정이 꽤나 비슷하단 걸 알 수 있습니다. 저는 저 과정속에서 다른 인간 개발자분과 이야기하듯 다른 대안을 제시하기도 Claude code의 반박에 납득하기도 했죠.&lt;/p>
&lt;p>&lt;strong>HOTL (Human-on-the-Loop):&lt;/strong> 파라미터 일괄 변경, Claude Rule, Skill 수정과 같은 단순 작업은 AI가 자율적으로 수행하고, 저는 결과만 확인하는 경우도 간혹 있었습니다. (ex.&lt;a href="https://github.com/12OneTwo12/upvy/pull/41"target="_blank" rel="noopener">PR-CLAUDE.md Skills로 분리&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>)&lt;/p>
&lt;p>위에서 언급했듯 PR에 자동화 도구들이 검증해주니, 최종적인 확인에서 제가 개입하는 정도로 충분한 작업들도 있었죠.
작업 특성에 따라 모드를 전환하는 게 핵심이라고 느꼈습니다.&lt;/p>
&lt;h3>결국&lt;span class="hx:absolute hx:-mt-20" id="결국">&lt;/span>
&lt;a href="#%ea%b2%b0%ea%b5%ad" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>AI에 반박할 수 있는 개발자가 되어야 한다.&lt;/strong>&lt;/p>
&lt;p>이게 제가 내린 결론이었습니다.&lt;/p>
&lt;ul>
&lt;li>AI가 작성한 코드가 맞는지 틀린지 판단하려면, 제가 그 기술을 알아야 합니다.&lt;/li>
&lt;li>AI가 잘못된 방향으로 가고 있을 때, 제가 반박할 수 있어야 합니다.&lt;/li>
&lt;li>AI를 통해 계속 공부하면서 성장해야 한다고 생각합니다..&lt;/li>
&lt;/ul>
&lt;p>맞는지 틀린지도 판단하지 못하는데 믿고 맡기는건 제가 도태되는 지름길 같다고 느꼈습니다.&lt;/p>
&lt;p>잘 쓰면 엄청난 생산성과 학습에 도움이 되는데, 아무생각없이 &lt;strong>&amp;ldquo;그냥 AI야 해줘&amp;rdquo;&lt;/strong> 하는 개발자가 돼버리면 경험도, 지식도 제게는 아무것도 남지 않을 것만 같다 느꼈습니다. 이는 절대 좋지 않은 결과를 초래하겠죠. 이런점에서 마치 **&amp;ldquo;양날의 검&amp;rdquo;**같다고 느껴졌습니다.&lt;/p>
&lt;p>그렇기에 앞으로도 반박할 수 있도록 꾸준히 공부하고 노력해 나가려 합니다. 역량 강화 및 학습에도 AI를 적극 활용해서 말이죠.&lt;/p>
&lt;p>그 과정에서 &lt;strong>증강 개발자(Augmented Developer)&lt;/strong> 로 성장할 수 있을 것 같다 생각합니다.&lt;/p>
&lt;hr>
&lt;h2>앞으로는&lt;span class="hx:absolute hx:-mt-20" id="앞으로는">&lt;/span>
&lt;a href="#%ec%95%9e%ec%9c%bc%eb%a1%9c%eb%8a%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>아직은 AI와의 협업도 부족한 점이 많은 것 같습니다. 저보다 더 나은 방법들로 훨씬 잘 활용하시는 분들도 많으실거라 생각이 듭니다. 그러니 늦은 만큼 더 열심히 해야겠죠.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;미래는 이미 와 있다. 다만, 모두에게 균등하게 온 것은 아니다&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>저는 이 문장의 의미를 이제는 알 것 같습니다.&lt;/p>
&lt;p>미래는 이미 저희 곁에 있는 것 같습니다. AI 코딩 툴, 자동화 도구들&amp;hellip; 모두 제 손에 있었습니다.&lt;/p>
&lt;p>다만 그것을 &lt;strong>제대로 받아들이고 활용할 수 있는 능력&lt;/strong>은 균등하게 주어지지 않는 것 같습니다.&lt;/p>
&lt;p>처음에는 막연한 불안감 때문에 AI를 제한적으로만 사용했지만 직접 부딪혀보니 잘 느껴지게 됐습니다.&lt;/p>
&lt;p>&lt;strong>AI에게 더 많은 일을 맡기려면, 내가 더 잘 알아야 한다.&lt;/strong>&lt;/p>
&lt;p>물론 아직 부족한 점이 너무 많은지라 앞으로도 저는 AI가 작성한 코드를 검증할 수 있도록 계속 공부하려고 합니다. AI의 제안에 무조건 수락하지 않고, 질문하고 반박하려고 합니다. 비효율을 발견하면 바로 개선하려고 합니다.&lt;/p>
&lt;p>AI를 단순 어시스트가 아닌 &lt;strong>학습 파트너이자 협업 도구&lt;/strong>로 활용하려고 합니다.&lt;/p>
&lt;p>&lt;strong>여러분도 손에 쥔 미래를 제대로 활용하고 계신가요?&lt;/strong>&lt;/p>
&lt;p>저는 이제 겨우 시작한 것 같습니다.&lt;/p>
&lt;hr>
&lt;h3>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://jeongil.dev/ko/blog/reflection/how-to-live-as-a-developer-in-the-ai-era/">토비님 밋업 참관기 - 31년차 개발자가 전하는 AI시대 개발자로 살아가는 법&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/12OneTwo12/upvy"target="_blank" rel="noopener">AI와 협업으로 진행하는 제 사이드 프로젝트 - GrowSnap&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://arxiv.org/html/2312.13010v2"target="_blank" rel="noopener">AgentCoder: Multiagent-Code Generation with Iterative Testing and Optimisation (2024)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> - Multi-agent 교차검증 효과 연구&lt;/li>
&lt;/ul></description></item><item><title>MySQL 컬럼의 타입을 bigint에서 varchar로 변경했더니 8배나 느려졌어요...! : 프로시저 성능 저하 트러블 슈팅</title><link>https://jeongil.dev/ko/blog/backend/troubleshooting/mysql-collation-performace/</link><pubDate>Mon, 20 Oct 2025 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/backend/troubleshooting/mysql-collation-performace/</guid><description>
&lt;h2>들어가며&lt;span class="hx:absolute hx:-mt-20" id="들어가며">&lt;/span>
&lt;a href="#%eb%93%a4%ec%96%b4%ea%b0%80%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>안녕하세요.&lt;/p>
&lt;p>프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 3년차 백엔드 개발자 정정일입니다.&lt;/p>
&lt;p>오늘은 저희 서비스에서 발생한 흥미로운 성능 이슈와 해결 과정을 공유하려고 합니다. MySQL 프로시저 하나가 갑자기 8배나 느려진 문제를 해결하면서, DB에 존재하는 다양한 문제들을 직면하게 됐는데요. 읽고 계신 분들도 문제를 따라가며 원인이 뭔지 추측해보면 재미있지 않을 까 싶습니다.&lt;/p>
&lt;hr>
&lt;h2>문제 발견: 갑자기 느려진 프로시저&lt;span class="hx:absolute hx:-mt-20" id="문제-발견-갑자기-느려진-프로시저">&lt;/span>
&lt;a href="#%eb%ac%b8%ec%a0%9c-%eb%b0%9c%ea%b2%ac-%ea%b0%91%ec%9e%90%ea%b8%b0-%eb%8a%90%eb%a0%a4%ec%a7%84-%ed%94%84%eb%a1%9c%ec%8b%9c%ec%a0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>회사에서 레거시 모놀리스 시스템을 MSA로 전환하는 프로젝트를 진행하고 있었습니다. 그 과정에서 &lt;code>item_id&lt;/code> 컬럼의 데이터 타입을 &lt;code>bigint&lt;/code>에서 &lt;code>varchar(30)&lt;/code>으로 변경하기로 결정했습니다. 서비스 간 데이터 일관성을 맞추고, 향후 다른 식별 체계로의 확장성을 고려한 의사결정이었습니다.&lt;/p>
&lt;p>테스트를 위해 개발 서버부터 마이그레이션을 완료하고 개발 환경에서 테스트를 진행하던 중, 특정 프로시저의 성능이 눈에 띄게 저하된 것을 발견했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>개발 환경 (varchar 파라미터): 457-465ms
운영 환경 (bigint 파라미터): 56-70ms&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>약 8배의 성능 차이였습니다. 같은 하드웨어 스펙, 같은 MySQL 버전(8.0.37), 비슷한 데이터 갯수임에도 불구하고 말입니다. 측정 오류를 의심하고 여러 차례 재실행해봤지만 결과는 일관되게 동일했습니다.&lt;/p>
&lt;p>문제가 된 프로시저는 레거시 서비스에서 사용하는 프로시저로 상세 정보를 조회하는 &lt;code>getItemDetailInfo&lt;/code>였습니다.&lt;/p>
&lt;blockquote>
&lt;p>글에 작성된 프로시저, 테이블, 파라미터, 컬럼명 등은 전부 예시입니다.&lt;/p>
&lt;/blockquote>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">CREATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">PROCEDURE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">getItemDetailInfo&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_ITEM_ID&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">varchar&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">30&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">-- bigint에서 varchar(30)으로 변경
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_AREA_SIZE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">double&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_PREFIX&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">varchar&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">5&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_USER_NO&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">int&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_ITEM_TYPE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">varchar&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">10&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">BEGIN&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 사용자 조회 기록 INSERT
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 빈번한 방문 기록 INSERT
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 아이템 상세 정보 SELECT (서브쿼리 포함)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">END&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>단순히 파라미터 타입만 바꿨을 뿐인데, 왜 이렇게 느려진 걸까요?&lt;/p>
&lt;hr>
&lt;h2>첫 번째 가설: 인덱스 문제&lt;span class="hx:absolute hx:-mt-20" id="첫-번째-가설-인덱스-문제">&lt;/span>
&lt;a href="#%ec%b2%ab-%eb%b2%88%ec%a7%b8-%ea%b0%80%ec%84%a4-%ec%9d%b8%eb%8d%b1%ec%8a%a4-%eb%ac%b8%ec%a0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>가장 먼저 의심한 것은 인덱스였습니다. 데이터 타입을 VARCHAR로 변경하면서 인덱스가 제대로 작동하지 않는 것은 아닐까 하는 생각이 들었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- 관련 테이블들의 인덱스 확인
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">COLUMN_NAME&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">COLUMN_KEY&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">DATA_TYPE&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">COLLATION_NAME&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">INFORMATION_SCHEMA&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">COLUMNS&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE_NAME&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;item_badge&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;user_history&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;item_special&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">AND&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">COLUMN_NAME&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;item_id&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>결과:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>item_badge.item_id → COLUMN_KEY = &amp;#39;MUL&amp;#39;, varchar(30)
user_history.item_id → COLUMN_KEY = &amp;#39;MUL&amp;#39;, varchar(30)
item_special.item_id → COLUMN_KEY = &amp;#39;MUL&amp;#39;, varchar(30)&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>의외의 결과였습니다. 인덱스는 모두 정상적으로 존재했고, 타입도 이미 &lt;code>varchar(30)&lt;/code>으로 통일되어 있었습니다. 인덱스 누락이나 타입 불일치는 문제의 원인이 아니었습니다. 첫 번째 가설은 빗나갔습니다.&lt;/p>
&lt;hr>
&lt;h2>두 번째 가설: 서브쿼리 성능 문제&lt;span class="hx:absolute hx:-mt-20" id="두-번째-가설-서브쿼리-성능-문제">&lt;/span>
&lt;a href="#%eb%91%90-%eb%b2%88%ec%a7%b8-%ea%b0%80%ec%84%a4-%ec%84%9c%eb%b8%8c%ec%bf%bc%eb%a6%ac-%ec%84%b1%eb%8a%a5-%eb%ac%b8%ec%a0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>인덱스가 아니라면 무엇이 문제일까요? 프로시저 코드를 다시 분석해봤습니다. 메인 SELECT 쿼리에 3개의 서브쿼리가 포함되어 있었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ia&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 서브쿼리 1: 뱃지 정보
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">IFNULL&lt;/span>&lt;span class="p">((&lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">badge&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_badge&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">0&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">badge_info&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 서브쿼리 2: 이벤트 개수
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">COUNT&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user_history&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">event_count&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 서브쿼리 3: 특별 항목 여부
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">exists&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">select&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">from&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_special&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">where&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;특별&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">category&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">as&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">category&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_info&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">INNER&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">JOIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_area&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ia&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ia&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_ITEM_ID&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>서브쿼리가 반복 실행되면서 N+1 문제를 일으키는 것은 아닐까 하는 가설을 세웠습니다. 이를 검증하기 위해 서브쿼리를 LEFT JOIN으로 변경해봤습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ia&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">IFNULL&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">ib&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">badge&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">0&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">badge_info&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">IFNULL&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">uh&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">event_count&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">0&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">event_count&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">IF&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">is&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">IS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">NOT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">NULL&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;특별&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">category&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">category&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_info&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">INNER&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">JOIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_area&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ia&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ia&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">LEFT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">JOIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_badge&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ib&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ib&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">LEFT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">JOIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">COUNT&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">event_count&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user_history&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">GROUP&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">BY&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">uh&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">uh&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">LEFT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">JOIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_special&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">is&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">is&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_ITEM_ID&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>결과: 477ms (오히려 20ms 더 느려짐)&lt;/p>
&lt;p>예상과 다른 결과였습니다. 오히려 더 느려진 것입니다. &lt;code>user_history&lt;/code> 테이블 전체를 GROUP BY 하면서 역효과가 발생한 것이었습니다. 개별 쿼리를 직접 실행해본 결과, 서브쿼리들은 각각 1ms도 걸리지 않았습니다. 서브쿼리는 성능 저하의 원인이 아니었습니다.&lt;/p>
&lt;hr>
&lt;h3>더 이상한 점: 개별 쿼리는 빠르다&lt;span class="hx:absolute hx:-mt-20" id="더-이상한-점-개별-쿼리는-빠르다">&lt;/span>
&lt;a href="#%eb%8d%94-%ec%9d%b4%ec%83%81%ed%95%9c-%ec%a0%90-%ea%b0%9c%eb%b3%84-%ec%bf%bc%eb%a6%ac%eb%8a%94-%eb%b9%a0%eb%a5%b4%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>더 당황스러운 것은, 프로시저 내부의 쿼리를 직접 실행해보면 매우 빠르다는 점이었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- 프로시저 내부 쿼리를 직접 실행
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_info&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;1168010609&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 1.8ms
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user_history&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;1168010609&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 0.7ms
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_badge&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;1168010609&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 1ms 미만&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>모든 개별 쿼리는 1~2ms 내외로 실행되었습니다. 그런데 같은 쿼리를 프로시저에 넣으면 457ms가 걸립니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>개별 쿼리: 1~2ms
프로시저: 457ms&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>같은 쿼리, 같은 데이터베이스, 같은 파라미터인데 200배 이상 차이가 납니다. 이게 대체 왜 그런 걸까요?&lt;/p>
&lt;hr>
&lt;h2>세 번째 시도: EXPLAIN으로 실행 계획 분석&lt;span class="hx:absolute hx:-mt-20" id="세-번째-시도-explain으로-실행-계획-분석">&lt;/span>
&lt;a href="#%ec%84%b8-%eb%b2%88%ec%a7%b8-%ec%8b%9c%eb%8f%84-explain%ec%9c%bc%eb%a1%9c-%ec%8b%a4%ed%96%89-%ea%b3%84%ed%9a%8d-%eb%b6%84%ec%84%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이쯤 되니 정말 답답했습니다. 인덱스도 있고, 서브쿼리도 문제가 없고 개별 쿼리로 실행하면 빠른데 프로시저로만 실행하면 느려지다니 도대체 대체 뭐가 문제일까요?&lt;/p>
&lt;p>뭔가 더 근본적인 걸 놓치고 있는 게 분명했습니다. 그래서 EXPLAIN으로 실행 계획을 분석해보기로 했어요.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- 변수 사용 시 (프로시저와 유사한 상황)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">SET&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">@&lt;/span>&lt;span class="n">v_item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;1168010609&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">EXPLAIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_info&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">@&lt;/span>&lt;span class="n">v_item_id&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>결과:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>type: ALL (풀 테이블 스캔)
rows: 45,453
Extra: Using where
경고: Cannot use ref access on index &amp;#39;PRIMARY&amp;#39; due to type or collation conversion on field &amp;#39;item_id&amp;#39;&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>중요한 단서를 발견했습니다. &lt;code>type: ALL&lt;/code>은 풀 테이블 스캔을 의미했습니다. 45,453개의 행을 전부 읽고 있었던 것입니다. 그리고 경고 메시지가 있었습니다. &amp;ldquo;type or collation conversion 때문에 인덱스를 사용할 수 없다&amp;quot;는 내용이었습니다.&lt;/p>
&lt;p>Collation&amp;hellip; 이 키워드가 눈에 띄었습니다. 비교를 위해 직접 값을 사용하는 경우도 테스트해봤습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">EXPLAIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_info&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;1168010609&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>결과:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>type: const (인덱스 사용)
rows: 1&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>명확한 차이가 있었습니다. 직접 값을 사용하면 &lt;code>type: const&lt;/code>로 인덱스를 완벽하게 사용하며, 단 1개의 행만 읽습니다. 하지만 변수를 사용하면 풀 테이블 스캔을 하는 것이었습니다.&lt;/p>
&lt;p>드디어 실마리를 잡았습니다. 경고 메시지의 &lt;code>type or collation conversion&lt;/code>이 핵심 키워드였습니다.&lt;/p>
&lt;hr>
&lt;h2>근본 원인 발견: Collation 불일치&lt;span class="hx:absolute hx:-mt-20" id="근본-원인-발견-collation-불일치">&lt;/span>
&lt;a href="#%ea%b7%bc%eb%b3%b8-%ec%9b%90%ec%9d%b8-%eb%b0%9c%ea%b2%ac-collation-%eb%b6%88%ec%9d%bc%ec%b9%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>Collation이라는 단어가 계속 머릿속을 맴돌았습니다. &amp;ldquo;분명 MySQL에서 문자열 비교 규칙 같은 거였는데&amp;hellip;&amp;rdquo; 경고 메시지를 단서로 테이블 컬럼의 collation을 확인해봤습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">SHOW&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FULL&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">COLUMNS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_info&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Field&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;item_id&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">SHOW&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FULL&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">COLUMNS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_area&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Field&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;item_id&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>결과:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>item_id, varchar(30), utf8mb3_general_ci&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>원인을 찾았습니다. 테이블 컬럼은 &lt;code>utf8mb3_general_ci&lt;/code>를 사용하고 있었습니다. 반면 MySQL 8.0에서는 기본 문자셋이 &lt;code>utf8mb4&lt;/code>이고, 기본 collation은 &lt;code>utf8mb4_0900_ai_ci&lt;/code>입니다.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;From MySQL 8.0, utf8mb4 is the default character set, and utf8mb4_0900_ai_ci is the default collation.&amp;rdquo;&lt;/p>
&lt;p>— &lt;a href="https://dev.mysql.com/doc/refman/8.0/en/charset-mysql.html"target="_blank" rel="noopener">MySQL 8.0 Reference Manual, Section 10.2 Character Sets and Collations in MySQL&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p>
&lt;/blockquote>
&lt;p>문제는 명확했습니다. utf8mb3와 utf8mb4, 두 개의 서로 다른 collation을 가진 값을 비교하면서 MySQL이 내부적으로 변환 작업을 수행하고 있었던 것입니다. 그리고 이 변환 과정에서 인덱스를 사용할 수 없게 되는 것이었습니다.&lt;/p>
&lt;h3>Collation 불일치가 일으키는 문제&lt;span class="hx:absolute hx:-mt-20" id="collation-불일치가-일으키는-문제">&lt;/span>
&lt;a href="#collation-%eb%b6%88%ec%9d%bc%ec%b9%98%ea%b0%80-%ec%9d%bc%ec%9c%bc%ed%82%a4%eb%8a%94-%eb%ac%b8%ec%a0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>MySQL은 collation이 다른 값을 비교할 때, 내부적으로 타입 변환(collation conversion)을 수행합니다. MySQL 공식 문서에 따르면:&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;Comparison of dissimilar columns (comparing a string column to a temporal or numeric column, for example) may prevent use of indexes if values cannot be compared directly without conversion.&amp;rdquo;&lt;/p>
&lt;p>— &lt;a href="https://dev.mysql.com/doc/refman/8.0/en/mysql-indexes.html"target="_blank" rel="noopener">MySQL 8.0 Reference Manual, Section 10.3.1 How MySQL Uses Indexes&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p>
&lt;/blockquote>
&lt;p>이 과정에서 다음과 같은 문제가 발생합니다:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>인덱스를 사용할 수 없게 됨&lt;/strong>: Collation이 다른 값을 직접 비교할 수 없어 변환이 필요하므로 인덱스 사용 불가&lt;/li>
&lt;li>&lt;strong>전체 테이블 스캔 수행&lt;/strong>: 45,453개 행을 모두 읽어야 함&lt;/li>
&lt;li>&lt;strong>각 행마다 collation 변환 수행&lt;/strong>: 매 행마다 문자열 변환 오버헤드 발생&lt;/li>
&lt;li>&lt;strong>결과&lt;/strong>: 수백 밀리초의 성능 저하&lt;/li>
&lt;/ol>
&lt;p>이 문제는 MySQL 버그 트래커에 여러 건 보고되어 있으며(Bug #83856, #83857 등), MySQL 공식 문서에도 명시된 제약사항입니다.&lt;/p>
&lt;p>PREPARE STATEMENT로 실제 차이를 측정해봤습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">SET&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">profiling&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">-- bigint로 바인딩 (collation 변환 발생)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">SET&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">@&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">1168010609&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">PREPARE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stmt&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;SELECT * FROM item_info WHERE item_id = ?&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">EXECUTE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stmt&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">USING&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">@&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">-- varchar로 바인딩 (collation 일치)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">SET&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">@&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;1168010609&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">PREPARE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stmt&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;SELECT * FROM item_info WHERE item_id = ?&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">EXECUTE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stmt&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">USING&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">@&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">SHOW&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">PROFILES&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>결과:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>bigint 바인딩: 202ms
varchar 바인딩: 0.6ms&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>335배 차이가 발생했습니다. 이제 프로시저가 느린 이유를 정확히 알게 되었습니다.&lt;/p>
&lt;hr>
&lt;h2>프로파일링으로 병목 지점 정확히 찾기&lt;span class="hx:absolute hx:-mt-20" id="프로파일링으로-병목-지점-정확히-찾기">&lt;/span>
&lt;a href="#%ed%94%84%eb%a1%9c%ed%8c%8c%ec%9d%bc%eb%a7%81%ec%9c%bc%eb%a1%9c-%eb%b3%91%eb%aa%a9-%ec%a7%80%ec%a0%90-%ec%a0%95%ed%99%95%ed%9e%88-%ec%b0%be%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>프로시저 내부에서 정확히 어디가 느린지 확인하기 위해 프로파일링을 실행했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">SET&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">profiling&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">CALL&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">getItemDetailInfo&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;1168010609&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">34&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;item&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">219786&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;type_a&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">SHOW&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">PROFILES&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>결과:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Query_ID&lt;/th>
&lt;th>Duration&lt;/th>
&lt;th>Query&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>1179&lt;/td>
&lt;td>0.225648초 (225ms)&lt;/td>
&lt;td>INSERT INTO user_view_log &amp;hellip; SELECT&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>1180&lt;/td>
&lt;td>0.202043초 (202ms)&lt;/td>
&lt;td>INSERT INTO frequent_visits &amp;hellip; SELECT&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>1181&lt;/td>
&lt;td>0.209143초 (209ms)&lt;/td>
&lt;td>SELECT (메인 쿼리)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>총 실행 시간: 약 636ms&lt;/p>
&lt;p>그런데 흥미로운 점이 있었습니다. 동일한 쿼리를 개별적으로 실행하면:&lt;/p>
&lt;ul>
&lt;li>INSERT user_view_log: 4.5ms&lt;/li>
&lt;li>INSERT frequent_visits: 0.7ms&lt;/li>
&lt;li>SELECT: 1.8ms&lt;/li>
&lt;/ul>
&lt;p>개별 쿼리를 직접 실행하면 매우 빠른 반면, 프로시저로 실행하면 636ms가 걸렸습니다. 이 차이는 프로시저 파라미터를 사용할 때 collation 변환이 발생하기 때문이었습니다.&lt;/p>
&lt;hr>
&lt;h2>임시 해결: 지역 변수로 Collation 맞추기&lt;span class="hx:absolute hx:-mt-20" id="임시-해결-지역-변수로-collation-맞추기">&lt;/span>
&lt;a href="#%ec%9e%84%ec%8b%9c-%ed%95%b4%ea%b2%b0-%ec%a7%80%ec%97%ad-%eb%b3%80%ec%88%98%eb%a1%9c-collation-%eb%a7%9e%ec%b6%94%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>원인을 알았으니 이제 해결책을 찾아야 했습니다. 하지만 데이터베이스 전체를 utf8mb4로 바꾸는 건 시간이 걸리고 리스크도 있었어요. 일단 빠르게 프로시저부터 고쳐보기로 했습니다.&lt;/p>
&lt;p>생각해낸 방법은 간단했습니다. 프로시저 내부에서 지역 변수를 만들고, 그 변수에 명시적으로 &lt;code>utf8mb3&lt;/code> collation을 지정하는 거였어요.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">CREATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">PROCEDURE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">getItemDetailInfo&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_ITEM_ID&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">varchar&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">30&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_AREA_SIZE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">double&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_PREFIX&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">varchar&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">5&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_USER_NO&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">int&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_ITEM_TYPE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">varchar&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">10&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">BEGIN&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 지역 변수에 utf8mb3 collation 명시
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">DECLARE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">v_item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">30&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">CHARACTER&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">SET&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">utf8mb3&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">COLLATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">utf8mb3_general_ci&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">DECLARE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">v_item_title&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">VARCHAR&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">255&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 파라미터 값을 지역 변수로 복사
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">SET&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">v_item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_ITEM_ID&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">IF&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_USER_NO&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">IS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">NOT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">NULL&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">THEN&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">-- v_item_id 사용 (P_ITEM_ID 대신)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">title&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">INTO&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">v_item_title&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_info&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">v_item_id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">LIMIT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">INSERT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">INTO&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user_view_log&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">user_no&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_title&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">area_size&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_type&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">VALUES&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">P_USER_NO&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">v_item_id&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">v_item_title&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_AREA_SIZE&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_ITEM_TYPE&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">DUPLICATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">KEY&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">UPDATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">created_at&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">NOW&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">INSERT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">INTO&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">frequent_visits&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">user_id&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">area_size&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_type&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">visit_count&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">last_visited&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">u&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">v_item_id&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_AREA_SIZE&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_ITEM_TYPE&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">now&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">users&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">u&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">no&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_USER_NO&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">DUPLICATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">KEY&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">UPDATE&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">area_size&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_AREA_SIZE&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">item_type&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_ITEM_TYPE&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">visit_count&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">IF&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">TIMESTAMPDIFF&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">HOUR&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">last_visited&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">NOW&lt;/span>&lt;span class="p">())&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">&amp;gt;=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">visit_count&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">+&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">visit_count&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">last_visited&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">IF&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">TIMESTAMPDIFF&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">HOUR&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">last_visited&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">NOW&lt;/span>&lt;span class="p">())&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">&amp;gt;=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">NOW&lt;/span>&lt;span class="p">(),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">last_visited&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">END&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">IF&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 메인 SELECT에서도 v_item_id 사용
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ia&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">...&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_info&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">INNER&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">JOIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">item_area&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ia&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ia&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">AND&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ia&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">area_size&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">P_AREA_SIZE&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">item_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">v_item_id&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">-- P_ITEM_ID 대신 v_item_id
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">END&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>결과: 457ms → 42ms (약 11배 개선)&lt;/p>
&lt;p>상당한 개선이었습니다. 프로파일링 결과를 보니 각 쿼리가 정상적인 속도로 실행되고 있었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>Query 1568: SELECT title → 0.55ms
Query 1569: INSERT user_view_log → 4.25ms
Query 1570: INSERT frequent_visits → 0.71ms
Query 1571: SELECT (메인 쿼리) → 1.40ms&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>당장의 성능 문제는 해결했지만, 여전히 찜찜한 부분이 남아있었습니다. 경고 메시지가 계속 출력되고 있었기 때문입니다.&lt;/p>
&lt;p>참고로 실제 프로시저를 실행해보면 다음과 같이 나타납니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>1 row retrieved starting from 1 in 404 ms (execution: 42 ms, fetching: 362 ms)&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>총 404ms 중 실제 쿼리 실행 시간은 42ms이고, 나머지 362ms는 데이터 전송(fetching) 시간입니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>[HY000][3778] &amp;#39;utf8mb3_general_ci&amp;#39; is a collation of the deprecated character set UTF8MB3.&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>utf8mb3가 deprecated 되었다는 경고 메시지였습니다. MySQL 공식 문서에서 utf8mb3는 deprecated 상태입니다. 이 방법은 어디까지나 임시방편이었습니다. 근본적으로 해결하려면 데이터베이스 전체를 utf8mb4로 마이그레이션해야 했습니다.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;The utf8mb3 character set is deprecated.&amp;rdquo;&lt;/p>
&lt;p>— &lt;a href="https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-utf8mb3.html"target="_blank" rel="noopener">MySQL 8.0 Reference Manual, Section 10.9.2 The utf8mb3 Character Set&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p>
&lt;/blockquote>
&lt;hr>
&lt;h2>근본 해결 방향: 전체 데이터베이스 utf8mb4 마이그레이션&lt;span class="hx:absolute hx:-mt-20" id="근본-해결-방향-전체-데이터베이스-utf8mb4-마이그레이션">&lt;/span>
&lt;a href="#%ea%b7%bc%eb%b3%b8-%ed%95%b4%ea%b2%b0-%eb%b0%a9%ed%96%a5-%ec%a0%84%ec%b2%b4-%eb%8d%b0%ec%9d%b4%ed%84%b0%eb%b2%a0%ec%9d%b4%ec%8a%a4-utf8mb4-%eb%a7%88%ec%9d%b4%ea%b7%b8%eb%a0%88%ec%9d%b4%ec%85%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>1단계: 마이그레이션 대상 확인&lt;span class="hx:absolute hx:-mt-20" id="1단계-마이그레이션-대상-확인">&lt;/span>
&lt;a href="#1%eb%8b%a8%ea%b3%84-%eb%a7%88%ec%9d%b4%ea%b7%b8%eb%a0%88%ec%9d%b4%ec%85%98-%eb%8c%80%ec%83%81-%ed%99%95%ec%9d%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>데이터베이스 상태를 확인해보니 상황이 복잡했습니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">TABLE_SCHEMA&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE_NAME&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">TABLE_COLLATION&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">INFORMATION_SCHEMA&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">TABLES&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">TABLE_SCHEMA&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">NOT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;information_schema&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;mysql&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>결과:&lt;/p>
&lt;ul>
&lt;li>utf8mb3 테이블: 약 100개&lt;/li>
&lt;li>utf8mb4_general_ci 테이블: 약 21개 (이미 일부 마이그레이션됨)&lt;/li>
&lt;li>합계: 121개 테이블&lt;/li>
&lt;/ul>
&lt;p>일부 테이블은 이미 utf8mb4_general_ci로 마이그레이션되어 있었습니다. 아마도 과거에 부분적으로 작업했던 것 같았습니다.&lt;/p>
&lt;p>이렇게 많은 테이블을 일일이 변경할 수는 없으니, 자동 스크립트를 생성했습니다.&lt;/p>
&lt;p>어떤 collation을 선택할지 고민했습니다. 기존에 사용하던 &lt;code>utf8mb4_general_ci&lt;/code>를 그대로 쓸지, MySQL 8.0 기본값인 &lt;code>utf8mb4_0900_ai_ci&lt;/code>를 사용할지 결정해야 했습니다.&lt;/p>
&lt;p>&lt;strong>&lt;code>utf8mb4_0900_ai_ci&lt;/code>를 선택한 이유:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>MySQL 8.0의 기본 collation&lt;/li>
&lt;li>더 정확한 유니코드 정렬 알고리즘 (UCA 9.0.0 기준)&lt;/li>
&lt;li>애플리케이션 레벨의 기본 collation과 일치하여 추가 변환 불필요&lt;/li>
&lt;li>향후 호환성 보장&lt;/li>
&lt;/ul>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">CONCAT&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;ALTER TABLE &amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">TABLE_SCHEMA&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;.&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE_NAME&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39; &amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;&amp;#39;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">alter_statement&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">INFORMATION_SCHEMA&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">TABLES&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">TABLE_COLLATION&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">LIKE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;utf8mb3%&amp;#39;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">AND&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">TABLE_SCHEMA&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">NOT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;information_schema&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;mysql&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>2단계: 첫 번째 장애물 - 인덱스 키 길이 제한&lt;span class="hx:absolute hx:-mt-20" id="2단계-첫-번째-장애물---인덱스-키-길이-제한">&lt;/span>
&lt;a href="#2%eb%8b%a8%ea%b3%84-%ec%b2%ab-%eb%b2%88%ec%a7%b8-%ec%9e%a5%ec%95%a0%eb%ac%bc---%ec%9d%b8%eb%8d%b1%ec%8a%a4-%ed%82%a4-%ea%b8%b8%ec%9d%b4-%ec%a0%9c%ed%95%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>스크립트로 생성한 ALTER 문을 실행할 차례였습니다. 첫 번째 테이블부터 변환을 시작했는데, 예상치 못한 문제가 발생했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">ALTER&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user_assignment&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">CONVERT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TO&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">CHARACTER&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">SET&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">utf8mb4&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">COLLATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">utf8mb4_0900_ai_ci&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>에러:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>[42000][1071] Specified key was too long; max key length is 1000 bytes&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>예상치 못한 에러가 발생했습니다. &amp;ldquo;인덱스 키가 너무 길다&amp;quot;는 메시지였습니다. utf8mb3에서는 문제없었는데, utf8mb4로 변환하는 순간 제약에 걸린 것입니다. 원인을 파악했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- 문제가 된 인덱스
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">INDEX&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">idx_user_assignment_1&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">userID&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">-- userID VARCHAR(255)&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>여기서 문자셋에 따른 바이트 계산이 중요합니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>utf8mb3: VARCHAR(255) × 3 bytes = 765 bytes ✅ (1000 bytes 미만)
utf8mb4: VARCHAR(255) × 4 bytes = 1020 bytes ❌ (1000 bytes 초과)&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>utf8mb3를 사용할 때는 765바이트로 MyISAM의 1000바이트 제한 안에 들어가서 문제가 없었습니다. 하지만 utf8mb4로 변경하는 순간 1020바이트가 되어 제한을 초과하게 된 것입니다.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;utf8mb4: A UTF-8 encoding of the Unicode character set using one to four bytes per character.&amp;rdquo;&lt;/p>
&lt;p>— &lt;a href="https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-utf8mb4.html"target="_blank" rel="noopener">MySQL 8.0 Reference Manual, Section 12.9.1 The utf8mb4 Character Set&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p>
&lt;/blockquote>
&lt;h3>3단계: ROW_FORMAT 변경 시도&lt;span class="hx:absolute hx:-mt-20" id="3단계-row_format-변경-시도">&lt;/span>
&lt;a href="#3%eb%8b%a8%ea%b3%84-row_format-%eb%b3%80%ea%b2%bd-%ec%8b%9c%eb%8f%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>InnoDB에서 ROW_FORMAT=DYNAMIC을 사용하면 인덱스 키 길이를 3072바이트까지 늘릴 수 있다는 것을 알고 있었습니다. 이 방법을 시도해봤습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">ALTER&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user_assignment&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ROW_FORMAT&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="k">DYNAMIC&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">ALTER&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user_assignment&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">CONVERT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TO&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">CHARACTER&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">SET&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">utf8mb4&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">COLLATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">utf8mb4_0900_ai_ci&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>그러나 여전히 같은 에러가 발생했습니다. ROW_FORMAT을 변경했음에도 제약이 해소되지 않았습니다. 뭔가 다른 요인이 있는 것 같았습니다.&lt;/p>
&lt;hr>
&lt;h2>숨겨진 문제 발견: MyISAM 스토리지 엔진&lt;span class="hx:absolute hx:-mt-20" id="숨겨진-문제-발견-myisam-스토리지-엔진">&lt;/span>
&lt;a href="#%ec%88%a8%ea%b2%a8%ec%a7%84-%eb%ac%b8%ec%a0%9c-%eb%b0%9c%ea%b2%ac-myisam-%ec%8a%a4%ed%86%a0%eb%a6%ac%ec%a7%80-%ec%97%94%ec%a7%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>문제의 근본 원인을 찾기 위해 테이블 구조를 직접 확인해봤습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">SHOW&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">CREATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user_assignment&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>결과:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">CREATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user_assignment&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">conversationID&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">varchar&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">255&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">null&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">createdAt&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">varchar&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">255&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">null&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">tradeType&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">varchar&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">255&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">null&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">userID&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">varchar&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">255&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">null&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ENGINE&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="n">MyISAM&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">COLLATE&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="n">utf8mb3_general_ci&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ROW_FORMAT&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="k">DYNAMIC&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>의외의 사실을 발견했습니다. 이 테이블은 InnoDB가 아니라 MyISAM 엔진을 사용하고 있었습니다. ROW_FORMAT이 DYNAMIC으로 설정되어 있어서 InnoDB로 착각했지만, 실제로는 MyISAM 테이블이었던 것입니다.&lt;/p>
&lt;h3>MyISAM vs InnoDB 인덱스 제한&lt;span class="hx:absolute hx:-mt-20" id="myisam-vs-innodb-인덱스-제한">&lt;/span>
&lt;a href="#myisam-vs-innodb-%ec%9d%b8%eb%8d%b1%ec%8a%a4-%ec%a0%9c%ed%95%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>엔진&lt;/th>
&lt;th>ROW_FORMAT&lt;/th>
&lt;th>최대 인덱스 키 길이&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>InnoDB&lt;/td>
&lt;td>COMPACT&lt;/td>
&lt;td>767 bytes&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>InnoDB&lt;/td>
&lt;td>DYNAMIC&lt;/td>
&lt;td>3072 bytes&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>MyISAM&lt;/td>
&lt;td>모든 포맷&lt;/td>
&lt;td>1000 bytes (고정)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>MySQL 공식 문서에 명시된 제한 사항입니다:&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;The index key prefix length limit is 3072 bytes for InnoDB tables that use DYNAMIC or COMPRESSED row format. The index key prefix length limit is 767 bytes for InnoDB tables that use the REDUNDANT or COMPACT row format.&amp;rdquo;&lt;/p>
&lt;p>— &lt;a href="https://dev.mysql.com/doc/refman/8.0/en/innodb-limits.html"target="_blank" rel="noopener">MySQL 8.0 Reference Manual, Section 17.22 InnoDB Limits&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p>
&lt;/blockquote>
&lt;p>MyISAM의 경우 1000바이트 제한이 고정되어 있습니다. MyISAM은 ROW_FORMAT과 관계없이 이 제한을 초과할 수 없습니다. ROW_FORMAT을 변경해도 문제가 해결되지 않았던 이유가 바로 이것이었습니다.&lt;/p>
&lt;h3>해결책: MyISAM → InnoDB 변환&lt;span class="hx:absolute hx:-mt-20" id="해결책-myisam--innodb-변환">&lt;/span>
&lt;a href="#%ed%95%b4%ea%b2%b0%ec%b1%85-myisam--innodb-%eb%b3%80%ed%99%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>문제의 원인을 파악했으니 해결책은 명확했습니다. MyISAM을 InnoDB로 변환하면 됩니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- 엔진 변환과 문자셋 변경을 한 번에 처리
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">ALTER&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user_assignment&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">CONVERT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TO&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">CHARACTER&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">SET&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">utf8mb4&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">COLLATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">utf8mb4_0900_ai_ci&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">ENGINE&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="n">InnoDB&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>변환에 성공했습니다. 이제 InnoDB의 3072바이트 인덱스 키 길이 제한을 활용할 수 있게 되었습니다.&lt;/p>
&lt;h3>MyISAM 테이블 일괄 변환 스크립트&lt;span class="hx:absolute hx:-mt-20" id="myisam-테이블-일괄-변환-스크립트">&lt;/span>
&lt;a href="#myisam-%ed%85%8c%ec%9d%b4%eb%b8%94-%ec%9d%bc%ea%b4%84-%eb%b3%80%ed%99%98-%ec%8a%a4%ed%81%ac%eb%a6%bd%ed%8a%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- MyISAM + utf8mb3 테이블 찾기
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">CONCAT&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;ALTER TABLE &amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">TABLE_SCHEMA&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;.&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE_NAME&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39; CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, &amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;ENGINE=InnoDB;&amp;#39;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">AS&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">alter_statement&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">INFORMATION_SCHEMA&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">TABLES&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">TABLE_SCHEMA&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">NOT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;information_schema&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;mysql&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;performance_schema&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;sys&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">AND&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">TABLE_COLLATION&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">LIKE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;utf8mb3%&amp;#39;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">AND&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ENGINE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">!=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;InnoDB&amp;#39;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">ORDER&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">BY&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">TABLE_SCHEMA&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE_NAME&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 스크립트를 통해 109개의 MyISAM 테이블을 InnoDB로 전환했습니다.&lt;/p>
&lt;hr>
&lt;h2>MyISAM → InnoDB 전환의 추가 이점&lt;span class="hx:absolute hx:-mt-20" id="myisam--innodb-전환의-추가-이점">&lt;/span>
&lt;a href="#myisam--innodb-%ec%a0%84%ed%99%98%ec%9d%98-%ec%b6%94%ea%b0%80-%ec%9d%b4%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>단순히 utf8mb4 마이그레이션 문제를 해결한 것을 넘어서, 성능과 안정성 측면에서도 큰 개선을 얻었습니다.&lt;/p>
&lt;h3>MyISAM vs InnoDB: 왜 전환해야 했을까?&lt;span class="hx:absolute hx:-mt-20" id="myisam-vs-innodb-왜-전환해야-했을까">&lt;/span>
&lt;a href="#myisam-vs-innodb-%ec%99%9c-%ec%a0%84%ed%99%98%ed%95%b4%ec%95%bc-%ed%96%88%ec%9d%84%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>MyISAM도 나름의 장점이 있습니다. 그렇다면 왜 InnoDB로 전환한 것일까요?&lt;/p>
&lt;h3>MyISAM의 장점&lt;span class="hx:absolute hx:-mt-20" id="myisam의-장점">&lt;/span>
&lt;a href="#myisam%ec%9d%98-%ec%9e%a5%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>MyISAM은 특정 상황에서 InnoDB보다 나은 성능을 보입니다:&lt;/p>
&lt;p>&lt;strong>1. 빠른 읽기 성능&lt;/strong>&lt;/p>
&lt;p>읽기 전용(read-only) 또는 읽기 위주(read-mostly) 환경에서 MyISAM은 매우 빠릅니다. 트랜잭션 오버헤드가 없기 때문입니다.&lt;/p>
&lt;p>&lt;strong>2. COUNT(*) 쿼리 최적화&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">COUNT&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">large_table&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>MyISAM은 테이블의 총 row 수를 메타데이터에 저장하기 때문에, WHERE 조건이 없는 COUNT(*) 쿼리가 거의 즉시 실행됩니다.&lt;/p>
&lt;p>&lt;strong>3. 작은 디스크 공간&lt;/strong>&lt;/p>
&lt;p>트랜잭션 로그나 MVCC(Multi-Version Concurrency Control)를 위한 추가 공간이 필요 없어 디스크 사용량이 적습니다.&lt;/p>
&lt;p>&lt;strong>4. 단순한 구조&lt;/strong>&lt;/p>
&lt;p>복잡한 트랜잭션 메커니즘이 없어 구조가 단순하고, 특정 상황에서는 관리가 쉽습니다.&lt;/p>
&lt;h3>MyISAM의 한계&lt;span class="hx:absolute hx:-mt-20" id="myisam의-한계">&lt;/span>
&lt;a href="#myisam%ec%9d%98-%ed%95%9c%ea%b3%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그러나 현대적인 웹 애플리케이션 환경에서는 MyISAM의 단점이 치명적입니다.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;MySQL uses table-level locking for MyISAM, MEMORY, and MERGE tables, permitting only one session to update those tables at a time.&amp;rdquo;&lt;/p>
&lt;p>— &lt;a href="https://dev.mysql.com/doc/refman/8.0/en/internal-locking.html"target="_blank" rel="noopener">MySQL 8.0 Reference Manual, Section 10.11.1 Internal Locking Methods&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p>
&lt;/blockquote>
&lt;p>&lt;strong>1. 테이블 레벨 락&lt;/strong>&lt;/p>
&lt;p>MyISAM은 테이블 전체에 락을 걸기 때문에 동시성이 매우 낮습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>사용자 A: INSERT 중... (전체 테이블 락)
사용자 B: SELECT 대기...
사용자 C: UPDATE 대기...&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>2. 트랜잭션 미지원&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">BEGIN&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">INSERT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">INTO&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">orders&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">VALUES&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(...);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">-- 오류 발생
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">ROLLBACK&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 작동하지 않음&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>MyISAM은 nontransactional 스토리지 엔진으로, 트랜잭션을 지원하지 않아 데이터 정합성 보장이 어렵습니다.&lt;/p>
&lt;p>&lt;strong>3. 크래시 복구 취약&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>서버 비정상 종료 → 테이블 손상 가능 → 수동 복구 필요&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>InnoDB의 장점&lt;span class="hx:absolute hx:-mt-20" id="innodb의-장점">&lt;/span>
&lt;a href="#innodb%ec%9d%98-%ec%9e%a5%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>MySQL 공식 문서에서 InnoDB의 장점을 명확히 설명하고 있습니다:&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;InnoDB implements standard row-level locking where there are two types of locks, shared (S) locks and exclusive (X) locks.&amp;rdquo;&lt;/p>
&lt;p>— &lt;a href="https://dev.mysql.com/doc/refman/8.0/en/innodb-locking.html"target="_blank" rel="noopener">MySQL 8.0 Reference Manual, Section 17.7.1 InnoDB Locking&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p>
&lt;/blockquote>
&lt;p>&lt;strong>1. Row 레벨 락 (동시성 향상)&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>사용자 A: 행 1 수정 중
사용자 B: 행 2 수정 가능 (동시 처리)
사용자 C: 행 3 수정 가능 (동시 처리)&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>2. ACID 트랜잭션&lt;/strong>&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;Isolation is the I in the acronym ACID; the isolation level is the setting that fine-tunes the balance between performance and reliability, consistency, and reproducibility of results.&amp;rdquo;&lt;/p>
&lt;p>— &lt;a href="https://dev.mysql.com/doc/refman/8.0/en/innodb-transaction-isolation-levels.html"target="_blank" rel="noopener">MySQL 8.0 Reference Manual, Section 17.7.2.1 Transaction Isolation Levels&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p>
&lt;/blockquote>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">BEGIN&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">INSERT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">INTO&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">orders&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">VALUES&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(...);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">INSERT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">INTO&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">payments&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">VALUES&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(...);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">-- 오류 발생
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">ROLLBACK&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">-- 모두 되돌림&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>3. 자동 크래시 복구&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>서버 비정상 종료 → 자동 복구 → 데이터 정합성 보장&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>특히 이전에 발견했던 프로시저 성능 문제에서 &lt;code>INSERT INTO user_view_log&lt;/code>가 225ms 걸렸던 것도, collation 변환뿐만 아니라 MyISAM의 테이블 락이 추가 오버헤드를 일으켰을 가능성이 높습니다.&lt;/p>
&lt;h3>우리 서비스에서 InnoDB를 선택한 이유&lt;span class="hx:absolute hx:-mt-20" id="우리-서비스에서-innodb를-선택한-이유">&lt;/span>
&lt;a href="#%ec%9a%b0%eb%a6%ac-%ec%84%9c%eb%b9%84%ec%8a%a4%ec%97%90%ec%84%9c-innodb%eb%a5%bc-%ec%84%a0%ed%83%9d%ed%95%9c-%ec%9d%b4%ec%9c%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>저희 서비스는 다음과 같은 특성이 있습니다:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>높은 동시성&lt;/strong>: 여러 사용자가 동시에 데이터를 읽고 쓰는 환경&lt;/li>
&lt;li>&lt;strong>빈번한 INSERT/UPDATE&lt;/strong>: 사용자 활동 로그, 방문 기록 등 지속적인 쓰기 작업&lt;/li>
&lt;li>&lt;strong>데이터 정합성 중요&lt;/strong>: 결제, 사용자 정보 등 일관성이 보장되어야 하는 데이터&lt;/li>
&lt;li>&lt;strong>트랜잭션 필요&lt;/strong>: 여러 테이블에 걸친 원자적 작업 필요&lt;/li>
&lt;/ul>
&lt;p>이런 환경에서는 MyISAM의 장점(빠른 읽기, COUNT(*) 최적화)보다 InnoDB의 장점(Row-level Lock, 트랜잭션, ACID)이 훨씬 중요했습니다. 특히 utf8mb4 마이그레이션을 위해 어차피 테이블을 변경해야 하는 상황이었기 때문에, 이 기회에 스토리지 엔진까지 현대화하는 것이 합리적인 선택이었습니다.&lt;/p>
&lt;hr>
&lt;h2>최종 성능 개선 결과&lt;span class="hx:absolute hx:-mt-20" id="최종-성능-개선-결과">&lt;/span>
&lt;a href="#%ec%b5%9c%ec%a2%85-%ec%84%b1%eb%8a%a5-%ea%b0%9c%ec%84%a0-%ea%b2%b0%ea%b3%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>프로시저 실행 시간&lt;span class="hx:absolute hx:-mt-20" id="프로시저-실행-시간">&lt;/span>
&lt;a href="#%ed%94%84%eb%a1%9c%ec%8b%9c%ec%a0%80-%ec%8b%a4%ed%96%89-%ec%8b%9c%ea%b0%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>단계&lt;/th>
&lt;th>실행 시간&lt;/th>
&lt;th>개선율&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>수정 전 (utf8mb3 + varchar 파라미터)&lt;/td>
&lt;td>457ms&lt;/td>
&lt;td>-&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>임시 해결 (utf8mb3 지역 변수)&lt;/td>
&lt;td>42ms&lt;/td>
&lt;td>약 11배 개선&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>최종 (utf8mb4 + InnoDB)&lt;/td>
&lt;td>42ms&lt;/td>
&lt;td>약 11배 개선&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3>쿼리별 실행 시간 변화&lt;span class="hx:absolute hx:-mt-20" id="쿼리별-실행-시간-변화">&lt;/span>
&lt;a href="#%ec%bf%bc%eb%a6%ac%eb%b3%84-%ec%8b%a4%ed%96%89-%ec%8b%9c%ea%b0%84-%eb%b3%80%ed%99%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>수정 전:&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>INSERT user_view_log: 225ms
INSERT frequent_visits: 202ms
SELECT (메인 쿼리): 209ms
총합: 636ms&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>수정 후:&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>SELECT title: 0.55ms
INSERT user_view_log: 4.25ms
INSERT frequent_visits: 0.71ms
SELECT (메인 쿼리): 1.40ms
총합: 6.91ms&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>데이터베이스 전체 개선 사항&lt;span class="hx:absolute hx:-mt-20" id="데이터베이스-전체-개선-사항">&lt;/span>
&lt;a href="#%eb%8d%b0%ec%9d%b4%ed%84%b0%eb%b2%a0%ec%9d%b4%ec%8a%a4-%ec%a0%84%ec%b2%b4-%ea%b0%9c%ec%84%a0-%ec%82%ac%ed%95%ad" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>121개 테이블 utf8mb4로 마이그레이션&lt;/li>
&lt;li>109개 MyISAM 테이블을 InnoDB로 전환&lt;/li>
&lt;li>모든 프로시저에서 collation 경고 제거&lt;/li>
&lt;li>향후 MySQL 버전 업그레이드 대비&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2>추가로 발견한 문제: Collation 불일치 재발&lt;span class="hx:absolute hx:-mt-20" id="추가로-발견한-문제-collation-불일치-재발">&lt;/span>
&lt;a href="#%ec%b6%94%ea%b0%80%eb%a1%9c-%eb%b0%9c%ea%b2%ac%ed%95%9c-%eb%ac%b8%ec%a0%9c-collation-%eb%b6%88%ec%9d%bc%ec%b9%98-%ec%9e%ac%eb%b0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>그런데 마이그레이션 후 애플리케이션을 실행하자 새로운 에러가 발생했습니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>java.sql.SQLException: Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT)
and (utf8mb4_general_ci,IMPLICIT) for operation &amp;#39;=&amp;#39;&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>문제를 파악해보니 기존에 일부 테이블들이 &lt;code>utf8mb4_general_ci&lt;/code>로 설정된 테이블들이 존재했습니다.&lt;/p>
&lt;p>결국 테이블 collation과 MySQL 8.0의 기본 collation 사이에 충돌이 발생한 것입니다.&lt;/p>
&lt;h3>원인&lt;span class="hx:absolute hx:-mt-20" id="원인">&lt;/span>
&lt;a href="#%ec%9b%90%ec%9d%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>테이블: &lt;code>utf8mb4_general_ci&lt;/code>&lt;/li>
&lt;li>Connection/Session 기본값: &lt;code>utf8mb4_0900_ai_ci&lt;/code> (MySQL 8.0 기본값)&lt;/li>
&lt;li>애플리케이션 레벨 파라미터: &lt;code>utf8mb4_0900_ai_ci&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>결국 같은 문제가 다른 형태로 재발한 것이었습니다.&lt;/p>
&lt;h3>최종 해결&lt;span class="hx:absolute hx:-mt-20" id="최종-해결">&lt;/span>
&lt;a href="#%ec%b5%9c%ec%a2%85-%ed%95%b4%ea%b2%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>모든 테이블을 MySQL 8.0의 기본값인 &lt;code>utf8mb4_0900_ai_ci&lt;/code>로 통일했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- 모든 테이블을 utf8mb4_0900_ai_ci로 재변환
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">ALTER&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TABLE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">table_name&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">CONVERT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TO&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nb">CHARACTER&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">SET&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">utf8mb4&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">COLLATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">utf8mb4_0900_ai_ci&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>&lt;code>utf8mb4_0900_ai_ci&lt;/code>를 선택한 이유:&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>MySQL 8.0의 기본 collation&lt;/li>
&lt;li>더 정확한 유니코드 정렬 알고리즘 (UCA 9.0.0 기준)&lt;/li>
&lt;li>애플리케이션 레벨의 기본값과 일치&lt;/li>
&lt;li>추가적인 collation 변환 불필요&lt;/li>
&lt;li>향후 MySQL 버전 업그레이드 시 호환성 보장&lt;/li>
&lt;/ol>
&lt;p>이 교훈을 통해 배운 것은, &lt;strong>단순히 utf8mb4로 변환하는 것만으로는 부족하고, 정확한 collation까지 일치시켜야 한다&lt;/strong>는 점이었습니다.&lt;/p>
&lt;hr>
&lt;h2>배운 점&lt;span class="hx:absolute hx:-mt-20" id="배운-점">&lt;/span>
&lt;a href="#%eb%b0%b0%ec%9a%b4-%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>1. Collation은 조용한 성능 킬러&lt;span class="hx:absolute hx:-mt-20" id="1-collation은-조용한-성능-킬러">&lt;/span>
&lt;a href="#1-collation%ec%9d%80-%ec%a1%b0%ec%9a%a9%ed%95%9c-%ec%84%b1%eb%8a%a5-%ed%82%ac%eb%9f%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>프로시저 파라미터나 세션 변수의 collation은 눈에 보이지 않습니다. MySQL 8.0에서는 기본값이 &lt;code>utf8mb4_0900_ai_ci&lt;/code>인데, 레거시 테이블은 &lt;code>utf8mb3_general_ci&lt;/code>를 사용하는 경우가 많습니다.&lt;/p>
&lt;p>EXPLAIN에서 이런 경고가 나온다면, 반드시 collation을 확인해야 합니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>Cannot use ref access on index due to type or collation conversion&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 경고는 인덱스를 사용할 수 없다는 명확한 신호입니다.&lt;/p>
&lt;h3>2. &amp;ldquo;동작한다&amp;rdquo; ≠ &amp;ldquo;최적화되어 있다&amp;rdquo;&lt;span class="hx:absolute hx:-mt-20" id="2-동작한다--최적화되어-있다">&lt;/span>
&lt;a href="#2-%eb%8f%99%ec%9e%91%ed%95%9c%eb%8b%a4--%ec%b5%9c%ec%a0%81%ed%99%94%eb%90%98%ec%96%b4-%ec%9e%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>개별 쿼리를 직접 실행하면 빠르게 동작하지만, 프로시저 내부에서는 파라미터 바인딩으로 인해 전혀 다른 성능을 보일 수 있습니다.&lt;/p>
&lt;p>반드시 실제 환경과 유사한 조건에서 테스트해야 합니다. 특히 프로시저의 경우 SET profiling을 활용한 상세 분석이 필수적입니다.&lt;/p>
&lt;h3>3. MyISAM은 이제 과거의 유물&lt;span class="hx:absolute hx:-mt-20" id="3-myisam은-이제-과거의-유물">&lt;/span>
&lt;a href="#3-myisam%ec%9d%80-%ec%9d%b4%ec%a0%9c-%ea%b3%bc%ea%b1%b0%ec%9d%98-%ec%9c%a0%eb%ac%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>MyISAM을 사용해야 할 특별한 이유가 없다면, InnoDB를 사용하는 것이 압도적으로 유리합니다:&lt;/p>
&lt;ul>
&lt;li>Row 레벨 락으로 동시성 향상&lt;/li>
&lt;li>트랜잭션 지원으로 데이터 정합성 보장&lt;/li>
&lt;li>자동 크래시 복구&lt;/li>
&lt;li>더 큰 인덱스 키 지원 (3072 bytes)&lt;/li>
&lt;li>Foreign Key 지원&lt;/li>
&lt;/ul>
&lt;p>특히 웹 서비스처럼 동시 접속이 많은 환경에서는 MyISAM의 테이블 락이 심각한 병목이 될 수 있습니다.&lt;/p>
&lt;h3>4. 단계적 마이그레이션의 중요성&lt;span class="hx:absolute hx:-mt-20" id="4-단계적-마이그레이션의-중요성">&lt;/span>
&lt;a href="#4-%eb%8b%a8%ea%b3%84%ec%a0%81-%eb%a7%88%ec%9d%b4%ea%b7%b8%eb%a0%88%ec%9d%b4%ec%85%98%ec%9d%98-%ec%a4%91%ec%9a%94%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>처음부터 완벽한 해결책을 찾으려 하지 말고 단계적으로 접근하는 것이 효과적입니다:&lt;/p>
&lt;ol>
&lt;li>빠른 임시 해결 (지역 변수로 collation 맞추기)&lt;/li>
&lt;li>근본 원인 파악 (utf8mb3 deprecated, MyISAM 제한)&lt;/li>
&lt;li>전체 시스템 개선 (utf8mb4 마이그레이션, InnoDB 전환)&lt;/li>
&lt;/ol>
&lt;p>이런 단계적 접근이 더 안전하고 효과적이었습니다. 특히 운영 중인 서비스에서는 한 번에 모든 것을 바꾸는 것보다 단계별로 검증하며 진행하는 것이 리스크를 줄일 수 있습니다.&lt;/p>
&lt;h3>5. EXPLAIN은 거짓말하지 않는다&lt;span class="hx:absolute hx:-mt-20" id="5-explain은-거짓말하지-않는다">&lt;/span>
&lt;a href="#5-explain%ec%9d%80-%ea%b1%b0%ec%a7%93%eb%a7%90%ed%95%98%ec%a7%80-%ec%95%8a%eb%8a%94%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>성능 문제가 발생하면 반드시 EXPLAIN으로 실행 계획을 확인해야 합니다. 특히 다음 사항들에 주의해야 합니다:&lt;/p>
&lt;ul>
&lt;li>&lt;code>type: ALL&lt;/code> → 풀 테이블 스캔 경고&lt;/li>
&lt;li>경고 메시지 → 무시하지 말고 정확한 원인 파악&lt;/li>
&lt;li>&lt;code>rows&lt;/code> 값 → 예상과 크게 다르다면 문제의 신호&lt;/li>
&lt;/ul>
&lt;p>EXPLAIN의 경고 메시지는 성능 문제의 가장 명확한 단서입니다.&lt;/p>
&lt;h3>6. 레거시 시스템의 숨겨진 기술 부채&lt;span class="hx:absolute hx:-mt-20" id="6-레거시-시스템의-숨겨진-기술-부채">&lt;/span>
&lt;a href="#6-%eb%a0%88%ea%b1%b0%ec%8b%9c-%ec%8b%9c%ec%8a%a4%ed%85%9c%ec%9d%98-%ec%88%a8%ea%b2%a8%ec%a7%84-%ea%b8%b0%ec%88%a0-%eb%b6%80%ec%b1%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이번 작업을 통해 발견한 것은 단순히 프로시저 성능 문제만이 아니었습니다.&lt;/p>
&lt;ul>
&lt;li>deprecated된 utf8mb3 사용&lt;/li>
&lt;li>레거시 스토리지 엔진 MyISAM 사용&lt;/li>
&lt;li>일관되지 않은 character set 및 collation&lt;/li>
&lt;/ul>
&lt;p>표면적인 문제 하나를 해결하려다 보면, 그 아래에 쌓여있던 기술 부채들을 발견하게 됩니다. 이를 기회로 삼아 전체 시스템을 개선할 수 있었습니다.&lt;/p>
&lt;hr>
&lt;h2>마치며&lt;span class="hx:absolute hx:-mt-20" id="마치며">&lt;/span>
&lt;a href="#%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>&amp;ldquo;왜 갑자기 느려진 거지?&amp;rdquo; 하는 단순한 의문에서 시작한 이번 작업은, 생각보다 훨씬 깊은 곳까지 이어졌습니다. Collation 불일치를 발견하고, MyISAM의 숨겨진 제약을 만나고, 결국 데이터베이스 전체를 현대화하는 여정이 되었습니다.&lt;/p>
&lt;p>457ms 걸리던 프로시저를 42ms로 개선했고(약 11배), 121개 테이블을 utf8mb4로 마이그레이션했으며, 109개의 MyISAM 테이블을 InnoDB로 전환했습니다. 숫자로 보면 큰 성과지만, 사실 더 의미 있었던 건 이 과정에서 배운 것들이었습니다.&lt;/p>
&lt;p>처음에는 빠른 해결에만 집중했습니다. 하지만 근본 원인을 파고들면서, 단순한 버그 픽스를 넘어 서비스 인프라를 한 단계 업그레이드하는 기회로 만들 수 있었습니다.&lt;/p>
&lt;p>이제 저희 서비스는&lt;/p>
&lt;ul>
&lt;li>이모지와 특수문자를 완벽하게 지원하고 (utf8mb4)&lt;/li>
&lt;li>더 나은 동시성을 제공하며 (InnoDB Row-level Lock)&lt;/li>
&lt;li>데이터 정합성이 보장되고 (트랜잭션)&lt;/li>
&lt;li>향후 MySQL 버전 업그레이드에도 문제없이 대응할 수 있습니다 (utf8mb3 deprecated 해결)&lt;/li>
&lt;/ul>
&lt;p>성능 문제 하나를 해결하려다 보니, 그동안 쌓여있던 기술 부채들이 하나씩 보였습니다. 표면적인 해결에 그치지 않고 근본 원인까지 파고든 것이 결과적으로 좋은 선택이었습니다.&lt;/p>
&lt;p>비슷한 문제로 고민하고 계신 분들께 이 글이 조금이나마 도움이 되었으면 합니다. 긴 글 읽어주셔서 감사합니다.&lt;/p>
&lt;hr>
&lt;h2>참고 자료&lt;span class="hx:absolute hx:-mt-20" id="참고-자료">&lt;/span>
&lt;a href="#%ec%b0%b8%ea%b3%a0-%ec%9e%90%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>MySQL 공식 문서&lt;span class="hx:absolute hx:-mt-20" id="mysql-공식-문서">&lt;/span>
&lt;a href="#mysql-%ea%b3%b5%ec%8b%9d-%eb%ac%b8%ec%84%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>Character Sets and Collations:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://dev.mysql.com/doc/refman/8.0/en/mysql-indexes.html"target="_blank" rel="noopener">MySQL 8.0 Reference Manual - How MySQL Uses Indexes (Section 10.3.1)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://dev.mysql.com/doc/refman/8.0/en/charset-mysql.html"target="_blank" rel="noopener">MySQL 8.0 Reference Manual - Character Sets and Collations (Section 10.2)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-utf8mb4.html"target="_blank" rel="noopener">MySQL 8.0 Reference Manual - The utf8mb4 Character Set (Section 12.9.1)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-utf8mb3.html"target="_blank" rel="noopener">MySQL 8.0 Reference Manual - The utf8mb3 Character Set (Section 12.9.2)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://dev.mysql.com/blog-archive/mysql-8-0-collations-migrating-from-older-collations/"target="_blank" rel="noopener">MySQL 8.0 Blog - Collations: Migrating from older collations&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>InnoDB and MyISAM:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://dev.mysql.com/doc/refman/8.0/en/innodb-limits.html"target="_blank" rel="noopener">MySQL 8.0 Reference Manual - InnoDB Limits (Section 17.22)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://dev.mysql.com/doc/refman/8.0/en/innodb-locking.html"target="_blank" rel="noopener">MySQL 8.0 Reference Manual - InnoDB Locking (Section 17.7.1)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://dev.mysql.com/doc/refman/8.0/en/innodb-transaction-isolation-levels.html"target="_blank" rel="noopener">MySQL 8.0 Reference Manual - Transaction Isolation Levels (Section 17.7.2.1)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://dev.mysql.com/doc/refman/8.0/en/internal-locking.html"target="_blank" rel="noopener">MySQL 8.0 Reference Manual - Internal Locking Methods (Section 10.11.1)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;h3>MySQL 버그 리포트&lt;span class="hx:absolute hx:-mt-20" id="mysql-버그-리포트">&lt;/span>
&lt;a href="#mysql-%eb%b2%84%ea%b7%b8-%eb%a6%ac%ed%8f%ac%ed%8a%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://bugs.mysql.com/bug.php?id=83856"target="_blank" rel="noopener">Bug #83856: Index ref not used for multi-column IN - type or collation conversion warning&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://bugs.mysql.com/bug.php?id=83857"target="_blank" rel="noopener">Bug #83857: Index not used for the implicit integer to string conversion&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2>주의 사항&lt;span class="hx:absolute hx:-mt-20" id="주의-사항">&lt;/span>
&lt;a href="#%ec%a3%bc%ec%9d%98-%ec%82%ac%ed%95%ad" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이 글은 실제 경험을 바탕으로 작성되었으며, MySQL 공식 문서를 참고하여 작성되었습니다. 하지만 일부 내용에 정확하지 않은 정보가 포함되어 있을 수 있습니다. 제 정보가 정확하지 않을 수 있으니 실제 프로덕션 환경에 적용하기 전에 반드시 공식 문서를 확인하시고, 충분한 테스트를 거치시기 바랍니다&amp;hellip;!&lt;/p></description></item><item><title>16개 레포지토리를 하나로 - MSA 멀티모듈 전환기</title><link>https://jeongil.dev/ko/blog/architecture/msa-to-multi-module/</link><pubDate>Thu, 16 Oct 2025 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/architecture/msa-to-multi-module/</guid><description>
&lt;h2>들어가며&lt;span class="hx:absolute hx:-mt-20" id="들어가며">&lt;/span>
&lt;a href="#%eb%93%a4%ec%96%b4%ea%b0%80%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>안녕하세요.&lt;/p>
&lt;p>저는 프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 3년차 백엔드 개발자 정정일입니다.&lt;/p>
&lt;p>저는 2025년 3월에 팀에 합류에 회사에 16개의 개별 &lt;code>Repository&lt;/code>에서 관리되던 백엔드 프로젝트를 단일 Repository 기반의 멀티모듈 구조로 변경하는 과정을 가지게 됐습니다.&lt;/p>
&lt;p>왜 이런 결정을 내렸고, 그 과정에서 어떤 현실적인 고민들이 있었는지, 그리고 무엇을 얻었는지 담아보려 합니다.&lt;/p>
&lt;hr>
&lt;h2>왜 멀티모듈로 전환했나?&lt;span class="hx:absolute hx:-mt-20" id="왜-멀티모듈로-전환했나">&lt;/span>
&lt;a href="#%ec%99%9c-%eb%a9%80%ed%8b%b0%eb%aa%a8%eb%93%88%eb%a1%9c-%ec%a0%84%ed%99%98%ed%96%88%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>합류 첫날의 충격&lt;span class="hx:absolute hx:-mt-20" id="합류-첫날의-충격">&lt;/span>
&lt;a href="#%ed%95%a9%eb%a5%98-%ec%b2%ab%eb%82%a0%ec%9d%98-%ec%b6%a9%ea%b2%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>저희 회사의 MSA 구조는 각 서비스가 개별 Git 레포지토리로 분리되어 운영되고 있었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>기존 레포 구조:
- agent-service (중개사 서비스)
- ai-service (AI 서비스)
- community-service (커뮤니티 서비스)
- event-service (이벤트 서비스)
- notification-service (알림 서비스)
- real-price-service (실거래가 서비스)
... 총 16개&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>얼핏 보면 MSA의 이상적인 모습처럼 보이지만 저는 팀에 합류한 첫날 꽤나 놀랐습니다.&lt;/p>
&lt;p>레포가 16개라고 놀랄 일인가? 하실 수 있지만 제가 놀란 부분은 &lt;strong>팀 규모 대비 관리하는 레포 갯수&lt;/strong>였습니다. 백엔드 팀의 규모는 저 포함 2명이였고 이는 단순히 계산해봐도 꽤나 인원 대비 관리해야할 레포가 많지 않나 싶었습니다. 16개인 이유는 저희 팀은 제가 합류하는 시점에 모놀리식한 서비스를 MSA로 전환하는 과정중에 있었고 각 서비스를 개별 레포로 관리하고 있었습니다. 이 인원으로 16개의 레포지토리를 관리한다는 건 관리의 용이성 측면에서 말이 안 됐습니다.&lt;/p>
&lt;p>다만 공통적으로 사용하는 코드들이 모듈화가 이루어져 한번의 수정으로 여러 서비스에 적용될 수 있다면 16개라 하더라도 괜찮을 수 있겠다 싶었지만 &lt;strong>아쉽게도 같은 기능을 하는 로직이면 서로 다른 레포에 똑같은 코드가 개별적으로 관리&lt;/strong>되고 있었습니다.&lt;/p>
&lt;h3>반복되는 비효율&lt;span class="hx:absolute hx:-mt-20" id="반복되는-비효율">&lt;/span>
&lt;a href="#%eb%b0%98%eb%b3%b5%eb%90%98%eb%8a%94-%eb%b9%84%ed%9a%a8%ec%9c%a8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>가장 큰 문제는 코드 중복과 설정 불일치였습니다. 예를 들어&lt;/p>
&lt;ul>
&lt;li>&lt;strong>공통 DTO&lt;/strong>: 같은 DTO가 여러 서비스에 복사되어 있었고, 하나를 수정하려면 모든 레포를 찾아다녀야 했습니다&lt;/li>
&lt;li>&lt;strong>유틸리티 클래스&lt;/strong>: &lt;code>FileUtils&lt;/code>, &lt;code>SqsMessageSender&lt;/code> 같은 유틸리티가 여러 곳에 중복 선언되어 있었습니다&lt;/li>
&lt;li>&lt;strong>CI/CD 설정&lt;/strong>: 각 레포마다 거의 동일한 파이프라인 설정을 별도로 관리해야 했습니다&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>가장 심각했던 건 똑같은 수정사항을 모든 레포에 적용해야 하는 경우였습니다.&lt;/strong> 공통 Exception 클래스를 수정할 일이 생겼을 때, 16개 레포를 모두 열어서 하나씩 수정하고 각각 PR을 16개 올리는 작업을 했습니다. 이때 확신했습니다. &lt;strong>&amp;ldquo;이 구조는 우리 팀 규모에 맞지 않다.&amp;rdquo;&lt;/strong>&lt;/p>
&lt;h3>제안과 설득&lt;span class="hx:absolute hx:-mt-20" id="제안과-설득">&lt;/span>
&lt;a href="#%ec%a0%9c%ec%95%88%ea%b3%bc-%ec%84%a4%eb%93%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>팀 합류 한 달쯤 되었을 때, 팀에 멀티모듈 전환을 제안했습니다. 제 생각에는 2~3명으로 운영되는 소규모 팀이 여러 레포로 관리하는 건 관리 용이성 측면에서 오버헤드가 크다고 생각했고, 우리 팀 규모에 맞는 방향이 필요하다 생각했습니다.&lt;/p>
&lt;p>설득은 어렵지 않았습니다. 현재 상황을 분석한 자료를 만들어 보여드렸고 같은 어려움을 몸소 느끼고 계셨던 팀원분들은 적극 찬성해 주셨습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>항목&lt;/th>
&lt;th>멀티레포 (기존)&lt;/th>
&lt;th>모노레포/멀티모듈 (전환 후)&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>공통 모듈 관리&lt;/td>
&lt;td>중복 존재, 수동 복사 필요&lt;/td>
&lt;td>한 곳에서 관리, 즉시 공유&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>CI/CD 구성&lt;/td>
&lt;td>서비스별로 분산 관리&lt;/td>
&lt;td>통합 관리 (독립 배포는 유지)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>테스트 편의성&lt;/td>
&lt;td>통합 테스트 어려움&lt;/td>
&lt;td>통합 테스트 용이&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>로컬 개발 환경&lt;/td>
&lt;td>여러 레포 클론 필요&lt;/td>
&lt;td>한 레포에서 전체 실행 가능&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>팀 규모 적합성&lt;/td>
&lt;td>대규모/조직별 분업&lt;/td>
&lt;td>소규모/협업 중심&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;hr>
&lt;h2>어떻게 전환했나?&lt;span class="hx:absolute hx:-mt-20" id="어떻게-전환했나">&lt;/span>
&lt;a href="#%ec%96%b4%eb%96%bb%ea%b2%8c-%ec%a0%84%ed%99%98%ed%96%88%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>Step 1: 멀티모듈 구조 전환&lt;span class="hx:absolute hx:-mt-20" id="step-1-멀티모듈-구조-전환">&lt;/span>
&lt;a href="#step-1-%eb%a9%80%ed%8b%b0%eb%aa%a8%eb%93%88-%ea%b5%ac%ec%a1%b0-%ec%a0%84%ed%99%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>팀원분들은 멀티모듈에 대한 정보가 거의 없는 상태였기에 멀티모듈로의 전환을 제가 리드하게 됐습니다.
팀원분들의 동의를 받고 일정을 산정한 이후 본격적으로 작업에 들어갔습니다. 첫 번째 단계는 16개의 개별 레포를 하나로 합치면서 멀티모듈 구조로 만드는 것이었습니다.&lt;/p>
&lt;h4>Git History 유지하기&lt;span class="hx:absolute hx:-mt-20" id="git-history-유지하기">&lt;/span>
&lt;a href="#git-history-%ec%9c%a0%ec%a7%80%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>가장 먼저 고민한 것은 기존 커밋 히스토리를 어떻게 유지할 것인가였습니다. 단순히 파일을 복사하면 수년간의 히스토리가 모두 사라지기 때문에, &lt;strong>Git Subtree&lt;/strong>를 이용해 형상관리 히스토리를 유지한 채로 통합했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 각 서비스를 subtree로 추가&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">git subtree add --prefix&lt;span class="o">=&lt;/span>agent-service &lt;span class="o">[&lt;/span>agent-repo-url&lt;span class="o">]&lt;/span> main
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">git subtree add --prefix&lt;span class="o">=&lt;/span>community-service &lt;span class="o">[&lt;/span>ai-repo-url&lt;span class="o">]&lt;/span> main
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># ... 반복&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 과정 덕분에 각 서비스의 개발 이력을 모두 보존할 수 있었습니다.&lt;/p>
&lt;h4>프로젝트 구조 설계&lt;span class="hx:absolute hx:-mt-20" id="프로젝트-구조-설계">&lt;/span>
&lt;a href="#%ed%94%84%eb%a1%9c%ec%a0%9d%ed%8a%b8-%ea%b5%ac%ec%a1%b0-%ec%84%a4%ea%b3%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>멀티모듈 구조를 설계하면서 가장 고민한 부분은 &lt;strong>&amp;ldquo;어떤 기준으로 모듈을 나눌 것인가&amp;rdquo;&lt;/strong> 였습니다.&lt;/p>
&lt;p>저희는 이미 도메인별로 서비스가 분리되어 있었기 때문에, &lt;strong>도메인 기반 모듈 분리 방식&lt;/strong>을 선택했습니다.&lt;/p>
&lt;p>최종적으로 다음과 같은 구조를 만들었습니다:&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/454e7c11-915d-4eae-8da9-83edce478f83/image.png" alt="" loading="lazy" />&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>multimodule_backend/
├── agent-service/ ← 도메인 모듈
├── ai-service/
├── community-service/
├── event-service/
├── notification-service/
├── real-price-service/
├── common/ ← 공통 모듈
├── settings.gradle.kts
└── build.gradle.kts ← 루트 빌드 설정&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>여기서 중요했던 것은 &lt;strong>모듈 간 의존성 방향을 명확히 하는 것&lt;/strong>이었습니다. 저희는 다음과 같은 원칙을 세웠습니다:&lt;/p>
&lt;ul>
&lt;li>각 도메인 서비스 모듈은 &lt;code>common&lt;/code> 모듈만 의존&lt;/li>
&lt;li>도메인 모듈 간에는 &lt;strong>직접 의존 금지&lt;/strong> (순환 참조 방지)&lt;/li>
&lt;li>필요시 이벤트 기반 통신 또는 API 호출 활용&lt;/li>
&lt;/ul>
&lt;h4>Gradle 멀티모듈 설정&lt;span class="hx:absolute hx:-mt-20" id="gradle-멀티모듈-설정">&lt;/span>
&lt;a href="#gradle-%eb%a9%80%ed%8b%b0%eb%aa%a8%eb%93%88-%ec%84%a4%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>멀티모듈 프로젝트를 구성하기 위해서는 3개 파일이 핵심입니다.&lt;/p>
&lt;p>&lt;strong>1) settings.gradle - 모듈 등록&lt;/strong>&lt;/p>
&lt;p>가장 먼저 루트에 &lt;code>settings.gradle&lt;/code> 파일을 만들어 포함할 모듈들을 선언합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-groovy" data-lang="groovy">&lt;span class="line">&lt;span class="cl">&lt;span class="n">rootProject&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">name&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s1">&amp;#39;multimodule_backend&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">include&lt;/span> &lt;span class="s1">&amp;#39;common&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">include&lt;/span> &lt;span class="s1">&amp;#39;agent-service&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">include&lt;/span> &lt;span class="s1">&amp;#39;ai-service&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">include&lt;/span> &lt;span class="s1">&amp;#39;community-service&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s">//&lt;/span> &lt;span class="o">...&lt;/span> &lt;span class="err">나머지&lt;/span> &lt;span class="err">서비스들&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>2) 루트 build.gradle.kts - 공통 설정 정의&lt;/strong>&lt;/p>
&lt;p>루트의 &lt;code>build.gradle.kts&lt;/code>에서 모든 서브 모듈이 공유할 플러그인과 의존성을 정의합니다. 핵심은 &lt;strong>&lt;code>apply false&lt;/code>를 사용해 플러그인 버전만 선언&lt;/strong>하고, 실제 적용은 &lt;code>subprojects&lt;/code> 블록에서 하는 것입니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="n">plugins&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">id&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;org.springframework.boot&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="n">version&lt;/span> &lt;span class="s2">&amp;#34;3.1.1&amp;#34;&lt;/span> &lt;span class="n">apply&lt;/span> &lt;span class="k">false&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">id&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;io.spring.dependency-management&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="n">version&lt;/span> &lt;span class="s2">&amp;#34;1.1.2&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">kotlin&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;jvm&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="n">version&lt;/span> &lt;span class="s2">&amp;#34;1.8.22&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">kotlin&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;plugin.spring&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="n">version&lt;/span> &lt;span class="s2">&amp;#34;1.8.22&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">kotlin&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;plugin.jpa&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="n">version&lt;/span> &lt;span class="s2">&amp;#34;1.8.22&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">val&lt;/span> &lt;span class="py">queryDslVersion&lt;/span> &lt;span class="k">by&lt;/span> &lt;span class="n">extra&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;5.0.0&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="c1">// 공통 버전 변수
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">subprojects&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">group&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;me.example&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">version&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;0.0.1-SNAPSHOT&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 모든 서브 모듈에 플러그인 적용
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">apply&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">plugin&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;org.springframework.boot&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">apply&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">plugin&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;io.spring.dependency-management&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">apply&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">plugin&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;kotlin&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">apply&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">plugin&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;kotlin-spring&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">apply&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">plugin&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;kotlin-jpa&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">dependencies&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 모든 모듈의 공통 의존성
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">implementation&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;org.springframework.boot:spring-boot-starter&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">implementation&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;org.jetbrains.kotlin:kotlin-reflect&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">testImplementation&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;org.springframework.boot:spring-boot-starter-test&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">tasks&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">withType&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">Test&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">useJUnitPlatform&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">maxParallelForks&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="nc">Runtime&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">getRuntime&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="n">availableProcessors&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">/&lt;/span> &lt;span class="m">2&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="n">takeIf&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="k">it&lt;/span> &lt;span class="p">&amp;gt;&lt;/span> &lt;span class="m">0&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="o">?:&lt;/span> &lt;span class="m">1&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>3) common 모듈 설정 - 라이브러리 모듈&lt;/strong>&lt;/p>
&lt;p>중요한 포인트는 &lt;strong>common 모듈은 실행 불가능한 라이브러리&lt;/strong>로 만들어야 한다는 점입니다. 루트 &lt;code>build.gradle.kts&lt;/code>에서 &lt;code>project(&amp;quot;:common&amp;quot;)&lt;/code> 블록으로 설정합니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 루트 build.gradle.kts 하단에 추가
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="n">project&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;:common&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// bootJar 비활성화 (실행 불가능)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">tasks&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">named&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">org&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">springframework&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">boot&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">gradle&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">tasks&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">bundling&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">BootJar&lt;/span>&lt;span class="p">&amp;gt;(&lt;/span>&lt;span class="s2">&amp;#34;bootJar&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">enabled&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="k">false&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// jar 활성화 (라이브러리용)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">tasks&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">named&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">Jar&lt;/span>&lt;span class="p">&amp;gt;(&lt;/span>&lt;span class="s2">&amp;#34;jar&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">enabled&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="k">true&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>4) 각 서비스 모듈 설정 - 실행 가능한 애플리케이션&lt;/strong>&lt;/p>
&lt;p>서비스 모듈들은 루트 &lt;code>build.gradle.kts&lt;/code>에서 &lt;code>project(&amp;quot;:서비스명&amp;quot;)&lt;/code> 블록으로 common 의존성만 추가하면 됩니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 루트 build.gradle.kts
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="n">project&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;:agent-service&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">dependencies&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">implementation&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">project&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;:common&amp;#34;&lt;/span>&lt;span class="p">))&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">project&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;:ai-service&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">dependencies&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">implementation&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">project&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;:common&amp;#34;&lt;/span>&lt;span class="p">))&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// ... 모든 서비스 반복&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>각 서비스의 &lt;code>build.gradle.kts&lt;/code>는 필요한 의존성만 추가:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// agent-service/build.gradle.kts
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">val&lt;/span> &lt;span class="py">queryDslVersion&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">String&lt;/span> &lt;span class="k">by&lt;/span> &lt;span class="n">rootProject&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">extra&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">dependencies&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">implementation&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;org.springframework.boot:spring-boot-starter-data-jpa&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">runtimeOnly&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;com.mysql:mysql-connector-j&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// QueryDSL
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">implementation&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;com.querydsl:querydsl-jpa:&lt;/span>&lt;span class="si">$queryDslVersion&lt;/span>&lt;span class="s2">:jakarta&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">kapt&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;com.querydsl:querydsl-apt:&lt;/span>&lt;span class="si">$queryDslVersion&lt;/span>&lt;span class="s2">:jakarta&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이렇게 설정하면:&lt;/p>
&lt;ul>
&lt;li>공통 설정은 루트에서 한 번만 관리&lt;/li>
&lt;li>각 서비스는 필요한 의존성만 추가&lt;/li>
&lt;li>common 모듈 변경 시 모든 서비스에 자동 반영&lt;/li>
&lt;/ul>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 전체 빌드&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">./gradlew build
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 특정 서비스만 빌드&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">./gradlew :agent-service:build
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 특정 서비스 실행&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">./gradlew :agent-service:bootRun&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h4>버전 통일의 고통&lt;span class="hx:absolute hx:-mt-20" id="버전-통일의-고통">&lt;/span>
&lt;a href="#%eb%b2%84%ec%a0%84-%ed%86%b5%ec%9d%bc%ec%9d%98-%ea%b3%a0%ed%86%b5" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>가장 시간이 오래 걸린 부분은 버전 통일이었습니다. 기존 프로젝트 중 가장 높은 버전인 &lt;code>Spring Boot:3.1.1&lt;/code>를 기준으로 마이그레이션했습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Spring Boot&lt;/strong> 2.7.* → 3.1.1&lt;/li>
&lt;li>&lt;strong>Kotlin&lt;/strong> 1.7.* → 1.8.22&lt;/li>
&lt;li>&lt;strong>AWS SDK&lt;/strong> 버전 업&lt;/li>
&lt;li>&lt;strong>QueryDSL&lt;/strong> 버전 충돌 해결&lt;/li>
&lt;/ul>
&lt;p>Spring Boot 3.x 마이그레이션은 특히 골치 아팠습니다. &lt;code>javax.*&lt;/code> 패키지가 &lt;code>jakarta.*&lt;/code>로 변경되면서 수많은 import 문을 수정해야 했고, 일부 라이브러리는 호환되지 않아 대체 라이브러리를 찾아야 했습니다.&lt;/p>
&lt;p>&lt;strong>230,909개의 라인이 추가&lt;/strong>된 거대한 PR이 만들어졌습니다. 😂&lt;/p>
&lt;h4>빌드 성능 개선&lt;span class="hx:absolute hx:-mt-20" id="빌드-성능-개선">&lt;/span>
&lt;a href="#%eb%b9%8c%eb%93%9c-%ec%84%b1%eb%8a%a5-%ea%b0%9c%ec%84%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>전체 프로젝트가 커지면서 빌드할 때 IntelliJ의 JVM이 heap이 터지는 경우도 있었습니다. 해당 문제를 해결하기 위해 Gradle 설정을 개선했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-properties" data-lang="properties">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># gradle.properties&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">org.gradle.jvmargs&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">-Xmx2g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">org.gradle.parallel&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">true&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// build.gradle.kts
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="n">tasks&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">withType&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="n">Test&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">useJUnitPlatform&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">maxParallelForks&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="nc">Runtime&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">getRuntime&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="n">availableProcessors&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">/&lt;/span> &lt;span class="m">2&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="n">takeIf&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="k">it&lt;/span> &lt;span class="p">&amp;gt;&lt;/span> &lt;span class="m">0&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="o">?:&lt;/span> &lt;span class="m">1&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 개선으로 전체 빌드 시간이 27분에서 8분으로 대폭 단축되었습니다!&lt;/p>
&lt;h3>Step 2: 공통 로직 정리 및 모듈화&lt;span class="hx:absolute hx:-mt-20" id="step-2-공통-로직-정리-및-모듈화">&lt;/span>
&lt;a href="#step-2-%ea%b3%b5%ed%86%b5-%eb%a1%9c%ec%a7%81-%ec%a0%95%eb%a6%ac-%eb%b0%8f-%eb%aa%a8%eb%93%88%ed%99%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>두 번째 단계는 중복되어 있던 코드들을 &lt;code>common&lt;/code> 모듈로 이전하는 작업이었습니다.&lt;/p>
&lt;h4>공통 모듈 설계&lt;span class="hx:absolute hx:-mt-20" id="공통-모듈-설계">&lt;/span>
&lt;a href="#%ea%b3%b5%ed%86%b5-%eb%aa%a8%eb%93%88-%ec%84%a4%ea%b3%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>&lt;code>common&lt;/code> 모듈에 다음과 같은 것들을 모았습니다:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>공통 DTO&lt;/strong>: 여러 서비스에서 사용하는 응답/요청 객체들&lt;/li>
&lt;li>&lt;strong>유틸리티 클래스&lt;/strong>: &lt;code>FileUtils&lt;/code>, &lt;code>SqsMessageSender&lt;/code> 등&lt;/li>
&lt;li>&lt;strong>공통 Exception&lt;/strong>: &lt;code>GlobalExceptionHandler&lt;/code>, 커스텀 예외 클래스들&lt;/li>
&lt;li>&lt;strong>공통 설정&lt;/strong>: Spring Bean 정의, Auto Configuration&lt;/li>
&lt;/ul>
&lt;h4>Auto Configuration 적용&lt;span class="hx:absolute hx:-mt-20" id="auto-configuration-적용">&lt;/span>
&lt;a href="#auto-configuration-%ec%a0%81%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>각 서비스에서 &lt;code>common&lt;/code> 모듈의 빈들을 자동으로 등록할 수 있도록 Spring Boot Auto Configuration을 구현했습니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// common/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="n">me&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">example&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">common&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">config&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">CommonAutoConfiguration&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;span class="lnt">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@AutoConfiguration&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@ConditionalOnProperty&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">prefix&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;example.common&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">name&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;enabled&amp;#34;&lt;/span>&lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">havingValue&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;true&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">matchIfMissing&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="k">true&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Import&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">CommonComponentConfig&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="k">class&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">CommonAutoConfiguration&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이제 각 서비스는 단순히 &lt;code>implementation(project(&amp;quot;:common&amp;quot;))&lt;/code>만 추가하면 공통 기능을 사용할 수 있게 되었습니다.&lt;/p>
&lt;h4>중복 코드 정리의 놀라움&lt;span class="hx:absolute hx:-mt-20" id="중복-코드-정리의-놀라움">&lt;/span>
&lt;a href="#%ec%a4%91%eb%b3%b5-%ec%bd%94%eb%93%9c-%ec%a0%95%eb%a6%ac%ec%9d%98-%eb%86%80%eb%9d%bc%ec%9b%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>작업을 진행하면서 놀라웠던 것은 중복 코드의 양이 생각보다 훨씬 많았다는 점입니다. 같은 목적의 Enum 클래스인데 서로 다른 서비스에서 필드 이름이 다른 경우도 있었고, 거의 동일한 유틸리티 메서드가 5~6개 서비스에 복사되어 있기도 했습니다.&lt;/p>
&lt;p>&lt;strong>5,545개의 라인 변경&lt;/strong>을 통해 이 모든 중복을 제거했습니다.&lt;/p>
&lt;h3>Step 3: CI/CD 파이프라인 재구성&lt;span class="hx:absolute hx:-mt-20" id="step-3-cicd-파이프라인-재구성">&lt;/span>
&lt;a href="#step-3-cicd-%ed%8c%8c%ec%9d%b4%ed%94%84%eb%9d%bc%ec%9d%b8-%ec%9e%ac%ea%b5%ac%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>멀티모듈 구조로 전환하면서 가장 중요했던 것 중 하나는 &lt;strong>독립적인 배포&lt;/strong>를 유지하는 것이었습니다. 한 서비스를 수정했다고 모든 서비스가 재배포되면 안 되니까요.&lt;/p>
&lt;p>저희는 CI/CD가 Github actions로 구성돼 있었기 때문에 배포 스크립트를 수정하는 과정을 거쳤습니다.&lt;/p>
&lt;hr>
&lt;h2>전환 후 달라진 점&lt;span class="hx:absolute hx:-mt-20" id="전환-후-달라진-점">&lt;/span>
&lt;a href="#%ec%a0%84%ed%99%98-%ed%9b%84-%eb%8b%ac%eb%9d%bc%ec%a7%84-%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h4>1. 개발 생산성 향상&lt;span class="hx:absolute hx:-mt-20" id="1-개발-생산성-향상">&lt;/span>
&lt;a href="#1-%ea%b0%9c%eb%b0%9c-%ec%83%9d%ec%82%b0%ec%84%b1-%ed%96%a5%ec%83%81" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>공통 코드 수정이 필요할 때 이제는 &lt;code>common&lt;/code> 모듈 한 곳만 수정하면 됩니다. 예를 들어 Exception 처리 로직을 개선하거나 새로운 유틸리티를 추가할 때, 16개 레포를 돌아다닐 필요가 없어졌습니다.&lt;/p>
&lt;h4>2. 일관된 코드 품질&lt;span class="hx:absolute hx:-mt-20" id="2-일관된-코드-품질">&lt;/span>
&lt;a href="#2-%ec%9d%bc%ea%b4%80%eb%90%9c-%ec%bd%94%eb%93%9c-%ed%92%88%ec%a7%88" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>버전과 설정이 통일되면서 코드의 일관성이 크게 향상되었습니다. 이제 모든 서비스가 동일한 Spring Boot 버전을 사용하고, 같은 코딩 컨벤션을 따릅니다.&lt;/p>
&lt;h4>3. 통합 테스트 용이&lt;span class="hx:absolute hx:-mt-20" id="3-통합-테스트-용이">&lt;/span>
&lt;a href="#3-%ed%86%b5%ed%95%a9-%ed%85%8c%ec%8a%a4%ed%8a%b8-%ec%9a%a9%ec%9d%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>여러 서비스 간의 통합 테스트를 작성하기가 훨씬 쉬워졌습니다. 같은 프로젝트 내에 있으니 서비스 간 인터페이스를 테스트하는 것도 자연스럽게 할 수 있습니다.&lt;/p>
&lt;h4>4. 신규 서비스 추가 시간 단축&lt;span class="hx:absolute hx:-mt-20" id="4-신규-서비스-추가-시간-단축">&lt;/span>
&lt;a href="#4-%ec%8b%a0%ea%b7%9c-%ec%84%9c%eb%b9%84%ec%8a%a4-%ec%b6%94%ea%b0%80-%ec%8b%9c%ea%b0%84-%eb%8b%a8%ec%b6%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>새로운 서비스를 추가할 때도 보일러플레이트 코드를 작성할 필요가 없어졌습니다. &lt;code>common&lt;/code> 모듈을 의존하고, 필요한 비즈니스 로직만 작성하면 됩니다.&lt;/p>
&lt;p>실제로 서비스를 하나 새로 추가할 때 기본 설정에 들어가는 시간이 크게 줄어들었습니다.&lt;/p>
&lt;h4>5. 팀 협업 개선&lt;span class="hx:absolute hx:-mt-20" id="5-팀-협업-개선">&lt;/span>
&lt;a href="#5-%ed%8c%80-%ed%98%91%ec%97%85-%ea%b0%9c%ec%84%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>코드 리뷰할 때도 전체 컨텍스트를 보기 쉬워졌습니다. 같은 레포지토리 안에서 영향받는 다른 서비스를 바로 확인할 수 있으니, 변경 사항의 영향 범위를 파악하기가 훨씬 수월해졌습니다.&lt;/p>
&lt;hr>
&lt;h2>겪었던 어려움과 해결&lt;span class="hx:absolute hx:-mt-20" id="겪었던-어려움과-해결">&lt;/span>
&lt;a href="#%ea%b2%aa%ec%97%88%eb%8d%98-%ec%96%b4%eb%a0%a4%ec%9b%80%ea%b3%bc-%ed%95%b4%ea%b2%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>1. 빌드 시간 증가&lt;span class="hx:absolute hx:-mt-20" id="1-빌드-시간-증가">&lt;/span>
&lt;a href="#1-%eb%b9%8c%eb%93%9c-%ec%8b%9c%ea%b0%84-%ec%a6%9d%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>초기에는 전체 프로젝트를 빌드할 때 시간이 오래 걸렸습니다. 특히 모든 테스트를 돌리면 상당한 시간이 소요됐죠.&lt;/p>
&lt;p>&lt;strong>해결책&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>Gradle 병렬 빌드 활성화&lt;/li>
&lt;li>변경된 모듈만 빌드하도록 스크립트 개선&lt;/li>
&lt;li>테스트도 병렬로 실행 (&lt;code>maxParallelForks&lt;/code> 설정)&lt;/li>
&lt;/ul>
&lt;h3>2. 버전 문제&lt;span class="hx:absolute hx:-mt-20" id="2-버전-문제">&lt;/span>
&lt;a href="#2-%eb%b2%84%ec%a0%84-%eb%ac%b8%ec%a0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>버전을 통일하는 과정에서 의존성 충돌이 발생하는 경우도 있었고, 기존 버전에선 문제 없던 설정이 버전을 올리며 문제가 되는 경우들도 있었습니다. 이 문제를 하나하나 해결해줘야했죠 🥲&lt;/p>
&lt;h3>3. CI/CD 파이프라인 복잡도&lt;span class="hx:absolute hx:-mt-20" id="3-cicd-파이프라인-복잡도">&lt;/span>
&lt;a href="#3-cicd-%ed%8c%8c%ec%9d%b4%ed%94%84%eb%9d%bc%ec%9d%b8-%eb%b3%b5%ec%9e%a1%eb%8f%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>16개 서비스를 독립적으로 배포하면서도 공통 모듈 변경 시 영향받는 모든 서비스를 재배포해야 하는 로직을 구현하는 것이 복잡했습니다.&lt;/p>
&lt;p>&lt;strong>해결책&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>&lt;code>common&lt;/code> 모듈 변경 시 모든 서비스 빌드&lt;/li>
&lt;li>개별 서비스 변경 시 해당 서비스만 빌드&lt;/li>
&lt;li>명확한 배포 매트릭스 정의&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2>배운 점&lt;span class="hx:absolute hx:-mt-20" id="배운-점">&lt;/span>
&lt;a href="#%eb%b0%b0%ec%9a%b4-%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>1. 아키텍처는 팀에 맞게&lt;span class="hx:absolute hx:-mt-20" id="1-아키텍처는-팀에-맞게">&lt;/span>
&lt;a href="#1-%ec%95%84%ed%82%a4%ed%85%8d%ec%b2%98%eb%8a%94-%ed%8c%80%ec%97%90-%eb%a7%9e%ea%b2%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>MSA를 멀티레포로 운영하는 것이 꼭 정답은 아니라고 생각합니다. 팀 규모, 조직 구조, 협업 방식에 따라 모노레포가 더 적합할 수 있지 않나 싶습니다. 저희 팀처럼 소규모 팀에서는 모노레포/멀티모듈이 훨씬 효율적인 것 같습니다.&lt;/p>
&lt;h3>2. 점진적 마이그레이션의 중요성&lt;span class="hx:absolute hx:-mt-20" id="2-점진적-마이그레이션의-중요성">&lt;/span>
&lt;a href="#2-%ec%a0%90%ec%a7%84%ec%a0%81-%eb%a7%88%ec%9d%b4%ea%b7%b8%eb%a0%88%ec%9d%b4%ec%85%98%ec%9d%98-%ec%a4%91%ec%9a%94%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>한 번에 모든 것을 바꾸려고 하면 부담이 너무 크다고 생각합니다. 저희는&lt;/p>
&lt;ol>
&lt;li>먼저 구조만 통합 (Step 1)&lt;/li>
&lt;li>그다음 공통 로직 정리 (Step 2)&lt;/li>
&lt;li>마지막으로 CI/CD 재구성 (Step 3)&lt;/li>
&lt;/ol>
&lt;p>이렇게 단계적으로 접근했기 때문에 각 단계에서 문제를 해결하고 안정화할 수 있었습니다.&lt;/p>
&lt;h3>3. 히스토리 보존의 가치&lt;span class="hx:absolute hx:-mt-20" id="3-히스토리-보존의-가치">&lt;/span>
&lt;a href="#3-%ed%9e%88%ec%8a%a4%ed%86%a0%eb%a6%ac-%eb%b3%b4%ec%a1%b4%ec%9d%98-%ea%b0%80%ec%b9%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Git Subtree를 사용해 커밋 히스토리를 보존한 것은 정말 잘한 선택이었습니다. 나중에 버그를 추적하거나 변경 이유를 파악할 때 큰 도움이 되었습니다.&lt;/p>
&lt;h3>4. 독립 배포는 꼭 유지&lt;span class="hx:absolute hx:-mt-20" id="4-독립-배포는-꼭-유지">&lt;/span>
&lt;a href="#4-%eb%8f%85%eb%a6%bd-%eb%b0%b0%ed%8f%ac%eb%8a%94-%ea%bc%ad-%ec%9c%a0%ec%a7%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>모노레포로 통합했지만 각 서비스의 독립적인 배포는 반드시 유지해야 합니다. 이것이 MSA의 핵심 장점이니까요. 저희는 CI/CD 파이프라인을 잘 설계해서 이 부분을 지킬 수 있었습니다.&lt;/p>
&lt;h3>5. Common 모듈은 최소화하라&lt;span class="hx:absolute hx:-mt-20" id="5-common-모듈은-최소화하라">&lt;/span>
&lt;a href="#5-common-%eb%aa%a8%eb%93%88%ec%9d%80-%ec%b5%9c%ec%86%8c%ed%99%94%ed%95%98%eb%9d%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>멀티모듈 전환의 가장 큰 함정 중 하나는 &lt;strong>&amp;ldquo;공통으로 사용하는 코드라면 common에&amp;rdquo;&lt;/strong> 라는 생각인것 같습니다. 원하든 원치 않든 여러 서비스가 공통적으로 사용할 코드는 늘어나고 변하고 삭제됩니다. 이럴때마다 Common 모듈은 변화하게 될텐데 이는 자칫 잘못하면 프로젝트 전체에 영향을 주게 된다는말과 다르지 않습니다.&lt;/p>
&lt;p>초기에는 저도 이렇게 접근하며 멀티모듈로 전환하다가 Common 모듈이 비대해지면서 &lt;strong>&amp;ldquo;이래도 되나&amp;hellip;?&amp;rdquo;&lt;/strong> 싶은 순간들이 생겼고, 작업하던 내용을 날리고 공통 모듈의 기준을 정확하게 새우고 작업을 해야겠다 다짐하게 됐습니다.&lt;/p>
&lt;p>&lt;strong>해결책은 간단했습니다. Common을 최소화하고, 나머지는 기능별로 분리하는 것입니다.&lt;/strong>&lt;/p>
&lt;p>감사하게도 저희가 겪으려던 과정을 이미 체험하신 개발자 분들이 계셨고 이를 &lt;a href="https://techblog.woowahan.com/2637/"target="_blank" rel="noopener">경험과 함께 공유&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>해주셨기 때문에 저희는 같은 문제를 겪지 않을 수 있었습니다.&lt;/p>
&lt;p>위 글에 적힌것처럼 common은 정말 &lt;strong>모든 서비스가 사용하는 Type, Enum, Util 정도만&lt;/strong> 포함시켰습니다. 인프라 관련 코드(JPA, Redis, S3 등)는 별도 모듈로 분리하여 필요한 서비스만 선택적으로 의존하도록 했습니다.&lt;/p>
&lt;h3>6. 순환 참조 방지의 중요성&lt;span class="hx:absolute hx:-mt-20" id="6-순환-참조-방지의-중요성">&lt;/span>
&lt;a href="#6-%ec%88%9c%ed%99%98-%ec%b0%b8%ec%a1%b0-%eb%b0%a9%ec%a7%80%ec%9d%98-%ec%a4%91%ec%9a%94%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>멀티모듈 구조에서 또 하나 조심해야할 것은 &lt;strong>순환 참조&lt;/strong>입니다. A 모듈이 B 모듈을 참조하고, B 모듈이 다시 A 모듈을 참조하면 빌드 자체가 실패합니다.&lt;/p>
&lt;p>저희는 이를 방지하기 위해&lt;/p>
&lt;ul>
&lt;li>도메인 모듈 간 직접 의존을 금지했습니다&lt;/li>
&lt;li>모듈 간 명확한 계층 구조를 정의했습니다&lt;/li>
&lt;li>서비스 간 통신이 필요하면 이벤트나 API 호출을 사용하도록 했습니다&lt;/li>
&lt;/ul>
&lt;p>초기에 이 원칙을 명확히 세워둔 덕분에 큰 문제 없이 진행할 수 있었습니다.&lt;/p>
&lt;hr>
&lt;h2>마치며&lt;span class="hx:absolute hx:-mt-20" id="마치며">&lt;/span>
&lt;a href="#%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>저희는 다행히 멀티모듈 전환 프로젝트를 무사히 마쳤습니다. 지금 돌이켜보면 팀에 합류한지 얼마 안된 저를 믿고 멀티모듈로의 전환을 맡겨주신 팀원분들께 감사했습니다. 팀의 신뢰와 지원 덕분에 해낼 수 있었다고 생각합니다.&lt;/p>
&lt;p>제가 이번 작업을 하면서 가장 크게 느낀 점은 &lt;strong>&amp;ldquo;좋은 아키텍처는 이론이 아니라 팀 상황에 맞춰야 한다&amp;rdquo;&lt;/strong> 는 것이었습니다. &amp;ldquo;MSA = 멀티레포&amp;quot;라는 고정관념에서 벗어나, 백엔드 2~3명이라는 우리 팀 현실에 맞는 구조를 찾았다는 게 뿌듯합니다.&lt;/p>
&lt;p>이제는 코드 중복 걱정 없이 개발할 수 있고, 팀원들도 협업이 훨씬 수월해졌다고 이야기합니다. 무엇보다 입사 초기에 이런 큰 프로젝트를 맡겨주신 팀에 감사하고, 좋은 결과로 보답할 수 있어서 다행입니다.&lt;/p>
&lt;p>여러분의 팀도 비슷한 고민을 하고 계신다면, 이 글이 조금이나마 도움이 되었으면 좋겠습니다. 긴 글 읽어주셔서 감사합니다!&lt;/p></description></item><item><title>개발자가 새 회사에 빠르게 적응하는 3가지 방법</title><link>https://jeongil.dev/ko/blog/culture/developers-to-quickly-adapt-to-a-new-company/</link><pubDate>Tue, 30 Sep 2025 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/culture/developers-to-quickly-adapt-to-a-new-company/</guid><description>
&lt;p>안녕하세요.&lt;/p>
&lt;p>프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 3년 차 백엔드 개발자 정정일입니다.&lt;/p>
&lt;p>이직은 누구에게나 쉽지 않은 일입니다. 새로운 코드베이스, 낯선 팀 문화, 모르는 비즈니스 도메인&amp;hellip; 저 역시 새 회사에 합류했을 때 막막했습니다.&lt;/p>
&lt;p>오늘은 제가 새로운 회사에 합류하면서 &lt;strong>어떻게 적응해 나갔는지&lt;/strong>, 그 과정에서 시도해본 방법들을 공유하려 합니다.&lt;/p>
&lt;p>입사 이튿날부터 온보딩 문서를 조금씩 업데이트하기 시작했고, 일주일 만에 시스템 아키텍처를 그려봤으며, 1.5개월 만에 모니터링 시스템을 구축할 수 있었습니다.&lt;/p>
&lt;p>물론 특별한 능력이 있어서가 아니라, 시행착오를 겪으며 조금씩 해나간 결과라고 생각합니다.&lt;/p>
&lt;hr>
&lt;h2>첫 출근날의 선택: 소비자인가, 생산자인가&lt;span class="hx:absolute hx:-mt-20" id="첫-출근날의-선택-소비자인가-생산자인가">&lt;/span>
&lt;a href="#%ec%b2%ab-%ec%b6%9c%ea%b7%bc%eb%82%a0%ec%9d%98-%ec%84%a0%ed%83%9d-%ec%86%8c%eb%b9%84%ec%9e%90%ec%9d%b8%ea%b0%80-%ec%83%9d%ec%82%b0%ec%9e%90%ec%9d%b8%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>새 회사 첫 출근날, 누구나 긴장하면서도 설레는 마음으로 사무실 문을 엽니다. 저 역시 마찬가지였습니다.&lt;/p>
&lt;p>저는 2025년 3월 새로운 팀에 합류하게 됐고 지금은 9월이니 벌써 6개월이 지나게 됐네요.&lt;/p>
&lt;p>입사 당시에 온보딩 담당자분께서 건네주신 문서들은 다음과 같았습니다.&lt;/p>
&lt;ul>
&lt;li>회사 소개서&lt;/li>
&lt;li>백엔드 온보딩 가이드&lt;/li>
&lt;li>기술 스택 문서&lt;/li>
&lt;li>개발 환경 셋업 가이드&lt;/li>
&lt;/ul>
&lt;p>온보딩 문서를 읽으면서 든 생각은 이랬습니다.&lt;/p>
&lt;p>&amp;ldquo;아, 이 부분은 업데이트가 안 됐네?&amp;rdquo;
&amp;ldquo;이 기술은 언제 추가된 거지? 문서에는 없는데&amp;hellip;&amp;rdquo;
&amp;ldquo;시스템 전체 구조가 한눈에 보이는 다이어그램이 있으면 좋겠다&amp;rdquo;&lt;/p>
&lt;p>&lt;strong>온보딩 문서가 완벽하지 않았습니다.&lt;/strong> 그런데 이건 당연한 일입니다. 문서는 항상 코드보다 뒤처지기 마련이고, 모든 것을 담을 수도 없습니다.&lt;/p>
&lt;p>여기서 저는 두 가지 선택지를 마주했습니다&lt;/p>
&lt;ol>
&lt;li>&lt;strong>소비자로 남기&lt;/strong>: 문서를 읽고, 부족한 부분은 직접 물어보면서 알아가기&lt;/li>
&lt;li>&lt;strong>생산자로 전환하기&lt;/strong>: 내가 배운 것을 문서에 추가하면서 알아가기&lt;/li>
&lt;/ol>
&lt;p>저는 2번을 선택했습니다.&lt;/p>
&lt;hr>
&lt;h2>전략 1: 온보딩 문서를 직접 개선해보기 - 소비자에서 생산자로&lt;span class="hx:absolute hx:-mt-20" id="전략-1-온보딩-문서를-직접-개선해보기---소비자에서-생산자로">&lt;/span>
&lt;a href="#%ec%a0%84%eb%9e%b5-1-%ec%98%a8%eb%b3%b4%eb%94%a9-%eb%ac%b8%ec%84%9c%eb%a5%bc-%ec%a7%81%ec%a0%91-%ea%b0%9c%ec%84%a0%ed%95%b4%eb%b3%b4%ea%b8%b0---%ec%86%8c%eb%b9%84%ec%9e%90%ec%97%90%ec%84%9c-%ec%83%9d%ec%82%b0%ec%9e%90%eb%a1%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>입사 이튿날, 첫 PR&lt;span class="hx:absolute hx:-mt-20" id="입사-이튿날-첫-pr">&lt;/span>
&lt;a href="#%ec%9e%85%ec%82%ac-%ec%9d%b4%ed%8a%bf%eb%82%a0-%ec%b2%ab-pr" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>입사 당일, 온보딩 문서를 읽으면서 발견한 것들을 메모했습니다. 그리고 다음 날, 첫 PR을 올렸습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-markdown" data-lang="markdown">&lt;span class="line">&lt;span class="cl">&lt;span class="gh"># 추가된 내용
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gh">&lt;/span>&lt;span class="k">-&lt;/span> Tech Stack: Spring Boot, Kotlin, MySQL, Redis, ...
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">-&lt;/span> 인프라: AWS, GCP (병행 사용 중)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- 모니터링: AWS CloudWatch 사용중&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&amp;ldquo;입사 다음날 PR을 올린다고?&amp;rdquo; 부담스럽게 느낄 수도 있는데, 저도 처음엔 망설였습니다. 하지만 이렇게 접근하니 생각보다 자연스러웠습니다&lt;/p>
&lt;ul>
&lt;li>&amp;ldquo;이 부분이 틀렸어요&amp;rdquo; (X)&lt;/li>
&lt;li>&amp;ldquo;이 부분이 궁금해서 알아봤는데, 제가 이해하고 있는게 맞을까요?&amp;rdquo; (O)&lt;/li>
&lt;/ul>
&lt;p>온보딩 문서 개선은 &lt;strong>비교적 안전하게 시작할 수 있는 기여&lt;/strong>였습니다.&lt;/p>
&lt;ul>
&lt;li>코드에 직접 손대지 않아도 됨&lt;/li>
&lt;li>실수해도 큰 문제가 되지 않음&lt;/li>
&lt;li>팀에 도움이 될 수 있음&lt;/li>
&lt;li>내가 배운 것을 정리하는 과정&lt;/li>
&lt;/ul>
&lt;h3>작지만 꾸준하게&lt;span class="hx:absolute hx:-mt-20" id="작지만-꾸준하게">&lt;/span>
&lt;a href="#%ec%9e%91%ec%a7%80%eb%a7%8c-%ea%be%b8%ec%a4%80%ed%95%98%ea%b2%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>입사 후 몇 주간, 저는 매일 조금씩 문서를 개선했습니다&lt;/p>
&lt;ul>
&lt;li>3월 11일: Tech Stack 추가&lt;/li>
&lt;li>3월 12일: AWS Lambda 추가&lt;/li>
&lt;li>3월 14일: DDD 설계 관련 내용 추가 (애그리게이트 vs 도메인 서비스)&lt;/li>
&lt;/ul>
&lt;p>제게는 &lt;strong>&amp;lsquo;완벽함&amp;rsquo;보다 내가 지금 이해하고 있는 부분에 대한 &amp;lsquo;정돈&amp;rsquo;&lt;/strong> 이 중요했습니다. 하루에 한 줄이라도, 내가 배운 것을 문서에 추가해 나갔습니다.&lt;/p>
&lt;h3>이렇게 하니 좋았던 점&lt;span class="hx:absolute hx:-mt-20" id="이렇게-하니-좋았던-점">&lt;/span>
&lt;a href="#%ec%9d%b4%eb%a0%87%ea%b2%8c-%ed%95%98%eb%8b%88-%ec%a2%8b%ec%95%98%eb%8d%98-%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ol>
&lt;li>&lt;strong>빠른 학습&lt;/strong>: 문서를 &amp;ldquo;읽기만&amp;rdquo; 하는 것보다 &amp;ldquo;쓰면서&amp;rdquo; 배우니 이해가 더 빨랐습니다&lt;/li>
&lt;li>&lt;strong>능동적 자세&lt;/strong>: 질문할 때도 &amp;ldquo;이거 뭐에요?&amp;ldquo;가 아니라 &amp;ldquo;이렇게 이해했는데 맞나요?&amp;ldquo;로 바뀌었습니다&lt;/li>
&lt;li>&lt;strong>팀에 기여&lt;/strong>: 다음 신입 개발자가 조금 더 수월하게 온보딩할 수 있게 됐습니다&lt;/li>
&lt;li>&lt;strong>신뢰 획득&lt;/strong>: 팀원들께 좋은 인상을 드릴 수 있었던 것 같습니다&lt;/li>
&lt;/ol>
&lt;hr>
&lt;h2>전략 2: 이해를 위해 그려보기 - 그림으로 시스템 파악하기&lt;span class="hx:absolute hx:-mt-20" id="전략-2-이해를-위해-그려보기---그림으로-시스템-파악하기">&lt;/span>
&lt;a href="#%ec%a0%84%eb%9e%b5-2-%ec%9d%b4%ed%95%b4%eb%a5%bc-%ec%9c%84%ed%95%b4-%ea%b7%b8%eb%a0%a4%eb%b3%b4%ea%b8%b0---%ea%b7%b8%eb%a6%bc%ec%9c%bc%eb%a1%9c-%ec%8b%9c%ec%8a%a4%ed%85%9c-%ed%8c%8c%ec%95%85%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>입사 1주일, 여전히 막막&lt;span class="hx:absolute hx:-mt-20" id="입사-1주일-여전히-막막">&lt;/span>
&lt;a href="#%ec%9e%85%ec%82%ac-1%ec%a3%bc%ec%9d%bc-%ec%97%ac%ec%a0%84%ed%9e%88-%eb%a7%89%eb%a7%89" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>입사 일주일 차, 저는 여전히 전체 시스템 구조를 완전히 파악하고 있진 않았습니다. 이는 사실 당연하기도 합니다. 운영중인 서비스의 전체적인 흐름을 일주일만에 파악하긴 어려우니까요.&lt;/p>
&lt;ul>
&lt;li>&amp;ldquo;레거시 서비스가 MSA를 호출하기도 하나?&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;AWS SQS는 어떤 서비스들이 컨슘하고 이벤트를 발행하고 있나?&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;Elastic Search는 어떻게 사용되고 있는거지?&amp;rdquo;&lt;/li>
&lt;/ul>
&lt;p>코드를 보면서 조각조각 이해는 되는데, 전체 그림이 그려지지 않았습니다.&lt;/p>
&lt;p>그래서 시도했습니다: &lt;strong>&amp;ldquo;직접 그려보자.&amp;rdquo;&lt;/strong>&lt;/p>
&lt;h3>Draw.io와의 사투&lt;span class="hx:absolute hx:-mt-20" id="drawio와의-사투">&lt;/span>
&lt;a href="#drawio%ec%99%80%ec%9d%98-%ec%82%ac%ed%88%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>주말에 Draw.io를 열고, 제가 이해한 시스템을 그리기 시작했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>[Client] → [API Gateway] → [User Service] → [MySQL]
→ [Match Service] → [Redis]
→ [Payment Service] → [외부 PG API]&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>처음에는 단순하게 시작했습니다. 그리고 하나하나 추가해나갔습니다:&lt;/p>
&lt;ul>
&lt;li>각 서비스 간 통신 방식 (REST API)&lt;/li>
&lt;li>데이터베이스 연결&lt;/li>
&lt;li>외부 API 연동&lt;/li>
&lt;li>메시지 큐 (SQS)&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>막히는 부분은 질문하고, 답을 들으면 다시 그림에 반영했습니다.&lt;/strong>&lt;/p>
&lt;h3>검증 과정&lt;span class="hx:absolute hx:-mt-20" id="검증-과정">&lt;/span>
&lt;a href="#%ea%b2%80%ec%a6%9d-%ea%b3%bc%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>그리고 시스템 아키턱처를 추가하는 PR을 올렸습니다.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;이 PR의 항목은 다음과 같습니다!&lt;/p>
&lt;ul>
&lt;li>백엔드 시스템 아키텍처 추가&lt;/li>
&lt;/ul>
&lt;p>혹시 수정이 필요하거나 개선할 점이 있다면 말씀해주시면 감사하겠습니다!
검토해 주셔서 감사합니다! 😊&amp;rdquo;&lt;/p>
&lt;/blockquote>
&lt;p>완벽한 다이어그램을 만들려는 게 아니라, &lt;strong>내가 이해한 것을 공유하고 피드백받기 위한 수단&lt;/strong>으로 활용했습니다.&lt;/p>
&lt;h3>이렇게 하니 좋았던 점&lt;span class="hx:absolute hx:-mt-20" id="이렇게-하니-좋았던-점-1">&lt;/span>
&lt;a href="#%ec%9d%b4%eb%a0%87%ea%b2%8c-%ed%95%98%eb%8b%88-%ec%a2%8b%ec%95%98%eb%8d%98-%ec%a0%90-1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ol>
&lt;li>&lt;strong>전체 시스템 이해&lt;/strong>: 그리는 과정에서 자연스럽게 전체 구조가 머릿속에 그려졌습니다&lt;/li>
&lt;li>&lt;strong>구체적인 질문&lt;/strong>: &amp;ldquo;이 부분이 어떻게 되나요?&amp;ldquo;가 아니라 &amp;ldquo;A와 B는 이렇게 연결되는 게 맞나요?&amp;ldquo;처럼 구체적으로 물을 수 있었습니다&lt;/li>
&lt;li>&lt;strong>팀의 반응&lt;/strong>: 다이어그램이 없었던 팀이라 필요해하셨던 것 같습니다&lt;/li>
&lt;li>&lt;strong>살아있는 문서&lt;/strong>: 이후 시스템이 변경될 때마다 계속 업데이트할 수 있었습니다&lt;/li>
&lt;/ol>
&lt;p>실제로 4월에 모니터링 시스템을 구축한 후, 다이어그램에 Metrics 서버를 추가했고, 8월에도 새로운 서비스가 추가되면서 계속 갱신했습니다.&lt;/p>
&lt;hr>
&lt;h2>전략 3: 빠르게 기여할 수 있는 것 찾기&lt;span class="hx:absolute hx:-mt-20" id="전략-3-빠르게-기여할-수-있는-것-찾기">&lt;/span>
&lt;a href="#%ec%a0%84%eb%9e%b5-3-%eb%b9%a0%eb%a5%b4%ea%b2%8c-%ea%b8%b0%ec%97%ac%ed%95%a0-%ec%88%98-%ec%9e%88%eb%8a%94-%ea%b2%83-%ec%b0%be%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>온보딩 문서를 개선하고, 시스템 아키텍처를 그리는 것도 좋지만, &lt;strong>실제로 팀에 도움이 되는 것&lt;/strong>을 만들어낼 수 있다면 더 좋을 것 같았습니다.&lt;/p>
&lt;h3>팀의 Pain Point 파악&lt;span class="hx:absolute hx:-mt-20" id="팀의-pain-point-파악">&lt;/span>
&lt;a href="#%ed%8c%80%ec%9d%98-pain-point-%ed%8c%8c%ec%95%85" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>입사 후 처음 몇 주간, 회의와 일상 대화에서 반복적으로 나오는 키워드들을 메모했습니다:&lt;/p>
&lt;ul>
&lt;li>&amp;ldquo;지금 장애가 나면 CS가 오기 전까진 알 수 가 없어요&amp;hellip;&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;로그를 확인하는데 너무 오래걸려요&amp;rdquo;&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>모니터링 시스템에 개선이 필요하다는 신호&lt;/strong>였습니다.&lt;/p>
&lt;h3>내가 할 수 있는 것 찾기&lt;span class="hx:absolute hx:-mt-20" id="내가-할-수-있는-것-찾기">&lt;/span>
&lt;a href="#%eb%82%b4%ea%b0%80-%ed%95%a0-%ec%88%98-%ec%9e%88%eb%8a%94-%ea%b2%83-%ec%b0%be%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>3년 차 개발자로서, 모든 걸 다 잘할 수는 없습니다. 하지만 &lt;strong>내가 비교적 해볼 수 있는 것&lt;/strong>을 찾을 수는 있었습니다.&lt;/p>
&lt;p>제 경우&lt;/p>
&lt;ul>
&lt;li>인프라/DevOps 경험이 조금 있음&lt;/li>
&lt;li>Grafana, Loki, Tempo, Prometheus 스택을 구축해본 경험이 있음&lt;/li>
&lt;li>쿠버네티스 운영 경험이 있음 (이건 나중에 쿠버네티스 구축 및 도입으로 이어집니다)&lt;/li>
&lt;li>회사 비즈니스 로직은 아직 모름&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>&amp;ldquo;내가 빠르게 기여할 수 있는 건 모니터링 시스템 개선일 것 같다&amp;rdquo;&lt;/strong>&lt;/p>
&lt;h3>입사 1.5개월, 모니터링 시스템 구축&lt;span class="hx:absolute hx:-mt-20" id="입사-15개월-모니터링-시스템-구축">&lt;/span>
&lt;a href="#%ec%9e%85%ec%82%ac-15%ea%b0%9c%ec%9b%94-%eb%aa%a8%eb%8b%88%ed%84%b0%eb%a7%81-%ec%8b%9c%ec%8a%a4%ed%85%9c-%ea%b5%ac%ec%b6%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>3월에 입사해서 4월에 모니터링 시스템을 구축했습니다&lt;/p>
&lt;ul>
&lt;li>OpenTelemetry로 통합 관측성 구축&lt;/li>
&lt;li>Prometheus, Loki, Tempo, Grafana 스택 구성&lt;/li>
&lt;li>모든 서비스에 일관된 메트릭 수집&lt;/li>
&lt;/ul>
&lt;p>이 과정은 &lt;a href="https://velog.io/write?id=079c21d1-e969-4526-8be4-e6c918ada224"target="_blank" rel="noopener">이전 블로그 글(서비스 장애는 사용자가 알려주지 않아도 알아야한다 - 사내 모니터링 시스템 구축기)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에서 자세히 다뤘습니다.&lt;/p>
&lt;h3>협업 문화 개선&lt;span class="hx:absolute hx:-mt-20" id="협업-문화-개선">&lt;/span>
&lt;a href="#%ed%98%91%ec%97%85-%eb%ac%b8%ed%99%94-%ea%b0%9c%ec%84%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>모니터링뿐 아니라, 온보딩 과정에서 느낀 다른 pain point들도 개선했습니다:&lt;/p>
&lt;p>&lt;strong>Git 전략 도입 및 문서 추가&lt;/strong> (4월 2일)&lt;/p>
&lt;ul>
&lt;li>Git Flow 소개 및 브랜치 전략 문서화&lt;/li>
&lt;li>Git commit 컨벤션&lt;/li>
&lt;li>브랜치 전략&lt;/li>
&lt;li>PR 규칙&lt;/li>
&lt;li>&lt;strong>이슈/PR 템플릿 추가&lt;/strong> (협업의 기준 마련)&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>PR Auto Code Review, Test Coverage 추가&lt;/strong> (4월 4일)&lt;/p>
&lt;ul>
&lt;li>Jacoco, dekekt, review dog&lt;/li>
&lt;li>CI/CD 환경 구축 가이드&lt;/li>
&lt;li>Self-hosted Runner 가이드&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>백엔드 개선과제 추가&lt;/strong> (8월)&lt;/p>
&lt;ul>
&lt;li>팀이 해결해야 할 기술 부채와 개선 과제 정리&lt;/li>
&lt;/ul>
&lt;h3>이렇게 하니 좋았던 점&lt;span class="hx:absolute hx:-mt-20" id="이렇게-하니-좋았던-점-2">&lt;/span>
&lt;a href="#%ec%9d%b4%eb%a0%87%ea%b2%8c-%ed%95%98%eb%8b%88-%ec%a2%8b%ec%95%98%eb%8d%98-%ec%a0%90-2" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ol>
&lt;li>&lt;strong>빠른 신뢰 획득&lt;/strong>: 팀원들께서 신뢰해주시는 것 같았습니다&lt;/li>
&lt;li>&lt;strong>명확한 역할&lt;/strong>: 팀 내에서 제 강점과 역할이 조금씩 명확해졌습니다&lt;/li>
&lt;li>&lt;strong>성취감&lt;/strong>: 실제로 팀에 도움이 되는 걸 만들었다는 만족감이 있었습니다&lt;/li>
&lt;li>&lt;strong>학습 기회&lt;/strong>: 실제 프로덕션 환경에서 경험을 쌓을 수 있었습니다&lt;/li>
&lt;/ol>
&lt;hr>
&lt;h2>실천 팁: 지금 당장 시도해볼 수 있는 것들&lt;span class="hx:absolute hx:-mt-20" id="실천-팁-지금-당장-시도해볼-수-있는-것들">&lt;/span>
&lt;a href="#%ec%8b%a4%ec%b2%9c-%ed%8c%81-%ec%a7%80%ea%b8%88-%eb%8b%b9%ec%9e%a5-%ec%8b%9c%eb%8f%84%ed%95%b4%eb%b3%bc-%ec%88%98-%ec%9e%88%eb%8a%94-%ea%b2%83%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>저도 처음엔 막연했지만, 이렇게 해보니 도움이 됐습니다.&lt;/p>
&lt;h3>1. 첫 주: 메모하고 정리하기&lt;span class="hx:absolute hx:-mt-20" id="1-첫-주-메모하고-정리하기">&lt;/span>
&lt;a href="#1-%ec%b2%ab-%ec%a3%bc-%eb%a9%94%eb%aa%a8%ed%95%98%ea%b3%a0-%ec%a0%95%eb%a6%ac%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-markdown" data-lang="markdown">&lt;span class="line">&lt;span class="cl">&lt;span class="gh"># 나의 온보딩 노트 (첫 주)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gh">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">## 궁금한 것들
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>&lt;span class="k">- [ ]&lt;/span> 레거시 서비스가 MSA를 호출하기도 하나?
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">- [ ]&lt;/span> AWS SQS는 어떤 서비스들이 컨슘하고 이벤트를 발행하고 있나?
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">- [x]&lt;/span> Elastic Search는 어떻게 사용되고 있는거지?
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">## 추가하면 좋을 것 같은 문서
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>&lt;span class="k">-&lt;/span> AWS Lambda 사용처 (현재 문서에 없음)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">-&lt;/span> 환경변수 설정 가이드
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">## 개선 아이디어
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>&lt;span class="k">-&lt;/span> Git commit 메시지 컨벤션이 명확하지 않음
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- PR 템플릿이 있으면 좋을 것 같음&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>매일 이렇게 메모하고, 정리해서 문서에 추가합니다.&lt;/p>
&lt;h3>2. 첫 달: 그려보기&lt;span class="hx:absolute hx:-mt-20" id="2-첫-달-그려보기">&lt;/span>
&lt;a href="#2-%ec%b2%ab-%eb%8b%ac-%ea%b7%b8%eb%a0%a4%eb%b3%b4%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>시스템을 이해하기 위해 그려보세요:&lt;/p>
&lt;p>&lt;strong>간단한 버전부터 시작&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>[Client] → [Backend] → [DB]&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>점진적으로 확장&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>[Client]
↓
[API Gateway]
↓
[Service A] → [DB A]
[Service B] → [DB B]
↓
[External API]&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>도구 추천:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Draw.io (무료, 웹 기반)&lt;/li>
&lt;li>Excalidraw (손그림 스타일)&lt;/li>
&lt;li>Mermaid (코드로 다이어그램 그리기)&lt;/li>
&lt;/ul>
&lt;h3>3. 둘째 달: 빠르게 기여하기&lt;span class="hx:absolute hx:-mt-20" id="3-둘째-달-빠르게-기여하기">&lt;/span>
&lt;a href="#3-%eb%91%98%ec%a7%b8-%eb%8b%ac-%eb%b9%a0%eb%a5%b4%ea%b2%8c-%ea%b8%b0%ec%97%ac%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>팀의 pain point를 파악하고, 내가 빠르게 해결할 수 있는 것을 찾으세요.&lt;/p>
&lt;p>&lt;strong>체크리스트:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;input disabled="" type="checkbox"> 팀에서 자주 나오는 불편함은 무엇인가?&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> 그중에서 내가 해결할 수 있는 것은?&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> 작게 시작할 수 있는가?&lt;/li>
&lt;li>&lt;input disabled="" type="checkbox"> 팀의 우선순위와 일치하는가?&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>예시:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>반복 작업 자동화 스크립트&lt;/li>
&lt;li>문서화 (특히 암묵지의 문서화)&lt;/li>
&lt;li>개발 환경 개선&lt;/li>
&lt;li>테스트 코드 추가&lt;/li>
&lt;li>코드 리뷰 개선 (리뷰 가이드, 체크리스트)&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2>마치며&lt;span class="hx:absolute hx:-mt-20" id="마치며">&lt;/span>
&lt;a href="#%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>많은 개발자들이 팀 적응을 &lt;strong>&amp;ldquo;회사가 나를 어떻게 도와주는가&amp;rdquo;&lt;/strong> 의 문제로 생각하는 경우들이 간혹 계신 것 같습니다. 물론 회사가 좋은 온보딩 프로그램을 제공하는 것도 중요하지만&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;빠른 적응은 회사의 지원만으로는 충분하지 않다. 나의 능동적인 자세도 필요하다.&amp;rdquo;&lt;/strong> 싶습니다.&lt;/p>
&lt;ul>
&lt;li>문서가 부족하면? → 내가 조금씩 추가해본다&lt;/li>
&lt;li>시스템이 복잡하면? → 내가 그려본다&lt;/li>
&lt;li>팀에 문제가 있으면? → 내가 해결할 수 있는 것을 찾아본다&lt;/li>
&lt;/ul>
&lt;p>이렇게 온보딩에 임하니&lt;/p>
&lt;ol>
&lt;li>비교적 빠르게 적응할 수 있었습니다&lt;/li>
&lt;li>팀에 조금이나마 도움을 줄 수 있었습니다&lt;/li>
&lt;li>자연스럽게 신뢰를 얻을 수 있었던 것 같습니다&lt;/li>
&lt;li>무엇보다, 성장할 수 있었습니다&lt;/li>
&lt;/ol>
&lt;p>문서도 코드처럼 계속 진화하고 개선되어야 한다 생각합니다. 그리고 그 개선은 신입부터 시니어까지 모두가 함께 해나가는 것인 것 같구요.&lt;/p>
&lt;p>여러분도 다음 회사에 입사하게 되면, 온보딩 문서에 추가하면 좋을 것 같은 점을 발견하신다면 PR을 올려보시는 건 어떨까요.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;첫 PR이 꼭 버그 픽스일 필요는 없지 않을까 싶습니다. 문서 개선도 첫 걸음으로는 충분한 기여라고 생각합니다. ㅎㅎ&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>이 글이 새로운 환경에 적응하고 계신 개발자분들께 조금이나마 도움이 되기를 바라며 이만 글을 마치겠습니다.&lt;/p>
&lt;p>긴 글 읽어주셔서 감사합니다.&lt;/p></description></item><item><title>개발 서버도 없던 팀이 GitOps를 갖추기까지: 맨땅에서 시작한 쿠버네티스 도입기</title><link>https://jeongil.dev/ko/blog/infrastructure/docker-compose-to-k8s/</link><pubDate>Thu, 24 Jul 2025 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/infrastructure/docker-compose-to-k8s/</guid><description>
&lt;p>안녕하세요.&lt;/p>
&lt;p>저는 프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 3년차 백엔드 개발자 정정일입니다.&lt;/p>
&lt;p>오늘은 저희 팀이 기존에 Docker 컨테이너 위에서 운영하던 Spring Cloud 기반 마이크로서비스(MSA)를 &lt;strong>쿠버네티스(Kubernetes) 기반으로 전환하기 위해, 제가 제안하고 구축했던 과정&lt;/strong>을 공유해볼까 합니다.&lt;/p>
&lt;p>이 과정에서 저희는 오랫동안 익숙하게 사용했던 Spring Cloud의 &lt;strong>Eureka와 API Gateway를 덜어내고, GKE(Google Kubernetes Engine)와 ArgoCD를 도입&lt;/strong>했습니다.&lt;/p>
&lt;p>제가 왜 이런 제안을 했고, 어떤 결정들을 내렸는지, 그 과정에서 어떤 현실적인 고민들이 있었는지, 그리고 무엇을 얻었는지 담아보려 합니다.&lt;/p>
&lt;hr>
&lt;h2>기존 아키텍처의 문제점&lt;span class="hx:absolute hx:-mt-20" id="기존-아키텍처의-문제점">&lt;/span>
&lt;a href="#%ea%b8%b0%ec%a1%b4-%ec%95%84%ed%82%a4%ed%85%8d%ec%b2%98%ec%9d%98-%eb%ac%b8%ec%a0%9c%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>제가 3월에 팀에 합류한 저희 회사의 기존 MSA 아키텍처는 &lt;code>docker-compose&lt;/code>나 셸 스크립트를 이용해 각 서비스를 도커 컨테이너로 실행하는, 초기에는 나름 잘 동작하는 구조였습니다. 하지만 서비스가 점점 많아지고 복잡해지면서, 피할 수 없는 &amp;lsquo;성장통&amp;rsquo;을 겪게 되었습니다.&lt;/p>
&lt;p>크게 두 가지 문제가 저희를 괴롭혔습니다.&lt;/p>
&lt;h3>1. 단일 인스턴스의 한계&lt;span class="hx:absolute hx:-mt-20" id="1-단일-인스턴스의-한계">&lt;/span>
&lt;a href="#1-%eb%8b%a8%ec%9d%bc-%ec%9d%b8%ec%8a%a4%ed%84%b4%ec%8a%a4%ec%9d%98-%ed%95%9c%ea%b3%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>제가 입사한 시점의 저희 회사는 큰 인스턴스 하나에 모든 컨테이너를 올려서 운영했습니다. 회사 자금에 여유가 없는 상태였기 때문에 비용적인 측면에서는 유리한 선택이었습니다.&lt;/p>
&lt;p>다만 레거시 모놀리스에서 MSA로 전환하는 과정을 진행하고 계셨고 그로 인해 서비스가 5개, 10개, 15개&amp;hellip; 늘어나는 과정이었습니다. 문제는 이로 인해 나타나기 시작했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl"> &lt;span class="c1"># 어느날 아침의 악몽&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> $ docker ps
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> CONTAINER ID STATUS
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> abc123... Up &lt;span class="m">2&lt;/span> hours
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> def456... Exited &lt;span class="o">(&lt;/span>137&lt;span class="o">)&lt;/span> &lt;span class="m">10&lt;/span> minutes ago &lt;span class="c1"># OOM Kill&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> ghi789... Up &lt;span class="m">1&lt;/span> hour&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>서비스가 증가함에 따라 메모리가 부족해지면 일부 서비스가 &lt;code>OOM Kill&lt;/code>이 일어나는 심각한 상황이 발생하기 시작했습니다.&lt;/p>
&lt;p>CPU도 마찬가지였습니다. 특정 서비스가 CPU를 독점하면 다른 서비스들의 응답속도가 느려지는 &lt;strong>&amp;rsquo;noisy neighbor&amp;rsquo;&lt;/strong> 문제가 발생하기도 했습니다.&lt;/p>
&lt;p>더 큰 인스턴스로 스케일업? 그것도 한계가 있었고, 무엇보다 &lt;strong>단일 장애점(SPOF)&lt;/strong> 이라는 근본적인 문제는 해결되지 않았습니다.&lt;/p>
&lt;p>또한 MSA의 큰 장점 중 하나로 고가용성으로 꼽을 수 있을 것 같은데, 이런 단일 장애지점이 존재하는 환경에서의 배포는 MSA 아키텍처의 의미를 크게 퇴색시키지 않나 싶습니다.&lt;/p>
&lt;h3>2. 개발 환경의 부재&lt;span class="hx:absolute hx:-mt-20" id="2-개발-환경의-부재">&lt;/span>
&lt;a href="#2-%ea%b0%9c%eb%b0%9c-%ed%99%98%ea%b2%bd%ec%9d%98-%eb%b6%80%ec%9e%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>또 한 가지 팀에 합류하고 꼭 개선하고 싶었던 점은, &lt;strong>개발 서버의 부재&lt;/strong>였습니다. 모든 테스트를 로컬에서 하거나, 아니면&amp;hellip; (끔찍하지만) 운영 환경에 조심스럽게 배포하면서 테스트했죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>&amp;#34;이거 테스트 좀 해봐야 하는데...&amp;#34;
&amp;#34;로컬에서 전체 MSA 띄우면 노트북 터져요...&amp;#34;
&amp;#34;그럼... 운영에 조심히...?&amp;#34;&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이런 대화가 일상이었습니다.&lt;/p>
&lt;p>이런 문제들을 겪으며 저희는 &amp;ldquo;더 이상 이렇게는 안 되겠다&amp;quot;는 결론에 이르렀고, 비즈니스의 연속성과 직결되는 &lt;strong>확장성과 고가용성, 그리고 제대로 된 개발 환경을 확실히 잡기 위해&lt;/strong> 컨테이너 오케스트레이션의 표준인 쿠버네티스 도입을 제가 제안하게 되었고 팀원 분들과 협의를 거쳐 도입을 결정하게 되었습니다.&lt;/p>
&lt;h3>3. 어쩌다 보니 제가 하게 되었습니다&lt;span class="hx:absolute hx:-mt-20" id="3-어쩌다-보니-제가-하게-되었습니다">&lt;/span>
&lt;a href="#3-%ec%96%b4%ec%a9%8c%eb%8b%a4-%eb%b3%b4%eb%8b%88-%ec%a0%9c%ea%b0%80-%ed%95%98%ea%b2%8c-%eb%90%98%ec%97%88%ec%8a%b5%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>사실 저는 전문 DevOps 엔지니어가 아닙니다. 다만 전 직장에서 운 좋게(?) 인프라를 깊게 파보고 쿠버네티스를 운영해 볼 기회가 있었습니다.&lt;/p>
&lt;p>전 직장에서 유일한 DevOps 담당자분이 퇴사하시게 되었는데, 후임자가 구해지지 않아 공백이 생길 뻔한 적이 있습니다. 그때 제가 담당자분을 찾아가 부탁드렸습니다.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;담당자님이 안 계시는 동안 혹시라도 서버에 문제가 생기면 누군가는 해결해야 할 텐데&amp;hellip; 실례가 안 된다면 조금만이라도 알려주실 수 있을까요? 부족한 지식으로라도 어떻게든 버텨보겠습니다.&amp;rdquo;&lt;/p>
&lt;/blockquote>
&lt;p>당시 그런 저를 좋게 봐주셨는지 담당자분께서 1개월간 집중 멘토링 및 인수인계를 제게 해주셨고, 덕분에 &lt;strong>쿠버네티스, AWS EKS, Jenkins, ArgoCD, ELK&lt;/strong> 등의 DevOps 및 인프라 관련 지식을 쌓을 수 있었습니다. 이후 7개월 정도 혼자 인프라를 운영을 했었거든요.&lt;/p>
&lt;blockquote>
&lt;p>사실 1개월 멘토링으로 다 습득할 수 있는 양은 아니었기 때문에 던져주시는 인프라 관련 키워드를 노트에 다 받아적어 하나하나 찾아보며 공부했던 기억이 있네요&amp;hellip; ㅎ..&lt;/p>
&lt;/blockquote>
&lt;p>지금 돌이켜보면 정말 무모한 도전이었지만&amp;hellip; 덕분에 정말 많이 배울 수 있어 제 인생에 있어 하나의 큰 행운이였던 것 같습니다. 그 전까진 많은 회사에서 그렇겠지만 인프라 접근 권한 자체가 없었거든요.&lt;/p>
&lt;p>새로 합류한 이번 팀도 상황은 비슷했습니다. 전문 DevOps 엔지니어가 따로 계시지 않았고, 백엔드 개발자들이 인프라 운영까지 겸하고 있었습니다.&lt;/p>
&lt;p>마침 팀 내에서 쿠버네티스 실무 경험이 있는 사람이 저밖에 없다 보니, 자연스럽게(?) 제가 이번 마이그레이션 작업을 주도하게 되었습니다.&lt;/p>
&lt;hr>
&lt;h2>의사결정의 순간들&lt;span class="hx:absolute hx:-mt-20" id="의사결정의-순간들">&lt;/span>
&lt;a href="#%ec%9d%98%ec%82%ac%ea%b2%b0%ec%a0%95%ec%9d%98-%ec%88%9c%ea%b0%84%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>쿠버네티스를 도입하기로 마음먹고 나니, 두 가지 큰 갈림길에 섰습니다.&lt;/p>
&lt;h3>1. Managed vs Self-managed&lt;span class="hx:absolute hx:-mt-20" id="1-managed-vs-self-managed">&lt;/span>
&lt;a href="#1-managed-vs-self-managed" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>첫 번째 선택은 &lt;strong>&amp;ldquo;GKE 같은 관리형(Managed) 서비스를 쓸까, 아니면 우리가 직접 클러스터를 구축(Self-managed)할까?&amp;rdquo;&lt;/strong> 였습니다.&lt;/p>
&lt;p>아마 쿠버네티스 도입을 고민하는 모든 팀이 거치는 과정일 겁니다. 저희 팀 역시 머리를 맞대고 각 방식의 장단점을 따져봤습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/1652e78f-f010-4aae-aac4-04916fbff634/image.png" alt="" loading="lazy" />&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>구분&lt;/th>
&lt;th>Managed Kubernetes&lt;/th>
&lt;th>Self-managed Kubernetes&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>장점&lt;/strong>&lt;/td>
&lt;td>- &lt;strong>빠른 구축과 쉬운 운영&lt;/strong>: 컨트롤 플레인 관리를 GCP가 다 해주니 정말 편함&lt;br>- &lt;strong>안정성 및 기본 기능&lt;/strong>: 오토스케일, 모니터링 등 필요한 기능이 바로 제공됨&lt;br>- &lt;strong>낮은 진입 장벽&lt;/strong>: K8s 전문가가 아니어도 빠르게 시작 가능&lt;/td>
&lt;td>- &lt;strong>높은 자유도&lt;/strong>: 우리 마음대로 인프라를 주무를 수 있음&lt;br>- &lt;strong>비용 최적화 가능성&lt;/strong>: 잘만 쓰면 비용을 아낄 수 있음&lt;br>- &lt;strong>특정 클라우드에 묶이지 않음&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>단점&lt;/strong>&lt;/td>
&lt;td>- &lt;strong>비용&lt;/strong>: 장기적으로 크레딧이 끝나면 비용이 더 나올 수 있음&lt;br>- &lt;strong>클라우드 종속성&lt;/strong>: 클라우드에 종속됨&lt;/td>
&lt;td>- &lt;strong>높은 초기/유지보수 비용&lt;/strong>: 구축, 업그레이드, 장애 대응&amp;hellip; 전부 우리 몫&lt;br>- &lt;strong>어려운 학습 곡선&lt;/strong>: 정말 잘 아는 전문가가 필요함&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;blockquote>
&lt;p>&lt;a href="https://gcore.com/learning/kubernetes-tco-comparison?utm_source=chatgpt.com"target="_blank" rel="noopener">관련 글&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>을 보면, &lt;strong>전체 K8s 사용자의 73%가 관리형 서비스를 사용&lt;/strong>한다고 해요. 그만큼 대부분의 팀이 속도와 안정성을 중요하게 생각한다는 뜻이겠죠.&lt;/p>
&lt;/blockquote>
&lt;p>결론적으로 저희 팀의 현재 인력과 시간을 고려했을 때, &lt;strong>초기 구축과 운영 부담이 적고 안정성이 보장되는 Managed Kubernetes가 현실적인 선택&lt;/strong>이었습니다. 일단 GKE로 쿠버네티스 운영 경험을 충분히 쌓고, 나중에 정말 필요해지면 그때 Self-managed로 넘어가도 늦지 않다고 판단했습니다.&lt;/p>
&lt;h3>2. Spring Cloud를 버리기로 한 결정&lt;span class="hx:absolute hx:-mt-20" id="2-spring-cloud를-버리기로-한-결정">&lt;/span>
&lt;a href="#2-spring-cloud%eb%a5%bc-%eb%b2%84%eb%a6%ac%ea%b8%b0%eb%a1%9c-%ed%95%9c-%ea%b2%b0%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>두 번째 선택은 &lt;strong>&amp;ldquo;Spring Cloud의 Eureka와 API Gateway, 계속 안고 가야 할까?&amp;rdquo;&lt;/strong> 였습니다. 단순히 인프라만 옮기는 게 아니라, 특정 프레임워크에 대한 종속성을 끊어낼 기회라고 생각했거든요.&lt;/p>
&lt;p>물론 &lt;code>Spring Cloud Kubernetes&lt;/code>라는 좋은 프로젝트가 있어서, 기존 코드를 거의 그대로 쓰면서 쿠버네티스와 통합할 수도 있었습니다. 하지만 이 방식은 여전히 우리 아키텍처를 Spring, 더 나아가 JVM 생태계에 묶어두는 것이나 다름없다고 생각했습니다.&lt;/p>
&lt;p>저희 회사는 AI 모델을 활용하는 등 &lt;strong>Java/Spring 외에 Python 같은 다른 언어로 만든 서비스의 중요성이 점점 커지고 있었습니다.&lt;/strong> 미래에 다양한 기술 스택의 서비스들을 아무 문제 없이 통합하고 확장하려면, 특정 언어에 얽매이지 않는(Language-Agnostic) 아키텍처가 필요했습니다.&lt;/p>
&lt;p>그래서 저희는 과감한 결정을 내렸습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>프레임워크 종속성 탈피:&lt;/strong> Spring Cloud 의존성을 걷어내자. 어떤 언어로 만든 서비스든 쿠버네티스 안에서 동등하게 대우받을 수 있도록&lt;/li>
&lt;li>&lt;strong>쿠버네티스 네이티브 기능 활용:&lt;/strong> Eureka의 역할은 쿠버네티스의 &lt;strong>&lt;code>K8s DNS + Service&lt;/code>&lt;/strong> 가, API Gateway의 역할은 &lt;strong>&lt;code>Ingress&lt;/code>&lt;/strong> 가 충분히 해줄 수 있다. 기술 스택을 단순화하고 중복을 없애자.&lt;/li>
&lt;li>&lt;strong>미래를 위한 확장성 확보:&lt;/strong> 나중에 Python 기반 AI 서비스가 들어오든, 어떤 새로운 서비스가 생기든, 쿠버네티스 표준 방식으로 매끄럽게 통합하자.&lt;/li>
&lt;/ol>
&lt;p>결론적으로 저희는 &lt;strong>Eureka와 API Gateway를 제거하고, 쿠버네티스의 Service와 Ingress를 사용하기로 결정&lt;/strong>했습니다.&lt;/p>
&lt;hr>
&lt;h2>아키텍처 전환 작업&lt;span class="hx:absolute hx:-mt-20" id="아키텍처-전환-작업">&lt;/span>
&lt;a href="#%ec%95%84%ed%82%a4%ed%85%8d%ec%b2%98-%ec%a0%84%ed%99%98-%ec%9e%91%ec%97%85" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>처음에는 Eureka와 API Gateway를 제거하고 Service와 Ingress를 도입하는 과정이 비교적 스무스하게 넘어갈 수 있을 거라 생각했습니다. 하지만 서비스 간에 Eureka를 통해 서로를 바라보는 Endpoint가 수정되어야 한다는 점에서 코드도 변경되어야 하는 부분이 있었습니다.&lt;/p>
&lt;h3>A. 코드 레벨 변경&lt;span class="hx:absolute hx:-mt-20" id="a-코드-레벨-변경">&lt;/span>
&lt;a href="#a-%ec%bd%94%eb%93%9c-%eb%a0%88%eb%b2%a8-%eb%b3%80%ea%b2%bd" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;h4>멀티모듈로 통합&lt;span class="hx:absolute hx:-mt-20" id="멀티모듈로-통합">&lt;/span>
&lt;a href="#%eb%a9%80%ed%8b%b0%eb%aa%a8%eb%93%88%eb%a1%9c-%ed%86%b5%ed%95%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>기존에는 MSA의 각 서비스들을 개별 레포에 관리하고 있었거든요.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code># 기존 레포 구조
- user-service/
- order-service/
- payment-service/
- notification-service/
- agent-service/
... (10개가 넘는 개별 레포)&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>Feign Client URL 하나 바꾸려면 16개 레포를 일일이 수정하고, Commit하고, PR 올리고&amp;hellip; 더 큰 문제는 &lt;strong>공통 코드가 각 프로젝트마다 복사되어&lt;/strong> 있었다는 점입니다.
또 공통적인 설정인 모니터링 관련해서도 프로젝트별로 설정이 제각각이라 관리 부담이 컸습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div class="hextra-code-filename not-prose" dir="auto">feign-client.java&lt;/div>&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// match-service 레포의 UserServiceClient&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@FeignClient&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;USER-SERVICE&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">interface&lt;/span> &lt;span class="nc">UserServiceClient&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">...&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">// notification-service 레포의 UserServiceClient (똑같은 코드!)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@FeignClient&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;USER-SERVICE&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">interface&lt;/span> &lt;span class="nc">UserServiceClient&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">...&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">// 이런 중복이 16개 레포에...&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">// Eureka 기반에서 환경변수를 통한 Kubernetes service URI endpoint로 변경&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@FeignClient&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;user-service&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">url&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;\${feign.client.config.urls.user-service}&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">interface&lt;/span> &lt;span class="nc">UserFeignClient&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">...&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-8">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>저희 팀의 인력이 여유로운 상태는 아니었기 때문에, 별도로 관리하는 리소스를 줄이고자 &lt;strong>프로젝트를 멀티모듈 형식으로 통합&lt;/strong>하기로 결정했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code># 새로운 멀티모듈 구조
multi-module-backend/
├── common/ # 공통 모듈
│ ├── feign-clients/ # 모든 Feign Client 모음
│ ├── dto/
│ └── utils/
├── user-service/
├── notification-service/
├── match-service/
└── ...&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>COMMON 모듈을 도입해서 Feign Client들을 한 곳으로 모으니, &lt;strong>수십 개 서비스의 Feign Client를 한 번에 수정&lt;/strong>할 수 있게 되었습니다.&lt;/p>
&lt;p>( 멀티모듈로 전환하는 과정은 차후 다른 글에서 자세히 다루도록 하겠습니다. )&lt;/p>
&lt;h3>B. 인프라 레벨 변경&lt;span class="hx:absolute hx:-mt-20" id="b-인프라-레벨-변경">&lt;/span>
&lt;a href="#b-%ec%9d%b8%ed%94%84%eb%9d%bc-%eb%a0%88%eb%b2%a8-%eb%b3%80%ea%b2%bd" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;h4>1. Eureka → K8s Service/DNS&lt;span class="hx:absolute hx:-mt-20" id="1-eureka--k8s-servicedns">&lt;/span>
&lt;a href="#1-eureka--k8s-servicedns" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>기존에 Eureka Server가 하던 서비스 디스커버리 역할을 이제 쿠버네티스의 &lt;strong>Service와 DNS&lt;/strong>가 대신하게 했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div class="hextra-code-filename not-prose" dir="auto">service.yml&lt;/div>&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># K8s Service 정의&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">apiVersion&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">v1&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">kind&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">Service&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">metadata&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">user-service-svc&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">spec&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">selector&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">app&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">user-service&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">ports&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">port&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">8080&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">targetPort&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">8080&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-8">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이제 &lt;code>user-service-svc&lt;/code>라는 이름으로 클러스터 내 어디서든 접근 가능합니다. Eureka Server 운영 부담도 사라졌죠.&lt;/p>
&lt;h4>2. API Gateway → Ingress&lt;span class="hx:absolute hx:-mt-20" id="2-api-gateway--ingress">&lt;/span>
&lt;a href="#2-api-gateway--ingress" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>기존 Spring Cloud Gateway 대신 쿠버네티스 &lt;strong>Ingress&lt;/strong>를 사용합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div class="hextra-code-filename not-prose" dir="auto">ingress.yml&lt;/div>&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># Ingress 설정 예시&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">apiVersion&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">networking.k8s.io/v1&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">kind&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">Ingress&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">metadata&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">example-ingress&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">spec&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">rules&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">host&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">example.co.kr&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">http&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">paths&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">path&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">/users&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">pathType&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">Prefix&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">backend&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">service&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">user-service-svc&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">port&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">number&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">8080&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-8">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이제 외부 트래픽은 Ingress가 받아서 적절한 서비스로 라우팅해줍니다.&lt;/p>
&lt;h4>3. GitOps with ArgoCD&lt;span class="hx:absolute hx:-mt-20" id="3-gitops-with-argocd">&lt;/span>
&lt;a href="#3-gitops-with-argocd" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>인프라 구성과 애플리케이션 배포는 &lt;strong>ArgoCD를 이용한 GitOps 방식&lt;/strong>으로 완전히 바꿨습니다. 쉽게 말해, &lt;strong>모든 인프라 설정을 Git 리포지토리(&lt;code>manifest-ops&lt;/code>)에서 코드로 관리&lt;/strong>하는 겁니다.&lt;/p>
&lt;p>저희 리포지토리 구조는 대략 이렇습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;span class="lnt">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">/
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">├── dev/ &lt;span class="c1"># 개발 환경 매니페스트&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ ├── agent-service/
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ │ ├── deployment.yaml
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ │ ├── service.yaml
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ │ └── hpa.yaml
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ ├── ... &lt;span class="o">(&lt;/span>다른 서비스들&lt;span class="o">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ └── ingress.yaml
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">├── prod/ &lt;span class="c1"># 운영 환경 매니페스트&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>제가 구축한 CI/CD 파이프라인은 다음과 같습니다.&lt;/p>
&lt;ol>
&lt;li>개발자가 코드를 수정하고 PR이 Merge되면 자동으로 &lt;code>deployment.yaml&lt;/code>의 이미지 태그만 바꿉니다. (저희는 이 부분을 Github Actions로 구축했습니다.)&lt;/li>
&lt;li>이미지 태그가 변경되면 ArgoCD가 &amp;ldquo;어, 변경 사항이 있네?&amp;rdquo; 하고 감지합니다.
&lt;ul>
&lt;li>개발 환경은 자동으로 Sync하도록 구성&lt;/li>
&lt;li>운영 환경은 안정성을 위해 개발자가 직접 Sync하도록 구성&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>이후 Git에 정의된 대로 클러스터의 상태를 자동으로 맞춰줍니다.&lt;/li>
&lt;/ol>
&lt;p>이 구조 덕분에 더 이상 제가 직접 &lt;code>kubectl apply&lt;/code> 같은 명령어를 직접 칠 필요가 없어졌습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/e91c4082-9184-4bf0-ba0e-46d4823308e2/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>&lt;strong>이제 모든 변경 이력이 Git에 남아서 누가, 언제, 왜 바꿨는지 명확하게 추적할 수 있고, 문제가 생기면 이전 버전으로 돌아가는 것도 훨씬 쉬워졌습니다.&lt;/strong>&lt;/p>
&lt;h3>C. 관측성(Observability) 개선&lt;span class="hx:absolute hx:-mt-20" id="c-관측성observability-개선">&lt;/span>
&lt;a href="#c-%ea%b4%80%ec%b8%a1%ec%84%b1observability-%ea%b0%9c%ec%84%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Spring Cloud 환경에서는 Prometheus가 Eureka를 통해 서비스를 발견하고 메트릭을 수집하도록 구성했었습니다. 하지만 Eureka를 제거하면서 모니터링 구조도 완전히 재설계해야 했습니다.&lt;/p>
&lt;h4>1. Prometheus: Pull에서 Push로의 전환&lt;span class="hx:absolute hx:-mt-20" id="1-prometheus-pull에서-push로의-전환">&lt;/span>
&lt;a href="#1-prometheus-pull%ec%97%90%ec%84%9c-push%eb%a1%9c%ec%9d%98-%ec%a0%84%ed%99%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>기존에는 Prometheus가 Eureka를 통해 서비스를 발견하고 메트릭을 긁어가도록 설정해뒀었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div class="hextra-code-filename not-prose" dir="auto">prometheus.yml&lt;/div>&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># 기존: prometheus.yml&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">scrape_configs&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">job_name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;eureka&amp;#39;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">eureka_sd_configs&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">server&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;http://3.36.158.119:8761/eureka&amp;#39;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">refresh_interval&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">30s &lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># 30초마다 서비스 목록 새로고침&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">relabel_configs&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># `prometheus.scrape=true` 설정이 있는 서비스만 스크랩&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">source_labels&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="l">__meta_eureka_app_instance_metadata_prometheus__scrape]&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">action&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">keep&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">regex&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># 서비스 이름을 app 라벨로 지정&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">source_labels&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="l">__meta_eureka_app_name]&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">target_label&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">app&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">action&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">replace&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># 서비스별 메트릭 경로 지정&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">source_labels&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="l">__meta_eureka_app_instance_metadata_prometheus__path]&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">action&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">replace&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">target_label&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">__metrics_path__&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">regex&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">(.+)&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-8">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>쿠버네티스로 전환하면서 이 구조를 완전히 뒤집었습니다. &lt;strong>OpenTelemetry를 통한 Push 방식&lt;/strong>으로요.&lt;/p>
&lt;p>새로운 방식에서는 각 서비스가 OpenTelemetry
Collector 사이드카로 메트릭을 보내고,
Collector가 다시 Prometheus로 전달하는
구조입니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div class="hextra-code-filename not-prose" dir="auto">otel-collector-config.yaml&lt;/div>&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;span class="lnt">45
&lt;/span>&lt;span class="lnt">46
&lt;/span>&lt;span class="lnt">47
&lt;/span>&lt;span class="lnt">48
&lt;/span>&lt;span class="lnt">49
&lt;/span>&lt;span class="lnt">50
&lt;/span>&lt;span class="lnt">51
&lt;/span>&lt;span class="lnt">52
&lt;/span>&lt;span class="lnt">53
&lt;/span>&lt;span class="lnt">54
&lt;/span>&lt;span class="lnt">55
&lt;/span>&lt;span class="lnt">56
&lt;/span>&lt;span class="lnt">57
&lt;/span>&lt;span class="lnt">58
&lt;/span>&lt;span class="lnt">59
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># OpenTelemetry Collector 설정&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">apiVersion&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">v1&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">kind&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">ConfigMap&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">metadata&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel-collector-config&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">data&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">config.yaml&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">|&lt;/span>&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> receivers:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> otlp:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> protocols:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> grpc:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> endpoint: 0.0.0.0:4317
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> http:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> endpoint: 0.0.0.0:4318
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> processors:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> batch:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> timeout: 10s
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> # 서비스별 리소스 속성 추가
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> resource:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> attributes:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> - key: service.namespace
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> value: bootalk
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> action: upsert
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> exporters:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> # Prometheus Remote Write
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> prometheusremotewrite:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> endpoint: http://prometheus-svc.monitoring.svc.cluster.local:9090/prometheus/api/v1/write
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> resource_to_telemetry_conversion:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> enabled: true
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> # Loki로 로그 전송
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> loki:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> endpoint: http://loki-svc.monitoring.svc.cluster.local:3100/otlp
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> # Tempo로 트레이스 전송
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> otlp/tempo:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> endpoint: http://tempo-svc.monitoring.svc.cluster.local:4317
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> tls:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> insecure: true
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> service:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> pipelines:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> metrics:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> receivers: [otlp]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> processors: [batch, resource]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> exporters: [prometheusremotewrite]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> logs:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> receivers: [otlp]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> processors: [batch, resource]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> exporters: [loki]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> traces:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> receivers: [otlp]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> processors: [batch, resource]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> exporters: [otlp/tempo]&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-8">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이제 각 서비스는 자신의 메트릭을 능동적으로 OpenTelemetry Collector(localhost:4317)로 보내고, Collector가 Prometheus Remote Write API를 통해 중앙 Prometheus 서버로 전달합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code> [Spring Boot App]
↓ (OTLP/gRPC)
[OTel Collector Sidecar]
↓ (Prometheus Remote Write)
[Prometheus Server]&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 전환이 쉽지는 않았습니다&amp;hellip; 기존 Grafana 대시보드를 전부 다시 만들어야 했고, 메트릭 이름도 다 바뀌어서 알람 규칙도 새로 짜야 했습니다. 하지만 결과적으로 &lt;strong>각 서비스가 자신의 메트릭을 능동적으로 보내는&lt;/strong> 더 확장 가능한 구조가 되었죠.&lt;/p>
&lt;h4>2. 사이드카 패턴으로 모니터링 통합&lt;span class="hx:absolute hx:-mt-20" id="2-사이드카-패턴으로-모니터링-통합">&lt;/span>
&lt;a href="#2-%ec%82%ac%ec%9d%b4%eb%93%9c%ec%b9%b4-%ed%8c%a8%ed%84%b4%ec%9c%bc%eb%a1%9c-%eb%aa%a8%eb%8b%88%ed%84%b0%eb%a7%81-%ed%86%b5%ed%95%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>앞서 저희의 문제점 중 하나로 &lt;strong>&amp;ldquo;서비스마다 모니터링 설정이 제각각이라 관리 부담이 크다&amp;rdquo;&lt;/strong> 는 점을 언급했습니다. 이 문제를 해결하기 위해, 저는 각 애플리케이션 Pod에 &lt;strong>OpenTelemetry Collector를 &amp;lsquo;사이드카&amp;rsquo; 컨테이너로 함께 배포&lt;/strong>하는 방식을 택했습니다. 말로만 하면 감이 잘 안 오니, 저희 설정 예시를 보여드리겠습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div class="hextra-code-filename not-prose" dir="auto">otel-sidecar-example-deployment.yml&lt;/div>&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;span class="lnt">45
&lt;/span>&lt;span class="lnt">46
&lt;/span>&lt;span class="lnt">47
&lt;/span>&lt;span class="lnt">48
&lt;/span>&lt;span class="lnt">49
&lt;/span>&lt;span class="lnt">50
&lt;/span>&lt;span class="lnt">51
&lt;/span>&lt;span class="lnt">52
&lt;/span>&lt;span class="lnt">53
&lt;/span>&lt;span class="lnt">54
&lt;/span>&lt;span class="lnt">55
&lt;/span>&lt;span class="lnt">56
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">spec&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">template&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">spec&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># 1. Init Container로 OpenTelemetry Java Agent 다운로드&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">initContainers&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel-agent-downloader&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">image&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">curlimages/curl:8.7.1&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">command&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">sh&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- -&lt;span class="l">c&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">curl -sSL -o /otel/opentelemetry-javaagent.jar https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.20.1/opentelemetry-javaagent.jar&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">volumeMounts&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel-agent&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">mountPath&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">/otel&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">containers&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># 2. 메인 애플리케이션 컨테이너&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">user-service&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">image&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">your-registry/user-service:latest&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">env&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">OTEL_SERVICE_NAME&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">value&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">user-service&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">OTEL_RESOURCE_ATTRIBUTES&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">value&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">deployment.environment=dev&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">JAVA_TOOL_OPTIONS&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">value&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">&amp;gt;-&lt;/span>&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> -javaagent:/otel/opentelemetry-javaagent.jar
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> -Dotel.javaagent.enabled=true
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> -Dotel.metrics.exporter=otlp
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> -Dotel.traces.exporter=otlp
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> -Dotel.logs.exporter=otlp
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> -Dotel.exporter.otlp.endpoint=http://localhost:4317
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> -Dotel.exporter.otlp.protocol=grpc&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">volumeMounts&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel-agent&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">mountPath&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">/otel&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">ports&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">containerPort&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">8080&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># 3. OpenTelemetry Collector 사이드카 컨테이너&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel-collector&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">image&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel/opentelemetry-collector-contrib:0.98.0&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">args&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="s2">&amp;#34;--config=/etc/otel/config.yaml&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">ports&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">containerPort&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">4317&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># gRPC&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">volumeMounts&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel-config&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">mountPath&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">/etc/otel&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">volumes&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel-agent &lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># 두 컨테이너가 공유하는 볼륨&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">emptyDir&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>{}&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel-config&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">configMap&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel-collector-config&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-8">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>구조를 간단히 설명드리면 이렇습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>메인 애플리케이션 컨테이너&lt;/strong>는 &lt;code>JAVA_TOOL_OPTIONS&lt;/code> 환경변수를 통해 Java Agent를 실행시켜서 로그, 트레이스, 메트릭 데이터를 수집합니다.&lt;/li>
&lt;li>바로 옆에 붙어있는 &lt;strong>&lt;code>otel-collector&lt;/code> 사이드카 컨테이너&lt;/strong>가 이 데이터들을 대신 받아줍니다.&lt;/li>
&lt;li>사이드카는 미리 약속된 설정(&lt;code>otel-collector-config&lt;/code>)에 따라 수집한 데이터를 Loki, Tempo, Prometheus 같은 곳으로 보내주는 역할을 합니다.&lt;/li>
&lt;/ol>
&lt;p>이 구조 덕분에, 저희는 애플리케이션 코드 한 줄 건드리지 않고 모든 서비스에 일관된 관측 가능성 기능을 붙일 수 있었습니다. 제각각이던 설정을 한 곳에서 관리하게 된 거죠.&lt;/p>
&lt;h4>3. Grafana로 모든 것을 한눈에&lt;span class="hx:absolute hx:-mt-20" id="3-grafana로-모든-것을-한눈에">&lt;/span>
&lt;a href="#3-grafana%eb%a1%9c-%eb%aa%a8%eb%93%a0-%ea%b2%83%ec%9d%84-%ed%95%9c%eb%88%88%ec%97%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>이렇게 중앙화된 파이프라인을 통해 Loki, Tempo, Prometheus로 모인 모든 데이터는 최종적으로 &lt;strong>Grafana 대시보드&lt;/strong>에서 통합되어 시각화됩니다.&lt;/p>
&lt;p>이제 저희 팀은 Grafana 화면 하나만으로 모든 서비스의 상태를 한눈에 파악하고, 장애가 발생하면 로그와 트레이스를 넘나들며 신속하게 원인을 분석할 수 있게 되었습니다. 제각각이던 모니터링 설정이 하나로 통합되면서 얻게 된 가장 큰 선물이었습니다.&lt;/p>
&lt;hr>
&lt;h2>개발 환경 구축: 쿠버네티스 검증을 겸한 전략적 선택&lt;span class="hx:absolute hx:-mt-20" id="개발-환경-구축-쿠버네티스-검증을-겸한-전략적-선택">&lt;/span>
&lt;a href="#%ea%b0%9c%eb%b0%9c-%ed%99%98%ea%b2%bd-%ea%b5%ac%ec%b6%95-%ec%bf%a0%eb%b2%84%eb%84%a4%ed%8b%b0%ec%8a%a4-%ea%b2%80%ec%a6%9d%ec%9d%84-%ea%b2%b8%ed%95%9c-%ec%a0%84%eb%9e%b5%ec%a0%81-%ec%84%a0%ed%83%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>쿠버네티스 도입 과정에서 저희가 내린 중요한 결정 중 하나는 &lt;strong>운영 환경보다 개발 환경을 먼저 구축&lt;/strong>하는 것이었습니다.&lt;/p>
&lt;p>앞서 언급했듯이 개발 환경의 필요성은 이미 절실했습니다. 하지만 단순히 개발 환경이 필요해서만은 아니었습니다. &lt;strong>쿠버네티스라는 새로운 환경을 검증하고, 문제를 안전하게 발견하고 해결할 수 있는 샌드박스가 필요&lt;/strong>했던 거죠.&lt;/p>
&lt;p>그래서 저는 다음과 같은 전략으로 접근했습니다:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>개발 환경을 먼저 쿠버네티스로 구축&lt;/strong> - 운영 환경에 영향 없이 안전하게 시행착오를 겪을 수 있는 환경&lt;/li>
&lt;li>&lt;strong>프론트엔드 팀에 협조 요청&lt;/strong> - 웹과 앱 팀에 개발/로컬 환경에서는 새로 구축한 쿠버네티스 개발 서버의 Endpoint를 호출하도록 요청&lt;/li>
&lt;li>&lt;strong>충분한 검증 후 운영 전환&lt;/strong> - 개발 환경에서 안정성이 확인되면 그때 운영 환경을 이관&lt;/li>
&lt;/ol>
&lt;p>이 접근법 덕분에 개발자들은 로컬에서 노트북을 터뜨리지 않고도, 그리고 운영 환경에 &amp;ldquo;조심스럽게&amp;rdquo; 배포하지 않고도 안전하게 테스트할 수 있게 되었습니다.&lt;/p>
&lt;p>물론 이 과정이 절대 쉬운 일은 아니었습니다&amp;hellip;
환경 변수로 분리되지 않고 하드코딩되어 있는 설정들도 있었어서 운영환경에서 AWS SQS에 발행된 이벤트를 개발 서버가 컨슘해버리는 일도 있었죠 😢 (이 사건은 뒤에서 자세히 다룹니다)&lt;/p>
&lt;hr>
&lt;h2>트러블슈팅: 고통스러웠던 순간들&lt;span class="hx:absolute hx:-mt-20" id="트러블슈팅-고통스러웠던-순간들">&lt;/span>
&lt;a href="#%ed%8a%b8%eb%9f%ac%eb%b8%94%ec%8a%88%ed%8c%85-%ea%b3%a0%ed%86%b5%ec%8a%a4%eb%9f%ac%ec%9b%a0%eb%8d%98-%ec%88%9c%ea%b0%84%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>1. 개발 환경이 운영 SQS를 컨슘해버리는 문제&lt;span class="hx:absolute hx:-mt-20" id="1-개발-환경이-운영-sqs를-컨슘해버리는-문제">&lt;/span>
&lt;a href="#1-%ea%b0%9c%eb%b0%9c-%ed%99%98%ea%b2%bd%ec%9d%b4-%ec%9a%b4%ec%98%81-sqs%eb%a5%bc-%ec%bb%a8%ec%8a%98%ed%95%b4%eb%b2%84%eb%a6%ac%eb%8a%94-%eb%ac%b8%ec%a0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>개발 환경을 처음 구축하면서 발생한 &lt;strong>가장 아찔했던 사고&lt;/strong>를 빼놓을 수 없을 것 같습니다.&lt;/p>
&lt;p>기존에는 개발 서버가 아예 없어서 모든 서비스가 운영 환경 하나만 바라보고 있었습니다. 그런데 코드를 살펴보니&amp;hellip;&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div class="hextra-code-filename not-prose" dir="auto">SQSConfig.java&lt;/div>&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 레거시 코드에 박혀있던 하드코딩&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">SQSConfig&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">static&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">final&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">QUEUE_URL&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;https://sqs.ap-northeast-2.amazonaws.com/123456/prod-order-queue&amp;#34;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 😱&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 환경변수? 그런 거 없었다...&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-8">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>네, &lt;strong>SQS URL이 코드에 하드코딩&lt;/strong>되어 있었던 겁니다. 개발 환경이 없었으니 당연히 환경별 분리 같은 건 고려가 안 되어 있었죠.&lt;/p>
&lt;p>개발 클러스터를 띄우고 나서 벌어진 일은 예상하신 그대로입니다.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;어? 왜 운영에서 통계 데이터가 이상하죠?&amp;rdquo;&lt;/p>
&lt;/blockquote>
&lt;p>&lt;strong>개발 환경이 운영 AWS SQS의 이벤트를 간헐적으로 컨슘해버린 것&lt;/strong>입니다. 😭 하드코딩된 URL 때문에 개발 환경도 똑같이 운영 큐를 바라보고 있었던 거죠.&lt;/p>
&lt;p>긴급하게 개발 환경을 내리고, 코드를 수정했습니다.
또 개발서버가 컨슘해버린 이벤트들을 개별적으로 발행해줘야 했죠 🥲&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div class="hextra-code-filename not-prose" dir="auto">SQSConfig.java&lt;/div>&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 긴급 패치: 환경변수로 분리&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">SQSConfig&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">static&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">final&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">QUEUE_URL&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">System&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getenv&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;AWS_SQS_URL&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 환경변수 도입&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-8">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 사건으로 깨달은 교훈:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>하드코딩은 시한폭탄&lt;/strong>이다&lt;/li>
&lt;li>&lt;strong>개발 환경이 없던 시스템&lt;/strong>에 개발 환경을 추가할 때는 모든 외부 연동 포인트를 점검해야 한다&lt;/li>
&lt;li>&lt;strong>&amp;ldquo;일단 돌아가게만 만들자&amp;quot;는 마인드&lt;/strong>가 나중에 얼마나 큰 빚이 되는지&amp;hellip;&lt;/li>
&lt;/ol>
&lt;p>지금은 모든 환경 설정을 코드에서 분리하고, 환경별로 철저히 격리했습니다. 다시는 이런 일이 없기를&amp;hellip;&lt;/p>
&lt;h3>2. 예상치 못한 네트워크 이슈: 사라진 외부 API 연동&lt;span class="hx:absolute hx:-mt-20" id="2-예상치-못한-네트워크-이슈-사라진-외부-api-연동">&lt;/span>
&lt;a href="#2-%ec%98%88%ec%83%81%ec%b9%98-%eb%aa%bb%ed%95%9c-%eb%84%a4%ed%8a%b8%ec%9b%8c%ed%81%ac-%ec%9d%b4%ec%8a%88-%ec%82%ac%eb%9d%bc%ec%a7%84-%ec%99%b8%eb%b6%80-api-%ec%97%b0%eb%8f%99" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>쿠버네티스 전환 중 당황스러웠던 순간 중 하나는 &lt;strong>외부 API가 갑자기 동작하지 않았을 때&lt;/strong>였습니다.&lt;/p>
&lt;p>개발 환경에서 테스트하던 중이었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>Connection timeout...
Connection timeout...
Connection timeout...&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>외부 파트너사의 API가 타임아웃을 뱉으며 계속 실패했습니다. 이상한 점은 &lt;strong>기존 인스턴스의 Docker 환경에서는 정상 동작&lt;/strong>한다는 거였습니다.&lt;/p>
&lt;p>&amp;ldquo;설정이 잘못됐나? DNS 문제인가?&amp;rdquo;&lt;/p>
&lt;p>코드도 같고, 설정도 같은데 왜 쿠버네티스에서만 안 되는 걸까요?
아마 많은 분들이 어렵지 않게 원인을 추측하실 수 있을 것 같습니다.&lt;/p>
&lt;h4>원인 파악: 문서화되지 않은 방화벽 설정&lt;span class="hx:absolute hx:-mt-20" id="원인-파악-문서화되지-않은-방화벽-설정">&lt;/span>
&lt;a href="#%ec%9b%90%ec%9d%b8-%ed%8c%8c%ec%95%85-%eb%ac%b8%ec%84%9c%ed%99%94%eb%90%98%ec%a7%80-%ec%95%8a%ec%9d%80-%eb%b0%a9%ed%99%94%eb%b2%bd-%ec%84%a4%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>문득 &amp;ldquo;혹시 방화벽?&amp;ldquo;이라는 생각이 들었습니다. 외부 파트너사에 조심스럽게 문의를 드렸죠.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;혹시 저희가 이용중인 서비스에 방화벽을 관리하고 계신지 확인 가능할까요?&amp;rdquo;&lt;/p>
&lt;/blockquote>
&lt;p>답변은 예상대로였습니다. 파트너사에서 우리 서버의 IP를 방화벽 whitelist에 등록해두고 있었던 겁니다.&lt;/p>
&lt;p>&lt;strong>문제는 이 사실을 아는 사람이 팀에 아무도 없었다는 점&lt;/strong>이었습니다. 3월에 합류한 저는 물론이고, 기존 팀원분들도 모르고 계셨어요. 레거시 시스템을 구축했던 분들은 이미 퇴사한 상태였고, 문서는 어디에도 없었습니다. 😢&lt;/p>
&lt;h4>해결책: Cloud NAT로 고정 IP 확보&lt;span class="hx:absolute hx:-mt-20" id="해결책-cloud-nat로-고정-ip-확보">&lt;/span>
&lt;a href="#%ed%95%b4%ea%b2%b0%ec%b1%85-cloud-nat%eb%a1%9c-%ea%b3%a0%ec%a0%95-ip-%ed%99%95%eb%b3%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>이제 원인은 알았는데, 해결이 문제였습니다.&lt;/p>
&lt;p>GKE는 노드를 오토스케일링하면서 IP가 동적으로 변합니다. 특정 노드 IP를 방화벽에 등록하는 방식으로는 근본적인 해결이 불가능했죠.&lt;/p>
&lt;p>고민 끝에 &lt;strong>Google Cloud NAT&lt;/strong>를 도입하기로 했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>[GKE Pods] → [Cloud NAT] → [고정 IP] → [외부 API]&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>Cloud NAT를 구성해서 모든 노드의 Egress 트래픽이 고정된 IP 하나로 나가도록 설정했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Cloud NAT 구성 예시&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">gcloud compute routers create example-router &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> --network default &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> --region asia-northeast3
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">gcloud compute routers nats create example-nat &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> --router example-router &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> --region asia-northeast3 &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> --nat-external-ip-pool example-nat-ip &lt;span class="se">\
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="se">&lt;/span> --nat-all-subnet-ip-ranges&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 고정 IP를 파트너사에 전달하고 방화벽에 등록한 후에야 정상적으로 API 호출이 가능해졌습니다.&lt;/p>
&lt;p>이 사건을 통해 배운 교훈:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>문서화는 선택이 아니라 필수다&lt;/strong> - 특히 외부 연동 관련 설정은 반드시 기록해야 한다&lt;/li>
&lt;li>&lt;strong>인프라 전환 시 외부 의존성 체크리스트가 필요하다&lt;/strong> - DB, 캐시만이 아니라 방화벽, VPN 등도 포함&lt;/li>
&lt;li>&lt;strong>레거시 시스템에는 숨겨진 지뢰가 있다&lt;/strong> - 충분한 시간을 두고 검증해야 한다&lt;/li>
&lt;/ol>
&lt;hr>
&lt;h2>그래서, 무엇이 달라졌을까?&lt;span class="hx:absolute hx:-mt-20" id="그래서-무엇이-달라졌을까">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%9e%98%ec%84%9c-%eb%ac%b4%ec%97%87%ec%9d%b4-%eb%8b%ac%eb%9d%bc%ec%a1%8c%ec%9d%84%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>Docker-compose에서 쿠버네티스 환경으로의 전환은 저희 팀에 정말 많은 긍정적인 변화를 가져왔습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>운영이 편해졌어요:&lt;/strong> 배포 자동화, 오토스케일링, 심지어 서비스가 죽으면 알아서 살려주는 자가 치유(Self-healing) 기능까지, 운영 부담이 정말 많이 줄었습니다.&lt;/li>
&lt;li>&lt;strong>개발자는 개발에만 집중:&lt;/strong> 개발자들은 더 이상 인프라를 신경 쓰지 않고 비즈니스 로직 개발에만 집중할 수 있게 되었습니다. 물론 저는 쿠버네티스 인프라까지 신경 써야 하긴 하지만요 ㅎㅎ..&lt;/li>
&lt;li>&lt;strong>Rollback의 간편화:&lt;/strong> ArgoCD는 ReplicaSet을 이용한 Rollback을 지원하기 때문에 특정 버전을 배포했을 때 문제가 있다면 기존에 개발자가 직접 하나하나 처리해줘야 했던 Rollback을 간단하게 할 수 있었습니다. 물론 Rollback할 일이 없는 게 가장 베스트겠지만요 ㅎ..&lt;/li>
&lt;/ol>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/b16bd57a-406b-49d1-b582-735b18ea8c88/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>노드들에 잘 떠있는 파드들을 보고만 있어도 뿌듯해집니다..
그 전에는 제 개인적으로 공부하고자 쿠버네티스 클러스터를 구성해본 적은 있지만 제 손으로 직접 회사 서비스를 운영 중에 무중단으로 쿠버네티스 환경으로 이관에 성공하고 구축했다는 게 엄청 큰 만족감을 주더라고요 😊&lt;/p>
&lt;hr>
&lt;h2>비용, 그 현실적인 이야기&lt;span class="hx:absolute hx:-mt-20" id="비용-그-현실적인-이야기">&lt;/span>
&lt;a href="#%eb%b9%84%ec%9a%a9-%ea%b7%b8-%ed%98%84%ec%8b%a4%ec%a0%81%ec%9d%b8-%ec%9d%b4%ec%95%bc%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>개발 블로그에서 잘 다뤄지지 않지만 누구나 궁금한 질문, &amp;ldquo;그래서 비용은 얼마나 나왔나요?&amp;rdquo;&lt;/p>
&lt;p>솔직히 말씀드리면, &lt;strong>쿠버네티스 전환 후 인프라 비용이 약 2.5~3배 정도 증가&lt;/strong>했습니다.&lt;/p>
&lt;h3>비용이 증가한 이유&lt;span class="hx:absolute hx:-mt-20" id="비용이-증가한-이유">&lt;/span>
&lt;a href="#%eb%b9%84%ec%9a%a9%ec%9d%b4-%ec%a6%9d%ea%b0%80%ed%95%9c-%ec%9d%b4%ec%9c%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ol>
&lt;li>&lt;strong>GKE 관리 비용&lt;/strong> - Managed Kubernetes의 컨트롤 플레인 비용&lt;/li>
&lt;li>&lt;strong>개발 환경 신규 구축&lt;/strong> - 기존에 없던 완전한 개발 클러스터 추가&lt;/li>
&lt;li>&lt;strong>고가용성을 위한 리소스&lt;/strong> - 노드 여러 개, 로드밸런서, Cloud NAT 등&lt;/li>
&lt;/ol>
&lt;p>하지만 저희는 &lt;strong>GCP 스타트업 프로그램&lt;/strong>을 활용해 1년간 충분한 크레딧을 확보한 상태였습니다.&lt;/p>
&lt;p>&amp;ldquo;어차피 1년 안에 다 못 쓸 크레딧인데, 제대로 된 인프라 만들어보자!&amp;rdquo;&lt;/p>
&lt;p>이런 전략적 판단으로 접근할 수 있었습니다. 크레딧이 끝나는 시점에는 다음과 같은 계획을 세우고 있습니다:&lt;/p>
&lt;ul>
&lt;li>불필요한 리소스 정리 및 Right-sizing&lt;/li>
&lt;li>개발 환경은 업무 시간에만 가동 (야간/주말 자동 중지)&lt;/li>
&lt;li>Spot Instance 활용 검토&lt;/li>
&lt;/ul>
&lt;h3>그럼에도 충분한 가치가 있었던 이유&lt;span class="hx:absolute hx:-mt-20" id="그럼에도-충분한-가치가-있었던-이유">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%9f%bc%ec%97%90%eb%8f%84-%ec%b6%a9%eb%b6%84%ed%95%9c-%ea%b0%80%ec%b9%98%ea%b0%80-%ec%9e%88%ec%97%88%eb%8d%98-%ec%9d%b4%ec%9c%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>비용만 보면 2배 이상 증가했지만, 얻은 것은 훨씬 많지 않았나 싶습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>개발자 생산성 향상&lt;/strong> - &amp;ldquo;운영에 조심히 배포&amp;quot;하던 시절과는 차원이 다릅니다&lt;/li>
&lt;li>&lt;strong>장애 대응 시간 단축&lt;/strong> - 통합 모니터링으로 MTTR(평균 복구 시간) 대폭 감소&lt;/li>
&lt;li>&lt;strong>운영 부담 감소&lt;/strong> - 자동화로 야근과 주말 대응이 줄었습니다&lt;/li>
&lt;li>&lt;strong>비즈니스 안정성&lt;/strong> - 더 이상 &amp;ldquo;서비스 하나 죽으면 전체 장애&amp;rdquo; 걱정 없음&lt;/li>
&lt;/ol>
&lt;p>시스템이 안정적으로 돌아가 사용자 신뢰도가 하락되는 일을 방지한 것만으로도 비용, 그 이상의 가치를 만들어낸다고 생각합니다.
불안정한 시스템으로 인한 안좋은 사용자 경험은 서비스 이탈을 야기하니까요.&lt;/p>
&lt;hr>
&lt;h2>마치며&lt;span class="hx:absolute hx:-mt-20" id="마치며">&lt;/span>
&lt;a href="#%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>Docker-compose에서 쿠버네티스로의 전환은 단순히 기술 스택을 바꾸는 것을 넘어, &lt;strong>저희 팀의 개발과 운영 문화를 한 단계 성장시키는 계기&lt;/strong>가 되었습니다. 선언적 인프라 관리와 GitOps 문화를 통해 팀 전체의 생산성과 시스템 안정성을 모두 잡을 수 있었으니까요.&lt;/p>
&lt;p>물론, 쿠버네티스의 방대한 학습 곡선이나 복잡한 네트워킹 등 아직 배워나가야 할 것들이 많다고 생각합니다. 하지만 이번 전환을 통해 얻은 경험은 앞으로 마주할 기술적 도전에도 맞설 수 있는 든든한 자산이 될 것이라 생각합니다.&lt;/p>
&lt;p>이 글이 저희와 비슷한 고민을 하고 있는 다른 개발자분들께 작은 도움이 되기를 바라며, 이만 글을 마치겠습니다. 긴 글 읽어주셔서 감사합니다.&lt;/p></description></item><item><title>점진적 MSA 전환은 환상일까? - 사내 강결합 레거시 서비스와의 사투기</title><link>https://jeongil.dev/ko/blog/architecture/is-gradual-msa-transition-an-illusion/</link><pubDate>Mon, 21 Jul 2025 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/architecture/is-gradual-msa-transition-an-illusion/</guid><description>
&lt;p>안녕하세요. 프롭테크 플랫폼에서 3년차 백엔드 개발자로 일하고 있는 정정일입니다.&lt;/p>
&lt;p>저는 최근 3월 팀에 합류했고 많은 기업들이 그렇듯, 저희 팀도 더 나은 확장성과 유지보수성을 위해 레거시 서비스를 마이크로서비스 아키텍처(MSA)로 전환하는 대장정을 진행하고 있었습니다.&lt;/p>
&lt;p>도메인별로 서비스를 착착 분리하고, 새로운 기술을 적용하며 점진적으로 시스템을 개선해나가는 청사진을 그렸죠.&lt;/p>
&lt;p>하지만 현실은 달랐습니다. 특히 &lt;strong>도메인 간의 강한 결합&lt;/strong>이라는 큰 벽에 부딪혔습니다. &amp;ldquo;하나씩, 점진적으로 전환하면 된다&amp;quot;는 이상적인 시나리오는 저희 회사의 강력하고 거대한 레거시 시스템 앞에서 힘을 잃었습니다.&lt;/p>
&lt;p>이 글에서는 저희가 레거시 서비스의 강한 결합 문제를 어떻게 마주하고, 어떤 고민 끝에 해결책을 찾아 나갔는지, 그 경험을 공유하고자 합니다.&lt;/p>
&lt;h3>&lt;strong>마주하게 된 과제 - 핵심 도메인 분리&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="마주하게-된-과제---핵심-도메인-분리">&lt;/span>
&lt;a href="#%eb%a7%88%ec%a3%bc%ed%95%98%ea%b2%8c-%eb%90%9c-%ea%b3%bc%ec%a0%9c---%ed%95%b5%ec%8b%ac-%eb%8f%84%eb%a9%94%ec%9d%b8-%eb%b6%84%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>제가 팀에 합류하는 시점에 저희 팀은 이미 MSA 전환 여정을 어느 정도 진행한 상태였습니다. 알림, 사용자 이벤트(쿠폰, 포인트 등)처럼 다른 도메인과 결합이 비교적 느슨한 서비스들은 성공적으로 분리하여 MSA의 장점을 맛보고 있었죠. 다음 타겟으로 핵심 도메인 중 하나인 &amp;lsquo;아파트 관련 기능&amp;rsquo;을 선택하게 됐습니다.&lt;/p>
&lt;p>하지만 이 결정은 우리가 이전에 겪어보지 못한, &lt;strong>&amp;lsquo;진짜 문제&amp;rsquo;&lt;/strong> 의 시작이었습니다. &lt;strong>&amp;lsquo;도메인 강결합&amp;rsquo;&lt;/strong> 이라는 거대한 산이 나타난 것입니다.&lt;/p>
&lt;p>아래 다이어그램은 저희가 마주했던 레거시 시스템의 내부를 단순화한 모습입니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/ce57af65-b6a1-4fed-9b84-ed5fc91f33ea/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>보시다시피, &lt;code>Matching Domain&lt;/code>의 핵심 로직이 &lt;code>Apartment Domain&lt;/code>의 데이터에 직접 의존하고 있었습니다.&lt;/p>
&lt;p>단순히 API를 호출하는 관계를 넘어, 같은 데이터베이스의 테이블을 공유하며 비즈니스 로직이 깊숙이 얽혀있었습니다.&lt;/p>
&lt;p>&lt;code>Apart-Service&lt;/code>를 분리한다는 것은 매칭 로직관련 로직의 수정이 불가피하다는 의미였습니다.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>&amp;ldquo;아파트 관련 기능만 이관하고 싶었으나, 레거시 서비스에서는 아파트 정보와 &amp;lsquo;매칭&amp;rsquo; 기능에 강한 결합이 있어 아파트만 분리할 수 없었다. 매칭도 같이 분리해야 하는데, 이런 경우들이 문제가 되는 경우들이 있어 점진적 전환이 어려운 부분이 있습니다.&amp;rdquo;&lt;/strong>&lt;/p>
&lt;/blockquote>
&lt;p>레거시 서비스에 대한 파악을 진행하고 팀 회의에서 이야기 해야했던 이 한마디가 저희가 처한 상황을 가장 정확하게 설명하고 있었습니다.&lt;/p>
&lt;h3>&lt;strong>기술적 기반 다지기와 드러난 진짜 문제&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="기술적-기반-다지기와-드러난-진짜-문제">&lt;/span>
&lt;a href="#%ea%b8%b0%ec%88%a0%ec%a0%81-%ea%b8%b0%eb%b0%98-%eb%8b%a4%ec%a7%80%ea%b8%b0%ec%99%80-%eb%93%9c%eb%9f%ac%eb%82%9c-%ec%a7%84%ec%a7%9c-%eb%ac%b8%ec%a0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>물론 저희도 MSA 전환을 진행하며 기술적 기반을 마련하기 위해 노력했습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>헥사고날 아키텍처 &amp;amp; CQS&lt;/strong>: 서비스 내부의 설계 품질을 높이고, 도메인 로직이 외부 기술에 의존하지 않도록 구조를 잡았습니다.&lt;/li>
&lt;li>&lt;strong>서비스 간 통신 (FeignClient)&lt;/strong>: 서비스간 통신에 &lt;code>gRPC&lt;/code>, &lt;code>Zero-Payload&lt;/code>, &lt;code>CQRS&lt;/code> 등을 고려했으나 Spring Cloud 환경에서 효율적인 동기 통신을 위해 &lt;code>FeignClient&lt;/code>를 표준으로 사용했습니다.&lt;/li>
&lt;li>&lt;strong>이벤트 기반 아키텍처 (SQS, Kubernetes)&lt;/strong>: 서비스 간의 비동기 처리가 필요한 경우를 대비해 SQS를 도입하고, 이 모든 것을 쿠버네티스 위에서 안정적으로 운영할 수 있는 환경을 구축했습니다.&lt;/li>
&lt;/ol>
&lt;p>이러한 노력들 덕분에 저희 MSA의 기술적인 안정성은 높아졌습니다.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>하지만 기술들은 근본적으로 &amp;lsquo;도메인 강결합으로 인한 점진적 MSA 전환의 어려움&amp;rsquo;을 해결해주지 못했습니다.&lt;/strong>&lt;/p>
&lt;/blockquote>
&lt;p>얽혀버린 도메인이라는 실타래를 푸는 것은 결국 저희의 &amp;lsquo;전략&amp;rsquo;에 달려있었습니다.&lt;/p>
&lt;h3>&lt;strong>현실적인 방법을 찾아서&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="현실적인-방법을-찾아서">&lt;/span>
&lt;a href="#%ed%98%84%ec%8b%a4%ec%a0%81%ec%9d%b8-%eb%b0%a9%eb%b2%95%ec%9d%84-%ec%b0%be%ec%95%84%ec%84%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>고민 끝에 저희는 두 가지 전략을 동시에 사용하는, 현실적인 방법을 선택했습니다.&lt;/p>
&lt;p>&lt;strong>1. 강결합된 도메인은 &amp;lsquo;함께&amp;rsquo; 전환한다.&lt;/strong> (부분적 빅뱅방식)
&amp;lsquo;점진적 전환&amp;rsquo;이라는 원칙을 일부 포기해야 했습니다. 아파트와 매칭, 이 두 도메인은 하나의 전환 단위로 묶어 동시에 MSA로 분리하기로 결정했습니다.&lt;/p>
&lt;p>이는 단기적으로 더 많은 리소스를 투입해야 하는 부담이 있었지만, 장기적으로 불완전한 분리로 인한 데이터 불일치나 비즈니스 로직의 꼬임을 막는 유일한 방법이라 판단했습니다.&lt;/p>
&lt;p>&lt;strong>2. 레거시 서비스의 &amp;lsquo;수정&amp;rsquo;을 감수하고, 과도기를 설정한다.&lt;/strong>
전환 기간 동안 레거시와 신규 MSA는 공존해야 하는 경우도 있었습니다. 이 과도기 동안 데이터 정합성과 서비스 연속성을 유지하기 위해, 레거시 서비스의 코드 수정을 피할 수 없었습니다. 저희는 다음과 같은 과도기 전략을 사용했습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>레거시에서 신규 MSA 호출&lt;/strong>: 레거시 시스템의 일부 로직을 수정하여, 새로 분리된 MSA의 API를 직접 호출하도록 변경했습니다. 이는 모든 기능을 한 번에 옮기지 않고, 필요한 부분부터 점진적으로 신규 서비스의 기능을 사용하도록 만드는 역할을 했습니다.&lt;/li>
&lt;li>&lt;strong>데이터 이중 적재 및 동기화&lt;/strong>: 전환 기간 동안 데이터의 일관성을 유지하는 것이 가장 큰 숙제였습니다. 저희는 사용자의 요청이 들어왔을 때 레거시 DB와 신규 MSA의 DB에 데이터를 이중으로 적재(Dual Write)하는 방식을 택했습니다. 물론 이 방식만으로는 데이터 정합성을 100% 보장할 수 없기에, 주기적으로 배치 작업을 실행하여 두 데이터베이스 간의 데이터를 동기화하는 고단한 과정을 거쳤습니다.&lt;/li>
&lt;/ul>
&lt;p>이런 강결합을 가진 도메인이 아파트와 매칭의 케이스만 존재했던게 아니기 때문에 두가지 전략을 케이스마다 적절히 선택해야했습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/0a379a40-54ee-43a9-b554-ec1c4979dace/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>아파트, 매칭 도메인의 경우 함께 전환하기로 결정했습니다.&lt;/p>
&lt;h3>&lt;strong>MSA 전환의 장단점&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="msa-전환의-장단점">&lt;/span>
&lt;a href="#msa-%ec%a0%84%ed%99%98%ec%9d%98-%ec%9e%a5%eb%8b%a8%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>덕분에 저희는 많은 것을 얻었습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>명확한 책임과 자율성&lt;/strong>: 도메인별로 팀의 책임이 명확해지고, 각 팀은 독립적으로 기술 스택을 선택하고 배포할 수 있게 되었습니다.&lt;/li>
&lt;li>&lt;strong>향상된 확장성&lt;/strong>: 트래픽이 몰리는 특정 서비스만 독립적으로 확장할 수 있어 비용 효율적인 운영이 가능해졌습니다.&lt;/li>
&lt;/ul>
&lt;p>하지만 솔직히 단점도 명확했습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>개발 리소스 증가&lt;/strong>: 당연하게도 관리해야 할 서비스와 인프라가 늘어나면서 초기 개발 및 운영 리소스가 크게 증가했습니다.&lt;/li>
&lt;li>&lt;strong>분산 시스템의 복잡성&lt;/strong>: 이벤트 기반 아키텍처에서 장애가 발생했을 때, 어떤 서비스에서 시작된 문제인지 추적하고 디버깅하는 것이 훨씬 어려워졌습니다. (이 문제를 해결하기 위해 저희는 별도의 모니터링 시스템을 구축하기도 했습니다.)&lt;/li>
&lt;/ul>
&lt;h3>&lt;strong>그래서, MSA가 정답일까?&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="그래서-msa가-정답일까">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%9e%98%ec%84%9c-msa%ea%b0%80-%ec%a0%95%eb%8b%b5%ec%9d%bc%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>저는 팀에 합류했을 때부터 MSA 전환이 이미 결정이된 상태였습니다. 하지만 이 과정을 겪고 난 지금, 저는 &amp;ldquo;서비스가 충분히 크고 복잡하지 않다면, 굳이 MSA를 도입해야 할까?&amp;ldquo;라는 질문을 스스로에게 던지게 됩니다.&lt;/p>
&lt;p>MSA는 은탄환이 아니라고 생각합니다. 오히려 &lt;strong>복잡한 문제&lt;/strong>를 해결하기 위해 서비스의 &lt;strong>복잡성을 감수해야 하는 트레이드오프&lt;/strong>에 가까운 것 같습니다.&lt;/p>
&lt;p>특히 저희처럼 도메인 간 결합이 강한 레거시 시스템을 전환할 때는, &amp;lsquo;점진적 전환&amp;rsquo;이라는 이상적인 말 뒤에 숨겨진 수많은 난관을 마주할 준비가 되어 있어야 하는 것 같습니다.&lt;/p>
&lt;p>만약 비슷한 고민을 하고 계신 분이 있다면, 기술적인 우아함이나 유행을 좇기보다는 우리 조직과 서비스의 &amp;lsquo;현실&amp;rsquo;을 냉정하게 진단하고, 가장 적합한 전략을 선택하시는 게 좋지 않을까 싶습니다.&lt;/p>
&lt;p>긴 글 읽어주셔서 감사합니다.&lt;/p></description></item><item><title>토비님 밋업 참관기 : 31년차 개발자가 전하는 AI시대, 개발자로 살아가는 법</title><link>https://jeongil.dev/ko/blog/reflection/how-to-live-as-a-developer-in-the-ai-era/</link><pubDate>Fri, 11 Jul 2025 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/reflection/how-to-live-as-a-developer-in-the-ai-era/</guid><description>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/5e2c0805-2c88-4ec3-a02b-a369511e7432/image.jpeg" alt="" loading="lazy" />&lt;/p>
&lt;p>어제(7월 10일), &lt;a href="https://www.inflearn.com/course/offline/31%EB%85%84%EC%B0%A8%EA%B0%9C%EB%B0%9C%EC%9E%90-ai%EC%8B%9C%EB%8C%80-%EC%A6%9D%EA%B0%95%EA%B0%9C%EB%B0%9C%EC%9E%90"target="_blank" rel="noopener">[31년차 개발자가 전하는 &amp;ldquo;AI시대, 개발자로 살아가는 법&amp;rdquo;]&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>이라는 제목의 밋업에 다녀왔습니다.&lt;/p>
&lt;p>인프런에서 주관하는 토비님의 강연이었는데, AI 코딩 시대에 개발자에게 요구되는 핵심 역량과 AI 협업 모델에 대한 지식을 얻을 수 있는 시간이였습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/719aa44f-1ff1-47f0-b4b7-a2b6325de85b/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>토비님은 스프링을 접하신분들이라면 한번쯤은 들어봤을 &amp;ldquo;토비의 스프링&amp;quot;의 저자십니다. 요즘은 인프런에서 강의도 올려주시고 계시죠.&lt;/p>
&lt;h3>1. AI 코딩 시대에 개발자에게 반드시 필요한 능력은?&lt;span class="hx:absolute hx:-mt-20" id="1-ai-코딩-시대에-개발자에게-반드시-필요한-능력은">&lt;/span>
&lt;a href="#1-ai-%ec%bd%94%eb%94%a9-%ec%8b%9c%eb%8c%80%ec%97%90-%ea%b0%9c%eb%b0%9c%ec%9e%90%ec%97%90%ea%b2%8c-%eb%b0%98%eb%93%9c%ec%8b%9c-%ed%95%84%ec%9a%94%ed%95%9c-%eb%8a%a5%eb%a0%a5%ec%9d%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>AI 코딩 시대는 과거와는 확연히 다른 역량을 요구한다고 합니다. 단순히 AI에게 명령하고 결과만 기다리는 수동적인 자세는 지양해야 한다고 토비님은 강조하셨어요.&lt;/p>
&lt;p>가장 먼저 중요하다고 언급하신 역량은 &lt;strong>멀티태스킹&lt;/strong>이었습니다.&lt;/p>
&lt;p>AI가 특정 Task를 수행하는 동안 개발자는 그 시간을 멍하니 보내는 것이 아니라, 다른 작업을 하거나 깊이 고민하는 등 시간을 효율적으로 활용해야 한다는 말씀에 깊이 공감했습니다.&lt;/p>
&lt;p>최근 저도 AI 도구를 활용하면서 특정 작업을 요청하고 멍때리는 시간은 없었는지 반성하게 되더라구요.&lt;/p>
&lt;p>또 AI에게 가이드 문서 제작이나 API 스펙 준수 개발을 의뢰하고 그 시간에 저는 더 상위 수준의 아키텍처나 기획에 집중하는 방식으로 시간을 배분해야겠다는 생각이 들었습니다.&lt;/p>
&lt;p>토비님은 지금을 &amp;lsquo;개발자들의 AI 대혼란의 시대&amp;rsquo;라고 표현하셨습니다.&lt;/p>
&lt;p>특히 토비님께서 &amp;ldquo;AI 시대 개발자가 어떻게 살아야 할지 솔직히 잘 모르겠습니다&amp;hellip;&amp;ldquo;라고 솔직하게 말씀하신 부분이 가장 기억에 남습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/c06da691-0d16-44ae-b665-809655b2d29a/image.jpeg" alt="" loading="lazy" />&lt;/p>
&lt;p>새로운 시대를 맞이하는 지금의 혼란스러운 상황을 있는 그대로 보여주는 듯했으니까요. 하지만 동시에 명확한 방향성을 제시해주셔서 많은 생각을 하게 되었습니다.&lt;/p>
&lt;p>개발자는 더 이상 고정된 직능이 아니라 AI와 함께 계속 새롭게 정의될 &lt;strong>유동적인 개념&lt;/strong>이 될 것이라는 말씀이 가장 와닿았습니다. 저 역시 끊임없이 변화하고 배우지 않으면 도태될 수 있다는 위기감과 동시에 새로운 기회를 발견할 수 있다는 기대감을 동시에 느끼고 있습니다.&lt;/p>
&lt;h3>2. AI 코딩 스펙트럼: 자율성 레벨 6단계 (0~5)&lt;span class="hx:absolute hx:-mt-20" id="2-ai-코딩-스펙트럼-자율성-레벨-6단계-05">&lt;/span>
&lt;a href="#2-ai-%ec%bd%94%eb%94%a9-%ec%8a%a4%ed%8e%99%ed%8a%b8%eb%9f%bc-%ec%9e%90%ec%9c%a8%ec%84%b1-%eb%a0%88%eb%b2%a8-6%eb%8b%a8%ea%b3%84-05" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>AI의 자율성 레벨을 이해하는 것은 AI 협업 전략 수립에 매우 중요하다고 하셨습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>레벨 0: 정적 도구(Static Tooling)&lt;/strong> (린터, 포맷터 등)&lt;/li>
&lt;li>&lt;strong>레벨 1: 토큰 수준 완성(Token-Level Completion)&lt;/strong> (IDE 자동 완성)&lt;/li>
&lt;li>&lt;strong>레벨 2: 블록 수준 완성(Block-Level Completion)&lt;/strong> (IntelliJ 인라인 완성)&lt;/li>
&lt;li>&lt;strong>레벨 3: 의도 기반 채팅 에이전트(Intent-Based Chat Agent)&lt;/strong> (ChatGPT, Gemini 등)&lt;/li>
&lt;li>&lt;strong>레벨 4: 로컬 자율 에이전트(Local Autonomous Agent)&lt;/strong>&lt;/li>
&lt;li>&lt;strong>레벨 5: 완전 자율 개발 에이전트(Fully Autonomous Dev Agent)&lt;/strong>&lt;/li>
&lt;/ul>
&lt;p>특히 레벨 2까지는 개발 흐름을 크게 깨지 않아 &lt;strong>적극적인 활용을 권장&lt;/strong>한다고 하셨습니다.&lt;/p>
&lt;p>저도 IDE 자동 완성이나 인라인 완성은 이미 일상적으로 사용하고 있지만 지금도 IDE에서 텔레메트리(제안, 수락/거절 로그)를 수집하여 모델을 고도화하는 등 AI가 점점 더 스마트해지고 있다는 점을 생각하면, 레벨 2단계까지도 더욱 활용할 수 있는 방식으로 개발해보려 노력해야겠다 싶었습니다.&lt;/p>
&lt;h3>3. 인간-AI 협업 모델&lt;span class="hx:absolute hx:-mt-20" id="3-인간-ai-협업-모델">&lt;/span>
&lt;a href="#3-%ec%9d%b8%ea%b0%84-ai-%ed%98%91%ec%97%85-%eb%aa%a8%eb%8d%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>인간 개발자와 AI의 협업은 단순히 인간 주도 또는 AI 주도의 이분법을 넘어선다고 합니다. 이 부분에서 굉장히 많은 것을 느꼈는데요.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>3.1. AI-in-the-Loop (AITL):&lt;/strong> AI가 보조자 역할, 인간이 개발 과정 완전 통제. (AI 자율성 레벨 1~3단계 해당)&lt;/li>
&lt;li>&lt;strong>3.2. Human-in-the-Loop (HITL):&lt;/strong> AI가 개발 프로세스 주도, 주요 결정마다 인간의 검증과 승인 필요. (AI 자율성 레벨 3 후반~4 해당)&lt;/li>
&lt;li>&lt;strong>3.3. Human-on-the-Loop (HOTL):&lt;/strong> AI가 자율적으로 작업 수행, 인간은 감독관 역할. (AI 자율성 레벨 4~5 해당)&lt;/li>
&lt;/ul>
&lt;p>토비님은 효율적인 개발자는 작업의 성격과 복잡성에 따라 협업 모델을 유연하게 전환할 수 있는 &lt;strong>&amp;lsquo;모드 전환자(Mode Switchers)&amp;rsquo;&lt;/strong> 가 되어야 한다고 강조하셨습니다.&lt;/p>
&lt;p>저는 사실 이런 용어가 있다는 것을 이번 밋업을 통해 알게됐는데요. 의식적으로 지금은 이런 모드가 적당하겠다 생각해본적은 없지만 본능적으로 해왔던 부분이 있던 것 같습니다.&lt;/p>
&lt;p>&lt;strong>저 스스로는 어느정도나 AI를 믿을 수 있는 작업인가?&lt;/strong> 가 저도 모르게 모드를 결정했왔던 것 같습니다.&lt;/p>
&lt;p>단순 반복적인 일은 &lt;strong>HOTL&lt;/strong> 모드로 검증이 필요한 경우는 &lt;strong>HITL&lt;/strong>모드로 아주 중요한 작업들, AI를 신뢰할 수 없는 상황 에서는 &lt;strong>AITL&lt;/strong> 모드 였던 것 같습니다.&lt;/p>
&lt;p>복잡한 도메인이나 아키텍처와 같은 미묘한 판단이 필요한 작업에서는 제가 주도하고 AI는 도구로 활용하는 방식이 익숙하죠. 하지만 앞으로 단순하고 반복적인 일에서는 HOTL 모델을 적극적으로 활용하여 효율을 높이는 연습을 해야겠다는 생각이 들었습니다.&lt;/p>
&lt;h3>4. AI와 협업을 위한 아키텍처 설계&lt;span class="hx:absolute hx:-mt-20" id="4-ai와-협업을-위한-아키텍처-설계">&lt;/span>
&lt;a href="#4-ai%ec%99%80-%ed%98%91%ec%97%85%ec%9d%84-%ec%9c%84%ed%95%9c-%ec%95%84%ed%82%a4%ed%85%8d%ec%b2%98-%ec%84%a4%ea%b3%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>여전히 상위 수준 아키텍처와 설계 결정은 인간 개발자가 통제하는 것이 이상적이라고 합니다.&lt;/p>
&lt;p>특히 &lt;strong>관심사와 책임이 분리된 명확한 계층 정의, 인터페이스를 계약(Contract)으로 사용, 작업을 작은 단위로 분해하고 점진적으로 개발&lt;/strong>하는 원칙을 강조하셨습니다. 아키텍처 설계 이유와 근거는 인간이 명확하게 기록해야 한다는 점도 인상 깊었습니다.&lt;/p>
&lt;p>&lt;strong>4.1. AI 개발에서도 클린 코드는 중요할까?&lt;/strong>
네, &lt;strong>&amp;lsquo;그렇습니다!&amp;rsquo;&lt;/strong> 인간이 코드를 잘 읽고, 이해하기 쉽고, 변경하기 쉽게 만들기 위한 모든 원칙과 전략은 효과적인 AI와의 협업을 위한 전제조건이라고 하셨습니다. 잘 설계된 아키텍처는 인간뿐만 아니라 AI에게도 가장 명확한 지침을 제공한다는 점을 강조 해주셨어요.&lt;/p>
&lt;p>결국, 기본을 지키는 것이 AI 시대에도 변함없이 중요하다는 것을 다시 한번 깨달았습니다.&lt;/p>
&lt;h3>5. 테스트 주도 개발(TDD)의 르네상스&lt;span class="hx:absolute hx:-mt-20" id="5-테스트-주도-개발tdd의-르네상스">&lt;/span>
&lt;a href="#5-%ed%85%8c%ec%8a%a4%ed%8a%b8-%ec%a3%bc%eb%8f%84-%ea%b0%9c%eb%b0%9ctdd%ec%9d%98-%eb%a5%b4%eb%84%a4%ec%83%81%ec%8a%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>AI 시대에는 &lt;strong>TDD를 하지 않으면 안 된다&lt;/strong>는 토비님의 강력한 주장이 있었습니다. 레벨 4 이상의 자율적인 에이전트를 안전하고 생산적으로 활용하기 위한 가장 효과적인 워크플로우이자 핵심적인 프레임워크가 TDD라는 것이죠.&lt;/p>
&lt;p>&lt;strong>5.1. TDD가 AI 협업에 중요한 이유&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;strong>명확한 성공 기준 제시:&lt;/strong> 테스트를 성공시키지 못하면 AI는 재시도합니다.&lt;/li>
&lt;li>&lt;strong>궁극적인 가드레일 역할:&lt;/strong> AI의 실수를 방지하는 안전장치입니다.&lt;/li>
&lt;li>&lt;strong>에이전트의 작업 루프와 완벽한 조화:&lt;/strong> AI가 테스트를 통과하기 위한 코드를 생성하고 수정하는 과정과 완벽하게 맞아떨어집니다.&lt;/li>
&lt;/ul>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/ac84b9e3-ae8d-4a4d-808e-c1b47d6c3e02/image.jpeg" alt="" loading="lazy" />&lt;/p>
&lt;p>&lt;strong>5.2. AI 지원 TDD 워크플로우 (Claude Code Best Practices)&lt;/strong>
인간이 실패하는 테스트를 만들고, AI가 이를 통과시키는 코드를 구현한 뒤, 인간이 리뷰하고 리팩토링하는 방식의 워크플로우를 보며 TDD가 AI와 얼마나 강력한 시너지를 낼 수 있는지 실감했습니다. 사실 TDD를 완벽하게 실천하지 못하고 있었는데, 이번 기회에 다시 한번 TDD의 중요성을 깨닫고 AI와 함께 TDD를 적극적으로 도입해보려고 합니다.&lt;/p>
&lt;h3>6. 탐험과 활용 딜레마&lt;span class="hx:absolute hx:-mt-20" id="6-탐험과-활용-딜레마">&lt;/span>
&lt;a href="#6-%ed%83%90%ed%97%98%ea%b3%bc-%ed%99%9c%ec%9a%a9-%eb%94%9c%eb%a0%88%eb%a7%88" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>많은 사람이 AI로 얼마나 빠르게 개발할 것인가, 즉 &lt;strong>생산성&lt;/strong> 이야기만 한다고 지적하셨습니다. 하지만 &lt;strong>강화학습의 탐험(Exploration)과 활용(Exploitation) 딜레마&lt;/strong>를 이해해야 한다고 하셨습니다. 즉각적인 생산성 추구와 지속적인 학습 및 기술 개발을 위한 의도적인 노력을 조화시키는 전략적인 접근이 필요하다는 것이죠.&lt;/p>
&lt;p>&lt;strong>6.2. 바이브 코딩과 생산성 우선 접근 방식&lt;/strong>
바이브 코딩은 단순히 속도에 관한 것이 아니라, 개발자의 역할이 &lt;strong>프로덕트 엔지니어, 의도 설계자, 크리에이티브 디렉터, 프롬프터, 가이드&lt;/strong> 등으로 변화하는 근본적인 변화를 의미한다고 합니다. AI를 통해 세부 구현에 대한 인지 부하를 줄이고, 더 고수준의 &amp;lsquo;의도 명세화&amp;rsquo;에 집중하는 것이 중요하다는 말씀이었습니다. 저도 앞으로는 AI에게 구현을 맡기고 저는 더 큰 그림과 의도를 설계하는 역할에 집중하는 연습을 해야겠습니다.&lt;/p>
&lt;h3>7. 역량 강화 및 학습을 위한 AI 활용&lt;span class="hx:absolute hx:-mt-20" id="7-역량-강화-및-학습을-위한-ai-활용">&lt;/span>
&lt;a href="#7-%ec%97%ad%eb%9f%89-%ea%b0%95%ed%99%94-%eb%b0%8f-%ed%95%99%ec%8a%b5%ec%9d%84-%ec%9c%84%ed%95%9c-ai-%ed%99%9c%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>AI는 생산성 도구뿐만 아니라 &lt;strong>학습 촉매제&lt;/strong>로서도 활용될 수 있다는 점 역시 알고있던 점이지만 다시금 흥미로운 부분이었습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>복잡한 코드 이해 및 분석&lt;/strong>&lt;/li>
&lt;li>&lt;strong>새로운 언어나 기술, API 학습&lt;/strong>&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>7.1. 기존 코드를 AI와 분석, 학습 (예: 스프링 프레임워크 7.0)&lt;/strong>
스프링 소스 코드를 AI(Claude Code)로 분석하고, 아키텍처, 코드 품질, 비동기 기술 사용 방식 등을 배우는 예시를 보면서 감탄했습니다. 저도 관심 있는 오픈소스 프로젝트를 AI와 함께 분석하고, 그 결과를 바탕으로 가이드 문서를 만들어보는 시도를 해봐야겠다고 생각했습니다.&lt;/p>
&lt;p>&lt;strong>7.2. 웹 브라우저 연결 (MCP)을 이용한 레퍼런스 문서 학습 개발&lt;/strong>
&lt;strong>7.3. 학습 소스를 모아두고 다양한 내용의 학습 자료 생성 (NotebookLM 적극 활용)&lt;/strong>
구매한 전자책, 웹사이트, 유튜브 영상 텍스트 등 다양한 소스를 NotebookLM에 등록하여 요약, 학습 가이드, 마인드맵 등을 생성할 수 있다는 점이 매우 유용해 보였습니다. 여러 자료를 모아 주제를 지정하고 공통점이나 차이점을 비교하며 개념을 정리하는 방식은 저에게 꼭 필요한 학습법이었습니다.&lt;/p>
&lt;h3>8. Deep Research 활용&lt;span class="hx:absolute hx:-mt-20" id="8-deep-research-활용">&lt;/span>
&lt;a href="#8-deep-research-%ed%99%9c%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Deep Research 기능을 활용하여 연구 목표, 내용, 결과물 형태를 지정하면 방대한 양의 검색과 여러 단계의 연구 방향 재설정을 통해 출처가 표시된 리포트를 생성해줍니다.&lt;/p>
&lt;p>조사가 필요한 주제가 있을 때 회의나 미팅 중에도 심층 분석을 요청할 수 있다는 점이 매력적이라고 언급해주셨어요.&lt;/p>
&lt;p>저 역시 사용은 해봤지만 적극적인 사용은 하지 않았었는데, 앞으로는 복잡한 기술 트렌드를 분석하거나 새로운 기술을 도입하기 전에 이 기능을 적극 활용해봐야겠습니다.&lt;/p>
&lt;h3>9. 밋업 페이지 내용 제작 과정 (발표자 토비님 사례)&lt;span class="hx:absolute hx:-mt-20" id="9-밋업-페이지-내용-제작-과정-발표자-토비님-사례">&lt;/span>
&lt;a href="#9-%eb%b0%8b%ec%97%85-%ed%8e%98%ec%9d%b4%ec%a7%80-%eb%82%b4%ec%9a%a9-%ec%a0%9c%ec%9e%91-%ea%b3%bc%ec%a0%95-%eb%b0%9c%ed%91%9c%ec%9e%90-%ed%86%a0%eb%b9%84%eb%8b%98-%ec%82%ac%eb%a1%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/82010850-4ef8-46bc-acef-8c369f99949a/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>이번 밋업 페이지 내용이 어떻게 제작되었는지 토비님의 사례를 들려주셨는데, 그 과정 자체가 AI와의 협업 모범 사례였습니다.&lt;/p>
&lt;ol>
&lt;li>AI 코딩 관련 주제 정리 후 연구 프롬프트 작성.&lt;/li>
&lt;li>ChatGPT, Gemini, Claude를 통해 심층 탐구 수행.&lt;/li>
&lt;li>리서치 결과 정독 및 환각(Hallucination) 확인.&lt;/li>
&lt;li>결과를 PDF로 변환하여 &lt;strong>NotebookLM에 등록&lt;/strong>.&lt;/li>
&lt;li>기존 밋업 안내 페이지 내용을 &lt;strong>one-shot&lt;/strong>으로 NotebookLM에 넣고, &amp;ldquo;이런 구조로 3가지 소스(AI 심층 탐구 결과)의 내용을 가지고 1시간 20분간 발표할 핵심 내용을 정리하여 문서로 작성해달라&amp;quot;고 요청.&lt;/li>
&lt;li>결과물 수정 후 인프런 전달.&lt;/li>
&lt;/ol>
&lt;p>이 과정을 보며, AI를 단순히 글쓰기 도구로 사용하는 것을 넘어, 정보 수집-정리-기획-초안 작성에 이르는 전 과정에 걸쳐 AI를 활용할 수 있음을 깨달았습니다.&lt;/p>
&lt;h3>10. AI 협업 시 가장 중요한 자세: &amp;lsquo;딸깍딸깍&amp;rsquo; 금지!&lt;span class="hx:absolute hx:-mt-20" id="10-ai-협업-시-가장-중요한-자세-딸깍딸깍-금지">&lt;/span>
&lt;a href="#10-ai-%ed%98%91%ec%97%85-%ec%8b%9c-%ea%b0%80%ec%9e%a5-%ec%a4%91%ec%9a%94%ed%95%9c-%ec%9e%90%ec%84%b8-%eb%94%b8%ea%b9%8d%eb%94%b8%ea%b9%8d-%ea%b8%88%ec%a7%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>토비님은 AI 협업 시 &lt;strong>&amp;lsquo;딸깍딸깍&amp;rsquo; 금지!&lt;/strong> 를 외치셨습니다. 특히 레벨 3~5단계에서 무조건 AI의 제안을 수락하는 습관은 매우 좋지 않다고 경고하셨죠. AI가 코드를 생성하면 요청 내용을 정제하고, 어떤 계획을 가지고 문제를 풀지, 각 단계마다 어떤 생각을 하는지, 그리고 코드에 대한 설명을 자세히 적어주는 이 모든 과정을 &amp;lsquo;꼭 봐야 한다&amp;rsquo;고 강조하셨습니다.&lt;/p>
&lt;p>AI와 함께 개발하면서 얼마나 많은 효과적인 학습이 가능한지를 우리가 놓치고 있다는 말씀에 깊이 공감했습니다. 시니어 개발자가 옆에서 자세한 설명을 하면서 코드를 만드는 것을 도와주는데, 코드 입력만 하고 설명은 다 무시하는 주니어 개발자라고 생각해 보면 그 중요성을 알 수 있다는 비유는 정말 명확하게 와닿았습니다. 저 역시 이제부터 AI의 설명을 더 꼼꼼히 살피고, 왜 이런 코드를 생성했는지 질문하며 학습하는 태도를 길러야겠습니다.&lt;/p>
&lt;h3>11. 탐험적 AI 사용에서 개발자의 역할&lt;span class="hx:absolute hx:-mt-20" id="11-탐험적-ai-사용에서-개발자의-역할">&lt;/span>
&lt;a href="#11-%ed%83%90%ed%97%98%ec%a0%81-ai-%ec%82%ac%ec%9a%a9%ec%97%90%ec%84%9c-%ea%b0%9c%eb%b0%9c%ec%9e%90%ec%9d%98-%ec%97%ad%ed%95%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>탐험적 AI 사용에서 개발자는 AI가 생성한 설명과 코드를 비판적으로 평가하고, AI 기능을 이용하여 &lt;strong>이해를 심화시키는 능동적인 학습자&lt;/strong>가 되어야 한다고 합니다. 단순히 &amp;lsquo;무엇을(What)&amp;rsquo; 말고 &lt;strong>&amp;lsquo;어떻게(How)&amp;rsquo; &amp;lsquo;왜(Why)&amp;rsquo;&lt;/strong> 라는 질문을 포함해야 하며, 이미 나온 코드 외에 &lt;strong>대안을 물어보고&lt;/strong> 어떤 이유로 현재 방식을 선택했는지 확인해야 한다고 합니다.&lt;/p>
&lt;h3>12. 학습을 위한 전용 시간 확보 및 의도적 수련&lt;span class="hx:absolute hx:-mt-20" id="12-학습을-위한-전용-시간-확보-및-의도적-수련">&lt;/span>
&lt;a href="#12-%ed%95%99%ec%8a%b5%ec%9d%84-%ec%9c%84%ed%95%9c-%ec%a0%84%ec%9a%a9-%ec%8b%9c%ea%b0%84-%ed%99%95%eb%b3%b4-%eb%b0%8f-%ec%9d%98%eb%8f%84%ec%a0%81-%ec%88%98%eb%a0%a8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>조직과 개별 개발자는 &lt;strong>탐험 모드에서 AI 도구를 사용할 특정 시간을 할당&lt;/strong>해야 한다고 합니다. 도전적이거나 익숙하지 않은 영역을 목표로 설정하고, AI를 학습 파트너로 적극 활용해야 한다는 것이죠.&lt;/p>
&lt;p>&lt;strong>12.1. 의도적 수련 필요&lt;/strong>
기억 인출 학습 방식으로 AI에게 어제 학습한 내용을 설명해보라고 요청하고, 나의 설명에 대해 평가해달라고 요청하는 등 &lt;strong>의도적인 수련&lt;/strong>을 통해 학습 효과를 극대화할 수 있다고 합니다. 이 부분은 개인적으로 바로 적용해 볼 수 있는 좋은 팁이라고 생각했습니다.&lt;/p>
&lt;h3>13. 결론: 증강 개발자로의 변화&lt;span class="hx:absolute hx:-mt-20" id="13-결론-증강-개발자로의-변화">&lt;/span>
&lt;a href="#13-%ea%b2%b0%eb%a1%a0-%ec%a6%9d%ea%b0%95-%ea%b0%9c%eb%b0%9c%ec%9e%90%eb%a1%9c%ec%9d%98-%eb%b3%80%ed%99%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>토비님은 인간의 지성과 AI의 효율성을 능숙하게 결합하는 &lt;strong>&amp;lsquo;증강 개발자&amp;rsquo;&lt;/strong> 로 변화해야 한다고 결론지었습니다. 작업의 성격에 따라 최적의 AI 협업 모드를 선택하고, AI가 최고의 성능을 발휘할 수 있도록 명확한 아키텍처와 지속 가능한 컨텍스트를 제공하는 것이 중요하다고 하셨습니다.&lt;/p>
&lt;p>또 중요한 것은, &lt;strong>AI가 생성한 결과물에 대해서 최종적인 판단을 책임져야 한다&lt;/strong>는 말씀이었습니다. 책임지려면 알아야 하고, 그러니 꾸준히 성장해야 하며, AI를 활용하면 더 효율적으로 성장할 수 있다는 메시지는 저에게 큰 동기 부여가 되었습니다.&lt;/p>
&lt;p>이번 밋업에서 얻은 인사이트를 바탕으로 개발 방식과 학습 전략에 대해 고민해볼 수 있어 너무 좋은 시간이였습니다.&lt;/p>
&lt;p>정말 운 좋게도 참석할 수 있었네요 ㅎㅎ..
이번 밋업은 선착순 모집 인원 80명이 였는데 20~30분만에 매진된 것으로 알고 있습니다. 다행히도 80명중 한명으로 참석할 수 있어 좋았네요. 무작위로 참석하는 밋업이나 컨퍼런스는 경쟁률이 치열해 많이 떨어졌거든요 😢&lt;/p>
&lt;p>다시금 다른 컨퍼런스나 밋업 참석한게 있다면 마찬가지로 남기도록 하겠습니다. 읽어주셔서 감사합니다.&lt;/p></description></item><item><title>온프레미스에서 클라우드로 - 무중단 마이그레이션 경험기</title><link>https://jeongil.dev/ko/blog/infrastructure/from-on-premises-to-cloud-a-zero-downtime-migration-story/</link><pubDate>Thu, 10 Jul 2025 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/infrastructure/from-on-premises-to-cloud-a-zero-downtime-migration-story/</guid><description>
&lt;p>안녕하세요
저는 프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 3년차 백엔드 개발자 정정일입니다.&lt;/p>
&lt;p>이번 글에서는 온프레미스 환경에서 운영되던 모놀리식 서버를 클라우드(AWS)로 이전한 경험과 그 과정에서 테라폼(Terraform)을 활용한 인프라 자동화 경험에 대해 공유하려 합니다.&lt;/p>
&lt;h2>배경 상황&lt;span class="hx:absolute hx:-mt-20" id="배경-상황">&lt;/span>
&lt;a href="#%eb%b0%b0%ea%b2%bd-%ec%83%81%ed%99%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>제가 올해 3월에 팀에 합류했을 때, 대부분의 서비스는 이미 클라우드 환경에서 운영되고 있었습니다. 하지만 서비스 중 하나가 여전히 IDC에서 모놀리식 아키텍처로 운영되고 있었습니다. 이 서버는 웹 애플리케이션과 데이터베이스가 동일한 물리적 서버에 구성되어 굉장히 단순한 구조를 가지고 있었죠.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/f2b5e2f9-523a-45cf-9e41-4014a22c54dd/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>이 서버는 하드웨어 접촉 불량으로 인한 서버 다운 이슈가 간헐적으로 발생했고, 트래픽 증가에 따른 스케일링에도 제약이 있었습니다.&lt;/p>
&lt;p>이런 문제들로 인해 서비스 안정성이 저하되고 운영 부담이 증가하는 상황이었습니다. 특히 하드웨어 접촉 불량으로 인한 예기치 않은 서버 다운은 사용자 경험에 굉장히 심각한 문제였습니다.&lt;/p>
&lt;h2>클라우드 마이그레이션 결정&lt;span class="hx:absolute hx:-mt-20" id="클라우드-마이그레이션-결정">&lt;/span>
&lt;a href="#%ed%81%b4%eb%9d%bc%ec%9a%b0%eb%93%9c-%eb%a7%88%ec%9d%b4%ea%b7%b8%eb%a0%88%ec%9d%b4%ec%85%98-%ea%b2%b0%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>여러 대안을 검토한 결과, 클라우드로의 마이그레이션이 최적의 해결책이라고 판단했습니다.&lt;/p>
&lt;p>이미 기존에 대부분의 서버들은 클라우드에서 운영중이기도 했고 아래와 같은 이유로도 클라우드로의 이관이 필수적이라고 판단했습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>안정성 향상&lt;/strong>: AWS의 높은 가용성 인프라 활용&lt;/li>
&lt;li>&lt;strong>유연한 스케일링&lt;/strong>: 트래픽 변화에 따른 자원 조정 용이&lt;/li>
&lt;li>&lt;strong>통합 운영 환경&lt;/strong>: 기존 클라우드 서버들과 동일한 관리 체계 적용&lt;/li>
&lt;li>&lt;strong>비용 효율성&lt;/strong>: 사용한 만큼 지불하는 모델로 리소스 효율화&lt;/li>
&lt;/ul>
&lt;p>또 가장 큰 이유는 회사에 클라우드 관련 크래딧이 있었기 때문에 비용적인 측면도 컸습니다.&lt;/p>
&lt;h2>마이그레이션 과제: 무중단 전환&lt;span class="hx:absolute hx:-mt-20" id="마이그레이션-과제-무중단-전환">&lt;/span>
&lt;a href="#%eb%a7%88%ec%9d%b4%ea%b7%b8%eb%a0%88%ec%9d%b4%ec%85%98-%ea%b3%bc%ec%a0%9c-%eb%ac%b4%ec%a4%91%eb%8b%a8-%ec%a0%84%ed%99%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>마이그레이션 계획 수립 시 가장 중요한 요구사항은 &lt;strong>서비스 다운타임 최소화&lt;/strong>였습니다. 사용자 경험을 해치지 않으면서 안전하게 전환하기 위해 다음과 같은 과제를 해결해야 했습니다:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>DNS 전파 시간 동안의 트래픽 처리&lt;/strong>: DNS 변경 후 전파가 완료될 때까지 일부 사용자는 IDC 서버로, 일부는 클라우드 서버로 접속하는 상황 발생&lt;/li>
&lt;li>&lt;strong>데이터 정합성 유지&lt;/strong>: 전환 기간 동안 두 환경에서 발생하는 데이터 변경사항의 일관성 보장&lt;/li>
&lt;li>&lt;strong>롤백 계획&lt;/strong>: 문제 발생 시 신속하게 원래 환경으로 복귀할 수 있는 방안 마련&lt;/li>
&lt;/ol>
&lt;h2>무중단 마이그레이션 전략&lt;span class="hx:absolute hx:-mt-20" id="무중단-마이그레이션-전략">&lt;/span>
&lt;a href="#%eb%ac%b4%ec%a4%91%eb%8b%a8-%eb%a7%88%ec%9d%b4%ea%b7%b8%eb%a0%88%ec%9d%b4%ec%85%98-%ec%a0%84%eb%9e%b5" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>기존에 운영중인 웹서버였기때문에 동일한 DNS 그대로 운영돼야 했습니다. 따라서 서버를 구성한다 하더라도 DNS의 Endpoint가 전파되는 시간이 존재했습니다.&lt;/p>
&lt;p>저희는 DNS 전파 시간을 고려하여, 다음과 같은 전략을 수립했습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>클라우드 환경 구축&lt;/strong>: AWS에 동일한 서버 환경을 미리 구성&lt;/li>
&lt;li>&lt;strong>이중 운영&lt;/strong>: DNS 변경 후 전파 기간 동안 IDC와 클라우드 양쪽 모두에서 서버 운영&lt;/li>
&lt;li>&lt;strong>DNS 전환&lt;/strong>: 준비가 완료되면 DNS를 클라우드 서버 IP로 변경&lt;/li>
&lt;li>&lt;strong>모니터링&lt;/strong>: 전환 과정 실시간 모니터링 및 문제 발생 시 즉시 대응&lt;/li>
&lt;li>&lt;strong>IDC 서버 종료&lt;/strong>: DNS 전파 완료 확인 후 IDC 서버 종료&lt;/li>
&lt;/ol>
&lt;p>이렇게 저희는 사용자들이 DNS 캐시 상태에 따라 자연스럽게 새 환경으로 전환되도록 하여 다운타임을 방지했습니다.&lt;/p>
&lt;h2>데이터 정합성 문제와 CDC 솔루션&lt;span class="hx:absolute hx:-mt-20" id="데이터-정합성-문제와-cdc-솔루션">&lt;/span>
&lt;a href="#%eb%8d%b0%ec%9d%b4%ed%84%b0-%ec%a0%95%ed%95%a9%ec%84%b1-%eb%ac%b8%ec%a0%9c%ec%99%80-cdc-%ec%86%94%eb%a3%a8%ec%85%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>마이그레이션 과정에서 가장 큰 기술적 과제는 &lt;strong>데이터 정합성 유지&lt;/strong>였습니다.&lt;/p>
&lt;p>저희는 클라우드의 관리형 데이터베이스로 이관할 결정을 했기때문에 기존의 IDC 로컬 DB를 계속 사용할 수 없었습니다.&lt;/p>
&lt;p>그러니 IDC 서버와 클라우드 서버가 동시에 운영되는 동안, 두 환경의 데이터베이스가 동기화되지 않으면 심각한 문제가 발생할 수 있었습니다.&lt;/p>
&lt;p>이 문제를 해결하기 위해 여러 대안을 검토했습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>데이터베이스 복제(Replication)&lt;/strong>: DB 자체의 복제 기능 활용&lt;/li>
&lt;li>&lt;strong>애플리케이션 수준 이중 쓰기(Dual Write)&lt;/strong>: 애플리케이션에서 두 DB에 동시에 쓰기&lt;/li>
&lt;li>&lt;strong>메시지 큐 기반 동기화&lt;/strong>: 데이터 변경을 메시지 큐에 발행하여 동기화&lt;/li>
&lt;li>&lt;strong>ETL 기반 배치 동기화&lt;/strong>: 주기적 배치 작업으로 데이터 동기화&lt;/li>
&lt;li>&lt;strong>CDC(Change Data Capture)&lt;/strong>: DB 변경 로그를 캡처하여 실시간 동기화&lt;/li>
&lt;/ol>
&lt;p>검토 결과, CDC 기술이 실시간성과 신뢰성 측면에서 가장 적합하다고 판단했습니다. 따라서 다음과 같이 구현했습니다.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>CDC 구성&lt;/strong>: IDC DB의 변경사항을 실시간으로 감지하여 AWS RDS로 복제&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>단방향 동기화&lt;/strong>: 전환 기간 동안 IDC DB → AWS RDS 방향으로만 동기화
&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/595493b0-98d2-467c-a205-412fca7d91d1/image.png" alt="" loading="lazy" />&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>애플리케이션 설정&lt;/strong>: 전환 기간 동안 모든 서버가 IDC DB를 참조하도록 구성
&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/91eb927d-7d81-4439-88c0-c37785182525/image.png" alt="" loading="lazy" />&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>전환 완료 후&lt;/strong>: DNS 전파 완료 확인 후 모든 서버의 DB 참조를 RDS로 변경&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>이후&lt;/strong>: 기존 IDC 서버 종료 및 CDC 구성 종료&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>이 접근 방식을 통해 DNS 전파 기간 동안 발생할 수 있는 데이터 불일치 문제를 해결했습니다.&lt;/p>
&lt;p>저희는 CDC 솔루션으로는 AWS DMS를 선택했습니다.
이유로는 아무래도 AWS 환경으로의 이관이다 RDS와 가장 호환성이 좋다고 판단했습니다.&lt;/p>
&lt;h2>인프라스트럭처 자동화 (IaC)&lt;span class="hx:absolute hx:-mt-20" id="인프라스트럭처-자동화-iac">&lt;/span>
&lt;a href="#%ec%9d%b8%ed%94%84%eb%9d%bc%ec%8a%a4%ed%8a%b8%eb%9f%ad%ec%b2%98-%ec%9e%90%eb%8f%99%ed%99%94-iac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>클라우드 환경 구축 과정에서 인프라스트럭처 자동화(IaC)를 위해 Terraform을 도입했습니다. 다음과 같은 주요 리소스를 코드로 관리했습니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-hcl" data-lang="hcl">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># EC2 인스턴스 생성
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">resource&lt;/span> &lt;span class="s2">&amp;#34;aws_instance&amp;#34; &amp;#34;web_server&amp;#34;&lt;/span> {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> ami&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">data&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">aws_ami&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">ubuntu&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">id&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> instance_type&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">var&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">ec2_instance_type&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> subnet_id&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">aws_subnet&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">public&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">id&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> vpc_security_group_ids&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="k">aws_security_group&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">ec2_sg&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">id&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> key_name&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">aws_key_pair&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">web_server_key_pair&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">key_name&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> iam_instance_profile&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">aws_iam_instance_profile&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">ec2_profile&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">name&lt;/span>&lt;span class="c1">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"> # 인스턴스 초기화 스크립트
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="n"> user_data&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">file&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;${path.module}/server_default_setting_example.sh&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="c1">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"> # 루트 볼륨 설정
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">root_block_device&lt;/span> {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> volume_type&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s2">&amp;#34;gp3&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> volume_size&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="m">50&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> delete_on_termination&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="kt">true&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> }
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">}&lt;span class="c1">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># RDS 인스턴스 생성 (MariaDB)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">resource&lt;/span> &lt;span class="s2">&amp;#34;aws_db_instance&amp;#34; &amp;#34;database&amp;#34;&lt;/span> {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> identifier&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s2">&amp;#34;example-database&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> engine&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s2">&amp;#34;mariadb&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> engine_version&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s2">&amp;#34;10.6&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> instance_class&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">var&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">rds_instance_type&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> allocated_storage&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="m">200&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> storage_type&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s2">&amp;#34;gp3&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> username&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">var&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">rds_username&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> password&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">var&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">rds_password&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> db_subnet_group_name&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">aws_db_subnet_group&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">rds&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">name&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> vpc_security_group_ids&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="k">aws_security_group&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">rds_sg&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">id&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> parameter_group_name&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s2">&amp;#34;default.mariadb10.6&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> publicly_accessible&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="kt">true&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> skip_final_snapshot&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="kt">true&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> multi_az&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="kt">false&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n"> backup_retention_period&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="m">7&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">}&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>Terraform을 사용함으로써 얻은 이점.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>인프라 코드화&lt;/strong>: 모든 인프라 구성을 코드로 관리하여 버전 관리 및 변경 추적 용이&lt;/li>
&lt;li>&lt;strong>재현성&lt;/strong>: 동일한 환경을 필요시 언제든지 재생성 가능&lt;/li>
&lt;li>&lt;strong>문서화&lt;/strong>: 코드 자체가 인프라 구성에 대한 문서 역할&lt;/li>
&lt;li>&lt;strong>자동화&lt;/strong>: 수동 작업 최소화로 인적 오류 감소&lt;/li>
&lt;/ol>
&lt;h2>마이그레이션 실행 과정&lt;span class="hx:absolute hx:-mt-20" id="마이그레이션-실행-과정">&lt;/span>
&lt;a href="#%eb%a7%88%ec%9d%b4%ea%b7%b8%eb%a0%88%ec%9d%b4%ec%85%98-%ec%8b%a4%ed%96%89-%ea%b3%bc%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>실제 마이그레이션은 다음과 같은 단계로 진행했습니다.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>사전 준비&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Terraform 코드 작성 및 테스트&lt;/li>
&lt;li>CDC 구성 및 동기화 테스트&lt;/li>
&lt;li>롤백 시나리오 검증&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>클라우드 환경 구축&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Terraform을 통한 AWS 인프라 프로비저닝&lt;/li>
&lt;li>애플리케이션 배포 및 구성&lt;/li>
&lt;li>기능 테스트 수행&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>데이터 동기화 시작&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>CDC 활성화&lt;/li>
&lt;li>초기 데이터 동기화 완료 확인&lt;/li>
&lt;li>실시간 복제 상태 모니터링&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>전환 실행&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>저부하 시간대 선택 (새벽)&lt;/li>
&lt;li>DNS 레코드 변경&lt;/li>
&lt;li>양쪽 환경 모니터링&lt;/li>
&lt;li>트래픽 전환 상황 실시간 추적&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>전환 완료&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>DNS 전파 완료 확인&lt;/li>
&lt;li>애플리케이션 DB 참조를 RDS로 변경&lt;/li>
&lt;li>CDC 중단&lt;/li>
&lt;li>IDC 서버 종료&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;h2>결과&lt;span class="hx:absolute hx:-mt-20" id="결과">&lt;/span>
&lt;a href="#%ea%b2%b0%ea%b3%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>마이그레이션 결과, 다음과 같은 성과를 얻었습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>무중단 전환 달성&lt;/strong>: 사용자 경험 저하 없이 성공적으로 마이그레이션 완료&lt;/li>
&lt;li>&lt;strong>안정성 향상&lt;/strong>: 하드웨어 접촉 불량으로 인한 서버 다운 이슈 해소&lt;/li>
&lt;li>&lt;strong>확장성 확보&lt;/strong>: 클라우드 환경에서 필요에 따른 유연한 스케일링 가능&lt;/li>
&lt;li>&lt;strong>운영 효율화&lt;/strong>: 모든 서버가 클라우드 환경으로 통합되어 관리 효율성 증가&lt;/li>
&lt;/ul>
&lt;p>이번 마이그레이션을 통해 저는 &lt;strong>철저한 계획의 중요성&lt;/strong>을 체감한 것 같습니다. 팀원분들과 함께 협업하여 계획을 구성하면서 문제가 발생할 가능성을 최대한 줄일 수 있었습니다.&lt;/p>
&lt;p>또 Terraform을 통해 인프라 자동화를 구성해보다보니 이제까지 하나하나 직접 구성하던 자신이 바보같이 느껴질 정도로 너무 관리하기 용이했습니다. 또 한 번에 모든 것을 전환하기보다 &lt;strong>단계적 접근이 리스크 감소에 효과적&lt;/strong>이라는 걸 다시금 느끼게 되네요.&lt;/p>
&lt;h2>결론&lt;span class="hx:absolute hx:-mt-20" id="결론">&lt;/span>
&lt;a href="#%ea%b2%b0%eb%a1%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>IDC에서 클라우드로의 마이그레이션은 또 하나의 도전이었지만, 열심히 준비한 계획과 적절한 기술 선택을 통해 성공적으로 완료할 수 있었습니다. 특히 CDC를 활용한 데이터 동기화 전략과 Terraform을 통한 인프라 자동화가 기억에 남네요.&lt;/p>
&lt;p>이런 제 경험이 비슷한 문제를 겪고 계시는 분들께 조금이나마 도움이 됐길 바라며 이만 글을 마치겠습니다. 감사합니다.&lt;/p>
&lt;hr>
&lt;h3>Reference&lt;span class="hx:absolute hx:-mt-20" id="reference">&lt;/span>
&lt;a href="#reference" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://docs.aws.amazon.com/ko_kr/dms/latest/userguide/CHAP_Source.MySQL.html"target="_blank" rel="noopener">https://docs.aws.amazon.com/ko_kr/dms/latest/userguide/CHAP_Source.MySQL.html&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://docs.aws.amazon.com/ko_kr/dms/latest/userguide/Welcome.html"target="_blank" rel="noopener">https://docs.aws.amazon.com/ko_kr/dms/latest/userguide/Welcome.html&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>서비스 장애는 사용자가 알려주지 않아도 알아야한다 - 사내 모니터링 시스템 구축기</title><link>https://jeongil.dev/ko/blog/infrastructure/building-a-monitoring-system/</link><pubDate>Fri, 04 Jul 2025 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/infrastructure/building-a-monitoring-system/</guid><description>
&lt;p>안녕하세요.&lt;/p>
&lt;p>프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 3년차 백엔드 개발자 정정일입니다.&lt;/p>
&lt;p>올해 3월에 팀에 합류한 후, 눈에 띈 것 중 한가지는 팀에서 모니터링 시스템에 개선할만한 부분들이 보였다는 것이었습니다.&lt;/p>
&lt;p>기존에는 AWS CloudWatch를 이용하고 있었지만 효과적으로 활용되지 않고 있다는 점이 존재했습니다.&lt;/p>
&lt;p>특히 장애가 발생하더라도 사용자 문의를 통해서만 문제를 인식할 수 있었고, 문제 발생부터 개발팀의 인식까지 시간이 오래 걸리는 상황이 반복되면서 더 효과적인 모니터링 시스템의 필요성을 절실히 느꼈습니다.&lt;/p>
&lt;p>이 글에서는 제가 왜 새로운 모니터링 시스템이 필요하다고 느꼈는지, 그리고 어떻게 구축했는지 공유하려고 합니다.&lt;/p>
&lt;h2>문제 상황: 사용자가 알려줘야 알 수 있었던 장애&lt;span class="hx:absolute hx:-mt-20" id="문제-상황-사용자가-알려줘야-알-수-있었던-장애">&lt;/span>
&lt;a href="#%eb%ac%b8%ec%a0%9c-%ec%83%81%ed%99%a9-%ec%82%ac%ec%9a%a9%ec%9e%90%ea%b0%80-%ec%95%8c%eb%a0%a4%ec%a4%98%ec%95%bc-%ec%95%8c-%ec%88%98-%ec%9e%88%ec%97%88%eb%8d%98-%ec%9e%a5%ec%95%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>팀에 합류했을 때, 서비스 장애 감지 프로세스는 다음과 같았습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>문제 발생 → 사용자 CS 접수 → 문제 인식 → 원인 파악 → 해결&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 프로세스의 가장 큰 문제점은 &lt;strong>사용자가 불편함을 겪고 직접 CS를 통해 알려줘야만&lt;/strong> 문제를 인식할 수 있다는 점이었습니다. 하지만 실제로 CS로 문의하는 사용자는 전체 문제 경험자의 극히 일부에 불과합니다.&lt;/p>
&lt;p>이와 관련된 부분은 &lt;a href="https://jeongil.dev/ko/blog/culture/naming-convention/">네이밍 컨벤션의 부재는 장애로 이어진다&lt;/a>에서도 한번 다룬 적이 있지만 제가 굉장히 중요하게 생각하는 부분이기 때문에 한번 더 언급하도록 하겠습니다.&lt;/p>
&lt;p>여러분은 흔히 앱을 사용하시다 이상한 문구가 뜨며 내가 원하는 기능이 동작하지 않을 때 어떻게 하시나요? 고객센터로 연락해서 설명하는 경우가 많으신가요? 아니면 &lt;strong>&amp;ldquo;에잇!!&amp;rdquo;&lt;/strong> 하며 앱을 꺼버리는 경우가 많으신가요?&lt;/p>
&lt;p>정말 필요한 기능이거나 많이 화나시지 않는 경우 &lt;strong>대부분 유저분들은 앱을 그냥 꺼버리거나 하는 경우가 많으실 겁니다.&lt;/strong> 이처럼 사용자가 예기치 못한 상황을 맞닥뜨리더라도 회사 내부적으로 파악하기는 모니터링 시스템 없이는 어려울 겁니다.&lt;/p>
&lt;p>이는 &lt;strong>사용자 이탈&lt;/strong>이라는 비즈니스적으로 &lt;strong>치명적인 결과를 야기&lt;/strong>할 수 있기 때문에 &lt;strong>아주 큰 문제&lt;/strong>가 될 수 있습니다.&lt;/p>
&lt;p>유저분들의 대략적인 CS 유입 확률입니다.
이 수치들은 직접적인 통계 자료라기보다는 광범위한 고객 행동 연구를 바탕으로 한 &lt;strong>경험적 추정치&lt;/strong>임을 참고해 주세요.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>요인 (Factor)&lt;/th>
&lt;th>설명 (Explanation)&lt;/th>
&lt;th>추정 유입 확률 (Estimated Inflow Probability)&lt;/th>
&lt;th>주요 출처 및 근거 (Key Sources &amp;amp; Rationale)&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>사용자 이탈 경향&lt;/strong>&lt;/td>
&lt;td>서비스 성능 저하(로딩 지연, 오류) 시 사용자의 인내심이 매우 낮으며, 문제 해결 시도보다 &lt;strong>즉각적인 이탈&lt;/strong>을 선호합니다.&lt;/td>
&lt;td>&lt;strong>5% 미만&lt;/strong>&lt;/td>
&lt;td>&lt;strong>Think with Google:&lt;/strong> 모바일 페이지 로딩 시간이 1초에서 3초로 늘어나면 이탈률이 32% 증가하며, 1초에서 5초로 늘어나면 90% 증가합니다. 이는 사용자가 문제에 직면했을 때 빠르게 이탈하는 경향을 보여줍니다. (&lt;a href="https://www.thinkwithgoogle.com/intl/en-gb/marketing-strategies/app-and-mobile/mobile-page-speed-new-industry-benchmarks/"target="_blank" rel="noopener">Find out how you stack up to new industry benchmarks for mobile page speed&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>불만족 고객의 침묵&lt;/strong>&lt;/td>
&lt;td>불만족한 고객은 불평하기보다 &lt;strong>조용히 서비스를 떠나는 경향&lt;/strong>이 강하며, 고객센터 문의는 추가적인 노력과 시간을 요구합니다.&lt;/td>
&lt;td>&lt;strong>5% ~ 10%&lt;/strong>&lt;/td>
&lt;td>&lt;strong>Qualtrics:&lt;/strong> 고객의 96%는 나쁜 경험을 했을 때 불평하지 않고 단순히 떠난다고 합니다. 이는 장애를 겪은 사용자가 고객센터로 문의하기보다 이탈할 확률이 높다는 것을 시사합니다. (&lt;a href="https://www.qualtrics.com/experience-management/customer/customer-loyalty/"target="_blank" rel="noopener">Customer Loyalty: What it is and how to build it&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>장애의 심각성 및 반복성&lt;/strong>&lt;/td>
&lt;td>치명적이고 반복적인 장애일수록 사용자가 문제 해결을 위해 고객센터에 연락할 가능성이 높아집니다.&lt;/td>
&lt;td>&lt;strong>5% ~ 20% (심각한 경우)&lt;/strong>&lt;/td>
&lt;td>&lt;strong>간접 추정:&lt;/strong> 특정 연구보다는 전반적인 &lt;strong>고객 서비스 및 사용자 경험(UX) 전문가들의 일반적인 견해&lt;/strong>를 바탕으로 합니다. 심각한 금전적 손실이나 서비스 이용 불능 상태는 고객의 문의 유발 가능성을 높입니다.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>고객센터 접근성&lt;/strong>&lt;/td>
&lt;td>문의 채널의 복잡성(ARS, 긴 대기시간)은 사용자에게 또 다른 장벽으로 작용합니다. 반대로, 쉽고 빠른 해결이 가능한 경우 유입이 증가할 수 있습니다.&lt;/td>
&lt;td>&lt;strong>접근성 낮을 시 1% 미만 접근성 높을 시 10% 이상 (최대)&lt;/strong>&lt;/td>
&lt;td>&lt;strong>간접 추정:&lt;/strong> &lt;strong>고객 경험(CX) 및 콜센터 관리 분야의 통계와 원칙&lt;/strong>에 기반합니다. 고객센터 응답 시간, 채널 다양성(챗봇, FAQ, 실시간 채팅 등)이 고객 만족도 및 문의율에 직접적인 영향을 미칩니다. (예: Zendesk, Genesys 등의 고객 서비스 리포트에서 관련 내용 확인 가능)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>사용자 관계/충성도&lt;/strong>&lt;/td>
&lt;td>서비스에 대한 충성도가 높거나, 필수적인 서비스로 인식하는 경우 사용자는 문제를 해결하기 위해 적극적으로 노력할 수 있습니다.&lt;/td>
&lt;td>&lt;strong>10% ~ 25% (충성 고객의 경우)&lt;/strong>&lt;/td>
&lt;td>&lt;strong>간접 추정:&lt;/strong> &lt;strong>고객 관계 관리(CRM) 및 고객 충성도 연구&lt;/strong>에서 나타나는 경향입니다. 충성 고객은 문제 해결에 더 많은 인내심을 보이고, 서비스 개선을 위한 피드백을 제공하려는 의지가 강합니다. (예: Bain &amp;amp; Company의 NPS(Net Promoter Score) 관련 연구 등)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>이처럼 사용자분들이 CS를 통해 유입해주시는 경우는 사용자 경험에 비해 굉장히 드물기 때문에 &lt;strong>저희는 사용자분들이 맞이한 장애를 CS 유입 없이 탐지할 필요가 있다고 생각합니다.&lt;/strong>&lt;/p>
&lt;h2>기존 CloudWatch의 한계와 낮은 활용도&lt;span class="hx:absolute hx:-mt-20" id="기존-cloudwatch의-한계와-낮은-활용도">&lt;/span>
&lt;a href="#%ea%b8%b0%ec%a1%b4-cloudwatch%ec%9d%98-%ed%95%9c%ea%b3%84%ec%99%80-%eb%82%ae%ec%9d%80-%ed%99%9c%ec%9a%a9%eb%8f%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>기존에는 AWS CloudWatch를 사용하고 있었지만, 다음과 같은 한계로 인해 활용도가 낮았습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>비용 효율성 문제&lt;/strong>: CloudWatch는 로그 양이 증가할수록 비용이 급격히 증가하는 구조. 따라서 충분히 탄탄하고 다양한 로그를 쌓기가 부담스러웠습니다.&lt;/li>
&lt;li>&lt;strong>검색 기능의 한계&lt;/strong>: 복잡한 쿼리나 상관관계 분석이 어려움&lt;/li>
&lt;li>&lt;strong>통합 관측성 부재&lt;/strong>: 로그, 메트릭, 트레이스를 통합적으로 보기 어려움&lt;/li>
&lt;li>&lt;strong>알림 시스템 구성의 복잡성&lt;/strong>: 세밀한 알림 규칙 설정이 번거로움&lt;/li>
&lt;li>&lt;strong>커스터마이징 제한&lt;/strong>: 대시보드나 시각화 도구의 유연성 부족&lt;/li>
&lt;/ol>
&lt;p>이러한 한계로 인해 CloudWatch는 주로 기본적인 로그 저장 용도로만 사용되었고, 실질적인 모니터링과 알림 시스템으로는 제대로 기능하지 못했습니다. 이러한 문제를 해결하기 위해, 오픈소스 기반의 새로운 로깅 및 모니터링 시스템을 구축하기로 결정했습니다.&lt;/p>
&lt;h2>새로운 모니터링 시스템 아키텍처&lt;span class="hx:absolute hx:-mt-20" id="새로운-모니터링-시스템-아키텍처">&lt;/span>
&lt;a href="#%ec%83%88%eb%a1%9c%ec%9a%b4-%eb%aa%a8%eb%8b%88%ed%84%b0%eb%a7%81-%ec%8b%9c%ec%8a%a4%ed%85%9c-%ec%95%84%ed%82%a4%ed%85%8d%ec%b2%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>새로운 모니터링 시스템은 다음과 같은 컴포넌트로 구성했습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/c8eb91a8-2c88-4524-bf73-065e5ab1d788/image.png" alt="" loading="lazy" />&lt;/p>
&lt;ul>
&lt;li>&lt;strong>OpenTelemetry&lt;/strong>: 애플리케이션 계측 및 텔레메트리 데이터 수집
&lt;ul>
&lt;li>Java Agent: 애플리케이션 코드 변경 없이 자동 계측&lt;/li>
&lt;li>Collector: 데이터 수집, 처리, 내보내기 담당&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>&lt;strong>Loki&lt;/strong>: 로그 집계 및 저장 (ELK Stack의 Elasticsearch + Logstash 대체)&lt;/li>
&lt;li>&lt;strong>Prometheus&lt;/strong>: 메트릭 수집 및 저장&lt;/li>
&lt;li>&lt;strong>Tempo&lt;/strong>: 분산 트레이싱 (APM)&lt;/li>
&lt;li>&lt;strong>Grafana&lt;/strong>: 통합 대시보드 및 알림 시스템&lt;/li>
&lt;/ul>
&lt;p>처음에 시스템 구축 과정에서 ELK Stack와 Loki, Grafana, Tempo, Prometheus 스택 사이에 고민을 많이 했습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/3be5a62d-1a12-4d68-9359-d8d9e5cefc3a/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>팀 내에서 회의도 여러 차례 진행하며 논의도 많이 진행했습니다.&lt;/p>
&lt;p>이 스택을 선택한 주요 이유는 다음과 같습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>비용 효율성&lt;/strong>: ELK Stack에 비해 Loki는 인덱싱 방식이 다르고 리소스 사용량이 적어 비용 효율적&lt;/li>
&lt;li>&lt;strong>통합 관측성&lt;/strong>: Grafana를 통해 로그(Loki), 메트릭(Prometheus), 트레이스(Tempo)를 한 곳에서 확인 가능&lt;/li>
&lt;li>&lt;strong>확장성&lt;/strong>: 쿠버네티스 환경에 최적화된 구성으로 서비스 확장에 유연하게 대응&lt;/li>
&lt;li>&lt;strong>커뮤니티 지원&lt;/strong>: 활발한 오픈소스 커뮤니티와 풍부한 레퍼런스&lt;/li>
&lt;/ol>
&lt;p>등등의 이유가 있는데 솔직하게 말씀드리면 Loki, Grafana, Tempo, Prometheus 스택으로 선택한 &lt;strong>가장 큰 이유는 비용 문제&lt;/strong>였습니다.&lt;/p>
&lt;p>아무래도 ELK Stack에 비해 가볍다 보니 Cloud에서 운영한다고 했었을 때 ELK Stack에 비해 스펙을 더 낮게 측정하고 운영이 가능했고 저희 회사가 &lt;strong>자금에 여유가 있는 상태는 아니었기 때문에 비용적으로 더 유리한 스택을 고른 것입니다.&lt;/strong>&lt;/p>
&lt;h3>ELK Stack vs Grafana + Loki 비용 예상 비교표&lt;span class="hx:absolute hx:-mt-20" id="elk-stack-vs-grafana--loki-비용-예상-비교표">&lt;/span>
&lt;a href="#elk-stack-vs-grafana--loki-%eb%b9%84%ec%9a%a9-%ec%98%88%ec%83%81-%eb%b9%84%ea%b5%90%ed%91%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>항목&lt;/th>
&lt;th>구성 요소&lt;/th>
&lt;th>최소 사양&lt;/th>
&lt;th>권장 사양&lt;/th>
&lt;th>EC2 인스턴스 유형 (서울)&lt;/th>
&lt;th>시간당 요금 (USD)&lt;/th>
&lt;th>월 예상 요금 (24h × 30일)&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>ELK Stack&lt;/td>
&lt;td>Elasticsearch, Logstash, Kibana&lt;/td>
&lt;td>8GB RAM, 2 vCPU&lt;/td>
&lt;td>16GB RAM, 4 vCPU&lt;/td>
&lt;td>t3.large / m5.xlarge&lt;/td>
&lt;td>$0.129 / $0.279&lt;/td>
&lt;td>$92.88 / $200.88&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Grafana + Loki&lt;/td>
&lt;td>Grafana, Loki&lt;/td>
&lt;td>1GB RAM, 1~2 vCPU&lt;/td>
&lt;td>2~4GB RAM, 2 vCPU&lt;/td>
&lt;td>t3.micro / t3.medium&lt;/td>
&lt;td>$0.017 / $0.052&lt;/td>
&lt;td>$12.24 / $37.44&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>실제로 저는 이전 사이드 프로젝트에서 t3a.small 인스턴스로도 Loki, Promtail, Grafana 스택을 무리 없이 운영한 경험이 있었습니다.&lt;/p>
&lt;h2>OpenTelemetry 적용하기: 단계별 진화&lt;span class="hx:absolute hx:-mt-20" id="opentelemetry-적용하기-단계별-진화">&lt;/span>
&lt;a href="#opentelemetry-%ec%a0%81%ec%9a%a9%ed%95%98%ea%b8%b0-%eb%8b%a8%ea%b3%84%eb%b3%84-%ec%a7%84%ed%99%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>모니터링 시스템 구축은 한 번에 완성된 것이 아니라, 점진적으로 개선해나간 과정이었습니다.&lt;/p>
&lt;h3>1단계: 각 서비스에 직접 OpenTelemetry Endpoint 설정&lt;span class="hx:absolute hx:-mt-20" id="1단계-각-서비스에-직접-opentelemetry-endpoint-설정">&lt;/span>
&lt;a href="#1%eb%8b%a8%ea%b3%84-%ea%b0%81-%ec%84%9c%eb%b9%84%ec%8a%a4%ec%97%90-%ec%a7%81%ec%a0%91-opentelemetry-endpoint-%ec%84%a4%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>처음에는 기존 EC2 환경에서 빠르게 적용하기 위해, &lt;strong>각 서비스마다 OpenTelemetry Collector endpoint를 직접 설정&lt;/strong>하는 방식으로 시작했습니다.&lt;/p>
&lt;p>&lt;strong>장점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>빠른 적용: 기존 인프라 변경 없이 설정만으로 적용 가능&lt;/li>
&lt;li>간단한 구조: 별도의 복잡한 설정 없이 endpoint만 설정&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>단점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>관리 포인트 증가: 각 서비스마다 개별 설정 필요&lt;/li>
&lt;li>일관성 유지 어려움: 서비스마다 설정이 달라질 수 있음&lt;/li>
&lt;li>업데이트 번거로움: OpenTelemetry 설정 변경 시 모든 서비스 개별 수정 필요&lt;/li>
&lt;/ul>
&lt;p>실제 적용 예시 (application.yml):&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># 각 서비스의 application.yml에 직접 설정&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">otel&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">exporter&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">otlp&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">endpoint&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">http://otel-collector:4317&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>각 서비스의 의존성에 OpenTelemetry Java Agent를 추가했습니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-gradle" data-lang="gradle">&lt;span class="line">&lt;span class="cl">&lt;span class="n">dependencies&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">implementation&lt;/span> &lt;span class="s1">&amp;#39;io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter:1.32.0-alpha&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">implementation&lt;/span> &lt;span class="s1">&amp;#39;io.opentelemetry:opentelemetry-exporter-otlp:1.32.0&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 방식으로 약 2개월간 운영하면서, 모니터링 시스템의 효과를 확인할 수 있었습니다. 하지만 서비스가 늘어나면서 관리의 어려움도 점점 커졌습니다.&lt;/p>
&lt;p>otel 버전을 업해야하거나 공통적인 설정을 변경해줘야한다면 모든 서비스에 직접 하나하나 적용을 해줘야 했으니까요.&lt;/p>
&lt;h3>2단계: 쿠버네티스 도입과 사이드카 패턴으로 전환&lt;span class="hx:absolute hx:-mt-20" id="2단계-쿠버네티스-도입과-사이드카-패턴으로-전환">&lt;/span>
&lt;a href="#2%eb%8b%a8%ea%b3%84-%ec%bf%a0%eb%b2%84%eb%84%a4%ed%8b%b0%ec%8a%a4-%eb%8f%84%ec%9e%85%ea%b3%bc-%ec%82%ac%ec%9d%b4%eb%93%9c%ec%b9%b4-%ed%8c%a8%ed%84%b4%ec%9c%bc%eb%a1%9c-%ec%a0%84%ed%99%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>6월부터 쿠버네티스 환경으로 점진적으로 이관하면서, OpenTelemetry Collector를 &lt;strong>사이드카 패턴&lt;/strong>으로 구현했습니다.&lt;/p>
&lt;p>&lt;strong>사이드카 패턴의 장점:&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>&lt;strong>애플리케이션 코드 변경 최소화&lt;/strong>: 기존 서비스 코드를 크게 수정하지 않고도 텔레메트리 데이터 수집 가능&lt;/li>
&lt;li>&lt;strong>일관된 데이터 수집&lt;/strong>: 모든 서비스에 동일한 방식으로 적용 가능&lt;/li>
&lt;li>&lt;strong>독립적인 업데이트&lt;/strong>: 애플리케이션과 모니터링 시스템을 독립적으로 업데이트 가능&lt;/li>
&lt;li>&lt;strong>중앙 관리&lt;/strong>: ConfigMap으로 설정을 중앙에서 관리&lt;/li>
&lt;/ol>
&lt;p>실제 구현은 다음과 같이 진행했습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>OpenTelemetry Java Agent 적용&lt;/strong>: Init Container로 Agent 다운로드&lt;/li>
&lt;li>&lt;strong>사이드카 컨테이너 구성&lt;/strong>: 각 서비스 Pod에 OpenTelemetry Collector 사이드카 컨테이너 추가&lt;/li>
&lt;li>&lt;strong>파이프라인 설정&lt;/strong>: 로그, 메트릭, 트레이스 데이터를 각각 Loki, Prometheus, Tempo로 전송하도록 설정&lt;/li>
&lt;/ol>
&lt;p>아래는 실제 이벤트 서비스의 배포 설정 일부입니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;span class="lnt">45
&lt;/span>&lt;span class="lnt">46
&lt;/span>&lt;span class="lnt">47
&lt;/span>&lt;span class="lnt">48
&lt;/span>&lt;span class="lnt">49
&lt;/span>&lt;span class="lnt">50
&lt;/span>&lt;span class="lnt">51
&lt;/span>&lt;span class="lnt">52
&lt;/span>&lt;span class="lnt">53
&lt;/span>&lt;span class="lnt">54
&lt;/span>&lt;span class="lnt">55
&lt;/span>&lt;span class="lnt">56
&lt;/span>&lt;span class="lnt">57
&lt;/span>&lt;span class="lnt">58
&lt;/span>&lt;span class="lnt">59
&lt;/span>&lt;span class="lnt">60
&lt;/span>&lt;span class="lnt">61
&lt;/span>&lt;span class="lnt">62
&lt;/span>&lt;span class="lnt">63
&lt;/span>&lt;span class="lnt">64
&lt;/span>&lt;span class="lnt">65
&lt;/span>&lt;span class="lnt">66
&lt;/span>&lt;span class="lnt">67
&lt;/span>&lt;span class="lnt">68
&lt;/span>&lt;span class="lnt">69
&lt;/span>&lt;span class="lnt">70
&lt;/span>&lt;span class="lnt">71
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># 초기화 컨테이너로 OpenTelemetry Java Agent 다운로드&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">initContainers&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel-agent-downloader&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">image&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">curlimages/curl:8.7.1&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">command&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">sh&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- -&lt;span class="l">c&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">curl -sSL -o /otel/opentelemetry-javaagent.jar https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.14.0/opentelemetry-javaagent.jar&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">volumeMounts&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel-agent&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">mountPath&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">/otel&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c"># 메인 애플리케이션 컨테이너&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">containers&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">event-service&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">image&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">asia-northeast3-docker.pkg.dev/btalk-dev/bootalk-dev/event-service:latest&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">env&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">SPRING_APPLICATION_JSON&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">value&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;{ &amp;#34;server.port&amp;#34;: 8080, &amp;#34;spring.profiles.active&amp;#34;: &amp;#34;dev&amp;#34; }&amp;#39;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">OTEL_EXPORTER_OTLP_ENDPOINT&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">value&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">http://localhost:4317 &lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># 같은 Pod 내 사이드카로 전송&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">OTEL_SERVICE_NAME&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">value&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">event-service&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">OTEL_RESOURCE_ATTRIBUTES&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">value&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">deployment.environment=dev&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">JAVA_TOOL_OPTIONS&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">value&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">&amp;gt;-&lt;/span>&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> -javaagent:/otel/opentelemetry-javaagent.jar
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> -Dotel.javaagent.enabled=true
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> -Dotel.metrics.exporter=otlp
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> -Dotel.traces.exporter=otlp
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> -Dotel.logs.exporter=otlp
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> -Dotel.exporter.otlp.endpoint=http://localhost:4317
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> -Dotel.exporter.otlp.protocol=grpc&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">volumeMounts&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel-agent&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">mountPath&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">/otel&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">ports&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">containerPort&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">8080&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">resources&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">requests&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">cpu&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">200m&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">memory&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">300Mi&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">limits&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">cpu&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">400m&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">memory&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">600Mi&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c"># OpenTelemetry Collector 사이드카 컨테이너&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel-collector&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">image&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel/opentelemetry-collector-contrib:0.98.0&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">args&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="s2">&amp;#34;--config=/etc/otel/config.yaml&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">ports&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">containerPort&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">4317&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c"># gRPC&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">resources&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">requests&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">cpu&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">50m&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">memory&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">64Mi&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">limits&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">cpu&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">100m&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">memory&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">128Mi&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">volumeMounts&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel-config&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">mountPath&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">/etc/otel&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">volumes&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel-agent&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">emptyDir&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>{}&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel-config&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">configMap&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel-collector-config&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>OpenTelemetry Collector 설정은 ConfigMap으로 중앙에서 관리합니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;span class="lnt">45
&lt;/span>&lt;span class="lnt">46
&lt;/span>&lt;span class="lnt">47
&lt;/span>&lt;span class="lnt">48
&lt;/span>&lt;span class="lnt">49
&lt;/span>&lt;span class="lnt">50
&lt;/span>&lt;span class="lnt">51
&lt;/span>&lt;span class="lnt">52
&lt;/span>&lt;span class="lnt">53
&lt;/span>&lt;span class="lnt">54
&lt;/span>&lt;span class="lnt">55
&lt;/span>&lt;span class="lnt">56
&lt;/span>&lt;span class="lnt">57
&lt;/span>&lt;span class="lnt">58
&lt;/span>&lt;span class="lnt">59
&lt;/span>&lt;span class="lnt">60
&lt;/span>&lt;span class="lnt">61
&lt;/span>&lt;span class="lnt">62
&lt;/span>&lt;span class="lnt">63
&lt;/span>&lt;span class="lnt">64
&lt;/span>&lt;span class="lnt">65
&lt;/span>&lt;span class="lnt">66
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">apiVersion&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">v1&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">kind&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">ConfigMap&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">metadata&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">otel-collector-config&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">namespace&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">default&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">data&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">config.yaml&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">|&lt;/span>&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> receivers:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> otlp:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> protocols:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> grpc:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> endpoint: 0.0.0.0:4317
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> http:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> endpoint: 0.0.0.0:4318
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> processors:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> batch:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> timeout: 1s
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> send_batch_size: 1024
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> attributes:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> actions:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> - key: &amp;#34;trace_id&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> from_context: &amp;#34;trace_id&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> action: &amp;#34;insert&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> resource:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> attributes:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> - key: cluster
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> value: btalk-dev
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> action: upsert
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> exporters:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> # Tempo로 트레이스 전송
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> otlp/tempo:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> endpoint: &amp;#34;http://tempo-dev-svc.monitoring.svc.cluster.local:4317&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> tls:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> insecure: true
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> # Prometheus로 메트릭 전송
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> prometheus:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> endpoint: &amp;#34;0.0.0.0:9090&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> namespace: &amp;#34;app&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> # Loki로 로그 전송
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> loki:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> endpoint: &amp;#34;http://loki-dev-svc.monitoring.svc.cluster.local:3100/loki/api/v1/push&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> headers:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> &amp;#34;X-Scope-OrgID&amp;#34;: &amp;#34;dev&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> # 디버깅용
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> logging:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> loglevel: info
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> service:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> pipelines:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> traces:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> receivers: [otlp]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> processors: [resource, batch]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> exporters: [otlp/tempo, logging]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> metrics:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> receivers: [otlp]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> processors: [resource, batch]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> exporters: [prometheus, logging]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> logs:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> receivers: [otlp]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> processors: [resource, batch, attributes]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sd"> exporters: [loki, logging]&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>두 방식의 비교&lt;span class="hx:absolute hx:-mt-20" id="두-방식의-비교">&lt;/span>
&lt;a href="#%eb%91%90-%eb%b0%a9%ec%8b%9d%ec%9d%98-%eb%b9%84%ea%b5%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>구분&lt;/th>
&lt;th>직접 Endpoint 설정&lt;/th>
&lt;th>사이드카 패턴&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>적용 환경&lt;/strong>&lt;/td>
&lt;td>EC2, VM&lt;/td>
&lt;td>Kubernetes&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>설정 위치&lt;/strong>&lt;/td>
&lt;td>각 서비스 내부&lt;/td>
&lt;td>ConfigMap (중앙 관리)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>관리 복잡도&lt;/strong>&lt;/td>
&lt;td>높음 (개별 관리)&lt;/td>
&lt;td>낮음 (중앙 관리)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>일관성&lt;/strong>&lt;/td>
&lt;td>보장 어려움&lt;/td>
&lt;td>보장됨&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>업데이트&lt;/strong>&lt;/td>
&lt;td>각 서비스 재배포 필요&lt;/td>
&lt;td>ConfigMap만 수정&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>리소스 사용&lt;/strong>&lt;/td>
&lt;td>약간 적음&lt;/td>
&lt;td>약간 많음 (사이드카 오버헤드)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>적용 속도&lt;/strong>&lt;/td>
&lt;td>빠름&lt;/td>
&lt;td>상대적으로 느림 (K8s 필요)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2>시스템 도입 효과: 장애 감지 프로세스의 변화&lt;span class="hx:absolute hx:-mt-20" id="시스템-도입-효과-장애-감지-프로세스의-변화">&lt;/span>
&lt;a href="#%ec%8b%9c%ec%8a%a4%ed%85%9c-%eb%8f%84%ec%9e%85-%ed%9a%a8%ea%b3%bc-%ec%9e%a5%ec%95%a0-%ea%b0%90%ec%a7%80-%ed%94%84%eb%a1%9c%ec%84%b8%ec%8a%a4%ec%9d%98-%eb%b3%80%ed%99%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>새로운 모니터링 시스템 도입 후, 장애 감지 프로세스가 다음과 같이 변화했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>문제 발생 → 알림 수신 → 문제 인식 → 원인 파악 → 해결&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이제는 사용자가 CS로 문의하기 전에 개발팀이 먼저 문제를 인지하고 대응할 수 있게 되었습니다. 특히 다음과 같은 효과가 있었습니다:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>장애 감지 시간 단축&lt;/strong>: 평균 감지 시간이 수 시간에서 수 분으로 단축&lt;/li>
&lt;li>&lt;strong>선제적 대응 가능&lt;/strong>: 사용자 영향이 커지기 전에 문제 해결 가능&lt;/li>
&lt;li>&lt;strong>정확한 원인 파악&lt;/strong>: 로그, 메트릭, 트레이스를 통합적으로 분석하여 정확한 원인 파악 가능&lt;/li>
&lt;li>&lt;strong>반복적인 문제 예방&lt;/strong>: 패턴 분석을 통한 사전 예방 조치 가능&lt;/li>
&lt;/ol>
&lt;h2>실제 사례: 모니터링 시스템의 효과&lt;span class="hx:absolute hx:-mt-20" id="실제-사례-모니터링-시스템의-효과">&lt;/span>
&lt;a href="#%ec%8b%a4%ec%a0%9c-%ec%82%ac%eb%a1%80-%eb%aa%a8%eb%8b%88%ed%84%b0%eb%a7%81-%ec%8b%9c%ec%8a%a4%ed%85%9c%ec%9d%98-%ed%9a%a8%ea%b3%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>모니터링 시스템 구축 후, 저희는 이전에는 발견하지 못했던 여러 문제들을 발견하고 해결할 수 있었습니다. 그중 대표적인 사례가 &amp;lsquo;월세&amp;rsquo; 검색 기능에서 발생한 예외였습니다.&lt;/p>
&lt;p>이 문제는 네이밍 컨벤션 불일치로 인한 것이었는데, 서비스 A에서는 월세를 &amp;lsquo;monthly&amp;rsquo;로, 서비스 B와 연결된 데이터베이스에서는 &amp;lsquo;rent&amp;rsquo;로 정의하고 있었습니다. 문제는 단순한 네이밍 불일치에 그치지 않았습니다. 데이터베이스 프로시저의 파라미터 중 &amp;lsquo;거래 유형&amp;rsquo; 필드는 문자열 길이가 제한되어 있었고(VARCHAR(5)), &amp;lsquo;monthly&amp;rsquo;(7자)는 이 제한을 초과하여 예외가 발생했던 것입니다. &lt;a href="https://jeongil.dev/ko/blog/culture/naming-convention/">(해당 케이스 관련 글 - 네이밍 컨벤션의 부재는 장애로 이어진다.)&lt;/a>&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/05ae0054-9512-41ed-b8e8-a06aca12b733/image.png" alt="예외 로그" loading="lazy" />&lt;/p>
&lt;p>이 문제는 사용 빈도가 낮은 기능이었기 때문에 오랫동안 발견되지 않았습니다. 기존 시스템에서는 사용자가 CS로 문의해야만 알 수 있었던 문제였지만, 새로운 모니터링 시스템 덕분에 실시간으로 감지하여 사용자 신고 없이도 빠르게 해결할 수 있었습니다.&lt;/p>
&lt;p>이처럼 모니터링 시스템은 사용자가 불편함을 겪기 전에, 또는 사용자가 불편함을 겪더라도 CS로 문의하지 않아 개발팀이 인지하지 못했던 문제들을 발견하고 해결할 수 있게 해주었습니다.&lt;/p>
&lt;h3>알림 시스템 구성&lt;span class="hx:absolute hx:-mt-20" id="알림-시스템-구성">&lt;/span>
&lt;a href="#%ec%95%8c%eb%a6%bc-%ec%8b%9c%ec%8a%a4%ed%85%9c-%ea%b5%ac%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Grafana의 알림 기능을 활용하여 다음과 같은 알림 규칙을 설정했습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/ab9019c5-c26f-428f-ad96-cb9e1120d480/image.png" alt="" loading="lazy" />&lt;/p>
&lt;ol>
&lt;li>&lt;strong>서비스 다운 알림&lt;/strong>: 인스턴스 중 하나라도 다운되면 알림 발송&lt;/li>
&lt;li>&lt;strong>에러 로그 알림&lt;/strong>: ERROR 레벨 로그 발생 시 알림 발송&lt;/li>
&lt;li>&lt;strong>높은 지연시간 알림&lt;/strong>: API 응답 시간이 임계값을 초과할 경우 알림 발송&lt;/li>
&lt;li>&lt;strong>리소스 사용량 알림&lt;/strong>: CPU, 메모리 사용량이 임계값을 초과할 경우 알림 발송&lt;/li>
&lt;/ol>
&lt;p>알림은 Telegram을 통해 실시간으로 전송되며, 각 알림에는 문제 해결을 위한 Runbook 링크가 포함되어 있어 빠른 대응이 가능합니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/7af340cc-092c-411e-84c5-c9e605ba35e4/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/bc3f3faf-69ca-4d0e-b7d6-5a23e6020354/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>위 이미지는 실제 운영 중인 시스템에서 발생한 알림의 예시입니다. 알림 메시지에는 다음과 같은 정보가 포함됩니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>알림 유형&lt;/strong>: &amp;lsquo;Firing&amp;rsquo;(문제 발생) 또는 &amp;lsquo;Resolved&amp;rsquo;(문제 해결)&lt;/li>
&lt;li>&lt;strong>알림 이름&lt;/strong>: &amp;lsquo;Service Down Report&amp;rsquo;(서비스 다운) 또는 &amp;lsquo;Bug Report&amp;rsquo;(에러 로그)&lt;/li>
&lt;li>&lt;strong>서비스 정보&lt;/strong>: 어떤 서비스에서 문제가 발생했는지 표시&lt;/li>
&lt;li>&lt;strong>Runbook 링크&lt;/strong>: 문제 해결을 위한 가이드 및 문제 탐색 링크&lt;/li>
&lt;/ul>
&lt;p>이러한 상세한 정보 덕분에 개발팀은 문제 상황을 빠르게 파악하고 적절히 대응할 수 있게 되었습니다.&lt;/p>
&lt;h3>트레이스와 APM을 통한 성능 개선&lt;span class="hx:absolute hx:-mt-20" id="트레이스와-apm을-통한-성능-개선">&lt;/span>
&lt;a href="#%ed%8a%b8%eb%a0%88%ec%9d%b4%ec%8a%a4%ec%99%80-apm%ec%9d%84-%ed%86%b5%ed%95%9c-%ec%84%b1%eb%8a%a5-%ea%b0%9c%ec%84%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/6a700eee-d91b-4965-be2e-6aedee781df4/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>Prometheus의 메트릭을 분석하여 개선이 필요한 API를 먼저 특정하고&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/a05fd553-721d-4cf4-ae10-724d178c56b6/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>APM인 Tempo를 통해 요청별로 병목지점을 파악할 수 있기 때문에 응답 속도 개선이 필요한 부분을 빠르게 특정 할 수 있게 됐습니다.&lt;/p>
&lt;h2>회고: 점진적 개선의 중요성&lt;span class="hx:absolute hx:-mt-20" id="회고-점진적-개선의-중요성">&lt;/span>
&lt;a href="#%ed%9a%8c%ea%b3%a0-%ec%a0%90%ec%a7%84%ec%a0%81-%ea%b0%9c%ec%84%a0%ec%9d%98-%ec%a4%91%ec%9a%94%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>모니터링 시스템 구축을 돌이켜보면, &lt;strong>완벽한 시스템을 한 번에 만들려고 하지 않은 것&lt;/strong>이 성공의 핵심이었던 것 같습니다.&lt;/p>
&lt;p>&lt;strong>1단계 (4월)&lt;/strong>: 빠르게 적용 가능한 방식으로 시작&lt;/p>
&lt;ul>
&lt;li>각 서비스에 직접 endpoint 설정&lt;/li>
&lt;li>빠르게 효과 확인&lt;/li>
&lt;li>문제점 파악&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>2단계 (6월~)&lt;/strong>: 개선된 아키텍처로 전환&lt;/p>
&lt;ul>
&lt;li>쿠버네티스 도입과 함께 사이드카 패턴 적용&lt;/li>
&lt;li>중앙 관리로 운영 효율성 향상&lt;/li>
&lt;li>확장성 확보&lt;/li>
&lt;/ul>
&lt;p>만약 처음부터 &amp;ldquo;완벽한&amp;rdquo; 쿠버네티스 + 사이드카 구조를 만들려고 했다면, 시간이 훨씬 오래 걸렸을 것이고 그 사이에 더 많은 장애를 놓쳤을 것입니다.&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;빠르게 시작하고, 점진적으로 개선하라&amp;rdquo;&lt;/strong> 는 교훈을 얻을 수 있었습니다.&lt;/p>
&lt;h2>결론&lt;span class="hx:absolute hx:-mt-20" id="결론">&lt;/span>
&lt;a href="#%ea%b2%b0%eb%a1%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>모니터링 시스템 구축을 통해 저희 팀은 서비스 안정성과 사용자 경험을 크게 향상시킬 수 있었습니다. 특히 사용자가 불편함을 겪고 문의하기 전에 문제를 감지하고 해결하여 서비스의 사용자 이탈이라는 크리티컬한 문제의 가능성을 낮췄다는 점에서 가장 큰 성과라고 생각합니다.&lt;/p>
&lt;p>모니터링 시스템은 단순히 기술적인 도구가 아니라, 서비스의 품질과 사용자 경험을 향상시키는 중요한 인프라라고 생각합니다. 특히 마이크로서비스 아키텍처에서는 통합된 관측성이 더욱 중요하다고 생각합니다.&lt;/p>
&lt;p>혹시 마찬가지로 모니터링, 예외 알림 시스템이 구축되어있지 않으셨거나 관련된 내용을 찾고 계셨던 분들께 조금이나마 도움이 됐길 바라며 이만 글을 마치겠습니다. 감사합니다!&lt;/p></description></item><item><title>네이밍 컨벤션의 부재는 장애로 이어진다.</title><link>https://jeongil.dev/ko/blog/culture/naming-convention/</link><pubDate>Mon, 30 Jun 2025 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/culture/naming-convention/</guid><description>
&lt;p>안녕하세요
저는 프롭테크 플랫폼에서 백엔드 개발자로 근무 중인 3년차 백엔드 개발자 정정일입니다.&lt;/p>
&lt;p>오늘은 소프트웨어 개발에서 중요한 것은 알지만 중요성에 비해 리소스 투자를 간과하기 쉬운 &lt;strong>네이밍 컨벤션의 중요성&lt;/strong>에 대해 이야기해보려 합니다.&lt;/p>
&lt;p>최근 저희 팀에서 실제로 겪었던 문제를 통해, 일관되지 않은 네이밍이 어떻게 시스템 안정성을 위협할 수 있는지 공유드리고자 합니다.&lt;/p>
&lt;hr>
&lt;h3>월세 검색 기능 오류&lt;span class="hx:absolute hx:-mt-20" id="월세-검색-기능-오류">&lt;/span>
&lt;a href="#%ec%9b%94%ec%84%b8-%ea%b2%80%ec%83%89-%ea%b8%b0%eb%8a%a5-%ec%98%a4%eb%a5%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>최근 저희 서비스의 특정 기능에서, &lt;strong>월세 키워드로 검색할 때 시스템 예외가 발생하는 문제&lt;/strong>가 있었습니다. 사용자 입장에서는 정상적인 검색 결과를 기대했지만, 특정 조건에서 시스템이 예외를 던지며 실패했던 것입니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/05ae0054-9512-41ed-b8e8-a06aca12b733/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>이 문제는 겉으로는 드러나지 않았지만, 제가 올해 3월 팀에 합류한 이후 시스템 전반을 점검하는 과정에서 우연히 발견하게 되었습니다.&lt;/p>
&lt;p>해당 기능의 동작 구조는 다음과 같습니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>클라이언트(웹) 요청 -&amp;gt; 서비스 A 클라이언트 반환 → 클라이언트(웹) A의 응답 값으로 요청 → 서비스 B → DB 프로시저를 통한 조회&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>문제는 이 데이터 흐름에서, 각 컴포넌트가 &amp;lsquo;월세&amp;rsquo;라는 개념을 다르게 정의하고 있었기 때문에 발생했습니다.&lt;/p>
&lt;hr>
&lt;h3>문제의 근본 원인: ‘월세’ 네이밍 불일치&lt;span class="hx:absolute hx:-mt-20" id="문제의-근본-원인-월세-네이밍-불일치">&lt;/span>
&lt;a href="#%eb%ac%b8%ec%a0%9c%ec%9d%98-%ea%b7%bc%eb%b3%b8-%ec%9b%90%ec%9d%b8-%ec%9b%94%ec%84%b8-%eb%84%a4%ec%9d%b4%eb%b0%8d-%eb%b6%88%ec%9d%bc%ec%b9%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>분석 결과, &lt;strong>‘월세’를 지칭하는 네이밍이 시스템 내에서 통일되어 있지 않았던 것&lt;/strong>이 예외 발생의 핵심 원인이었습니다.&lt;/p>
&lt;p>저희는 마이크로서비스 아키텍처(MSA)를 기반으로 서비스가 구성되어 있으며, 각 서비스는 독립적으로 운영되지만 상호 연동은 필수적입니다. 이런 환경에서 &lt;strong>공통 개념에 대한 명확한 약속이 없을 경우, 사소한 문자열 하나가 치명적인 오류를 일으킬 수 있습니다.&lt;/strong>&lt;/p>
&lt;p>예를 들어 &lt;code>서비스 A&lt;/code>에서는 월세를 다음과 같이 &lt;code>monthly&lt;/code>로 반환하고 있었습니다:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="k">val&lt;/span> &lt;span class="py">dealType&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="k">when&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="c1">// 실제로는 Enum 클래스입니다. 설명을 위해 간략화 했습니다.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="n">dto&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">isDeal&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="s2">&amp;#34;deal&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">dto&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">isLease&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="s2">&amp;#34;lease&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">dto&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">isMonthly&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="s2">&amp;#34;monthly&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">else&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="s2">&amp;#34;none&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>반면, 이 값을 수신하는 &lt;code>서비스 B&lt;/code>와 연결된 데이터베이스에서는 월세를 &lt;strong>&lt;code>rent&lt;/code>&lt;/strong> 로 정의하고 있었습니다. 문제는 단순한 네이밍 불일치에 그치지 않았습니다. &lt;strong>데이터베이스 프로시저의 파라미터 중 ‘거래 유형’ 필드는 문자열 길이가 제한되어 있었고&lt;/strong>(&lt;code>VARCHAR(5)&lt;/code>), &lt;code>monthly&lt;/code>(7자)는 대상에서 초과되어 예외가 발생한 것이었습니다.&lt;/p>
&lt;p>즉, &lt;code>서비스 A&lt;/code> → &lt;code>서비스 B&lt;/code> → DB로 전달되는 과정에서, &lt;strong>DB는 &lt;code>monthly&lt;/code>라는 값을 받아들이지 못해 유효성 예외를 던진 것&lt;/strong>입니다.&lt;/p>
&lt;p>이를 임시로 해결하기 위해 &lt;code>서비스 A&lt;/code>의 코드를 다음과 같이 수정했습니다&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="k">val&lt;/span> &lt;span class="py">dealType&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="k">when&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">dto&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">isDeal&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="s2">&amp;#34;deal&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">dto&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">isLease&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="s2">&amp;#34;lease&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">dto&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">isMonthly&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="s2">&amp;#34;rent&amp;#34;&lt;/span> &lt;span class="c1">// 일시적 대응
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">else&lt;/span> &lt;span class="o">-&amp;gt;&lt;/span> &lt;span class="s2">&amp;#34;none&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>하지만 이는 근본적인 해결책이 아니며, 네이밍 불일치가 또 다른 기능이나 서비스에서 문제를 일으킬 수 있는 &lt;strong>잠재적 위험&lt;/strong>을 그대로 안고 있는 상태였습니다.&lt;/p>
&lt;hr>
&lt;h3>왜 지금까지 문제가 드러나지 않았을까?&lt;span class="hx:absolute hx:-mt-20" id="왜-지금까지-문제가-드러나지-않았을까">&lt;/span>
&lt;a href="#%ec%99%9c-%ec%a7%80%ea%b8%88%ea%b9%8c%ec%a7%80-%eb%ac%b8%ec%a0%9c%ea%b0%80-%eb%93%9c%eb%9f%ac%eb%82%98%ec%a7%80-%ec%95%8a%ec%95%98%ec%9d%84%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이번 문제는 단순한 코드 오류처럼 보이지만, 그동안 왜 이 오류가 &lt;strong>운영 중인 서비스에서 전혀 감지되지 않았는지&lt;/strong>는 중요한 포인트입니다.&lt;/p>
&lt;p>이유는 다음과 같습니다:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>월세 키워드로 요청이 오는 경우 자체가 드문 기능이었기 때문&lt;/strong>입니다. 이 기능은 특정 조건에서만 활성화되며, 사용자도 특정 상황에서만 접근하는 구조여서 발생 빈도가 낮았습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>E2E 테스트의 미비&lt;/strong>. 사실 ISTQB와 같은 테스팅 관련 자격증에서도 완벽한 테스트란 존재하지 않고 &lt;strong>결함이 없는 서비스는 존재하지 않는다&lt;/strong>고 말하고 있습니다.&lt;/p>
&lt;p>그렇기 때문에 꼭 테스트를 탓할 수 는 없지만 저희 팀이 단위 테스트에 좀더 집중한 면이 있었고 이때문에 E2E 테스트 케이스가 미비한 부분들이 있었습니다. &lt;strong>E2E 테스트의 케이스가 좀 더 체계적이고 세밀했다면 사전에 결함을 탐지할 수 있었을 거라 생각합니다&lt;/strong>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>회사에 실시간 예외 감지 시스템이 없었습니다.&lt;/strong> 시스템 내부에서 예외가 발생해도 이를 자동으로 탐지하거나 알림으로 받아볼 수 없었기 때문에, 대부분의 오류는 &lt;strong>사용자가 직접 고객센터에 제보해야만 파악이 가능&lt;/strong>했습니다. 이 부분이 저로써는 굉장히 빠르게 개선해야하는 부분이라는 생각이 들었습니다&lt;/p>
&lt;/li>
&lt;/ol>
&lt;hr>
&lt;h3>유저분들은 장애가 있으면 그냥 떠나버린다.&lt;span class="hx:absolute hx:-mt-20" id="유저분들은-장애가-있으면-그냥-떠나버린다">&lt;/span>
&lt;a href="#%ec%9c%a0%ec%a0%80%eb%b6%84%eb%93%a4%ec%9d%80-%ec%9e%a5%ec%95%a0%ea%b0%80-%ec%9e%88%ec%9c%bc%eb%a9%b4-%ea%b7%b8%eb%83%a5-%eb%96%a0%eb%82%98%eb%b2%84%eb%a6%b0%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>여러분은 흔히 앱을 사용하시다 이상한 문구가 뜨며 내가 원하는 기능이 동작하지 않을때 어떻게 하시나요? 고객센터로 연락해서 설명하는 경우가 많으신가요? 아니면 &lt;strong>&amp;ldquo;에잇!!&amp;rdquo;&lt;/strong> 하며 앱을 꺼버리는 경우가 많으신가요?&lt;/p>
&lt;p>정말 필요한 기능이거나 많이 화나시지 않는 경우 &lt;strong>대부분 유저분들은 앱을 그냥 꺼버리거나 하는 경우가 많으실 겁니다.&lt;/strong> 이처럼 사용자가 예기치 못한 상황을 맞닥드리더라도 회사 내부적으로 파악하기는 모니터링 시스템 없이는 어려울겁니다.&lt;/p>
&lt;p>이는 &lt;strong>사용자 이탈&lt;/strong>이라는 비지니스적으로 &lt;strong>치명적인 결과를 야기&lt;/strong>할 수 있기 때문에 &lt;strong>아주 큰 문제&lt;/strong>가 될 수 있습니다.&lt;/p>
&lt;p>유저분들의 대략적인 CS 유입 확률입니다.
이 수치들은 직접적인 통계 자료라기보다는 광범위한 고객 행동 연구를 바탕으로 한 &lt;strong>경험적 추정치&lt;/strong>임을 참고해 주세요.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>요인 (Factor)&lt;/th>
&lt;th>설명 (Explanation)&lt;/th>
&lt;th>추정 유입 확률 (Estimated Inflow Probability)&lt;/th>
&lt;th>주요 출처 및 근거 (Key Sources &amp;amp; Rationale)&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>사용자 이탈 경향&lt;/strong>&lt;/td>
&lt;td>서비스 성능 저하(로딩 지연, 오류) 시 사용자의 인내심이 매우 낮으며, 문제 해결 시도보다 &lt;strong>즉각적인 이탈&lt;/strong>을 선호합니다.&lt;/td>
&lt;td>&lt;strong>5% 미만&lt;/strong>&lt;/td>
&lt;td>&lt;strong>Think with Google:&lt;/strong> 모바일 페이지 로딩 시간이 1초에서 3초로 늘어나면 이탈률이 32% 증가하며, 1초에서 5초로 늘어나면 90% 증가합니다. 이는 사용자가 문제에 직면했을 때 빠르게 이탈하는 경향을 보여줍니다. (&lt;a href="https://www.thinkwithgoogle.com/intl/en-gb/marketing-strategies/app-and-mobile/mobile-page-speed-new-industry-benchmarks/"target="_blank" rel="noopener">Find out how you stack up to new industry benchmarks for mobile page speed&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>불만족 고객의 침묵&lt;/strong>&lt;/td>
&lt;td>불만족한 고객은 불평하기보다 &lt;strong>조용히 서비스를 떠나는 경향&lt;/strong>이 강하며, 고객센터 문의는 추가적인 노력과 시간을 요구합니다.&lt;/td>
&lt;td>&lt;strong>5% ~ 10%&lt;/strong>&lt;/td>
&lt;td>&lt;strong>Qualtrics:&lt;/strong> 고객의 96%는 나쁜 경험을 했을 때 불평하지 않고 단순히 떠난다고 합니다. 이는 장애를 겪은 사용자가 고객센터로 문의하기보다 이탈할 확률이 높다는 것을 시사합니다. (&lt;a href="https://www.qualtrics.com/experience-management/customer/customer-loyalty/"target="_blank" rel="noopener">Customer Loyalty: What it is and how to build it&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>장애의 심각성 및 반복성&lt;/strong>&lt;/td>
&lt;td>치명적이고 반복적인 장애일수록 사용자가 문제 해결을 위해 고객센터에 연락할 가능성이 높아집니다.&lt;/td>
&lt;td>&lt;strong>5% ~ 20% (심각한 경우)&lt;/strong>&lt;/td>
&lt;td>&lt;strong>간접 추정:&lt;/strong> 특정 연구보다는 전반적인 &lt;strong>고객 서비스 및 사용자 경험(UX) 전문가들의 일반적인 견해&lt;/strong>를 바탕으로 합니다. 심각한 금전적 손실이나 서비스 이용 불능 상태는 고객의 문의 유발 가능성을 높입니다.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>고객센터 접근성&lt;/strong>&lt;/td>
&lt;td>문의 채널의 복잡성(ARS, 긴 대기시간)은 사용자에게 또 다른 장벽으로 작용합니다. 반대로, 쉽고 빠른 해결이 가능한 경우 유입이 증가할 수 있습니다.&lt;/td>
&lt;td>&lt;strong>접근성 낮을 시 1% 미만 접근성 높을 시 10% 이상 (최대)&lt;/strong>&lt;/td>
&lt;td>&lt;strong>간접 추정:&lt;/strong> &lt;strong>고객 경험(CX) 및 콜센터 관리 분야의 통계와 원칙&lt;/strong>에 기반합니다. 고객센터 응답 시간, 채널 다양성(챗봇, FAQ, 실시간 채팅 등)이 고객 만족도 및 문의율에 직접적인 영향을 미칩니다. (예: Zendesk, Genesys 등의 고객 서비스 리포트에서 관련 내용 확인 가능)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>사용자 관계/충성도&lt;/strong>&lt;/td>
&lt;td>서비스에 대한 충성도가 높거나, 필수적인 서비스로 인식하는 경우 사용자는 문제를 해결하기 위해 적극적으로 노력할 수 있습니다.&lt;/td>
&lt;td>&lt;strong>10% ~ 25% (충성 고객의 경우)&lt;/strong>&lt;/td>
&lt;td>&lt;strong>간접 추정:&lt;/strong> &lt;strong>고객 관계 관리(CRM) 및 고객 충성도 연구&lt;/strong>에서 나타나는 경향입니다. 충성 고객은 문제 해결에 더 많은 인내심을 보이고, 서비스 개선을 위한 피드백을 제공하려는 의지가 강합니다. (예: Bain &amp;amp; Company의 NPS(Net Promoter Score) 관련 연구 등)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>이처럼 사용자분들이 CS를 통해 유입해주시는 경우는 사용자 경험에 비해 굉장히 드물기 때문에 &lt;strong>저희는 사용자 분들이 맞이한 장애를 CS유입 없이 탐지할 필요가 있다고 저는 생각합니다.&lt;/strong>&lt;/p>
&lt;p>제가 3월에 합류한 이후, 운영 안정성을 높이기 위한 작업의 일환으로 &lt;strong>Loki, Grafana, Tempo 기반의 관측 및 모니터링 시스템을 구축 하는 티켓을 발행하여 작업을 진행&lt;/strong>했고, 그 과정에서 &lt;strong>예외 알림 시스템도 함께 도입&lt;/strong>했습니다.&lt;/p>
&lt;p>이 과정은 따로 글로 한번 다루도록 하겠습니다.&lt;/p>
&lt;p>이 시스템 덕분에, 비정상 요청에 대한 예외가 실시간 알림으로 도착했고, 그제서야 이 문제가 있다는 것을 팀에서 명확히 인지하게 된 것입니다.&lt;/p>
&lt;p>결국 이 문제는 &lt;strong>낮은 사용 빈도&lt;/strong>와 &lt;strong>관측 도구의 부재&lt;/strong>라는 두 가지 이유로 그동안 수면 위로 드러나지 않았던 것입니다.&lt;/p>
&lt;hr>
&lt;h3>드러나지 않았던 기술 부채&lt;span class="hx:absolute hx:-mt-20" id="드러나지-않았던-기술-부채">&lt;/span>
&lt;a href="#%eb%93%9c%eb%9f%ac%eb%82%98%ec%a7%80-%ec%95%8a%ec%95%98%eb%8d%98-%ea%b8%b0%ec%88%a0-%eb%b6%80%ec%b1%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이 문제를 계기로 시스템 전체를 살펴보면서, ‘월세’라는 개념을 지칭하는 방식이 서비스별로 얼마나 다르게 사용되고 있었는지 확인할 수 있었습니다.&lt;/p>
&lt;p>예시로는 다음과 같습니다:&lt;/p>
&lt;ul>
&lt;li>어떤 DB 필드는 &lt;code>monthly&lt;/code>를 사용&lt;/li>
&lt;li>어떤 DB 필드는 &lt;code>rent&lt;/code>를 사용&lt;/li>
&lt;li>다른 API에서는 &lt;code>MONTHLY_LEASE&lt;/code>&lt;/li>
&lt;li>특정 enum 구조에서는 &lt;code>MONTHLY_LEASE&lt;/code>와 &lt;code>SHORT_TERM_LEASE&lt;/code>가 같은 값으로 설정되어 있음:&lt;/li>
&lt;/ul>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-kotlin" data-lang="kotlin">&lt;span class="line">&lt;span class="cl">&lt;span class="k">enum&lt;/span> &lt;span class="k">class&lt;/span> &lt;span class="nc">OfficeDealType&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="o">..&lt;/span>&lt;span class="p">.)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">SALE&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;매매&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;DEAL&amp;#34;&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">LEASE&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;전세&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;LEASE&amp;#34;&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">MONTHLY_LEASE&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;월세&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;MONTHLY_LEASE&amp;#34;&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">SHORT_TERM_LEASE&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;단기임대&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;MONTHLY_LEASE&amp;#34;&lt;/span>&lt;span class="p">),&lt;/span> &lt;span class="c1">// 단기임대도 동일한 값 사용
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;ul>
&lt;li>또 어떤 DB에서는 아예 한글로 &lt;strong>&lt;code>월세&lt;/code>&lt;/strong>, &lt;strong>&lt;code>전세&lt;/code>&lt;/strong> 등 한글 명칭을 그대로 사용하고 있음&lt;/li>
&lt;/ul>
&lt;p>이처럼 하나의 개념(월세)을 두고 네이밍이 제각각 사용되고 있는 상황은, 단순한 코드 스타일의 문제를 넘어 &lt;strong>시스템의 일관성과 안정성을 해치는 기술 부채&lt;/strong>로 이어집니다.&lt;/p>
&lt;p>마치 &lt;strong>끊어지기 직전의 줄을 타고 있는 듯한 위험한 상태&lt;/strong>였던 셈이죠.&lt;/p>
&lt;p>특히 이번 조사를 통해 확인한 바에 따르면, &lt;strong>&lt;code>deal_type&lt;/code> 관련 네이밍 불일치를 수정해야 할 테이블만 약 30개에 달하며&lt;/strong>, 서비스 전체에 대해서도 &lt;strong>전수조사가 필요한 상황&lt;/strong>입니다.&lt;/p>
&lt;p>결국, &lt;strong>초기 단계에서의 작은 귀찮음과 컨벤션 부재가 시간이 지날수록 더 큰 개발 및 유지보수 리소스를 소모하게 만든다는 사실&lt;/strong>을 명확히 보여주는 사례이기도 합니다.&lt;/p>
&lt;p>이 작업을 해야하는 저는 많이 힘들겠죠? 🤣&lt;/p>
&lt;hr>
&lt;h3>네이밍 컨벤션은 시스템 견고성을 위한 최소한의 약속&lt;span class="hx:absolute hx:-mt-20" id="네이밍-컨벤션은-시스템-견고성을-위한-최소한의-약속">&lt;/span>
&lt;a href="#%eb%84%a4%ec%9d%b4%eb%b0%8d-%ec%bb%a8%eb%b2%a4%ec%85%98%ec%9d%80-%ec%8b%9c%ec%8a%a4%ed%85%9c-%ea%b2%ac%ea%b3%a0%ec%84%b1%ec%9d%84-%ec%9c%84%ed%95%9c-%ec%b5%9c%ec%86%8c%ed%95%9c%ec%9d%98-%ec%95%bd%ec%86%8d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이번 사례를 통해 저희 팀은 &lt;strong>네이밍 컨벤션의 중요성&lt;/strong>을 다시 한 번 실감했습니다. 특히 마이크로서비스 기반 환경에서는 서비스 간 데이터를 주고받는 일이 빈번하기 때문에, 명확한 명세와 일관된 네이밍이 없다면 다음과 같은 문제들이 쉽게 발생합니다&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>예측 불가능한 시스템 오류&lt;/strong>
네이밍 불일치와 필드 제약이 맞물리면, 사용자 경험과 직결되는 예외가 언제든 발생할 수 있습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>개발 및 유지보수 비용 증가&lt;/strong>
개발자는 올바른 값이 무엇인지 유추하기 위해 코드를 계속 추적해야 하며, 잘못된 네이밍으로 인해 발생한 버그를 해결하는 데 불필요한 리소스가 낭비됩니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>가독성과 시스템 이해도 저하&lt;/strong>
하나의 개념이 여러 방식으로 표현되면, 전체 시스템의 맥락을 이해하기 어려워집니다. 이는 신규 개발자 온보딩에도 큰 장애물이 됩니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>협업 비효율&lt;/strong>
개발자 간 커뮤니케이션에서 용어의 불일치는 오해를 유발하고, 리뷰 및 문서화 과정에서도 혼선을 초래합니다.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;hr>
&lt;h3>앞으로의 계획: 네이밍 일관성 확보를 위한 전사적 표준화&lt;span class="hx:absolute hx:-mt-20" id="앞으로의-계획-네이밍-일관성-확보를-위한-전사적-표준화">&lt;/span>
&lt;a href="#%ec%95%9e%ec%9c%bc%eb%a1%9c%ec%9d%98-%ea%b3%84%ed%9a%8d-%eb%84%a4%ec%9d%b4%eb%b0%8d-%ec%9d%bc%ea%b4%80%ec%84%b1-%ed%99%95%eb%b3%b4%eb%a5%bc-%ec%9c%84%ed%95%9c-%ec%a0%84%ec%82%ac%ec%a0%81-%ed%91%9c%ec%a4%80%ed%99%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>저희 팀은 이번 문제를 단순한 버그 수정으로 끝내지 않고, &lt;strong>시스템 전반의 네이밍 컨벤션을 통일하기 위한 정비 작업&lt;/strong>에 착수했습니다.&lt;/p>
&lt;p>단기적으로는 ‘월세’와 같은 주요 개념에 대한 명확한 명세를 마련하고, 중장기적으로는 전 서비스에서 일관되게 적용될 수 있도록 구조화된 표준안을 마련할 예정입니다.&lt;/p>
&lt;p>이는 단순히 코드 품질을 높이는 차원을 넘어, &lt;strong>시스템 안정성, 운영 효율성, 개발 생산성&lt;/strong>을 모두 높이는 아주 중요한 작업이라고 판단하고 있습니다.&lt;/p>
&lt;hr>
&lt;h3>마치며&lt;span class="hx:absolute hx:-mt-20" id="마치며">&lt;/span>
&lt;a href="#%eb%a7%88%ec%b9%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>사소해 보이는 네이밍 하나가 시스템 전체에 얼마나 큰 영향을 줄 수 있는지, 이번 일은 제게 아주 큰 교훈을 줬습니다.&lt;/p>
&lt;p>네이밍 컨벤션을 위해 팀 전체가 협의하는 과정들을 거쳐야 한다는 이유때문에, 혹은 귀찮음, 또는 당연히 이렇게 쓰고있겠지 하는 추측 등으로 팀 전체가 하나의 네이밍 컨벤션을 가지지 못하는 경우들이 있었는데 저 또한 이런점을 간과하거나 미루는 경우들이 있었습니다.&lt;/p>
&lt;p>다시 한번 반성하게 됐고 저부터가 이런 일이 없도록 팀 전체가 네이밍을 공유할 수 있는 환경을 구성하려 합니다.&lt;/p>
&lt;p>혹시 비슷한 일이 있으셨다면 이 글이 조금이라도 도움이 됐으면 하며 이만 글을 마치겠습니다. 읽어주셔서 감사합니다.&lt;/p></description></item><item><title>😨 입금된 돈이 사라졌다? 계좌 잔고 정합성 검증 배치, Tasklet에서 Chunk &amp; Partitioning으로의 전환기</title><link>https://jeongil.dev/ko/blog/backend/performance/spring-batch-tasklet-to-chunk/</link><pubDate>Tue, 24 Dec 2024 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/backend/performance/spring-batch-tasklet-to-chunk/</guid><description>
&lt;p>안녕하세요.&lt;br>
저는 대출 및 투자 연계 플랫폼에서 &lt;strong>백엔드 개발자&lt;/strong>로 근무 중인 2년 차 개발자 &lt;strong>정정일&lt;/strong>입니다.&lt;/p>
&lt;p>운영 중인 회사 서비스에서 내부적으로 데이터 정합성을 검증하던 중, &lt;strong>트랜잭션 처리 시간&lt;/strong>과 &lt;strong>배치 작업의 비효율성&lt;/strong>으로 &lt;strong>은행 계좌 잔고와 서비스 내부 포인트(Point)의 불일치&lt;/strong>로 인해 정합성 검증 작업이 실패하거나, 잘못된 노티가 발송되는 경우가 있었습니다.&lt;/p>
&lt;p>이 글에서는 기존의 &lt;strong>Tasklet 기반 배치 처리 방식&lt;/strong>에서 발생한 문제점을 해결하기 위해, &lt;strong>Chunk 기반 처리와 Partitioning 기법&lt;/strong>을 도입한 경험을 공유하려 합니다.&lt;/p>
&lt;hr>
&lt;h3>1. 배경 상황&lt;span class="hx:absolute hx:-mt-20" id="1-배경-상황">&lt;/span>
&lt;a href="#1-%eb%b0%b0%ea%b2%bd-%ec%83%81%ed%99%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>저희 회사는 온라인투자연계 금융플랫폼입니다.
현재는 안전한 자금운용을 위해 신한은행을 통한 예치금 신탁 운용을 하고 있습니다. 회사의 자금 흐름을 간단한 다이어그램으로 그려보도록 하겠습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/dc176ce2-0191-4f41-87e9-78e90d0b94dd/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>물론 다이어그램에 그려진 것 외에 자금 흐름이 존재하지만 현재 문제를 이해하기 위한 부분과는 무관하니 빼도록 했습니다.&lt;/p>
&lt;p>문제를 이해하기 위해 위 그림에서 가장 중요한 부분은 실제 자금은 신한은행에서 관리를 해준다는 점입니다.&lt;/p>
&lt;p>투자자가 만원을 신한은행 가상계좌로 입금한다면 실제 입금된 만원은 신한은행에서 관리하고 만원이 입금됐다는 사실만 자사로 통지된다는 것 입니다.&lt;/p>
&lt;p>저희 역시 내부적으로 신한은행과는 별개로 사용자의 잔고에 대한 데이터를 관리하고 정합성을 검증하고 있습니다. &lt;strong>저희가 관리하는 사용자 잔고는 Point라 명명&lt;/strong>하고 있습니다.&lt;/p>
&lt;p>글에서는 명칭을 다음과 같이 하도록 하겠습니다.&lt;/p>
&lt;ul>
&lt;li>계좌 잔고 : 신한은행 예치금&lt;/li>
&lt;li>Point : 자사에서 관리하는 예치금&lt;/li>
&lt;/ul>
&lt;p>그렇다면 &lt;strong>계좌 잔고와 Point사이의 데이터 정합성이 불일치하는 경우&lt;/strong>들이 생길 수 있습니다. 예로는 다음과 같은 경우들이 있을 수 있죠.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>투자자 A가 입금을 했지만 은행과 자사 서비스간 사이의 입금 통지 사이 문제로 Point에 반영이 되지 않았을 때&lt;/p>
&lt;/li>
&lt;li>
&lt;p>원리금 지급 요청으로 신한은행에서 투자자 가상계좌로 입금 처리 했으나 Point에는 반영되지 않은 경우&lt;/p>
&lt;/li>
&lt;li>
&lt;p>투자자가 투자한 이후에 Point는 차감했으나 실제 대출은 실행되지 않아 계좌 잔고에서는 차감되지 않은 경우&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>물론 돈에 관련된 굉장히 굉장히 중요한 데이터이기 때문에 데이터 정합성 문제를 해결하기 위한 수많은 방어로직들이 있습니다. 그렇기에 정합성이 깨지는 경우는 굉장히 드물다고 말씀 드릴 수 있습니다.&lt;/strong>&lt;/p>
&lt;p>제가 말씀드리고 싶었던 부분은 실제 계좌 잔고와 Point 사이의 간극이 생길 수 있다는 부분을 설명드리고 싶었습니다.
이런 배경부분을 설명드리며 문제상황으로 넘어가도록 하겠습니다.&lt;/p>
&lt;hr>
&lt;h3>2. 문제 상황&lt;span class="hx:absolute hx:-mt-20" id="2-문제-상황">&lt;/span>
&lt;a href="#2-%eb%ac%b8%ec%a0%9c-%ec%83%81%ed%99%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>위에서 언급한대로 계좌 잔고와 Point는 돈과 관련된 굉장히 중요한 데이터임으로 수많은 방어로직 외에도 데이터 검증을 위해 하루에 한번 사용자분들의 계좌 잔고와 Point 데이터 사이에 차이가 존재하는지 예치금을 비교하고 계좌 잔액과 Point의 차이가 있다면 해당 목록을 저장하고 관리자에게 노티해주는 배치가 돌고 있습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/2a5ddf32-9212-4dae-829e-360087a137b4/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>기존 Tasklet 방식으로 작동하던 예치금 비교 Job입니다.
위 그림만 보더라도 몇가지 문제점을 언급할 수 있을 것 같습니다.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>투자자간 잔고는 서로 의존성이 없는데도 동기, 블로킹 방식으로 작동하고 있습니다. 이로 인해 해당 Job이 결과적으로 Batch의 리소스를 필요 이상으로 많이 잡아먹게 됩니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>한 step안에서 차액 비교와 비교 결과에 대한 핸들링을 모두 하고있습니다. 한 Step안에 책임이 여러개 존재하게돼 가독성 및 유지보수성이 떨어지게 됩니다.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>위 언급한 문제점 외에 &lt;strong>가장 중요한 한가지 문제점이 더 존재&lt;/strong>했는데 이 이유를 근거로 관리자분을 설득하여 리펙토링을 진행할 수 있었습니다.&lt;/p>
&lt;p>&lt;strong>Tasklet이 해당 Step이 끝날때까지 한 Transaction으로 동작했기때문에 예치금 비교도중 데이터 정합성이 맞지 않는 경우가 발생&lt;/strong>했습니다.
바로 아래와 같은 경우인데요.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/2226eab4-cc1c-4476-8740-673f63669bc3/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>7시에 Transaction이 시작하고 7시 10분쯤 입금 통지가 발생했다면 해당 point를 읽지 못하는 경우가 생겼습니다.&lt;/p>
&lt;p>저희는 DB로 Mysql을 사용하고 있었고 Mysql의 기본 격리 수준은 &lt;code>REPEATABLE READ&lt;/code>이기 때문에 MVCC로 동작해 transaction 시작 시점의 스냅샷의 데이터를 읽어버린 것이죠.&lt;/p>
&lt;p>(비교 로직에는 Point 뿐만 아닌 여러개의 테이블의 데이터들도 필요합니다. ex) 상환 예정 금액, 투자 대기 금액, 지급 예정 금액 등. 예시에서는 Point만 테이블만 예시로 들었습니다. )&lt;/p>
&lt;p>불행중 다행으로는 노티를 받아보는 관리자는 내부 사용자 (회사 직원분) 이시기 때문에 노티를 받아보고도 백오피스에서 현재 데이터를 확인하고 계좌 잔고에 데이터 정합성에 문제가 없는 것을 확인해주시지만 관리자 입장에서는 불필요한 업무가 느는 것이고 개발적인 관점에서는 잘못된 데이터로 노티를 보내니 이는 잘못된 부분이라 할 수 있다고 생각합니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/cfdbb72a-aa9f-47b1-ba0a-d9fb1ead4ba0/image.png" alt="" loading="lazy" />&lt;/p>
&lt;hr>
&lt;h3>3. 해결 방법: Chunk와 Partitioning 기반으로 전환&lt;span class="hx:absolute hx:-mt-20" id="3-해결-방법-chunk와-partitioning-기반으로-전환">&lt;/span>
&lt;a href="#3-%ed%95%b4%ea%b2%b0-%eb%b0%a9%eb%b2%95-chunk%ec%99%80-partitioning-%ea%b8%b0%eb%b0%98%ec%9c%bc%eb%a1%9c-%ec%a0%84%ed%99%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>기존 Tasklet 방식으로 구현된 배치 작업은 하나의 트랜잭션 내에서 모든 작업이 처리되다 보니, 트랜잭션 종료 전까지 변경된 데이터를 반영하지 못하는 문제가 있었습니다. 특히 7시에 배치 작업이 시작된 후 입금 통지가 7시 10분에 발생하면 해당 데이터는 배치 결과에 반영되지 않는 상황이 발생했습니다.&lt;/p>
&lt;p>뿐만 아니라 한 트랜잭션 내에서 비교 작업과 알림 처리 로직을 모두 수행하다 보니, 배치 작업 시간이 길어지고 실패 시 처음부터 재작업해야 하는 구조적 문제도 있었습니다. 이를 해결하기 위해 다음 세 가지를 목표로 설정했습니다.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>트랜잭션 단위 최소화&lt;/strong>&lt;br>
트랜잭션을 가능한 짧은 단위로 분리해 데이터 정합성을 개선.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>책임 분리&lt;/strong>&lt;br>
데이터 검증과 알림 처리 로직을 분리하여 코드 가독성과 유지보수성 향상.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>병렬 처리 도입&lt;/strong>&lt;br>
데이터 간 의존성이 없는 특성을 활용해 작업 속도를 최적화.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h4>Chunk 기반 처리로의 전환&lt;span class="hx:absolute hx:-mt-20" id="chunk-기반-처리로의-전환">&lt;/span>
&lt;a href="#chunk-%ea%b8%b0%eb%b0%98-%ec%b2%98%eb%a6%ac%eb%a1%9c%ec%9d%98-%ec%a0%84%ed%99%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>Tasklet 방식에서 Chunk 방식으로 전환하며 가장 큰 변화는 트랜잭션 단위가 작아졌다는 점입니다. 기존에는 하나의 트랜잭션이 전체 작업을 아우르다 보니 작업 중간에 변경된 데이터가 반영되지 않는 문제가 있었습니다. 이를 Chunk로 나누어 처리하며 각 Chunk마다 독립적으로 트랜잭션이 커밋되도록 설계했습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Chunk 처리 방식&lt;/strong>
&lt;ol>
&lt;li>&lt;strong>Reader&lt;/strong>: 데이터베이스에서 설정된 Chunk 크기만큼 데이터를 읽어옴.&lt;/li>
&lt;li>&lt;strong>Processor&lt;/strong>: Reader가 읽어온 데이터를 비교하거나 가공하는 작업 수행.&lt;/li>
&lt;li>&lt;strong>Writer&lt;/strong>: 가공된 데이터를 저장하거나 알림을 보내는 후속 작업 수행.&lt;/li>
&lt;/ol>
&lt;/li>
&lt;/ul>
&lt;p>Chunk 방식의 가장 큰 장점은 트랜잭션 범위를 제한할 수 있다는 점입니다. 이로 인해 배치 실행 중에도 변경된 데이터가 반영될 수 있었고, 처리 중 오류가 발생했을 때 특정 Chunk만 재처리할 수 있게 되었습니다.&lt;/p>
&lt;h4>Partitioning을 통한 병렬 처리 도입&lt;span class="hx:absolute hx:-mt-20" id="partitioning을-통한-병렬-처리-도입">&lt;/span>
&lt;a href="#partitioning%ec%9d%84-%ed%86%b5%ed%95%9c-%eb%b3%91%eb%a0%ac-%ec%b2%98%eb%a6%ac-%eb%8f%84%ec%9e%85" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>Chunk 기반 처리로 데이터 정합성을 개선했지만, 각 Chunk 사이즈 내에서는 마찬가지로 블로킹 방식으로 동작하니 마찬가지로 서버 리소스를 필요 이상으로 잡아먹는 문제는 여전했습니다.&lt;/p>
&lt;p>투자자 잔고, Point 데이터간에는 의존성이 없으므로 블로킹 방식으로 동작할 필요는 없었죠.&lt;/p>
&lt;p>이를 보완하기 위해 Partitioning 기법을 적용했습니다. 데이터를 여러 개의 Partition으로 나눠 병렬로 처리하면서 속도를 개선했습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Partitioning 적용 방식&lt;/strong>
&lt;ol>
&lt;li>데이터를 GridSize로 나누어 각 Partition에 독립적으로 할당.&lt;/li>
&lt;li>각 Partition은 독립적인 트랜잭션으로 처리.&lt;/li>
&lt;li>Spring Batch의 &lt;code>PartitionHandler&lt;/code>를 활용해 관리.&lt;/li>
&lt;/ol>
&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h3>Partitioning에서 동적 데이터 조회를 위한 QuerydslItemReader 구현&lt;span class="hx:absolute hx:-mt-20" id="partitioning에서-동적-데이터-조회를-위한-querydslitemreader-구현">&lt;/span>
&lt;a href="#partitioning%ec%97%90%ec%84%9c-%eb%8f%99%ec%a0%81-%eb%8d%b0%ec%9d%b4%ed%84%b0-%ec%a1%b0%ed%9a%8c%eb%a5%bc-%ec%9c%84%ed%95%9c-querydslitemreader-%ea%b5%ac%ed%98%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Partitioning을 사용하면 데이터를 미리 정의된 Partition 단위로 나눠 병렬 처리를 수행할 수 있습니다. 일반적으로는 &lt;code>Partitioner&lt;/code>가 데이터를 GridSize에 따라 미리 나눠 각 Partition에 분배하고, 각 Partition은 자신에게 할당된 데이터를 처리합니다.&lt;/p>
&lt;p>하지만 Partition을 미리 고정 크기로 나누면, 각 파티션 스레드 별 종료 시간이 크게 상이함에도 놀고있는 스레드에서 추가로 데이터를 처리하지 않으니 총 처리시간은 늘어나게 됩니다.&lt;/p>
&lt;p>저희 팀에서는 이런점을 해결하기 위해 모든 파티션의 Reader가 현재 조회지점을 스레드 세이프하도록 공유하게 해서 먼저 writer의 작업까지 끝낸 파티션이 다음작업을 할당 받을 수 있도록 구현하였습니다.&lt;/p>
&lt;hr>
&lt;p>&lt;strong>QuerydslPagingItemReader 구현 코드 예제&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Bean&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@StepScope&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">QuerydslPagingItemReader&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">BalanceCheckDto&lt;/span>&lt;span class="o">&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">querydslItemReader&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nd">@Value&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;#{jobParameters[&amp;#39;startDate&amp;#39;]}&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Date&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">startDate&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nd">@Value&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;#{jobParameters[&amp;#39;endDate&amp;#39;]}&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Date&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">endDate&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">QuerydslPagingItemReader&lt;/span>&lt;span class="o">&amp;lt;&amp;gt;&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">entityManagerFactory&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">DEFAULT_CHUNK_SIZE&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">queryFactory&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">-&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">QBalanceCheck&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">balanceCheck&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">QBalanceCheck&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">balanceCheck&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">queryFactory&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">selectFrom&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">balanceCheck&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">where&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">balanceCheck&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">createdDate&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">between&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">startDate&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">endDate&lt;/span>&lt;span class="p">))&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">orderBy&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">balanceCheck&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">id&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">asc&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">});&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;ul>
&lt;li>&lt;code>startDate&lt;/code>, &lt;code>endDate&lt;/code>: 배치 실행 시 동적으로 제공되는 파라미터.&lt;/li>
&lt;/ul>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="kt">long&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">currentExecutionOrder&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">executionOrder&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getAndIncrement&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kt">long&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">startIndex&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">currentExecutionOrder&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">getPageSize&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kt">int&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">totalRecords&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepContext&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getInt&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;totalRecords&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">startIndex&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">&amp;gt;=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">totalRecords&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">initResults&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 빈 결과로 초기화&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">tx&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">commit&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kt">int&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">chunkSizeToRead&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Math&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">min&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">getPageSize&lt;/span>&lt;span class="p">(),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="kt">int&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">totalRecords&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">startIndex&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 남은 데이터 크기만큼 읽기&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">// QueryDSL Query 생성&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">JPQLQuery&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">T&lt;/span>&lt;span class="o">&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">query&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">createQuery&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">offset&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">startIndex&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">limit&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">chunkSizeToRead&lt;/span>&lt;span class="p">);&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>왜 QuerydslPagingItemReader를 선택했는가?&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>
&lt;p>기존 저희 회사는 복잡한 쿼리를 QueryDSL 기반으로 구현해왔기 때문에 일관성을 맞추고자 했습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>컴파일 시점에 타입에 대한 검증을 위해도 사용했습니다.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h4>리펙토링 후 아키텍쳐&lt;span class="hx:absolute hx:-mt-20" id="리펙토링-후-아키텍쳐">&lt;/span>
&lt;a href="#%eb%a6%ac%ed%8e%99%ed%86%a0%eb%a7%81-%ed%9b%84-%ec%95%84%ed%82%a4%ed%85%8d%ec%b3%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/ce53019f-63db-4622-8ce3-2f8b8d49eeba/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>&lt;strong>개선된 점&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Querydsl 기반 Reader를 도입하며 Reader가 동적으로 데이터를 조회하면서 더 유연하고 효율적인 배치 작업이 가능해졌다고 생각합니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Step을 각 책임에 맞게 분리하여 유지보수성 및 가독성을 향상시켰습니다. 각 Step은 다음과 같은 책임들을 맡고 있습니다.&lt;/p>
&lt;ul>
&lt;li>balanceInitializeStep : Partitioning을 위한 초기화 작업&lt;/li>
&lt;li>balancePartitionStep : Partitioning을 이용한 병렬 예치금 비교 작업&lt;/li>
&lt;li>balanceSendSnsStep : 예치금 비교하며 차액 발생한 대상 관리자 노티&lt;/li>
&lt;li>balanceResetStep : 이전 모든 스탭 완료 후 데이터 초기화 작업&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;p>그리고 저희는 트랜잭션의 단위를 최소화하기 위해 Reader, Processor, Writer의 트랜잭션을 각각 분리하여 구현했습니다.&lt;/p>
&lt;p>일반적으로는 Reader, Processor, Writer를 청크 단위로 트랜잭션을 묶어 작업하게 되는데 저희는 계좌 잔액이라는 데이터 자체가 신한은행에서 관리하다보니 청크단위로 Reader, Processor, Writer의 transaction을 묶는다 하더라도 의미가 없다고 생각했습니다.&lt;/p>
&lt;hr>
&lt;h3>성과와 개선된 점&lt;span class="hx:absolute hx:-mt-20" id="성과와-개선된-점">&lt;/span>
&lt;a href="#%ec%84%b1%ea%b3%bc%ec%99%80-%ea%b0%9c%ec%84%a0%eb%90%9c-%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>1. 데이터 정합성 강화&lt;/strong>&lt;br>
트랜잭션 단위를 최소화하면서 데이터 정합성 문제의 확률이 현저하게 줄어들게 됐습니다. 작업 중간에 발생한 입금 통지나 기타 변경사항도 거의 실시간으로 반영할 수 있게 되었습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>최대 트랜잭션 처리 시간&lt;/strong>&lt;br>
기존: 약 22분 → 변경 후: 0.01초 수준으로 감소.
(데이터 정합성 문제 발생확률 1/132,000 )&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>2. 처리 속도와 리소스 효율성&lt;/strong>&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/b57fac5f-4a88-4a80-85a7-13e4bd7b3381/image.png" alt="" loading="lazy" />&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Row당 처리 시간&lt;/strong>
기존: 3.74초 → 변경 후: 0.72초 (80% 단축).&lt;/li>
&lt;/ul>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/82d6aedf-62a0-4efd-9adf-db3bf4a3e67f/image.png" alt="" loading="lazy" />&lt;/p>
&lt;ul>
&lt;li>&lt;strong>평균 소요 시간&lt;/strong>&lt;br>
기존 Tasklet 방식: 13.27분 → Chunk/Partitioning 방식: 4.77분 (64% 단축).&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h3>개발 과정에서의 고민과 시행착오&lt;span class="hx:absolute hx:-mt-20" id="개발-과정에서의-고민과-시행착오">&lt;/span>
&lt;a href="#%ea%b0%9c%eb%b0%9c-%ea%b3%bc%ec%a0%95%ec%97%90%ec%84%9c%ec%9d%98-%ea%b3%a0%eb%af%bc%ea%b3%bc-%ec%8b%9c%ed%96%89%ec%b0%a9%ec%98%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;strong>스레드 관리와 병렬 처리&lt;/strong>&lt;br>
병렬 처리를 위해 &lt;code>SimpleAsyncTaskExecutor&lt;/code>와 &lt;code>ThreadPoolTaskExecutor&lt;/code>를 비교 테스트하며 최적의 설정을 찾았습니다. 스레드 풀 크기에 따른 속도를 비교하여 적절한 스레드 갯수를 탐색했습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/43efce90-335e-424b-9bbb-ba4d1f5838bf/image.png" alt="" loading="lazy" />
위와 같은 테스트 결과 gridSize 및 thread 개수는 10으로 고정했습니다.&lt;/p>
&lt;p>&lt;strong>트랜잭션을 커밋하지 않고 EntityManager를 그냥 close해버렸을 때&lt;/strong>
테스트하는 과정에서 Reader에서 transaction을 close하지 않고 entityManager를 close해버렸을 때 HikariCP Deadlock 문제를 맞이하게 됐습니다. transaction을 entityManager가 close 됐을때 commit하겠거니 생각했었는데 아니여서 당황했었죠. 생각해보면 당연한건데 말입니다.&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/df31cd01-30df-47d6-923f-e6c3ea333c35/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/25261115-2128-473b-a205-c82c011e250b/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>해당 문제는 transaction을 close하고 entityManager를 close하면서 해결하게 됩니다.&lt;/p>
&lt;p>&lt;strong>Reader, Processor, Writer, Listener 간 역할 분리&lt;/strong>&lt;br>
로직 분리 과정에서 가장 고민이 되었던 부분중 하나는 Processor와 Writer 간의 역할이 중첩되지 않도록 설계하는 것이었습니다. 노티해야할 회원 목록 데이터를 어떻게 다음 Step으로 안전하게 전달할지 고민한 끝에 &lt;code>ConcurrentLinkedQueue&lt;/code>를 사용해 스레드 안전한 데이터 공유를 구현했습니다.&lt;/p>
&lt;p>또한 구현 초기에 initialize 작업이나 초기화 작업이 Listener에 구현이 되어있었습니다. 해당 부분이 클래스의 역할과 맞지 않았기 때문에 별도에 Step으로 분리하여 구현했습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/c10e14aa-d77a-48c5-9337-efd65eeb053f/image.png" alt="" loading="lazy" />
&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/d45e1113-2ec1-4b2d-90ce-cb11d91a862b/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>(해당 코드 리뷰후에 스크럼을 통해 개선점을 조율하고 수정했습니다!)&lt;/p>
&lt;hr>
&lt;h3>마무리하며&lt;span class="hx:absolute hx:-mt-20" id="마무리하며">&lt;/span>
&lt;a href="#%eb%a7%88%eb%ac%b4%eb%a6%ac%ed%95%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>저로서는 Chunk, Partitioning 도입을 통한 문제해결이 가능하다는 것을 어필하여 팀장님을 설득하는 과정부터가 도전이였습니다.
다행히 팀장님또한 필요성을 공감해주셨고 저희 팀에서 맡아서 진행할 수 있었습니다.&lt;/p>
&lt;p>이번 리팩토링 프로젝트는 단순히 예외 발생확률의 하락 및 성능을 개선하는 데 그치지 않고, 코드 구조를 재정립해 유지보수성과 재사용성을 확보했다는 점에서 중요한 경험이 되었습니다.&lt;/p>
&lt;p>특히 Chunk와 Partitioning 기법의 장점을 최대한 활용해 효율적인 배치를 설계한 점은 향후 다른 배치 작업에도 적용할 수 있는 좋은 선례가 될 수 있을 것 같습니다.&lt;/p>
&lt;p>여러가지 경험하며 Spring Batch에 대한 이해도도 크게 높일 수 있었던 시간이라고 생각합니다.&lt;/p>
&lt;p>이번 리팩토링에서 저는 실제 구현을 담당하진 않았습니다. Chunk, Partitioning 도입 제안, 참여 인원 결정, 일정 조율, 스크럼 진행, 도입 기술 결정, 코드 리뷰 등을 담당했고 아키텍쳐 설계, 트러블 슈팅, 구현방향 설정 등에 참여했습니다.&lt;/p>
&lt;p>가장 중요한 Chunk, Partitioning 방식 구현 및 테스트를 담당해주신 저희 팀에 태성님, 병욱님께 감사인사드리며 이만글을 마치도록 하겠습니다.&lt;/p>
&lt;hr>
&lt;h3>Reference&lt;span class="hx:absolute hx:-mt-20" id="reference">&lt;/span>
&lt;a href="#reference" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;a href="https://techblog.woowahan.com/2662/"target="_blank" rel="noopener">https://techblog.woowahan.com/2662/&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://jojoldu.tistory.com/336"target="_blank" rel="noopener">https://jojoldu.tistory.com/336&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://jojoldu.tistory.com/339"target="_blank" rel="noopener">https://jojoldu.tistory.com/339&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://docs.spring.io/spring-batch/reference/readersAndWriters.html"target="_blank" rel="noopener">https://docs.spring.io/spring-batch/reference/readersAndWriters.html&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p></description></item><item><title>🚀 외부 API 성능 개선기: Look-aside 캐시로 5100ms ➔ 57ms 단축</title><link>https://jeongil.dev/ko/blog/backend/performance/look-aside-cache-api-perf/</link><pubDate>Mon, 16 Dec 2024 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/backend/performance/look-aside-cache-api-perf/</guid><description>
&lt;p>안녕하세요. 저는 현재 대출 및 투자 연계 플랫폼에서 백엔드 개발자로 근무 중인 2년 차 개발자입니다. 이번 글에서는 &lt;strong>Look-aside 캐시 패턴을 활용하여 외부 API 성능을 개선한 경험&lt;/strong>을 공유하려고 합니다.&lt;/p>
&lt;p>이 과정에서 제가 직면했던 문제들은 단순하지 않았습니다. API 호출의 지연, 중복 호출로 인한 비용 문제, 그리고 사용자 경험의 저하 등 다양한 문제들이 얽혀 있었습니다.&lt;/p>
&lt;p>특히, 외부 API의 평균 응답 시간이 약 5100ms에 달하면서 사용자 대기 시간이 지나치게 길어졌고, 이는 사용자 이탈로 이어질 수 있는 중대한 문제로 인식되었습니다.&lt;/p>
&lt;p>이러한 문제들을 단순히 외부 API 개선요구에만 의존하기에는 어려웠기에, 외부 API의 성능개선을 위해 내가 할 수 있는 건 없을까 고민하다 &lt;strong>캐시를 도입하기로 결정하게 됐습니다.&lt;/strong>&lt;/p>
&lt;p>이 글에서는 Look-aside 캐시의 개념, 구현 과정, 그리고 실제 적용 결과에 대해 다루려 합니다.&lt;/p>
&lt;h3>1. 문제 상황&lt;span class="hx:absolute hx:-mt-20" id="1-문제-상황">&lt;/span>
&lt;a href="#1-%eb%ac%b8%ec%a0%9c-%ec%83%81%ed%99%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>저희 회사의 대출 중계 상품 중 하나인 &lt;strong>주택담보대출 서비스&lt;/strong>는 사용자가 주택 주소를 입력하면 해당 주택의 시세에 따라 대출 한도를 계산해 보여줍니다. 여기서 핵심은 &lt;strong>주택 시세 및 단지, 평형 정보 데이터&lt;/strong>로, 이 정보를 외부 API를 통해 가져오고 있었습니다.&lt;/p>
&lt;h4>&lt;strong>주요 문제&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="주요-문제">&lt;/span>
&lt;a href="#%ec%a3%bc%ec%9a%94-%eb%ac%b8%ec%a0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;ul>
&lt;li>
&lt;p>&lt;strong>응답 속도 지연&lt;/strong>: 외부 API의 평균 응답 시간이 약 5100ms로, 사용자 대기 시간이 지나치게 길어졌습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>외부 시스템 개선의 어려움&lt;/strong>: 고객사의 입장에서 성능개선을 요구한다 하더라도 개선이 바로 이루어지기엔 어려움이 있었습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>중복 요청 발생&lt;/strong>: 대출 신청 프로세스 중 임시 저장 기능이 있어, 동일한 주소에 대해 중복 조회가 발생했습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>비용 문제&lt;/strong>: 외부 API 호출 비용이 누적되면서 운영 비용이 증가했습니다.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/f6718b3d-e3cc-41e1-9dd4-d23df18f7394/image.png" alt="" loading="lazy" />
(외부 API 응답속도 최저 3006ms 최대 9412ms)&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/25af37e4-f525-4802-bcbd-70568d6c4914/image.png" alt="" loading="lazy" />&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>API 응답 속도 분석&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>최저: 3006ms&lt;/li>
&lt;li>평균: 5132ms&lt;/li>
&lt;li>최대: 9412ms&lt;/li>
&lt;/ul>
&lt;/blockquote>
&lt;p>이로 인해 사용자 불만이 증가했고, 서비스 품질 저하로 이어졌습니다. 특히, 대출 신청 과정에서의 반복 호출로 인해 불필요한 비용이 발생했습니다.&lt;/p>
&lt;hr>
&lt;h3>2. 해결 방법: Look-aside 캐시 패턴 도입&lt;span class="hx:absolute hx:-mt-20" id="2-해결-방법-look-aside-캐시-패턴-도입">&lt;/span>
&lt;a href="#2-%ed%95%b4%ea%b2%b0-%eb%b0%a9%eb%b2%95-look-aside-%ec%ba%90%ec%8b%9c-%ed%8c%a8%ed%84%b4-%eb%8f%84%ec%9e%85" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>외부 API의 성능을 개선하는 방법으로 &lt;strong>Look-aside 캐시 패턴&lt;/strong>을 선택했습니다.&lt;/p>
&lt;h4>&lt;strong>Look-aside 캐시란?&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="look-aside-캐시란">&lt;/span>
&lt;a href="#look-aside-%ec%ba%90%ec%8b%9c%eb%9e%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>Look-aside 캐시는 &lt;strong>데이터베이스(DB) 또는 외부 API에 접근하기 전에 캐시를 먼저 확인하는 캐싱 전략&lt;/strong>입니다. 만약 캐시에 데이터가 존재하면 이를 반환하고, 없다면 외부 API를 호출한 후 캐시에 저장하는 방식입니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/141a4a30-e9e5-416a-aaba-2a4408fb3b0a/image.png" alt="" loading="lazy" />&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>동작 원리&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>사용자의 요청이 들어오면 &lt;strong>캐시(Cache)&lt;/strong> 에서 데이터 존재 여부를 확인합니다.&lt;/li>
&lt;li>캐시에 데이터가 있으면 반환합니다 (&lt;strong>cache hit&lt;/strong>).&lt;/li>
&lt;li>캐시에 데이터가 없으면 &lt;strong>외부 API에 요청&lt;/strong>을 보내고, 응답받은 데이터를 캐시에 저장한 후 반환합니다 (&lt;strong>cache miss&lt;/strong>).&lt;/li>
&lt;/ol>
&lt;/blockquote>
&lt;blockquote>
&lt;p>&lt;strong>예시 흐름&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>[사용자 요청] ➞ [캐시 확인] ➞ &lt;strong>(데이터가 있으면 반환)&lt;/strong> ➞ [응답]&lt;/li>
&lt;li>[사용자 요청] ➞ [캐시 확인] ➞ &lt;strong>(데이터가 없으면)&lt;/strong> ➞ [외부 API 호출] ➞ [캐시에 저장] ➞ [응답]&lt;/li>
&lt;/ul>
&lt;/blockquote>
&lt;h4>&lt;strong>왜 Look-aside 캐시를 선택했을까?&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="왜-look-aside-캐시를-선택했을까">&lt;/span>
&lt;a href="#%ec%99%9c-look-aside-%ec%ba%90%ec%8b%9c%eb%a5%bc-%ec%84%a0%ed%83%9d%ed%96%88%ec%9d%84%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;ul>
&lt;li>
&lt;p>&lt;strong>불확실한 요청 패턴&lt;/strong>: 사용자가 요청하는 주택의 주소가 사전에 예측되지 않기때문에, 미리 데이터를 적재할 수 없었습니다. 만약 특정할 수 있었다면 Cache Warm up을 고려했을 것 같습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>중복 요청 문제 해결&lt;/strong>: 문제점에서 언급했던대로 대출 신청 프로세스 중 임시 저장 기능이 있었는데, 임시 저장된 데이터를 불러올 때마다 동일한 주소에 대해 중복 조회가 발생했습니다. 그렇기 때문에 임시저장을 불러올때 Cache hit 가능성이 높을 거라 판단했습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>첫 요청 지연 감수&lt;/strong>: Look-aside 패턴의 특성상 첫 요청은 기존 속도와 동일 할테지만 이후 동일한 요청은 캐시로부터 빠르게 제공할 수 있습니다.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h3>3. 구현 과정&lt;span class="hx:absolute hx:-mt-20" id="3-구현-과정">&lt;/span>
&lt;a href="#3-%ea%b5%ac%ed%98%84-%ea%b3%bc%ec%a0%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;h4>&lt;strong>기술 스택&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="기술-스택">&lt;/span>
&lt;a href="#%ea%b8%b0%ec%88%a0-%ec%8a%a4%ed%83%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;ul>
&lt;li>&lt;strong>Redis&lt;/strong>: 인메모리 DB로 Redis를 채택했습니다. 기존에 분산 락 및 Session Clustering 용도로 redis를 사용중이기도 해서 추가적인 Infra 셋팅이 필요하지 않는다는 점이 가장 매력적이였습니다.&lt;/li>
&lt;/ul>
&lt;h4>&lt;strong>구현 흐름&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="구현-흐름">&lt;/span>
&lt;a href="#%ea%b5%ac%ed%98%84-%ed%9d%90%eb%a6%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>[사용자 요청] ➞ [캐시 확인] ➞ [캐시에 데이터가 있으면 반환] ➞ [없으면 외부 API 호출] ➞ [응답 데이터 캐시에 저장] ➞ [응답 반환]&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h4>&lt;strong>주요 구현 코드 예시&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="주요-구현-코드-예시">&lt;/span>
&lt;a href="#%ec%a3%bc%ec%9a%94-%ea%b5%ac%ed%98%84-%ec%bd%94%eb%93%9c-%ec%98%88%ec%8b%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Bean&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">RedisCacheManager&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">cacheManager&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">RedisConnectionFactory&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">redisConnectionFactory&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">RedisCacheConfiguration&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">defaultCacheConfig&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">RedisCacheConfiguration&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">defaultCacheConfig&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">entryTtl&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Duration&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">ofSeconds&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">86400&lt;/span>&lt;span class="p">))&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">serializeValuesWith&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">RedisSerializationContext&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">SerializationPair&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">fromSerializer&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">GenericJackson2JsonRedisSerializer&lt;/span>&lt;span class="p">()));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">Map&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">RedisCacheConfiguration&lt;/span>&lt;span class="o">&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">cacheConfigurations&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">HashMap&lt;/span>&lt;span class="o">&amp;lt;&amp;gt;&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">cacheConfigurations&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">put&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;realPrice&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">getRealPriceCacheConfiguration&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">RedisCacheManager&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">builder&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">redisConnectionFactory&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">cacheDefaults&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">defaultCacheConfig&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">withInitialCacheConfigurations&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">cacheConfigurations&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">build&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">RedisCacheConfiguration&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">getRealPriceCacheConfiguration&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kt">long&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">secondsUntilThursday&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ChronoUnit&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">SECONDS&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">between&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">LocalDateTime&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">now&lt;/span>&lt;span class="p">(),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">LocalDateTime&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">now&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">with&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">TemporalAdjusters&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">nextOrSame&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">DayOfWeek&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">THURSDAY&lt;/span>&lt;span class="p">)).&lt;/span>&lt;span class="na">withHour&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">23&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="na">withMinute&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">30&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">RedisCacheConfiguration&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">defaultCacheConfig&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">entryTtl&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Duration&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">ofSeconds&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">secondsUntilThursday&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="o">!&lt;/span>&lt;span class="n">noCache&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">try&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">Cache&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">searchCache&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">cacheManager&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getCache&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;realPrice&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">cacheKey&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">buildingCd&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">RealPriceInquiryResponse&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">cacheData&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">searchCache&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">get&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">cacheKey&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">RealPriceInquiryResponse&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">class&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">cacheData&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">!=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">cacheData&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">catch&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Exception&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">log&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">error&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;Cache lookup failed&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">RealPriceInquiryResponse&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">response&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">webClient&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">requestRealPriceApi&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">try&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">searchCache&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">put&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">cacheKey&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">response&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">catch&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Exception&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">log&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">error&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;Cache save failed&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">response&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/1108dfed-3124-495c-864f-f1672acf4bde/image.png" alt="" loading="lazy" />&lt;/p>
&lt;ul>
&lt;li>Client Server : 일반사용자가 Client인 WAS&lt;/li>
&lt;li>Admin Server : 백오피스 WAS&lt;/li>
&lt;li>API Server : 외부 서버와 통신을 추상화한 서버&lt;/li>
&lt;li>External Api Server : 외부 API 서버&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>위 그림은 &lt;strong>API 서버의 캐시 구조를 포함한 서버 아키텍처&lt;/strong>를 나타낸 것입니다. &lt;strong>API 서버는 외부 서버와 통신을 추상화한 서버&lt;/strong>로, 은행 전문 등 다양한 외부 시스템과의 통신을 통합하기 위해 설계되었습니다.&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;p>Client Server와 Admin Server는 API Server로 요청을 보내며, 이때 API 서버는 먼저 &lt;strong>캐시를 확인&lt;/strong>하여 데이터를 조회합니다. 만약 캐시에 데이터가 없다면 &lt;strong>외부 API 서버와 통신&lt;/strong>하여 데이터를 조회하고, 이 데이터를 캐시에 저장한 후 반환합니다.&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;p>단, Admin Server의 경우, &lt;strong>대출 한도 심사와 같이 더 정확한 정보가 요구&lt;/strong>되므로, &lt;strong>캐시된 데이터가 아닌 외부 API 서버와 직접 통신&lt;/strong>하여 최신 정보를 가져옵니다.&lt;/p>
&lt;/blockquote>
&lt;hr>
&lt;h3>4. 성과 및 개선 효과&lt;span class="hx:absolute hx:-mt-20" id="4-성과-및-개선-효과">&lt;/span>
&lt;a href="#4-%ec%84%b1%ea%b3%bc-%eb%b0%8f-%ea%b0%9c%ec%84%a0-%ed%9a%a8%ea%b3%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/22da82d3-80af-4884-a273-2f9914d476a4/image.png" alt="" loading="lazy" />
(첫 요청은 평균 약 5100ms로 동일 캐시 hit시 평균 57ms)&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/8db5c419-e105-4129-9dcf-6dfe7df3d4dc/image.png" alt="" loading="lazy" />&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;strong>구분&lt;/strong>&lt;/th>
&lt;th>&lt;strong>도입 전&lt;/strong>&lt;/th>
&lt;th>&lt;strong>도입 후&lt;/strong>&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>평균 응답 시간&lt;/strong>&lt;/td>
&lt;td>5132ms&lt;/td>
&lt;td>1299ms&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Cache Miss&lt;/strong>&lt;/td>
&lt;td>5132ms&lt;/td>
&lt;td>5231ms&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Cache Hit&lt;/strong>&lt;/td>
&lt;td>X&lt;/td>
&lt;td>57ms&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>API 호출 횟수&lt;/strong>&lt;/td>
&lt;td>100%&lt;/td>
&lt;td>76% 감소&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>사용자 만족도&lt;/strong>&lt;/td>
&lt;td>낮음&lt;/td>
&lt;td>비교적 상승&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>응답 속도 개선&lt;/strong>: 평균 5132ms였던 응답 시간이 1299ms로 74.69% 개선됐습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>API 비용 절감&lt;/strong>: 외부 API 호출 횟수가 76% 이상 감소했습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>사용자 경험 향상&lt;/strong>: 페이지 로딩 속도가 빨라져 사용자 만족도가 개선되었습니다.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h3>5. 캐시 만료 전략&lt;span class="hx:absolute hx:-mt-20" id="5-캐시-만료-전략">&lt;/span>
&lt;a href="#5-%ec%ba%90%ec%8b%9c-%eb%a7%8c%eb%a3%8c-%ec%a0%84%eb%9e%b5" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>캐시된 데이터를 목적하는 바에 부합하게 데이터를 유지하는 것은 굉장히 중요하다고 생각합니다. 저희같은 경우는 외부 API의 데이터가 변경되었음에도 불구하고 캐시가 갱신되지 않으면, 정확하지 않은 대출한도가 사용자에게 제공될 위험이 있었습니다.&lt;/p>
&lt;p>이 문제를 해결하기 위해 &lt;strong>외부 API의 데이터가 변경되는 시점에 캐시를 비우는 전략을 선택&lt;/strong>했습니다. 외부 API의 &lt;strong>데이터 변경 주기가 일정&lt;/strong>했기 때문에 이 시간에 맞춰 Redis에 저장된 특정 키의 캐시 데이터를 삭제하도록 설정했습니다.&lt;/p>
&lt;p>Redis 메모리가 제한된 상황에서 오래된 데이터가 쌓이는 문제를 해결하기 위해 &lt;strong>LRU(Least Recently Used) 정책&lt;/strong>을 적용했습니다.&lt;/p>
&lt;hr>
&lt;h3>6. 결론&lt;span class="hx:absolute hx:-mt-20" id="6-결론">&lt;/span>
&lt;a href="#6-%ea%b2%b0%eb%a1%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이번 &lt;strong>Look-aside 캐시 도입&lt;/strong>을 통해 외부 API 호출에 의존하는 서비스에 캐시를 활용함으로써 응답 속도를 조금이라도 개선 할 수 있었습니다.&lt;/p>
&lt;p>외부 시스템에 대한 의존성은 서비스 운영에 있어 피할 수 없는 순간들이 있을 수 있다고 생각합니다. 그렇지만 주어진 환경 안에서 최선의 방법을 찾는것이 중요하지 않나 싶습니다.&lt;/p>
&lt;p>이번 작업을 통해 얻은 경험들과 개선사항들이 여러분들에게 조금이라도 도움이 됐으면하며 이만 글을 마치도록 하겠습니다.&lt;/p></description></item><item><title>Cherry-pick 지옥에서 탈출하기: 주니어 개발자들의 PR 단위 코드리뷰와 Git Flow 도입기</title><link>https://jeongil.dev/ko/blog/culture/git-flow-introduction/</link><pubDate>Tue, 10 Dec 2024 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/culture/git-flow-introduction/</guid><description>
&lt;h3>들어가며&lt;span class="hx:absolute hx:-mt-20" id="들어가며">&lt;/span>
&lt;a href="#%eb%93%a4%ec%96%b4%ea%b0%80%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>안녕하세요. 이 글에서는 &lt;strong>Pull Request(PR)&lt;/strong> 이 없던 회사의 혼돈의 로컬 개발 환경에서, &lt;strong>PR 단위 코드리뷰와 Git Flow&lt;/strong>를 도입했던 경험을 풀어보려고 합니다.&lt;/p>
&lt;p>당시 저희 팀은 각자 로컬에서 Merge하고 Push하는 방식으로 작업했고, 모든 개발이 단일 브랜치(dev)에서 이루어졌기에 &lt;strong>Cherry-pick 남발&lt;/strong>과 그로 인한 &lt;strong>conflict&lt;/strong>가 반복되고 있었습니다.&lt;/p>
&lt;p>이를 해결하기 위해 주니어 개발자인 저와 동료들의 변화가 만들어낸 이야기를 전해드리려 합니다.&lt;/p>
&lt;hr>
&lt;h3>❔ 왜 도입을 결심하게 되었나?&lt;span class="hx:absolute hx:-mt-20" id="-왜-도입을-결심하게-되었나">&lt;/span>
&lt;a href="#-%ec%99%9c-%eb%8f%84%ec%9e%85%ec%9d%84-%ea%b2%b0%ec%8b%ac%ed%95%98%ea%b2%8c-%eb%90%98%ec%97%88%eb%82%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;h4>&lt;strong>기존의 작업 방식&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="기존의-작업-방식">&lt;/span>
&lt;a href="#%ea%b8%b0%ec%a1%b4%ec%9d%98-%ec%9e%91%ec%97%85-%eb%b0%a9%ec%8b%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>도입 전 우리 팀의 브랜치 구조와 git 전략은 아래와 같았습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>- prod(main): 운영 환경에 반영되는 브랜치
- staging: 운영과 동일한 환경에서 테스트를 진행하는 브랜치
- dev: 모든 개발자가 작업하고 커밋하는 브랜치 &lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이 구조는 GitLab Flow 방식으로 장단점이 있었지만, 저희의 작업 방식에 문제가 있었습니다.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>로컬 중심의 Merge&lt;/strong>
각자 자신의 로컬에서 Merge하고 Push하다 보니, 충돌 발생 시 해결은 전적으로 개인 몫이었습니다.
개발자마다 로컬 상태가 다르다 보니, 누군가는 커밋을 뒤늦게 가져오면서 충돌을 마주하기도 했습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>단일 dev 브랜치에 모든 작업이 몰림&lt;/strong>
기능 개발, 버그 수정, 핫픽스 등 모든 작업이 dev 브랜치 하나에 몰려 관리가 어려웠습니다.
어떤 기능이 완료되었고, 어떤 기능이 아직 미완성인지 구분이 어려웠습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>긴급 배포의 어려움&lt;/strong>
특정 기능이나 긴급한 버그만 배포해야 할 때, Cherry-pick으로 staging에 특정 커밋만 가져와 반영했습니다.
이후 dev 브랜치를 다시 staging으로 병합할 때, 이미 Cherry-pick으로 들어간 커밋과 dev의 동일한 커밋이 충돌을 일으켰습니다.
이 충돌을 매번 해결해야 했고, 점점 더 복잡해졌습니다.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h4>&lt;strong>Cherry-pick 지옥&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="cherry-pick-지옥">&lt;/span>
&lt;a href="#cherry-pick-%ec%a7%80%ec%98%a5" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>문제는 특히 &lt;strong>dev 브랜치&lt;/strong>에서 작업하던 코드 중, &lt;strong>특정 커밋만 운영 환경(prod)에 먼저 반영&lt;/strong>해야 할 때 발생했습니다. 긴급한 버그 수정이나 특정 기능이 필요할 때 Cherry-pick을 사용했지만, 이는 &lt;strong>반복적인 충돌 지옥&lt;/strong>을 유발했습니다.&lt;/p>
&lt;p>&lt;strong>왜 Cherry-pick이 문제였을까?&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>불완전한 반영 흐름&lt;/strong>:&lt;br>
dev에 커밋된 코드 중 일부만 Cherry-pick으로 staging에 반영하고, staging을 다시 prod로 Merge했을 때 dev와 staging 간 병합 이력이 맞지 않으면서 충돌이 발생했습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>반복적인 충돌&lt;/strong>:&lt;br>
이후 dev 브랜치를 staging으로 Merge하려 할 때, 이미 Cherry-pick으로 staging에 반영된 커밋과 dev의 동일한 커밋이 충돌을 일으켰습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>작업 중단&lt;/strong>:&lt;br>
이러한 충돌을 해결하는 과정에서 다른 작업이 중단되었고, 결과적으로 &lt;strong>staging → prod&lt;/strong>로 이어지는 작업 흐름이 계속해서 방해받았습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>관리 복잡성 증가&lt;/strong>:&lt;br>
dev, staging, prod 간 병합 히스토리가 불일치하면서, 이후 작업 시 추가적인 충돌이 발생하는 악순환이 이어졌습니다.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h3>설득의 시작: Cherry-pick 문제를 중심으로&lt;span class="hx:absolute hx:-mt-20" id="설득의-시작-cherry-pick-문제를-중심으로">&lt;/span>
&lt;a href="#%ec%84%a4%eb%93%9d%ec%9d%98-%ec%8b%9c%ec%9e%91-cherry-pick-%eb%ac%b8%ec%a0%9c%eb%a5%bc-%ec%a4%91%ec%8b%ac%ec%9c%bc%eb%a1%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;h4>&lt;strong>설득의 어려움&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="설득의-어려움">&lt;/span>
&lt;a href="#%ec%84%a4%eb%93%9d%ec%9d%98-%ec%96%b4%eb%a0%a4%ec%9b%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>저와 동료는 이러한 문제를 해결하기 위해 &lt;strong>PR 기반 코드리뷰&lt;/strong>와 &lt;strong>Git Flow&lt;/strong> 도입을 제안했습니다. 하지만 처음부터 모두가 이 방식을 환영했던 것은 아니었습니다.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>팀원들:&lt;br>
&amp;ldquo;해본적이 없어서 어려워 보인다.&amp;rdquo;
&amp;ldquo;PR 같은 걸 하면 더 오래 걸릴 것 같은데?&amp;rdquo;&lt;br>
&amp;ldquo;지금도 충분히 잘 되고 있는 거 아닌가?&amp;rdquo;&lt;/p>
&lt;/li>
&lt;li>
&lt;p>관리자:&lt;br>
&amp;ldquo;시간 낭비처럼 보인다.&amp;rdquo;&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>이런 반응 속에서 Cherry-pick 문제를 중심으로 동료들과 관리자를 설득하기 시작했습니다.&lt;/p>
&lt;hr>
&lt;h4>&lt;strong>Git Flow 전략의 대안 제시&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="git-flow-전략의-대안-제시">&lt;/span>
&lt;a href="#git-flow-%ec%a0%84%eb%9e%b5%ec%9d%98-%eb%8c%80%ec%95%88-%ec%a0%9c%ec%8b%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>저는 과거 Cherry-pick 문제로 인해 발생했던 충돌 사례를 기반으로 설득을 진행했습니다.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>충돌 사례 재현&lt;/strong>:&lt;br>
이전에 발생했던 Cherry-pick 충돌 상황을 재현해 보여주며, dev → staging → prod 간 작업 흐름이 얼마나 쉽게 꼬이는지를 시각적으로 설명했습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Git Flow 전략의 대안 제시&lt;/strong>:&lt;br>
Git Flow 전략을 사용하면, 브랜치 관리가 체계적으로 이루어져 Cherry-pick 없이도 특정 작업을 staging에 반영할 수 있습니다. 또한, 병합 전 리뷰와 테스트를 통해 충돌 가능성을 사전에 제거할 수 있음을 강조했습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>시간 절약 효과&lt;/strong>:&lt;br>
Git Flow와 PR 도입이 초기에는 익숙하지 않을 수 있지만, 장기적으로 충돌 해결에 드는 시간을 줄이고 작업 흐름을 개선할 수 있음을 어필했습니다.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h4>&lt;strong>작은 시작: 테스트 MR&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="작은-시작-테스트-mr">&lt;/span>
&lt;a href="#%ec%9e%91%ec%9d%80-%ec%8b%9c%ec%9e%91-%ed%85%8c%ec%8a%a4%ed%8a%b8-mr" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>설득만으로는 부족했기에, 저는 테스트 MR을 만들어 팀원들이 변화를 직접 체감할 수 있도록 했습니다.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>테스트 환경 구성&lt;/strong>:&lt;br>
간단한 기능을 dev 브랜치에서 작업한 뒤, 해당 기능을 PR 단위로 staging과 prod로 Merge하는 시뮬레이션을 진행했습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>기존 방식과 비교&lt;/strong>:&lt;br>
Cherry-pick 방식과 PR 방식을 비교하며, PR 방식을 통해 충돌이 발생하지 않고 작업 흐름이 매끄럽게 진행되는 모습을 보여줬습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>참여 독려&lt;/strong>:&lt;br>
팀원들이 직접 PR을 작성하고 리뷰를 요청해 볼 수 있도록 유도해, PR 작성과 리뷰가 복잡하지 않다는 점을 체감하게 만들었습니다.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/e28bbed8-4131-4b14-b886-bfaf4b889457/image.png" alt="" loading="lazy" />
(당시 설득을 위한 Test MR)&lt;/p>
&lt;hr>
&lt;h3>🌱 PR 기반 코드리뷰와 Git Flow의 실제 도입&lt;span class="hx:absolute hx:-mt-20" id="-pr-기반-코드리뷰와-git-flow의-실제-도입">&lt;/span>
&lt;a href="#-pr-%ea%b8%b0%eb%b0%98-%ec%bd%94%eb%93%9c%eb%a6%ac%eb%b7%b0%ec%99%80-git-flow%ec%9d%98-%ec%8b%a4%ec%a0%9c-%eb%8f%84%ec%9e%85" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;h4>&lt;strong>Git Flow 도입&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="git-flow-도입">&lt;/span>
&lt;a href="#git-flow-%eb%8f%84%ec%9e%85" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>Git Flow는 dev, staging, prod 간의 혼란을 정리하는 데 중요한 역할을 했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>- main (prod): 운영 환경
- staging: 운영과 동일한 조건의 테스트 환경
- dev: 개발 통합 브랜치
- feature/*: 기능 단위의 작업 브랜치
- hotfix/*: 긴급 수정 사항 처리 브랜치 &lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;ul>
&lt;li>&lt;strong>효과&lt;/strong>:
&lt;ol>
&lt;li>기능 개발과 병합 단계가 명확히 분리되면서 Cherry-pick 없이도 특정 작업만 staging에 반영 가능.&lt;/li>
&lt;li>Merge 전 리뷰와 테스트가 진행되면서 충돌 가능성이 대폭 감소.&lt;/li>
&lt;li>작업 이력이 명확히 관리되어, 누가 무엇을 했는지 쉽게 파악 가능.&lt;/li>
&lt;/ol>
&lt;/li>
&lt;/ul>
&lt;h4>&lt;strong>PR 코드리뷰: 최소 강제, 최대 자율&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="pr-코드리뷰-최소-강제-최대-자율">&lt;/span>
&lt;a href="#pr-%ec%bd%94%eb%93%9c%eb%a6%ac%eb%b7%b0-%ec%b5%9c%ec%86%8c-%ea%b0%95%ec%a0%9c-%ec%b5%9c%eb%8c%80-%ec%9e%90%ec%9c%a8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;p>코드리뷰를 강제적으로 도입하지 않고, 팀원들이 부담 없이 적응할 수 있도록 설계했습니다.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>리뷰어 지정 방식&lt;/strong>:&lt;br>
리뷰 요청자가 스스로 리뷰어를 지정할 수 있도록 해 강제성을 줄였습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Pn룰 도입&lt;/strong>:&lt;br>
Pn룰을 추가해 리뷰 강도 조절를 조절할 수 있게 하여 리뷰 과정을 협업과 학습의 장으로 만들었습니다.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>P1: 꼭 반영해주세요 (Request changes)
P2: 적극적으로 고려해주세요 (Request changes)
P3: 웬만하면 반영해 주세요 (Comment)
P4: 반영해도 좋고 넘어가도 좋습니다 (Approve)
P5: 그냥 사소한 의견입니다 (Approve)&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>저희는 다음과 같은 리뷰들이 주로 생기게 됐습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/03119a0d-20e6-4c05-8e74-9f9f72669494/image.png" alt="" loading="lazy" />
&lt;strong>물어보기&lt;/strong>&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/9e185383-0c74-4d50-9a35-51acd670dcfd/image.png" alt="" loading="lazy" />
&lt;strong>칭찬하기&lt;/strong>&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/8f0aba3c-0156-48a9-ae75-6b221ca9402b/image.png" alt="" loading="lazy" />
&lt;strong>놓친부분 있는지 확인해주기&lt;/strong>&lt;/p>
&lt;hr>
&lt;h3>도입 후 변화와 느낀 점&lt;span class="hx:absolute hx:-mt-20" id="도입-후-변화와-느낀-점">&lt;/span>
&lt;a href="#%eb%8f%84%ec%9e%85-%ed%9b%84-%eb%b3%80%ed%99%94%ec%99%80-%eb%8a%90%eb%82%80-%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;h4>&lt;strong>도입 후 성과&lt;/strong>&lt;span class="hx:absolute hx:-mt-20" id="도입-후-성과">&lt;/span>
&lt;a href="#%eb%8f%84%ec%9e%85-%ed%9b%84-%ec%84%b1%ea%b3%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;ol>
&lt;li>
&lt;p>&lt;strong>충돌 문제 감소&lt;/strong>:&lt;br>
PR 단위로 작업하면서 Cherry-pick이 필요 없어졌고, dev → staging → prod 병합 과정에서 충돌이 거의 발생하지 않았습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>작업 흐름의 투명성&lt;/strong>:&lt;br>
Git Flow와 PR을 통해 작업 이력과 변경 사항이 명확히 기록되면서 관리 효율이 증가했습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>협업 문화 정착&lt;/strong>:&lt;br>
코드리뷰는 단순한 오류 검출이 아니라, 협업과 학습의 장이 되었습니다.
작업자와 리뷰어가 소통하며 더 나은 코드에 대해 토론했고, 팀의 코드 품질이 전반적으로 향상되었습니다.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;hr>
&lt;h3>✨ 마무리하며&lt;span class="hx:absolute hx:-mt-20" id="-마무리하며">&lt;/span>
&lt;a href="#-%eb%a7%88%eb%ac%b4%eb%a6%ac%ed%95%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>PR 기반 코드리뷰와 Git Flow는 단순히 도구를 도입하는 것이 아니라, 팀 전체의 협업 문화를 바꾸는 여정이었습니다.&lt;/p>
&lt;p>새로운 시도를 한다는 건 언제나 쉽지 않습니다. 하지만 저희 팀원들은 &lt;strong>작은 변화에서 시작&lt;/strong>하여 이제는 없으면 안되는 회사의 개발 문화를 만들게 됐습니다.&lt;/p>
&lt;p>이 경험이 비슷한 상황을 고민하고 계신 분들께 작은 힌트가 되었으면 좋겠습니다. 😊&lt;/p></description></item><item><title>내가 느낀 클린 코드와 현실의 괴리</title><link>https://jeongil.dev/ko/blog/reflection/cleancode-and-real/</link><pubDate>Tue, 03 Dec 2024 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/reflection/cleancode-and-real/</guid><description>
&lt;p>개발을 하다 보면 &lt;strong>&amp;ldquo;클린 코드&amp;rdquo;&lt;/strong> 라는 단어를 접하게 됩니다.&lt;/p>
&lt;p>코드는 읽기 쉽고, 의도를 명확히 드러내며, 유지보수하기 쉬워야 한다는 원칙들이죠. 처음 클린 코드를 배울때 참 많은 것들을 느꼈습니다.&lt;/p>
&lt;p>변수하나의 네이밍을 붙이면서도 많은 고민을 해야하구나 하는 생각을 처음으로 하게 됐었거든요.&lt;/p>
&lt;p>하지만 실무에 발을 들이고 여러 프로젝트를 경험하다 보니 현실은 생각보다 복잡했습니다.&lt;/p>
&lt;p>마감일, 팀의 우선순위, 이미 존재하는 코드베이스의 복잡성 등 이상을 가로막는 다양한 현실적인 제약들이 있었죠.&lt;/p>
&lt;p>특히, &lt;strong>&amp;ldquo;이름 짓기&amp;rdquo;&lt;/strong> 라는 지점에서 이상과 현실의 괴리를 느낄때가 있었습니다. 클린 코드에서 강조하는 &lt;strong>&amp;ldquo;의도를 드러내는 이름&amp;rdquo;&lt;/strong> 은 당연히 중요하지만, 때때로 이상과 타협해야 할 순간들이 오곤 했던 것 같습니다.&lt;/p>
&lt;hr>
&lt;h3>클린 코드의 이상&lt;span class="hx:absolute hx:-mt-20" id="클린-코드의-이상">&lt;/span>
&lt;a href="#%ed%81%b4%eb%a6%b0-%ec%bd%94%eb%93%9c%ec%9d%98-%ec%9d%b4%ec%83%81" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>클린 코드를 배우면서 가장 인상 깊었던 것 중 하나는 &lt;strong>&amp;ldquo;의도를 드러내는 이름&amp;rdquo;&lt;/strong> 이었습니다. 이름만 봐도 클래스나 함수가 어떤 일을 하는지 알 수 있어야 한다는 원칙은 코드 가독성을 크게 높여준다고 생각합니다.&lt;/p>
&lt;p>예를 들어, &lt;code>OrderManager&lt;/code>라는 이름은 간결하면서도 클래스가 &amp;ldquo;주문을 관리&amp;quot;한다는 것을 한눈에 알아볼 수 있게 해주죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">OrderManager&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 주문 생성, 수정, 취소와 관련된 로직&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이런 이름은 직관적이고, 읽기 쉽고, 협업에서도 도움이 된다고 생각합니다. 저 또한 이런 이름을 짓기 위해 많은 노력을 기울이고 있고 고민하고 노력하는 만큼 제 코드가 깔끔해지는 것 같아 뿌듯함을 느끼고 있습니다.&lt;/p>
&lt;hr>
&lt;h3>이름 짓기의 어려움&lt;span class="hx:absolute hx:-mt-20" id="이름-짓기의-어려움">&lt;/span>
&lt;a href="#%ec%9d%b4%eb%a6%84-%ec%a7%93%ea%b8%b0%ec%9d%98-%ec%96%b4%eb%a0%a4%ec%9b%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>하지만, 항상 간결하고 직관적인 이름을 짓는 게 가능하진 않다는 걸 깨닫게 됐습니다. 복잡한 요구사항이나 협업 환경에서는 이름이 길고 복잡해질 수밖에 없는 상황이 발생하곤 했습니다.&lt;/p>
&lt;p>실제로, 이름 짓기의 어려움을 극단적으로 보여주는 사례를 한 가지 소개하겠습니다. Java의 &lt;code>AspectJ&lt;/code> 라이브러리에는 다음과 같은 클래스가 존재합니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">HasThisTypePatternTriedToSneakInSomeGenericOrParameterizedTypePatternMatchingStuffAnywhereVisitor&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">extends&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">AbstractPatternNodeVisitor&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>처음 이 이름을 봤을 때, &amp;ldquo;이게 진짜 클래스 이름인가?&amp;rdquo; 싶었습니다. 이름만 봐도 이 클래스가 &amp;ldquo;제네릭 또는 매개변수화된 타입 패턴 매칭을 시도했는지 확인하는 방문자&amp;quot;라는 역할을 한다는 점은 알겠지만, 너무 길고 복잡해서 다음과 같은 문제를 느끼게 됩니다.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>가독성 저하&lt;/strong>&lt;br>
IDE에서 이름이 잘리거나, 메서드 체인에 등장했을 때 코드의 가독성을 심각하게 해칩니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>협업의 비효율성&lt;/strong>&lt;br>
팀원과 코드에 대해 논의할 때, 이런 이름을 언급하는 데도 시간이 걸립니다. &amp;ldquo;그 긴 클래스 이름&amp;quot;이라고 불리는 상황이 될 가능성이 높다고 생각합니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>유지보수의 부담&lt;/strong>&lt;br>
이름을 오타 없이 정확히 작성하거나 변경해야 할 때, 길이와 복잡성 때문에 작업 시간이 늘어납니다.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;hr>
&lt;h3>왜 이런 이름이 만들어질까?&lt;span class="hx:absolute hx:-mt-20" id="왜-이런-이름이-만들어질까">&lt;/span>
&lt;a href="#%ec%99%9c-%ec%9d%b4%eb%9f%b0-%ec%9d%b4%eb%a6%84%ec%9d%b4-%eb%a7%8c%eb%93%a4%ec%96%b4%ec%a7%88%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>제가 생각하는 이런 이름이 탄생하는 이유는 다음과 같은 것들이 있습니다.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>명확성을 지나치게 추구할 때&lt;/strong>&lt;br>
이름에 모든 정보를 담으려다 보니 자연스럽게 길어지게 됩니다. 특히, 역할이 복잡하거나 다중 책임을 다룰 때는 이를 설명하려는 시도 자체가 이름을 장황하게 만든다고 생각합니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>특수한 도메인 요구사항&lt;/strong>&lt;br>
AspectJ와 같은 라이브러리는 복잡한 패턴 매칭과 관련된 작업을 다루기 때문에, 이름 자체가 도메인의 복잡성을 반영하는 경우가 있을 수 있다고 생각합니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>협업과 타협의 산물&lt;/strong>&lt;br>
팀 내에서 이름을 논의하다 보면, 모호함을 줄이기 위해 구체적으로 작성하자는 합의가 이루어질 때가 있다고 생각합니다. 결과적으로는 이런 컨벤션이 오히려 가독성을 해치는 경우도 있는 것 같습니다.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;hr>
&lt;h3>실제 경험&lt;span class="hx:absolute hx:-mt-20" id="실제-경험">&lt;/span>
&lt;a href="#%ec%8b%a4%ec%a0%9c-%ea%b2%bd%ed%97%98" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>저도 이런 딜레마를 겪은 적이 있습니다. 결제 관련 기능을 개발하던 중, 다음과 같은 이름을 고민했던 사례가 있었습니다.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>처음에는 &lt;code>PaymentProcessor&lt;/code>라는 이름을 지었습니다.&lt;br>
이 클래스가 결제를 처리한다는 점에서는 네이밍이 잘 됐다고 생각했습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>시간이 지나면서 클래스가 점점 다양한 역할을 맡게 되었습니다.&lt;br>
승인, 취소, 환불 같은 기능이 추가되면서, 기존의 이름만으로는 모든 역할을 설명하기 어렵다는 생각이 들었습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>그래서 &lt;code>PaymentApprovalAndRefundHandler&lt;/code>라는 이름으로 변경했습니다.&lt;br>
역할을 좀 더 명확히 드러내려고 했지만, 이름이 길어지니 오히려 코드 가독성이 떨어졌습니다. 그리고 기능이 추가될때마다 이름이 더 길어져야하나&amp;hellip;? 라는 생각을 가지게 됐습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>결국 다시 &lt;code>PaymentHandler&lt;/code>로 간결하게 바꾸고, 상세한 역할 설명은 주석으로 보완했습니다.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>이 과정에서 느낀 건 이름에 모든 걸 담으려고 하기보다는, 코드 자체의 가독성과 유지보수를 고려하는 것이 더 중요하구나 라는 점이었습니다.&lt;/p>
&lt;hr>
&lt;h3>이상과 현실 사이에서의 타협&lt;span class="hx:absolute hx:-mt-20" id="이상과-현실-사이에서의-타협">&lt;/span>
&lt;a href="#%ec%9d%b4%ec%83%81%ea%b3%bc-%ed%98%84%ec%8b%a4-%ec%82%ac%ec%9d%b4%ec%97%90%ec%84%9c%ec%9d%98-%ed%83%80%ed%98%91" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>결국, 클린 코드의 원칙을 지키면서도 현실과 타협하기 위한 기준을 세워야 한다는 것을 배웠습니다. 제가 현재 생각하는 기준은 다음과 같습니다.&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>단일책임 원칙을 기억하자&lt;/strong>
클래스가 하나의 책임만 가지게 하면 이름이 간결해지기 쉽다고 생각합니다. 여러 책임을 가지게 된다면 네이밍이 어려워질 가능성이 큰 것 같습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>간결함을 우선으로&lt;/strong>&lt;br>
이름은 핵심적인 역할만 담도록 합니다. 구체적인 설명이 필요할때는 주석으로 보완합니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>컨텍스트를 고려&lt;/strong>&lt;br>
코드가 작성된 도메인이나 프로젝트 맥락에서 충분히 이해될 수 있는 이름을 짓습니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>팀 규칙 우선&lt;/strong>&lt;br>
팀원들과 논의해 합의된 명명 규칙을 따릅니다. 협업에서는 일관성이 중요하다고 생각합니다.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>코드와 이름은 함께 발전한다&lt;/strong>&lt;br>
코드가 변경되면 이름도 바뀌어야 한다고 생각합니다. 완벽한 이름을 처음부터 정하겠다는 부담을 덜어낼 필요가 있는 것 같습니다.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;hr>
&lt;h3>결론&lt;span class="hx:absolute hx:-mt-20" id="결론">&lt;/span>
&lt;a href="#%ea%b2%b0%eb%a1%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;code>HasThisTypePatternTriedToSneakInSomeGenericOrParameterizedTypePatternMatchingStuffAnywhereVisitor&lt;/code> 같은 이름이 클린 코드와 현실의 괴리를 보여주는 사례 중 하나라고 생각합니다. 처음엔 &amp;ldquo;이게 뭐야?&amp;rdquo; 싶었지만, 이를 통해 &lt;strong>&amp;ldquo;네이밍은 이상과 현실 사이에서 늘 고민해야 한다&amp;rdquo;&lt;/strong> 는 점을 다시금 느끼게 되네요.&lt;/p>
&lt;p>아직 완벽한 답을 얻지는 못했지만, 이런 고민들을 통해 매번 조금이라도 더 나은 코드를 작성하고 싶다고 생각하고 있습니다. :)&lt;/p></description></item><item><title>[회고록] JPA와 MyBatis 혼용으로 발생한 HikariCP Deadlock 문제를 해결하며</title><link>https://jeongil.dev/ko/blog/reflection/hikaricp-deadlock-with-jpa-mybatis-memoir/</link><pubDate>Mon, 02 Dec 2024 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/reflection/hikaricp-deadlock-with-jpa-mybatis-memoir/</guid><description>
&lt;p>2024년 초, 예상치 못한 문제와 마주한 사건이 있었습니다. &lt;a href="https://jeongil.dev/ko/blog/backend/troubleshooting/hikaricp-deadlock-with-jpa-mybatis/">(해당 글)&lt;/a>
당시의 상황에 대한 회고록을 작성하려 합니다.&lt;/p>
&lt;p>JPA와 MyBatis를 혼용한 코드에서 HikariCP Deadlock 문제가 발생했는데요.
몇 달간 문제없이 운영되던 코드였기에 더욱 당황스러웠습니다.&lt;/p>
&lt;p>해결 과정에서 JPA, HikariCP, 그리고 영속성 컨텍스트의 동작 원리를 깊이 이해할 수 있었던 이 경험을 정리해보았습니다.&lt;/p>
&lt;hr>
&lt;h2>문제와의 첫 만남: 예상 밖의 Deadlock&lt;span class="hx:absolute hx:-mt-20" id="문제와의-첫-만남-예상-밖의-deadlock">&lt;/span>
&lt;a href="#%eb%ac%b8%ec%a0%9c%ec%99%80%ec%9d%98-%ec%b2%ab-%eb%a7%8c%eb%82%a8-%ec%98%88%ec%83%81-%eb%b0%96%ec%9d%98-deadlock" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>📌 Slack 알림으로 시작된 문제&lt;span class="hx:absolute hx:-mt-20" id="-slack-알림으로-시작된-문제">&lt;/span>
&lt;a href="#-slack-%ec%95%8c%eb%a6%bc%ec%9c%bc%eb%a1%9c-%ec%8b%9c%ec%9e%91%eb%90%9c-%eb%ac%b8%ec%a0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>트래픽이 몰리는 시간, Slack에 아래와 같은 알림이 도착했습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30008ms.&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>처음에는 제가 모르는 Connection Pool 관련 Exception으로 생각했습니다. 하지만 로그를 확인하며 문제의 심각성을 깨달았습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>HikariPool-1 - Timeout failure stats (total=40, active=40, idle=0, waiting=46)&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>HikariCP에서 &lt;code>maximum-pool-size&lt;/code>로 설정된 40개의 Connection이 모두 점유된 상태였고, 대기 큐까지 꽉 차 있었습니다. 더욱 당황스러웠던 점은 이 로직이 몇 달 동안 잘 작동해왔다는 것입니다.&lt;/p>
&lt;h3>왜 갑자기 문제가 발생했을까?&lt;span class="hx:absolute hx:-mt-20" id="왜-갑자기-문제가-발생했을까">&lt;/span>
&lt;a href="#%ec%99%9c-%ea%b0%91%ec%9e%90%ea%b8%b0-%eb%ac%b8%ec%a0%9c%ea%b0%80-%eb%b0%9c%ec%83%9d%ed%96%88%ec%9d%84%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>첫 번째 의문은 &amp;ldquo;왜 지금 이 문제가 발생했는가?&amp;ldquo;였습니다.&lt;/p>
&lt;ul>
&lt;li>설정 문제라면 이전에도 발생했어야 했습니다.&lt;/li>
&lt;li>코드가 수정된 적이 없는데 문제가 생긴 이유는 무엇일까요?&lt;/li>
&lt;/ul>
&lt;p>이 의문은 문제를 해결하는 내내 저를 괴롭혔고, 결국 문제 해결의 중요한 단서가 되었습니다.&lt;/p>
&lt;hr>
&lt;h2>원인 분석: 의심과 확인의 반복&lt;span class="hx:absolute hx:-mt-20" id="원인-분석-의심과-확인의-반복">&lt;/span>
&lt;a href="#%ec%9b%90%ec%9d%b8-%eb%b6%84%ec%84%9d-%ec%9d%98%ec%8b%ac%ea%b3%bc-%ed%99%95%ec%9d%b8%ec%9d%98-%eb%b0%98%eb%b3%b5" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>1. 재현 환경 구축: Local에서 재현&lt;span class="hx:absolute hx:-mt-20" id="1-재현-환경-구축-local에서-재현">&lt;/span>
&lt;a href="#1-%ec%9e%ac%ed%98%84-%ed%99%98%ea%b2%bd-%ea%b5%ac%ec%b6%95-local%ec%97%90%ec%84%9c-%ec%9e%ac%ed%98%84" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>먼저 문제를 재현하기 위해 테스트 환경에서 &lt;code>maximum-pool-size&lt;/code>를 1로 설정했습니다. 이로서 Exception 발생지점을 특정할 수 있었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">long&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">findBy&lt;/span>&lt;span class="o">~~~&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">factory&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">select&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">serviceNotice&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">count&lt;/span>&lt;span class="p">())&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">from&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">serviceNotice&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">where&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">serviceNotice&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">actType&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">eq&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;특정 조건&amp;#34;&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">serviceNotice&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">section&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">eq&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;특정 조건&amp;#34;&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">serviceNotice&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">actEnable&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">eq&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">fetchOne&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>QueryDSL로 작성된 단순한 Select 쿼리였는데도 Connection이 반환되지 않고 점유 상태로 남아 있었습니다.&lt;/p>
&lt;hr>
&lt;h3>2. Connection Leak인가?&lt;span class="hx:absolute hx:-mt-20" id="2-connection-leak인가">&lt;/span>
&lt;a href="#2-connection-leak%ec%9d%b8%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>처음엔 Connection Leak을 의심했습니다.&lt;/p>
&lt;ul>
&lt;li>&amp;ldquo;이 로직이 끝난 후 Connection을 반환하지 않는 이유는 무엇일까?&amp;rdquo;&lt;/li>
&lt;li>&amp;ldquo;Connection 반환 로직이 누락되었을 가능성은 없을까?&amp;rdquo;&lt;/li>
&lt;/ul>
&lt;p>하지만 QueryDSL을 사용하는 코드 내부에서 명시적으로 Connection을 닫지 않아도 Connection이 자동으로 반환되어야 합니다. 관련 문서를 확인한 결과 OSIV(Open Session In View)와 관련된 문제일 가능성이 떠올랐습니다.&lt;/p>
&lt;hr>
&lt;h3>3. OSIV와 영속성 컨텍스트&lt;span class="hx:absolute hx:-mt-20" id="3-osiv와-영속성-컨텍스트">&lt;/span>
&lt;a href="#3-osiv%ec%99%80-%ec%98%81%ec%86%8d%ec%84%b1-%ec%bb%a8%ed%85%8d%ec%8a%a4%ed%8a%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>OSIV는 웹 요청이 끝날 때까지 영속성 컨텍스트(EntityManager)를 유지합니다.&lt;br>
이는 Lazy Loading을 가능하게 하고, View 계층에서 데이터베이스와의 연동을 지원하지만, Connection 반환을 지연시키는 단점이 있습니다.&lt;/p>
&lt;blockquote>
&lt;p>OSIV로 인해 트랜잭션이 끝난 뒤에도 Connection이 반환되지 않고 점유 상태로 남아 있었습니다.&lt;/p>
&lt;/blockquote>
&lt;hr>
&lt;h3>4. OSIV와 상관없는 Deadlock? 트랜잭션 내부 혼용의 문제&lt;span class="hx:absolute hx:-mt-20" id="4-osiv와-상관없는-deadlock-트랜잭션-내부-혼용의-문제">&lt;/span>
&lt;a href="#4-osiv%ec%99%80-%ec%83%81%ea%b4%80%ec%97%86%eb%8a%94-deadlock-%ed%8a%b8%eb%9e%9c%ec%9e%ad%ec%85%98-%eb%82%b4%eb%b6%80-%ed%98%bc%ec%9a%a9%ec%9d%98-%eb%ac%b8%ec%a0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>문제를 더 깊이 조사한 결과, OSIV 설정 여부와 상관없이 &lt;strong>동일 Transaction 내에서 JPA와 MyBatis를 혼용&lt;/strong>하면 Deadlock이 발생할 수 있다는 점을 확인했습니다.&lt;br>
동일 Transaction 내에서 JPA가 Connection을 점유한 상태로 MyBatis가 추가로 Connection을 요청했기 때문입니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Transactional&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">problematicMethod&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">jpaSelectMethod&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// Connection Pool에서 1개 점유&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">mybatisSelectMethod&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 추가 Connection 요청 -&amp;gt; Deadlock&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>HikariCP Deadlock이 발생할 수 있는 조건은 하나의 요청에서 동시에 두개 이상의 Connection을 필요로하는 경우임으로 위와 같은 경우 조건을 만족하게 됩니다.&lt;/p>
&lt;hr>
&lt;h3>5. 왜 지금 발생했는가?&lt;span class="hx:absolute hx:-mt-20" id="5-왜-지금-발생했는가">&lt;/span>
&lt;a href="#5-%ec%99%9c-%ec%a7%80%ea%b8%88-%eb%b0%9c%ec%83%9d%ed%96%88%eb%8a%94%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>이 문제가 몇 달 동안 발생하지 않았던 이유는 쿠버네티스 파드 수 때문이었습니다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>기존:&lt;/strong> 트래픽 분산을 위해 최소 5개의 파드를 운영.&lt;/li>
&lt;li>&lt;strong>현재:&lt;/strong> 비용 절감을 위해 파드 수를 2개로 줄임.&lt;/li>
&lt;/ul>
&lt;p>파드 수 감소로 인해 한 파드에 트래픽이 몰리면서 Connection Pool이 모두 점유되는 상황이 발생하게 되었던 것입니다.&lt;/p>
&lt;hr>
&lt;h2>해결 방법&lt;span class="hx:absolute hx:-mt-20" id="해결-방법">&lt;/span>
&lt;a href="#%ed%95%b4%ea%b2%b0-%eb%b0%a9%eb%b2%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>1. OSIV 비활성화&lt;span class="hx:absolute hx:-mt-20" id="1-osiv-비활성화">&lt;/span>
&lt;a href="#1-osiv-%eb%b9%84%ed%99%9c%ec%84%b1%ed%99%94" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>OSIV를 비활성화(&lt;code>spring.jpa.open-in-view=false&lt;/code>)하면 트랜잭션 종료 시 Connection을 반환하도록 설정할 수 있었습니다. 하지만 OSIV를 끄면 Lazy Loading 처리 방식에 영향을 줄 수 있어 기존 코드의 수정이 필요했습니다.&lt;/p>
&lt;p>또한 OSIV 옵션과는 별개로 한 Transaction 안에서 혼용할 경우 마찬가지로 Deadlock이 발생할 수 있었음으로 근본적인 해결책은 아니였습니다.&lt;/p>
&lt;p>&lt;strong>결론:&lt;/strong> OSIV 설정 변경은 보류.&lt;/p>
&lt;hr>
&lt;h3>2. JPA와 MyBatis 혼용 제거&lt;span class="hx:absolute hx:-mt-20" id="2-jpa와-mybatis-혼용-제거">&lt;/span>
&lt;a href="#2-jpa%ec%99%80-mybatis-%ed%98%bc%ec%9a%a9-%ec%a0%9c%ea%b1%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>문제의 원인은 동일 Transaction 내에서 JPA와 MyBatis를 동시에 사용하는 것이었습니다.&lt;/p>
&lt;p>JPA와 Mybatis를 한 Transaction 내에서 동시에 사용하지 않도록 코드를 리팩토링한다면 발생시키지 않을 수 있어 코드레벨에서의 문제 해결이 가능했습니다.&lt;/p>
&lt;p>&lt;strong>결론:&lt;/strong> JPA와 MyBatis의 분리가 근본적인 해결책.&lt;/p>
&lt;hr>
&lt;h3>임시 조치: 파드 수 증가&lt;span class="hx:absolute hx:-mt-20" id="임시-조치-파드-수-증가">&lt;/span>
&lt;a href="#%ec%9e%84%ec%8b%9c-%ec%a1%b0%ec%b9%98-%ed%8c%8c%eb%93%9c-%ec%88%98-%ec%a6%9d%ea%b0%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>문제 해결 전까지 쿠버네티스의 파드 수를 기존 2개에서 5개로 다시 늘려 트래픽을 분산시켰습니다.&lt;/p>
&lt;hr>
&lt;h2>회고: 이 문제에서 배운 것들&lt;span class="hx:absolute hx:-mt-20" id="회고-이-문제에서-배운-것들">&lt;/span>
&lt;a href="#%ed%9a%8c%ea%b3%a0-%ec%9d%b4-%eb%ac%b8%ec%a0%9c%ec%97%90%ec%84%9c-%eb%b0%b0%ec%9a%b4-%ea%b2%83%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이번 경험은 단순한 문제 해결을 넘어, 기본 개념을 깊이 이해하는 계기가 되었습니다.&lt;/p>
&lt;p>&lt;strong>배운 점 1. JPA와 Connection Pool의 상호작용&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>영속성 컨텍스트와 Connection 반환 시점을 명확히 이해해야 한다는 점.&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>배운 점 2. 문제를 재현하는 방법론&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>문제가 발생한 조건을 테스트 환경에서 재현하며 원인을 좁혀나가는 것이 중요했습니다.&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>배운 점 3. 기술 혼용의 리스크&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>JPA와 MyBatis처럼 서로 다른 Connection 관리 방식을 사용하는 기술을 혼용할 때의 위험성을 느꼈습니다.&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2>마무리&lt;span class="hx:absolute hx:-mt-20" id="마무리">&lt;/span>
&lt;a href="#%eb%a7%88%eb%ac%b4%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이 문제는 주니어 개발자인 저에게 많은 것을 가르쳐 준 사건이었습니다.&lt;br>
특히, 문제를 정의하고 원인을 좁혀가는 과정에서 느꼈던 성취는 잊지 못할 경험이 되었습니다. 앞으로도 이런 경험을 통해 한 단계씩 성장해 나가고 싶습니다.&lt;/p>
&lt;hr>
&lt;h3>Reference&lt;span class="hx:absolute hx:-mt-20" id="reference">&lt;/span>
&lt;a href="#reference" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;a href="https://techblog.woowahan.com/2664/"target="_blank" rel="noopener">https://techblog.woowahan.com/2664/&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://techblog.woowahan.com/2663/"target="_blank" rel="noopener">https://techblog.woowahan.com/2663/&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://colin-d.medium.com/querydsl-%EC%97%90%EC%84%9C-db-connection-leak-%EC%9D%B4%EC%8A%88-40d426fd4337"target="_blank" rel="noopener">https://colin-d.medium.com/querydsl-%EC%97%90%EC%84%9C-db-connection-leak-%EC%9D%B4%EC%8A%88-40d426fd4337&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://saramin.github.io/2023-04-27-order-error/"target="_blank" rel="noopener">https://saramin.github.io/2023-04-27-order-error/&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://github.com/brettwooldridge/HikariCP"target="_blank" rel="noopener">https://github.com/brettwooldridge/HikariCP&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://perfectacle.github.io/2021/05/24/entity-manager-lifecycle/"target="_blank" rel="noopener">https://perfectacle.github.io/2021/05/24/entity-manager-lifecycle/&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://ykh6242.tistory.com/m/entry/JPA-OSIVOpen-Session-In-View%EC%99%80-%EC%84%B1%EB%8A%A5-%EC%B5%9C%EC%A0%81%ED%99%94"target="_blank" rel="noopener">https://ykh6242.tistory.com/m/entry/JPA-OSIVOpen-Session-In-View%EC%99%80-%EC%84%B1%EB%8A%A5-%EC%B5%9C%EC%A0%81%ED%99%94&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://www.blog.kcd.co.kr/jpa-%EC%98%81%EC%86%8D%EC%84%B1-%EC%BB%A8%ED%85%8D%EC%8A%A4%ED%8A%B8%EC%99%80-osiv-3c5521e6de9f"target="_blank" rel="noopener">https://www.blog.kcd.co.kr/jpa-%EC%98%81%EC%86%8D%EC%84%B1-%EC%BB%A8%ED%85%8D%EC%8A%A4%ED%8A%B8%EC%99%80-osiv-3c5521e6de9f&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p></description></item><item><title>JPA의 설계 철학과 SQL의 간극, 그리고 현실적인 대안</title><link>https://jeongil.dev/ko/blog/architecture/jpa-sql-ideology-and-gap/</link><pubDate>Thu, 28 Nov 2024 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/architecture/jpa-sql-ideology-and-gap/</guid><description>
&lt;p>JPA를 사용하다 보면 &amp;ldquo;어라, 이건 왜 안 되지?&amp;ldquo;라는 순간을 마주하게 됩니다. SQL에서는 당연하게 사용하던 기능이 JPQL에서는 지원되지 않아 당황했던 경험, 아마 JPA를 사용해보신 분이라면 한 번쯤은 있으실 거라 생각합니다.&lt;/p>
&lt;p>이 글에서는 JPA와 SQL 사이의 간극이 왜 존재하는지, 그리고 실무에서 이런 한계를 어떻게 극복할 수 있는지 제 경험을 바탕으로 이야기해보려 합니다.&lt;/p>
&lt;h2>JPA가 추구하는 것&lt;span class="hx:absolute hx:-mt-20" id="jpa가-추구하는-것">&lt;/span>
&lt;a href="#jpa%ea%b0%80-%ec%b6%94%ea%b5%ac%ed%95%98%eb%8a%94-%ea%b2%83" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>JPA와 SQL의 간극을 이해하려면, 먼저 JPA가 왜 만들어졌는지를 이해할 필요가 있다고 생각합니다.&lt;/p>
&lt;p>JPA는 단순히 &amp;ldquo;SQL을 자바 코드로 감싸는 도구&amp;quot;가 아닌 것 같습니다. &lt;strong>객체 지향적인 방식으로 데이터를 다루자&lt;/strong>는 철학을 가지고 설계된 것으로 보입니다.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
subgraph &amp;#34;전통적인 접근&amp;#34;
App1[&amp;#34;애플리케이션&amp;#34;] --&amp;gt; SQL[&amp;#34;SQL 작성&amp;#34;]
SQL --&amp;gt; DB1[&amp;#34;Database&amp;#34;]
end
subgraph &amp;#34;JPA의 접근&amp;#34;
App2[&amp;#34;애플리케이션&amp;#34;] --&amp;gt; Entity[&amp;#34;Entity 조작&amp;#34;]
Entity --&amp;gt; JPA[&amp;#34;JPA&amp;#34;]
JPA --&amp;gt; DB2[&amp;#34;Database&amp;#34;]
end
&lt;/pre>&lt;p>제가 이해한 JPA의 핵심 설계 원칙을 정리하면 다음과 같습니다.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>원칙&lt;/th>
&lt;th>설명&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>엔티티 중심&lt;/strong>&lt;/td>
&lt;td>테이블이 아닌 객체(Entity)를 중심으로 사고&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>데이터베이스 독립성&lt;/strong>&lt;/td>
&lt;td>특정 DBMS에 종속되지 않는 추상화 계층&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>객체 그래프 탐색&lt;/strong>&lt;/td>
&lt;td>연관 관계를 통한 자연스러운 데이터 접근&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>영속성 컨텍스트&lt;/strong>&lt;/td>
&lt;td>1차 캐시, 변경 감지 등 객체 상태 관리&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>이런 철학 때문에 JPA(JPQL)는 의도적으로 SQL의 모든 기능을 지원하지 않는 것 같습니다. &lt;strong>&amp;ldquo;엔티티 중심의 사고를 했다면 이 기능이 필요할까?&amp;rdquo;&lt;/strong> 라는 관점에서 설계된 게 아닐까 싶어요.&lt;/p>
&lt;h2>JPQL에서 지원하지 않는 것들&lt;span class="hx:absolute hx:-mt-20" id="jpql에서-지원하지-않는-것들">&lt;/span>
&lt;a href="#jpql%ec%97%90%ec%84%9c-%ec%a7%80%ec%9b%90%ed%95%98%ec%a7%80-%ec%95%8a%eb%8a%94-%ea%b2%83%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>그렇다면 JPQL에서 지원하지 않는 기능들에는 어떤 것들이 있을까요? 제가 실무에서 직접 마주쳤던 대표적인 케이스들을 살펴보겠습니다.&lt;/p>
&lt;h3>1. UNION / UNION ALL&lt;span class="hx:absolute hx:-mt-20" id="1-union--union-all">&lt;/span>
&lt;a href="#1-union--union-all" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>SQL에서 &lt;code>UNION&lt;/code>은 여러 쿼리 결과를 하나로 합치는 기본적인 기능입니다. 하지만 JPQL은 이를 지원하지 않습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- SQL에서는 가능
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;CUSTOMER&amp;#39;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">as&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">type&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">customer&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">UNION&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ALL&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;PARTNER&amp;#39;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">as&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">type&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">partner&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>왜 지원하지 않을까요? 제가 생각해본 바로는, JPA 관점에서 &lt;strong>UNION은 서로 다른 테이블(엔티티)의 결과를 하나로 합치는 연산&lt;/strong>입니다. 그런데 JPA는 엔티티 단위로 사고하도록 설계되었기 때문에, &amp;ldquo;Customer 엔티티와 Partner 엔티티를 합친다&amp;quot;는 개념 자체가 객체 지향적 관점에서는 어색할 수 있는 것 같습니다.&lt;/p>
&lt;p>어떻게 보면 JPA가 이렇게 묻는 것 같기도 합니다.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;왜 서로 다른 엔티티를 합쳐야 하죠? 상속 관계로 설계하면 안 되나요?&amp;rdquo;&lt;/p>
&lt;/blockquote>
&lt;p>물론 실무에서는 UNION이 필요한 상황이 분명히 있습니다. 레거시 테이블 구조를 다뤄야 하거나, 리포트 쿼리를 작성해야 하는 경우처럼요.&lt;/p>
&lt;h3>2. FROM 절 서브쿼리&lt;span class="hx:absolute hx:-mt-20" id="2-from-절-서브쿼리">&lt;/span>
&lt;a href="#2-from-%ec%a0%88-%ec%84%9c%eb%b8%8c%ec%bf%bc%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>SQL에서는 서브쿼리를 FROM 절에 넣어 임시 테이블처럼 사용할 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- SQL에서는 가능
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user_id&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">SUM&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">amount&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">as&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">total&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">orders&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">GROUP&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">BY&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user_id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">as&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user_totals&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">total&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">10000&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>JPQL에서는 이것이 불가능합니다. JPA는 &lt;strong>엔티티를 기준으로 쿼리&lt;/strong>하기 때문에, &amp;ldquo;임시로 만들어진 결과 집합&amp;quot;을 대상으로 쿼리한다는 개념이 맞지 않는 것 같습니다.&lt;/p>
&lt;h3>3. 서브쿼리 내 LIMIT&lt;span class="hx:absolute hx:-mt-20" id="3-서브쿼리-내-limit">&lt;/span>
&lt;a href="#3-%ec%84%9c%eb%b8%8c%ec%bf%bc%eb%a6%ac-%eb%82%b4-limit" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>SQL에서는 서브쿼리 내에서도 LIMIT을 사용할 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;span class="lnt">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- SQL에서는 가능
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">users&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">u&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">u&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">o&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">user_id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">orders&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">o&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">ORDER&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">BY&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">o&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">created_at&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">DESC&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">LIMIT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">100&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">);&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>JPQL에서는 메인 쿼리에서만 &lt;code>setMaxResults()&lt;/code>로 페이징이 가능하고, 서브쿼리 내에서는 불가능합니다.&lt;/p>
&lt;h3>4. INSERT 문&lt;span class="hx:absolute hx:-mt-20" id="4-insert-문">&lt;/span>
&lt;a href="#4-insert-%eb%ac%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>JPQL은 &lt;code>INSERT&lt;/code>를 지원하지 않습니다. JPA에서 데이터를 저장하려면 &lt;code>EntityManager.persist()&lt;/code>를 사용해야 하죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// JPQL로는 불가능&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">// INSERT INTO User (name, email) VALUES (&amp;#39;홍길동&amp;#39;, &amp;#39;hong@example.com&amp;#39;)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">// JPA 방식&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">User&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">User&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;홍길동&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;hong@example.com&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">entityManager&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">persist&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="p">);&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이건 JPA의 설계 철학과 가장 맞닿아 있는 부분이라고 생각합니다. JPA는 &lt;strong>객체의 상태 변화를 추적하고, 그것을 DB에 반영&lt;/strong>하는 방식으로 동작하기 때문에, 직접 INSERT 쿼리를 날리는 건 이 철학과 맞지 않는 것 같습니다.&lt;/p>
&lt;h2>왜 이런 설계를 했을까?&lt;span class="hx:absolute hx:-mt-20" id="왜-이런-설계를-했을까">&lt;/span>
&lt;a href="#%ec%99%9c-%ec%9d%b4%eb%9f%b0-%ec%84%a4%ea%b3%84%eb%a5%bc-%ed%96%88%ec%9d%84%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>처음에는 &amp;ldquo;왜 이렇게 제한이 많지?&amp;ldquo;라고 생각했습니다. 하지만 JPA의 입장에서 생각해보면 나름의 이유가 있다고 느꼈습니다.&lt;/p>
&lt;h3>데이터베이스 독립성&lt;span class="hx:absolute hx:-mt-20" id="데이터베이스-독립성">&lt;/span>
&lt;a href="#%eb%8d%b0%ec%9d%b4%ed%84%b0%eb%b2%a0%ec%9d%b4%ec%8a%a4-%eb%8f%85%eb%a6%bd%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>JPA는 특정 DBMS에 종속되지 않는 것을 목표로 하는 것 같습니다. &lt;code>LIMIT&lt;/code>은 MySQL 문법이고, Oracle에서는 &lt;code>ROWNUM&lt;/code>이나 &lt;code>FETCH FIRST&lt;/code>를 사용합니다. 모든 DBMS의 고유 기능을 다 지원하려면 추상화가 깨지게 되겠죠.&lt;/p>
&lt;h3>객체 그래프 중심 사고&lt;span class="hx:absolute hx:-mt-20" id="객체-그래프-중심-사고">&lt;/span>
&lt;a href="#%ea%b0%9d%ec%b2%b4-%ea%b7%b8%eb%9e%98%ed%94%84-%ec%a4%91%ec%8b%ac-%ec%82%ac%ea%b3%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>JPA는 테이블 간의 JOIN보다 &lt;strong>엔티티 간의 연관 관계 탐색&lt;/strong>을 권장하는 것 같습니다. &lt;code>user.getOrders()&lt;/code>처럼 객체를 통해 관련 데이터에 접근하는 방식이죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// JPA가 권장하는 방식&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">User&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">entityManager&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">find&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">User&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">class&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">List&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">Order&lt;/span>&lt;span class="o">&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">orders&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getOrders&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// Lazy Loading&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">// SQL 중심의 방식&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">users&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">u&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">JOIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">orders&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">o&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">u&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">o&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">user_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">u&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>엔티티 설계의 강제&lt;span class="hx:absolute hx:-mt-20" id="엔티티-설계의-강제">&lt;/span>
&lt;a href="#%ec%97%94%ed%8b%b0%ed%8b%b0-%ec%84%a4%ea%b3%84%ec%9d%98-%ea%b0%95%ec%a0%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>JPQL의 제약은 어떻게 보면 &lt;strong>&amp;ldquo;엔티티 설계를 더 잘 하라&amp;quot;는 강제&lt;/strong>일 수도 있다고 생각합니다. UNION이 필요하다면 상속 구조로 설계할 수는 없는지, 서브쿼리가 필요하다면 연관 관계로 해결할 수는 없는지 고민하게 만드니까요.&lt;/p>
&lt;h2>그러나 요구사항은 언제든 변한다&lt;span class="hx:absolute hx:-mt-20" id="그러나-요구사항은-언제든-변한다">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%9f%ac%eb%82%98-%ec%9a%94%ea%b5%ac%ec%82%ac%ed%95%ad%ec%9d%80-%ec%96%b8%ec%a0%9c%eb%93%a0-%eb%b3%80%ed%95%9c%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>위에서 JPA의 설계 철학을 설명했지만, 현실적인 개발 환경에서는 요구사항이 자주 변하며, 데이터베이스와 객체 간의 간극이 생기는 경우가 있습니다.&lt;/p>
&lt;h3>1. 내가 설계한 테이블이 아닐 때&lt;span class="hx:absolute hx:-mt-20" id="1-내가-설계한-테이블이-아닐-때">&lt;/span>
&lt;a href="#1-%eb%82%b4%ea%b0%80-%ec%84%a4%ea%b3%84%ed%95%9c-%ed%85%8c%ec%9d%b4%eb%b8%94%ec%9d%b4-%ec%95%84%eb%8b%90-%eb%95%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>프로젝트 초기부터 객체 지향적 설계를 기반으로 데이터베이스를 설계했다면, 간극은 좁아질 수 있습니다. 하지만 실무에서는 대부분 이미 설계된 테이블, 즉 &lt;strong>레거시 데이터베이스&lt;/strong>를 다뤄야 할 때가 많습니다.&lt;/p>
&lt;p>그럴때마다 &lt;strong>단지 JPA를 사용하기 위해서 스키마를 변경하고 데이터를 마이그레이션 해야하는 걸까요?&lt;/strong>&lt;/p>
&lt;p>저도 실무에서 이런 상황을 겪었습니다. 기존 시스템의 테이블 구조는 JPA 친화적이지 않았고, 테이블 구조 변경은 다른 시스템에도 영향을 주기 때문에 함부로 할 수 없었습니다.&lt;/p>
&lt;h3>2. 갑작스러운 요구사항 변경&lt;span class="hx:absolute hx:-mt-20" id="2-갑작스러운-요구사항-변경">&lt;/span>
&lt;a href="#2-%ea%b0%91%ec%9e%91%ec%8a%a4%eb%9f%ac%ec%9a%b4-%ec%9a%94%ea%b5%ac%ec%82%ac%ed%95%ad-%eb%b3%80%ea%b2%bd" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>요구사항은 항상 변합니다. 처음에는 단순했던 데이터 모델이 시간이 지나면서 복잡해지고, 비즈니스 로직이 변경되며 기존의 설계나 시스템에 영향을 미칠 수 있습니다. 이때 JPA가 제공하는 추상화 계층이 유연성을 확보하는 데 도움이 되기보다는 오히려 장애물이 되는 경우도 있다고 생각합니다.&lt;/p>
&lt;p>만약 처음에는 단순히 &amp;ldquo;고객과 주문&amp;quot;이라는 두 개의 테이블만 처리하면 되었지만, 이후 주문 테이블에 &amp;ldquo;배송 상태&amp;rdquo;, &amp;ldquo;결제 이력&amp;rdquo;, &amp;ldquo;환불 처리&amp;rdquo; 등 추가 정보를 관리해야 하는 상황이 발생했다고 가정해보면 기존 설계를 유지하면서 데이터를 처리하기 위해 추가적인 엔티티나 관계 매핑이 필요하게 됩니다. 이러한 요구사항은 기존의 코드 전체에 영향을 미칠 수 있습니다. 특히, 연관 관계가 깊게 설정된 엔티티일수록 변경으로 인한 영향 범위가 기하급수적으로 커집니다.&lt;/p>
&lt;h3>3. 복잡한 쿼리 요구사항&lt;span class="hx:absolute hx:-mt-20" id="3-복잡한-쿼리-요구사항">&lt;/span>
&lt;a href="#3-%eb%b3%b5%ec%9e%a1%ed%95%9c-%ec%bf%bc%eb%a6%ac-%ec%9a%94%ea%b5%ac%ec%82%ac%ed%95%ad" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>기존의 단순한 데이터 조회에서 벗어나, 갑작스럽게 &amp;ldquo;가장 많이 구매한 고객&amp;rdquo;, &amp;ldquo;특정 기간 내 주문 증가율&amp;rdquo; 등 비즈니스 인사이트를 위한 복잡한 집계 쿼리를 작성해야 할 때가 있습니다.&lt;/p>
&lt;p>이럴때 JPQL은 위에 제약들로 복잡한 집계나 조건부 쿼리에 적합하지 않은 경우들이 있습니다. 특히, 서브쿼리, 조인, 그룹화, 윈도우 함수 등 SQL의 고급 기능을 활용하기 어려운 상황이 생깁니다.&lt;/p>
&lt;p>이런 경우, 결국 다시금 Native Query로 돌아가야 합니다.&lt;/p>
&lt;h2>현실적인 대안들&lt;span class="hx:absolute hx:-mt-20" id="현실적인-대안들">&lt;/span>
&lt;a href="#%ed%98%84%ec%8b%a4%ec%a0%81%ec%9d%b8-%eb%8c%80%ec%95%88%eb%93%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>그렇다면 실무에서는 이런 한계를 어떻게 극복할 수 있을까요? 제가 경험하거나 알아본 방법들을 공유해봅니다.&lt;/p>
&lt;h3>1. Native Query&lt;span class="hx:absolute hx:-mt-20" id="1-native-query">&lt;/span>
&lt;a href="#1-native-query" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>가장 직접적인 방법은 &lt;strong>Native Query&lt;/strong>입니다. JPA에서도 SQL을 직접 실행할 수 있도록 지원하죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Query&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">value&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;&amp;#34;&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s"> SELECT name, &amp;#39;CUSTOMER&amp;#39; as type FROM customer
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s"> UNION ALL
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s"> SELECT name, &amp;#39;PARTNER&amp;#39; as type FROM partner
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s"> &amp;#34;&amp;#34;&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">nativeQuery&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">List&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">Object&lt;/span>&lt;span class="o">[]&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">findAllNamesWithType&lt;/span>&lt;span class="p">();&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>장점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>SQL의 모든 기능 사용 가능&lt;/li>
&lt;li>DBMS 고유 기능 활용 가능&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>단점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>데이터베이스 종속성 발생&lt;/li>
&lt;li>타입 안전성 저하 (Object[] 반환)&lt;/li>
&lt;li>엔티티 매핑의 이점을 활용하기 어려움&lt;/li>
&lt;/ul>
&lt;h3>2. QueryDSL&lt;span class="hx:absolute hx:-mt-20" id="2-querydsl">&lt;/span>
&lt;a href="#2-querydsl" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>QueryDSL은 타입 안전한 쿼리 빌더로, JPQL의 한계를 일부 보완해주는 것 같습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">List&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">UserDto&lt;/span>&lt;span class="o">&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">users&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">queryFactory&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">select&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Projections&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">constructor&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">UserDto&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">class&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">name&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">order&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">amount&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">sum&lt;/span>&lt;span class="p">()))&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">from&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">join&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">orders&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">order&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">groupBy&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">id&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">fetch&lt;/span>&lt;span class="p">();&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>장점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>컴파일 타임 타입 체크&lt;/li>
&lt;li>IDE 자동완성 지원&lt;/li>
&lt;li>동적 쿼리 작성이 편리&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>단점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>JPQL의 한계를 완전히 벗어나지는 못함&lt;/li>
&lt;li>추가 라이브러리 의존성&lt;/li>
&lt;li>설정이 다소 복잡&lt;/li>
&lt;/ul>
&lt;h3>3. MyBatis 병행 사용&lt;span class="hx:absolute hx:-mt-20" id="3-mybatis-병행-사용">&lt;/span>
&lt;a href="#3-mybatis-%eb%b3%91%ed%96%89-%ec%82%ac%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>복잡한 쿼리가 많은 프로젝트에서는 &lt;strong>JPA와 MyBatis를 함께 사용&lt;/strong>하는 경우도 있습니다. CRUD는 JPA로, 복잡한 조회는 MyBatis로 처리하는 방식이죠.&lt;/p>
&lt;p>&lt;strong>장점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>SQL의 완전한 제어권&lt;/li>
&lt;li>복잡한 쿼리 작성이 용이&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>단점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>두 가지 기술 스택 관리 필요&lt;/li>
&lt;li>Connection 관리 주의 필요 (앞서 다룬 &lt;a href="https://jeongil.dev/ko/blog/backend/troubleshooting/hikaricp-deadlock-with-jpa-mybatis/">HikariCP Deadlock 문제&lt;/a> 참고)&lt;/li>
&lt;/ul>
&lt;h3>4. View 또는 Stored Procedure&lt;span class="hx:absolute hx:-mt-20" id="4-view-또는-stored-procedure">&lt;/span>
&lt;a href="#4-view-%eb%98%90%eb%8a%94-stored-procedure" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>복잡한 쿼리 로직을 &lt;strong>Database View&lt;/strong>나 &lt;strong>Stored Procedure&lt;/strong>로 만들어두고, JPA에서는 이를 단순하게 호출하는 방식도 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Entity&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Table&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;user_order_summary_view&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">UserOrderSummary&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nd">@Id&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Long&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">BigDecimal&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">totalAmount&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Long&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">orderCount&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>장점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>복잡한 로직을 DB 레벨에서 캡슐화&lt;/li>
&lt;li>JPA에서는 단순한 엔티티로 취급 가능&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>단점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>DB 종속성 증가&lt;/li>
&lt;li>비즈니스 로직이 분산됨&lt;/li>
&lt;/ul>
&lt;h2>어떤 방법을 선택해야 할까?&lt;span class="hx:absolute hx:-mt-20" id="어떤-방법을-선택해야-할까">&lt;/span>
&lt;a href="#%ec%96%b4%eb%96%a4-%eb%b0%a9%eb%b2%95%ec%9d%84-%ec%84%a0%ed%83%9d%ed%95%b4%ec%95%bc-%ed%95%a0%ea%b9%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>제 경험상 정답은 **&amp;ldquo;상황에 따라 다르다&amp;rdquo;**인 것 같습니다. 다만 몇 가지 기준을 제시해볼 수 있을 것 같아요.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>상황&lt;/th>
&lt;th>추천 방법&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>단순 CRUD 중심의 애플리케이션&lt;/td>
&lt;td>JPA + QueryDSL&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>복잡한 조회가 일부 있는 경우&lt;/td>
&lt;td>JPA + Native Query&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>복잡한 조회가 많은 경우&lt;/td>
&lt;td>JPA + MyBatis 병행&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>리포트/통계 시스템&lt;/td>
&lt;td>MyBatis 또는 순수 JDBC&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>레거시 DB 연동&lt;/td>
&lt;td>상황에 따라 유연하게&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>중요한 건 &lt;strong>도구에 얽매이지 않는 것&lt;/strong>이라고 생각합니다. JPA가 좋다고 모든 것을 JPA로 해결하려 하거나, SQL이 익숙하다고 JPA의 장점을 무시하는 건 바람직하지 않은 것 같아요.&lt;/p>
&lt;h2>정리&lt;span class="hx:absolute hx:-mt-20" id="정리">&lt;/span>
&lt;a href="#%ec%a0%95%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>JPA와 SQL 사이의 간극은 &lt;strong>JPA의 설계 철학에서 비롯된 의도적인 제약&lt;/strong>이라고 생각합니다. JPA는 데이터베이스 독립성과 객체 지향적 사고를 위해 SQL의 일부 기능을 지원하지 않기로 선택한 것 같습니다.&lt;/p>
&lt;p>하지만 현실에서는 이런 제약이 문제가 되는 경우가 많습니다. 레거시 시스템, 복잡한 쿼리 요구사항, 성능 최적화 등의 이유로 SQL의 기능이 필요한 상황이 발생하기 마련이죠.&lt;/p>
&lt;p>결국 중요한 건 &lt;strong>각 도구의 장단점을 이해하고, 상황에 맞는 적절한 방법을 선택&lt;/strong>하는 것이 아닐까 싶습니다. JPA만 고집하지 않고, 필요할 때는 Native Query, QueryDSL, 또는 MyBatis 같은 도구를 유연하게 활용하는 것이 현실적인 접근법이라고 생각합니다.&lt;/p>
&lt;hr>
&lt;h3>Reference&lt;span class="hx:absolute hx:-mt-20" id="reference">&lt;/span>
&lt;a href="#reference" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://hibernate.org/orm/documentation/"target="_blank" rel="noopener">Hibernate ORM 공식 문서&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://jcp.org/en/jsr/detail?id=338"target="_blank" rel="noopener">JPA 스펙 (JSR 338)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="http://querydsl.com/static/querydsl/latest/reference/html/"target="_blank" rel="noopener">QueryDSL Reference&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>DB Replication 복제 지연, 어떻게 해결할 것인가</title><link>https://jeongil.dev/ko/blog/backend/troubleshooting/db-replication-lag/</link><pubDate>Fri, 15 Nov 2024 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/backend/troubleshooting/db-replication-lag/</guid><description>
&lt;p>데이터베이스 Replication을 사용하는 환경에서 개발하다 보면, 언젠가 한번쯤은 마주치게 되는 문제가 있습니다. 바로 &lt;strong>복제 지연(Replication Lag)&lt;/strong> 문제입니다.&lt;/p>
&lt;p>저 역시 회사에서 이 문제를 직면했고, 해결 과정에서 여러 고민을 했던 경험이 있습니다. 이 글에서는 복제 지연이 왜 발생하는지, 그리고 어떤 해결 방법들이 있는지 제 경험을 바탕으로 공유해보려 합니다.&lt;/p>
&lt;h2>복제 지연이란?&lt;span class="hx:absolute hx:-mt-20" id="복제-지연이란">&lt;/span>
&lt;a href="#%eb%b3%b5%ec%a0%9c-%ec%a7%80%ec%97%b0%ec%9d%b4%eb%9e%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>복제 지연 문제를 이야기하기 전에, 먼저 왜 Replication을 사용하는지부터 짚어보겠습니다.&lt;/p>
&lt;p>데이터베이스 Replication은 &lt;strong>읽기 부하를 분산&lt;/strong>하기 위해 널리 사용되는 방식입니다. Master에서는 쓰기(INSERT, UPDATE, DELETE)를 처리하고, Slave에서는 읽기(SELECT)를 처리하도록 구성하면 부하를 효과적으로 분산할 수 있죠.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
App[&amp;#34;애플리케이션&amp;#34;]
Proxy[&amp;#34;ProxySQL&amp;#34;]
Master[&amp;#34;Master DB&amp;#34;]
Slave[&amp;#34;Slave DB&amp;#34;]
App --&amp;gt; Proxy
Proxy --&amp;gt;|&amp;#34;INSERT/UPDATE/DELETE&amp;#34;| Master
Proxy --&amp;gt;|&amp;#34;SELECT&amp;#34;| Slave
Master --&amp;gt;|&amp;#34;복제&amp;#34;| Slave
&lt;/pre>&lt;p>저희 회사에서도 위와 같은 구조로 ProxySQL을 통해 쿼리를 라우팅하고 있었습니다. SELECT 문은 Slave로, 쓰기 작업은 Master로 전송되는 방식이죠.&lt;/p>
&lt;p>그런데 여기서 문제가 발생합니다. &lt;strong>Master에서 Slave로 데이터가 복제되는 데는 시간이 걸린다&lt;/strong>는 점입니다. 아무리 빨라도 0은 아니거든요.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant User as 사용자
participant App as 애플리케이션
participant Master as Master DB
participant Slave as Slave DB
User-&amp;gt;&amp;gt;App: 데이터 저장 요청
App-&amp;gt;&amp;gt;Master: INSERT
Master--&amp;gt;&amp;gt;App: 저장 완료
App--&amp;gt;&amp;gt;User: 저장 완료 응답
Note over Master,Slave: 복제 중... (지연 발생)
User-&amp;gt;&amp;gt;App: 방금 저장한 데이터 조회
App-&amp;gt;&amp;gt;Slave: SELECT
Slave--&amp;gt;&amp;gt;App: 데이터 없음 ❌
App--&amp;gt;&amp;gt;User: &amp;#34;데이터가 없습니다&amp;#34;
&lt;/pre>&lt;p>사용자 입장에서는 방금 저장한 데이터를 조회했는데 없다고 나오니, &amp;ldquo;분명 저장했는데 왜 없지?&amp;ldquo;라는 혼란을 겪게 됩니다. 실제로 저희 서비스에서도 이런 문제로 인해 Slack에 예외 알림이 오거나, 사용자 문의가 들어오는 경우가 종종 있었습니다.&lt;/p>
&lt;h2>문제 상황&lt;span class="hx:absolute hx:-mt-20" id="문제-상황">&lt;/span>
&lt;a href="#%eb%ac%b8%ec%a0%9c-%ec%83%81%ed%99%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>저희 서비스에서 복제 지연 문제가 발생했던 대표적인 시나리오는 다음과 같았습니다.&lt;/p>
&lt;ol>
&lt;li>사용자가 특정 데이터를 저장 (Master에 INSERT)&lt;/li>
&lt;li>저장 완료 후 바로 해당 데이터를 조회 (Slave에서 SELECT)&lt;/li>
&lt;li>아직 복제가 완료되지 않아 데이터가 조회되지 않음&lt;/li>
&lt;li>후속 로직에서 &amp;ldquo;데이터가 없다&amp;quot;는 예외 발생&lt;/li>
&lt;/ol>
&lt;p>이 문제가 까다로운 이유는 &lt;strong>항상 발생하는 게 아니라는 점&lt;/strong>입니다. 대부분의 경우에는 복제가 빠르게 완료되어 문제가 없지만, 트래픽이 몰리거나 Master에 부하가 걸리면 복제 지연이 길어지면서 문제가 표면화됩니다.&lt;/p>
&lt;h2>해결 방법 검토&lt;span class="hx:absolute hx:-mt-20" id="해결-방법-검토">&lt;/span>
&lt;a href="#%ed%95%b4%ea%b2%b0-%eb%b0%a9%eb%b2%95-%ea%b2%80%ed%86%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>복제 지연 문제를 해결하기 위한 방법은 여러 가지가 있습니다. 각 방법의 특징과 trade-off를 살펴보겠습니다.&lt;/p>
&lt;h3>1. Read-Your-Own-Write (자신이 쓴 데이터 읽기)&lt;span class="hx:absolute hx:-mt-20" id="1-read-your-own-write-자신이-쓴-데이터-읽기">&lt;/span>
&lt;a href="#1-read-your-own-write-%ec%9e%90%ec%8b%a0%ec%9d%b4-%ec%93%b4-%eb%8d%b0%ec%9d%b4%ed%84%b0-%ec%9d%bd%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>가장 직관적인 해결책입니다. &lt;strong>쓰기 작업을 수행한 사용자의 후속 읽기는 Master에서 처리&lt;/strong>하는 방식이죠.&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart LR
subgraph &amp;#34;Read-Your-Own-Write&amp;#34;
User[&amp;#34;사용자 A&amp;#34;]
Master[&amp;#34;Master DB&amp;#34;]
Slave[&amp;#34;Slave DB&amp;#34;]
User --&amp;gt;|&amp;#34;1. INSERT&amp;#34;| Master
User --&amp;gt;|&amp;#34;2. SELECT (본인 데이터)&amp;#34;| Master
User --&amp;gt;|&amp;#34;3. SELECT (타인 데이터)&amp;#34;| Slave
end
&lt;/pre>&lt;p>&lt;strong>장점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>자신이 쓴 데이터는 항상 즉시 조회 가능&lt;/li>
&lt;li>구현이 비교적 단순&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>단점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&amp;ldquo;자신이 쓴 데이터&amp;quot;를 어떻게 판별할 것인지 추가 로직 필요&lt;/li>
&lt;li>세션이나 쿠키 기반으로 구현 시 서버 간 상태 공유 문제&lt;/li>
&lt;/ul>
&lt;h3>2. Monotonic Reads (단조 읽기)&lt;span class="hx:absolute hx:-mt-20" id="2-monotonic-reads-단조-읽기">&lt;/span>
&lt;a href="#2-monotonic-reads-%eb%8b%a8%ec%a1%b0-%ec%9d%bd%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>한 사용자의 읽기 요청이 &lt;strong>시간 순서대로 일관성 있게&lt;/strong> 처리되도록 보장하는 방식입니다. 한번 특정 시점의 데이터를 읽었다면, 이후에는 그보다 과거의 데이터를 읽지 않도록 하는 거죠.&lt;/p>
&lt;p>&lt;strong>장점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>시간 역전 현상 방지&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>단점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>구현 복잡도가 높음&lt;/li>
&lt;li>복제 지연 자체를 해결하지는 않음&lt;/li>
&lt;/ul>
&lt;h3>3. 트랜잭션 활용&lt;span class="hx:absolute hx:-mt-20" id="3-트랜잭션-활용">&lt;/span>
&lt;a href="#3-%ed%8a%b8%eb%9e%9c%ec%9e%ad%ec%85%98-%ed%99%9c%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>ProxySQL과 같은 프록시를 사용하는 경우, &lt;strong>트랜잭션 내에서는 모든 쿼리가 Master로 라우팅&lt;/strong>되는 특성을 활용할 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Transactional&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">processOrder&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">OrderRequest&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">request&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// INSERT와 SELECT 모두 Master에서 처리됨&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">orderRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">save&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">order&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">Order&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">savedOrder&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">orderRepository&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">findById&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">order&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// ...&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>장점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>기존 코드에 &lt;code>@Transactional&lt;/code>만 추가하면 됨&lt;/li>
&lt;li>가장 간단한 해결책&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>단점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>읽기 전용 쿼리도 Master로 가면서 부하 분산 효과 감소&lt;/li>
&lt;li>트랜잭션 범위를 신중하게 설계해야 함&lt;/li>
&lt;/ul>
&lt;h3>4. AbstractRoutingDataSource 활용&lt;span class="hx:absolute hx:-mt-20" id="4-abstractroutingdatasource-활용">&lt;/span>
&lt;a href="#4-abstractroutingdatasource-%ed%99%9c%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Spring에서 제공하는 &lt;code>AbstractRoutingDataSource&lt;/code>를 사용하면 &lt;strong>비즈니스 로직에 따라 동적으로 DataSource를 선택&lt;/strong>할 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">RoutingDataSource&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">extends&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">AbstractRoutingDataSource&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nd">@Override&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">protected&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Object&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">determineCurrentLookupKey&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">TransactionSynchronizationManager&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">isCurrentTransactionReadOnly&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;slave&amp;#34;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;master&amp;#34;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>장점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>세밀한 제어 가능&lt;/li>
&lt;li>AOP와 결합하여 유연하게 구성 가능&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>단점:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>초기 설정이 다소 복잡&lt;/li>
&lt;li>DataSource 관리 포인트 증가&lt;/li>
&lt;/ul>
&lt;h2>저희의 선택&lt;span class="hx:absolute hx:-mt-20" id="저희의-선택">&lt;/span>
&lt;a href="#%ec%a0%80%ed%9d%ac%ec%9d%98-%ec%84%a0%ed%83%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>여러 방법을 검토한 결과, 저희는 &lt;strong>단계적 접근&lt;/strong>을 선택했습니다.&lt;/p>
&lt;h3>1단계: 주요 비즈니스 로직에 트랜잭션 적용&lt;span class="hx:absolute hx:-mt-20" id="1단계-주요-비즈니스-로직에-트랜잭션-적용">&lt;/span>
&lt;a href="#1%eb%8b%a8%ea%b3%84-%ec%a3%bc%ec%9a%94-%eb%b9%84%ec%a6%88%eb%8b%88%ec%8a%a4-%eb%a1%9c%ec%a7%81%ec%97%90-%ed%8a%b8%eb%9e%9c%ec%9e%ad%ec%85%98-%ec%a0%81%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>가장 빠르게 적용할 수 있는 방법으로, INSERT 후 즉시 SELECT가 필요한 주요 비즈니스 로직에 &lt;code>@Transactional&lt;/code>을 적용했습니다. 이렇게 하면 ProxySQL이 해당 트랜잭션 내의 모든 쿼리를 Master로 라우팅합니다.&lt;/p>
&lt;h3>2단계: AbstractRoutingDataSource + AOP 도입&lt;span class="hx:absolute hx:-mt-20" id="2단계-abstractroutingdatasource--aop-도입">&lt;/span>
&lt;a href="#2%eb%8b%a8%ea%b3%84-abstractroutingdatasource--aop-%eb%8f%84%ec%9e%85" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>장기적으로는 &lt;code>AbstractRoutingDataSource&lt;/code>를 활용하여 더 세밀한 제어가 가능하도록 구성했습니다. 커스텀 어노테이션을 만들어 특정 메서드에서는 무조건 Master를 바라보도록 설정할 수 있게 했죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Target&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">ElementType&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">METHOD&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Retention&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">RetentionPolicy&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">RUNTIME&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nd">@interface&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">UseMasterDB&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Aspect&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Component&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">DataSourceRoutingAspect&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nd">@Around&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;@annotation(UseMasterDB)&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Object&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">routeToMaster&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">ProceedingJoinPoint&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">joinPoint&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">throws&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Throwable&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">try&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">DataSourceContextHolder&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setDataSourceType&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;master&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">joinPoint&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">proceed&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">finally&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">DataSourceContextHolder&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">clear&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>3단계: 일부 서비스는 Master 직접 연결&lt;span class="hx:absolute hx:-mt-20" id="3단계-일부-서비스는-master-직접-연결">&lt;/span>
&lt;a href="#3%eb%8b%a8%ea%b3%84-%ec%9d%bc%eb%b6%80-%ec%84%9c%eb%b9%84%ec%8a%a4%eb%8a%94-master-%ec%a7%81%ec%a0%91-%ec%97%b0%ea%b2%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>복제 지연에 특히 민감한 핵심 비즈니스 로직을 다루는 애플리케이션의 경우, ProxySQL을 거치지 않고 Master에 직접 연결하도록 구성했습니다. 이는 부하 분산 효과를 포기하는 대신 데이터 일관성을 우선시한 결정이었습니다.&lt;/p>
&lt;h2>남은 고민&lt;span class="hx:absolute hx:-mt-20" id="남은-고민">&lt;/span>
&lt;a href="#%eb%82%a8%ec%9d%80-%ea%b3%a0%eb%af%bc" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>이 방식으로 대부분의 복제 지연 문제는 해결되었지만, 완벽한 해결책은 아닙니다.&lt;/p>
&lt;p>예를 들어, 사용자 A가 데이터를 저장하고 사용자 B가 그 데이터를 조회하는 경우에는 여전히 복제 지연 문제가 발생할 수 있습니다. 다만 이런 케이스는 빈도가 낮고, 발생하더라도 잠시 후 다시 조회하면 데이터가 보이기 때문에 치명적인 문제로 이어지지는 않았습니다.&lt;/p>
&lt;p>복제 지연 문제는 Replication 구조를 사용하는 한 완전히 피하기 어려운 문제라고 생각합니다. 결국 &lt;strong>어느 정도의 지연을 허용할 것인지, 어떤 케이스에서 강한 일관성이 필요한지&lt;/strong>를 비즈니스 요구사항에 맞게 판단하고, 그에 맞는 전략을 선택하는 것이 중요한 것 같습니다.&lt;/p>
&lt;h2>정리&lt;span class="hx:absolute hx:-mt-20" id="정리">&lt;/span>
&lt;a href="#%ec%a0%95%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>복제 지연 문제를 해결하면서 배운 점을 정리하면 다음과 같습니다.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>모든 읽기를 Master에서 처리하면 해결되지만&lt;/strong>, 그러면 Replication을 쓰는 의미가 없어짐&lt;/li>
&lt;li>&lt;strong>트레이드오프를 이해하고 선택&lt;/strong>해야 함 (일관성 vs 성능)&lt;/li>
&lt;li>&lt;strong>점진적 개선&lt;/strong>이 현실적 (한 번에 완벽한 구조를 만들기보다 단계적으로 개선)&lt;/li>
&lt;li>&lt;strong>비즈니스 요구사항에 따라 전략이 달라짐&lt;/strong> (모든 상황에 맞는 정답은 없음)&lt;/li>
&lt;/ol>
&lt;p>이 경험은 NAVER 컨퍼런스 DAN24에서 김진한님의 &lt;a href="https://dan.naver.com/24/sessions/635"target="_blank" rel="noopener">네이버페이 결제 시스템의 성장과 변화&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> 세션을 듣고 영감을 받아 본격적으로 해결하게 된 계기가 되었습니다. 비슷한 문제를 겪고 계신 분들께 조금이나마 도움이 되었으면 합니다.&lt;/p>
&lt;hr>
&lt;h3>Reference&lt;span class="hx:absolute hx:-mt-20" id="reference">&lt;/span>
&lt;a href="#reference" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://drunkenhw.github.io/java/select-database/"target="_blank" rel="noopener">https://drunkenhw.github.io/java/select-database/&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://velog.io/@ghkvud2/AbstractRoutingDataSource-%EC%A0%81%EC%9A%A9%ED%95%98%EA%B8%B0"target="_blank" rel="noopener">https://velog.io/@ghkvud2/AbstractRoutingDataSource-%EC%A0%81%EC%9A%A9%ED%95%98%EA%B8%B0&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>Martin Kleppmann - &lt;em>Designing Data-Intensive Applications&lt;/em> (O&amp;rsquo;Reilly, 2017) - Chapter 5: Replication&lt;/li>
&lt;/ul></description></item><item><title>[트러블슈팅] QueryDSL StackOverflowError 탐방기</title><link>https://jeongil.dev/ko/blog/backend/troubleshooting/querydsl-stack-overflow/</link><pubDate>Fri, 15 Mar 2024 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/backend/troubleshooting/querydsl-stack-overflow/</guid><description>
&lt;p>이번에 회사에서 직면했던 Querydsl StackOverflow에 관한 내용을 공유하고자 글을 남깁니다.&lt;/p>
&lt;hr>
&lt;h2>문제 발생&lt;span class="hx:absolute hx:-mt-20" id="문제-발생">&lt;/span>
&lt;a href="#%eb%ac%b8%ec%a0%9c-%eb%b0%9c%ec%83%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/c0d01332-d81a-4671-8d23-e08ec17593d2/image.png" alt="Slack 메시지" loading="lazy" />&lt;/p>
&lt;p>오늘도 어김없이 문제는 Slack 메시지로부터 시작합니다.&lt;/p>
&lt;p>메시지를 받자마자 어라? 라는 반응을 할 수밖에 없었습니다.
&lt;strong>StackOverflow?&lt;/strong> 서버에 재귀식으로 구현된 코드가 있었던가?&lt;/p>
&lt;hr>
&lt;h2>StackOverflow란&lt;span class="hx:absolute hx:-mt-20" id="stackoverflow란">&lt;/span>
&lt;a href="#stackoverflow%eb%9e%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>여러분들 모두 잘 알고 계시겠지만 StackOverflow란 지정한 스택 메모리 사이즈보다 더 많은 스택 메모리를 사용하게 되어 에러가 발생하는 상황입니다.&lt;/p>
&lt;p>&lt;img src="https://www.artima.com/insidejvm/ed2/images/fig5-3.gif" alt="JVM Stack" loading="lazy" />&lt;/p>
&lt;p>메서드가 호출되면 호출 스택에 새 &lt;code>Stack frame&lt;/code>이 생성됩니다. 이 &lt;code>Stack frame&lt;/code>은 호출된 메서드의 매개 변수, 로컬 변수 및 메서드의 반환 주소, 즉 호출된 메서드가 반환된 후 메서드 실행이 계속되어야 하는 지점을 포함합니다.&lt;/p>
&lt;p>&lt;code>Stack frame&lt;/code> 생성은 중첩된 메서드 내에서 발견된 메서드 호출의 끝에 도달할 때까지 계속됩니다.&lt;/p>
&lt;p>이 과정에서 JVM이 새 스택 프레임을 생성할 공간이 없는 상황이 발생하면 StackOverflowError가 발생합니다.&lt;/p>
&lt;p>JVM이 이 상황에 직면하는 가장 일반적인 원인은 &lt;strong>종료되지 않은/무한 재귀&lt;/strong>입니다.&lt;/p>
&lt;hr>
&lt;h2>원인&lt;span class="hx:absolute hx:-mt-20" id="원인">&lt;/span>
&lt;a href="#%ec%9b%90%ec%9d%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>원인 발생지점은 어렵지 않게 찾을 수 있었습니다.&lt;/p>
&lt;p>JPA를 사용하며 동적쿼리 작성을 용이하기 위해 사용한 QueryDsl이 문제지점이였습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/cb22d02a-cbc5-4fca-9038-02007fa6c042/image.png" alt="StackTrace" loading="lazy" />&lt;/p>
&lt;p>Stacktrace를 보자마자 아&amp;hellip;&lt;/p>
&lt;p>이거 Querydsl이 재귀식으로 구현돼있는 부분이 있나보구나 했습니다.&lt;/p>
&lt;p>코드를 까보죠.&lt;/p>
&lt;p>해당하는 각 &lt;code>JPAMapAccessVisitor&lt;/code>, &lt;code>OperationImpl&lt;/code>, &lt;code>ReplaceVisitor&lt;/code>를 보겠습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/64441f9f-c057-4a17-9ab4-734eb7974551/image.png" alt="JPAMapAccessVisitor" loading="lazy" />&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/62cbc40e-b180-493c-ac0a-00402cb886cc/image.png" alt="OperationImpl" loading="lazy" />&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/a81591c1-b4e9-4ef1-869b-90b2a5089a62/image.png" alt="ReplaceVisitor 1" loading="lazy" />&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/fb524f75-4aac-4c12-900f-205078a17f0d/image.png" alt="ReplaceVisitor 2" loading="lazy" />&lt;/p>
&lt;p>코드를 까서보니 조건 &lt;code>Expression&lt;/code>을 만드는 과정에서 재귀식으로 구현돼있는게 맞았습니다.&lt;/p>
&lt;p>위 &lt;code>JPAMapAccessVisitor&lt;/code> 27,58 라인, &lt;code>OperationImpl&lt;/code> 88 라인, &lt;code>ReplaceVisitor&lt;/code> 51,161 라인을 계속 돌며 Stack frame을 열심히 차곡차곡 쌓아갔던 겁니다.&lt;/p>
&lt;h3>그런데 말입니다&lt;span class="hx:absolute hx:-mt-20" id="그런데-말입니다">&lt;/span>
&lt;a href="#%ea%b7%b8%eb%9f%b0%eb%8d%b0-%eb%a7%90%ec%9e%85%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>처음엔 우리가 익히 쓰는 BooleanBuilder를 사용할 경우 위와 같은 로직을 타서 문제가 생긴다고 생각했습니다.&lt;/p>
&lt;p>&lt;strong>하지만&lt;/strong> 실제 원인은 &lt;strong>BooleanExpression을 체이닝하는 방식&lt;/strong>이었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// ❌ 이렇게 쓰면 문제가 됩니다&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">BooleanExpression&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">expression&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Long&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">apartId&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">apartIds&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// apartId가 2000개 이상...&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">BooleanExpression&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">condition&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">qApart&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">id&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">eq&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">apartId&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">expression&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">expression&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">==&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">condition&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">expression&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">or&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">condition&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>왜 이게 문제가 될까요?&lt;/p>
&lt;p>BooleanExpression은 &lt;strong>불변(Immutable) 객체&lt;/strong>입니다. &lt;code>and()&lt;/code> 또는 &lt;code>or()&lt;/code>를 호출할 때마다 매번 새로운 객체를 만들어내죠.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// BooleanExpression.or() 내부 코드&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">BooleanExpression&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">or&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nd">@Nullable&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Predicate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">right&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Expressions&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">booleanOperation&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Ops&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">OR&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">mixin&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">right&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// ↑ 새 객체를 생성해서 반환합니다&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>2000개의 조건을 이렇게 체이닝하면 다음과 같은 구조가 만들어집니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code> OR
/ \
OR expr2000
/ \
OR expr1999
/ \
OR expr1998
...
/ \
expr1 expr2&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>깊이가 2000인 트리가 만들어지는 겁니다.&lt;/p>
&lt;p>그리고 이 트리를 쿼리로 변환(직렬화)할 때 재귀 호출을 2000번 하게 되고, 결국 StackOverflow가 터지게 됩니다.&lt;/p>
&lt;p>위 슬랙 메세지가 온 경우에는 조건이 2000개가 넘었습니다.&lt;/p>
&lt;hr>
&lt;h2>해결&lt;span class="hx:absolute hx:-mt-20" id="해결">&lt;/span>
&lt;a href="#%ed%95%b4%ea%b2%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>그럼 어떻게 해결해야 할까요?&lt;/p>
&lt;h3>방법 1. BooleanBuilder 활용&lt;span class="hx:absolute hx:-mt-20" id="방법-1-booleanbuilder-활용">&lt;/span>
&lt;a href="#%eb%b0%a9%eb%b2%95-1-booleanbuilder-%ed%99%9c%ec%9a%a9" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 이렇게 하면 안전합니다&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">BooleanBuilder&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">builder&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">BooleanBuilder&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Long&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">apartId&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">apartIds&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 2000개 이상도 OK&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">builder&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">or&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">qApart&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">id&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">eq&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">apartId&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">List&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">Apart&lt;/span>&lt;span class="o">&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">result&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">queryFactory&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">selectFrom&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">qApart&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">where&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">builder&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">fetch&lt;/span>&lt;span class="p">();&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>BooleanBuilder는 BooleanExpression과 다르게 &lt;strong>가변(Mutable) 객체&lt;/strong>입니다.&lt;/p>
&lt;p>내부 코드를 보면 다음과 같습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// BooleanBuilder.java&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">BooleanBuilder&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">implements&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Predicate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nd">@Nullable&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Predicate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">predicate&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 단일 필드&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">BooleanBuilder&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">or&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Predicate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">right&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">predicate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">==&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">predicate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">right&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">else&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">predicate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ExpressionUtils&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">or&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">predicate&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">right&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">this&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 자기 자신을 반환&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>매번 새 객체를 만드는게 아니라, 내부의 &lt;code>predicate&lt;/code> 필드를 업데이트하는 방식이죠.&lt;/p>
&lt;p>따라서 불필요한 재귀 호출 없이 메모리를 효율적으로 사용할 수 있습니다.&lt;/p>
&lt;h3>방법 2. ExpressionUtils.inAny() 사용 (QueryDSL 3.6.0+)&lt;span class="hx:absolute hx:-mt-20" id="방법-2-expressionutilsinany-사용-querydsl-360">&lt;/span>
&lt;a href="#%eb%b0%a9%eb%b2%95-2-expressionutilsinany-%ec%82%ac%ec%9a%a9-querydsl-360" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>대량 IN 조건이라면 QueryDSL이 제공하는 유틸을 사용할 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;span class="lnt">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Guava 라이브러리로 999개씩 나눔 (Oracle 제한 때문)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">List&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">List&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">Long&lt;/span>&lt;span class="o">&amp;gt;&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">partitions&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Lists&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">partition&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">apartIds&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">999&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">BooleanExpression&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">expression&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ExpressionUtils&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">inAny&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">qApart&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">id&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">partitions&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">List&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">Apart&lt;/span>&lt;span class="o">&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">result&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">queryFactory&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">selectFrom&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">qApart&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">where&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">expression&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">fetch&lt;/span>&lt;span class="p">();&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>999개씩 나누는 이유&lt;/strong>&lt;/p>
&lt;p>Oracle DB는 IN 절에 최대 1000개까지만 넣을 수 있습니다(ORA-01795 에러).
안전하게 999개씩 나누는 것을 권장합니다.&lt;/p>
&lt;h3>방법 3. 수동으로 파티셔닝하기&lt;span class="hx:absolute hx:-mt-20" id="방법-3-수동으로-파티셔닝하기">&lt;/span>
&lt;a href="#%eb%b0%a9%eb%b2%95-3-%ec%88%98%eb%8f%99%ec%9c%bc%eb%a1%9c-%ed%8c%8c%ed%8b%b0%ec%85%94%eb%8b%9d%ed%95%98%ea%b8%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">List&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">List&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">Long&lt;/span>&lt;span class="o">&amp;gt;&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">partitions&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Lists&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">partition&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">apartIds&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">999&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">BooleanBuilder&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">builder&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">BooleanBuilder&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">List&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">Long&lt;/span>&lt;span class="o">&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">partition&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">partitions&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">builder&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">or&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">qApart&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">id&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">in&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">partition&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// IN 절로 처리&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">List&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">Apart&lt;/span>&lt;span class="o">&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">result&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">queryFactory&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">selectFrom&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">qApart&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">where&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">builder&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">fetch&lt;/span>&lt;span class="p">();&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>이렇게 하면 SQL이 다음처럼 생성됩니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">apart_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">...,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">999&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">OR&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">apart_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">1000&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">1001&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">...,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">1999&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">OR&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">apart_id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">2000&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">2001&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">...,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">2500&lt;/span>&lt;span class="p">)&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>방법 4. 임시 테이블 활용 (정말 많을 때)&lt;span class="hx:absolute hx:-mt-20" id="방법-4-임시-테이블-활용-정말-많을-때">&lt;/span>
&lt;a href="#%eb%b0%a9%eb%b2%95-4-%ec%9e%84%ec%8b%9c-%ed%85%8c%ec%9d%b4%eb%b8%94-%ed%99%9c%ec%9a%a9-%ec%a0%95%eb%a7%90-%eb%a7%8e%ec%9d%84-%eb%95%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>조건이 수만 개 이상으로 극단적으로 많을 경우에는 이 방법도 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 1. 임시 테이블에 ID 넣기&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">jdbcTemplate&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">batchUpdate&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;INSERT INTO temp_apart_ids (id) VALUES (?)&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">apartIds&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">apartIds&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">size&lt;/span>&lt;span class="p">(),&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">-&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setLong&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">// 2. JOIN으로 조회&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">sql&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;&amp;#34;&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s"> SELECT a.*
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s"> FROM apart a
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s"> INNER JOIN temp_apart_ids t ON a.id = t.id
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s"> &amp;#34;&amp;#34;&amp;#34;&lt;/span>&lt;span class="p">;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;h3>방법 5. JPQL 직접 작성&lt;span class="hx:absolute hx:-mt-20" id="방법-5-jpql-직접-작성">&lt;/span>
&lt;a href="#%eb%b0%a9%eb%b2%95-5-jpql-%ec%a7%81%ec%a0%91-%ec%9e%91%ec%84%b1" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>저는 프로젝트 상황상 JPQL을 사용하는 것으로 결론지었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;span class="lnt">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="n">List&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">Apart&lt;/span>&lt;span class="o">&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">result&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ArrayList&lt;/span>&lt;span class="o">&amp;lt;&amp;gt;&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">List&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">List&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">Long&lt;/span>&lt;span class="o">&amp;gt;&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">partitions&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Lists&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">partition&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">apartIds&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">999&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">List&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">Long&lt;/span>&lt;span class="o">&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">partition&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">partitions&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jpql&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;SELECT a FROM Apart a WHERE a.id IN :ids&amp;#34;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">result&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">addAll&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">entityManager&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">createQuery&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">jpql&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Apart&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">class&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setParameter&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;ids&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">partition&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getResultList&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>주의:&lt;/strong> JPQL도 IN 절에 대량 조건을 그대로 넣으면 똑같은 문제가 생길 수 있어서, 파티셔닝을 함께 적용했습니다.&lt;/p>
&lt;hr>
&lt;h2>해결 방법 비교&lt;span class="hx:absolute hx:-mt-20" id="해결-방법-비교">&lt;/span>
&lt;a href="#%ed%95%b4%ea%b2%b0-%eb%b0%a9%eb%b2%95-%eb%b9%84%ea%b5%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>방법&lt;/th>
&lt;th>장점&lt;/th>
&lt;th>단점&lt;/th>
&lt;th>권장 상황&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>BooleanBuilder&lt;/strong>&lt;/td>
&lt;td>간단하고 안전, 타입 안전성 유지&lt;/td>
&lt;td>-&lt;/td>
&lt;td>✅ 일반적인 경우&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>ExpressionUtils.inAny()&lt;/strong>&lt;/td>
&lt;td>가장 깔끔한 코드&lt;/td>
&lt;td>QueryDSL 3.6.0+ 필요&lt;/td>
&lt;td>✅ 최신 버전 사용 시&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>수동 파티셔닝&lt;/strong>&lt;/td>
&lt;td>모든 버전 호환&lt;/td>
&lt;td>코드가 조금 길어짐&lt;/td>
&lt;td>✅ 구버전 사용 시&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>임시 테이블&lt;/strong>&lt;/td>
&lt;td>대량 데이터에 최적&lt;/td>
&lt;td>복잡도 증가&lt;/td>
&lt;td>⚠️ 수만 개 이상&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>JPQL 직접 작성&lt;/strong>&lt;/td>
&lt;td>완전한 제어&lt;/td>
&lt;td>타입 안전성 포기&lt;/td>
&lt;td>⚠️ 최후의 수단&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>저희는 BooleanBuilder로 일관된 사용을 하기로 결론 지었습니다.&lt;/p>
&lt;hr>
&lt;h2>추가 팁&lt;span class="hx:absolute hx:-mt-20" id="추가-팁">&lt;/span>
&lt;a href="#%ec%b6%94%ea%b0%80-%ed%8c%81" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;h3>JVM 스택 크기 조정 (임시 방편)&lt;span class="hx:absolute hx:-mt-20" id="jvm-스택-크기-조정-임시-방편">&lt;/span>
&lt;a href="#jvm-%ec%8a%a4%ed%83%9d-%ed%81%ac%ea%b8%b0-%ec%a1%b0%ec%a0%95-%ec%9e%84%ec%8b%9c-%eb%b0%a9%ed%8e%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>근본 해결책은 아니지만, 급한 경우 스택 크기를 늘릴 수 있습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># 스택 크기를 2MB로 증가&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">java -Xss2m -jar application.jar&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>&lt;strong>⚠️ 주의:&lt;/strong> 이는 임시방편일 뿐이며, 근본 해결책은 &lt;strong>조건 분할&lt;/strong>입니다.&lt;/p>
&lt;h3>Oracle IN 절 제한&lt;span class="hx:absolute hx:-mt-20" id="oracle-in-절-제한">&lt;/span>
&lt;a href="#oracle-in-%ec%a0%88-%ec%a0%9c%ed%95%9c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">-- ❌ 에러 발생 (ORA-01795)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">apart&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">3&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">...,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">1001&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1">-- ✅ 999개씩 분할
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">apart&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">WHERE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">...,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">999&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">OR&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">id&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">IN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">1000&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">1001&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">...,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">1998&lt;/span>&lt;span class="p">);&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;hr>
&lt;h2>정리하며&lt;span class="hx:absolute hx:-mt-20" id="정리하며">&lt;/span>
&lt;a href="#%ec%a0%95%eb%a6%ac%ed%95%98%eb%a9%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>오랜만에 보는 StackOverflowError라서 반갑기도 했습니다.&lt;/p>
&lt;p>한편으로는 Querydsl도 애플리케이션 입장에서보면 의존성이 하나 더 생기는 것이기때문에 장애발생 가능지점이 하나 늘어나는 거구나 싶긴합니다.&lt;/p>
&lt;h3>핵심 교훈&lt;span class="hx:absolute hx:-mt-20" id="핵심-교훈">&lt;/span>
&lt;a href="#%ed%95%b5%ec%8b%ac-%ea%b5%90%ed%9b%88" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ol>
&lt;li>&lt;strong>BooleanExpression 체이닝은 위험합니다&lt;/strong> (대량 조건 시 StackOverflow 발생)&lt;/li>
&lt;li>&lt;strong>BooleanBuilder를 사용하는 것이 안전합니다&lt;/strong> (가변 객체라 안전함)&lt;/li>
&lt;li>&lt;strong>Oracle IN 절은 1000개 제한&lt;/strong> (999개씩 나누기)&lt;/li>
&lt;li>&lt;strong>상황에 맞는 해결책을 선택하시면 됩니다&lt;/strong> (ExpressionUtils.inAny() &amp;gt; BooleanBuilder &amp;gt; JPQL)&lt;/li>
&lt;/ol>
&lt;p>Querydsl 사용할때 대량 조건 처리 다들 조심하십쇼!&lt;/p>
&lt;hr>
&lt;h2>Reference&lt;span class="hx:absolute hx:-mt-20" id="reference">&lt;/span>
&lt;a href="#reference" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;ul>
&lt;li>&lt;a href="https://github.com/querydsl/querydsl/issues/721"target="_blank" rel="noopener">QueryDSL GitHub Issue #721 - StackOverflow error&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://groups.google.com/g/querydsl/c/PJX9o6yxx-A"target="_blank" rel="noopener">Google Groups - StackOverflowError discussion&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/querydsl/querydsl/blob/master/querydsl-core/src/main/java/com/querydsl/core/BooleanBuilder.java"target="_blank" rel="noopener">QueryDSL BooleanBuilder Source Code&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/querydsl/querydsl/blob/master/querydsl-core/src/main/java/com/querydsl/core/types/dsl/BooleanExpression.java"target="_blank" rel="noopener">QueryDSL BooleanExpression Source Code&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul>
&lt;hr>
&lt;blockquote>
&lt;p>위 본문 내용중 정확하지 않은 내용이 포함돼 있을 수 있습니다.
저는 1년차 백엔드 개발자로 스스로 굉장히 부족한 사람이라는 점을 인지하고 있는지라
제가 적은 정보가 정확하지 않을까 걱정하고 있습니다.
혹여 제 정보가 잘못 됐을 수 있으니 단지 참고용으로만 봐주시고 관련된 내용을 한번 직접 알아보시는 걸 추천합니다.
혹여 잘못된 내용이 있거나 말씀해주시고 싶은 부분이 있으시다면 부담없이 적어주세요.
수용하고 개선하기 위해 노력하겠습니다.&lt;/p>
&lt;/blockquote></description></item><item><title>[트러블슈팅] Kubernetes Pod Scale In 과정에서 실패한 Graceful Shutdown, 소실된 비동기 로직 탐색 여정</title><link>https://jeongil.dev/ko/blog/backend/troubleshooting/graceful-shutdown-async/</link><pubDate>Fri, 09 Feb 2024 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/backend/troubleshooting/graceful-shutdown-async/</guid><description>
&lt;p>이번에 회사에서 직면했던 실패한 Graceful Shotdown에 관한 내용을 공유하고자 글을 남깁니다.&lt;/p>
&lt;hr>
&lt;h3>문제 발생&lt;span class="hx:absolute hx:-mt-20" id="문제-발생">&lt;/span>
&lt;a href="#%eb%ac%b8%ec%a0%9c-%eb%b0%9c%ec%83%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>평소에는 예외상황이나 문제상황들을 Slack으로 많이 접하는 편인데요.
오늘은 평소와 다르게 문제를 접하게 됐습니다.
이번 문제는 백오피스 사용자의 문의로부터 시작됩니다.&lt;/p>
&lt;blockquote>
&lt;p>&amp;ldquo;데이터가 하나가 안맞는 거 같아요&amp;hellip;!&amp;rdquo;&lt;/p>
&lt;/blockquote>
&lt;p>바로 부랴부랴 데이터를 확인해보기 시작했습니다.&lt;/p>
&lt;p>확인 결과 특정 테이블에서 각 튜플의 상태값을 나타내는 Flag 컬럼중 하나가 기대했던 값과는 다른 상태였습니다.&lt;/p>
&lt;p>서비스에 큰 영향이 있을 정도의 Flag는 아니였기 때문에 급하게 해결해야 하는 문제는 아니였다는 점에서는 아주 다행이였습니다.&lt;/p>
&lt;p>그러나 Flag 컬럼이 어째서 기대했던 값과 달랐던 것인지 정확히 분석할 필요가 당연히 있었습니다.&lt;/p>
&lt;p>해당 서버를 담당하시는 개발자 분이 확인해본다고 하셨고 어떤 이유에서인지 들을 준비를 하고있었습니다만 그 분이 열심히 원인을 찾다가 말씀해주셨습니다.&lt;/p>
&lt;blockquote>
&lt;p>해당 Flag 컬럼을 업데이트하는 로직이 포함돼 있는 요청을 던진 Request가 정상적으로 Response까지 뱉었는데 이게 왜 Update가 안됐는지 모르겠네&amp;hellip;? 뭐지???&lt;/p>
&lt;/blockquote>
&lt;h4>자&amp;hellip; Debug 여행의 시작이였습니다.&lt;span class="hx:absolute hx:-mt-20" id="자-debug-여행의-시작이였습니다">&lt;/span>
&lt;a href="#%ec%9e%90-debug-%ec%97%ac%ed%96%89%ec%9d%98-%ec%8b%9c%ec%9e%91%ec%9d%b4%ec%98%80%ec%8a%b5%eb%8b%88%eb%8b%a4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>&lt;hr>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ResponseModel&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">someMethod&lt;/span>&lt;span class="p">(){&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 특정 로직들 수행&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">flagColumnAsyncUpdateMethod&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ResponseModel&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Async&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">flagColumnAsyncUpdateMethod&lt;/span>&lt;span class="p">(){&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// Flag Column update&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>해당 Flag 컬럼이 업데이트되는 로직은 다음과 같았습니다.&lt;/p>
&lt;p>사실 이렇게 보면 별거 없는 로직입니다.
그래서 처음에는 더 이해가 안됐습니다.&lt;/p>
&lt;p>이게 Response까지 정상으로 반환했는데
Flag 컬럼만 업데이트 안될 이유가 뭐가 있지&amp;hellip;? 도대체?&lt;/p>
&lt;p>원인을 생각하고 로그를 막 뒤져보다 문득 이건가? 하고 떠오르는게 있었습니다.&lt;/p>
&lt;blockquote>
&lt;p>이미 제목에서 힌트를 얻으신 분들은 눈치 채셨을지도 모르겠습니다만 저때는 생각도 못하고 있었기 때문에 찾는데 조금 시간이 걸린 것 같습니다.&lt;/p>
&lt;/blockquote>
&lt;p>생각의 흐름은 이러했습니다&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>1. 혹시 로직이 돌다 죽었나?
2. 서버가 죽을 일이 뭐가 있지?
3. Kubernetes HPA가 있겠구나
4. 근데 설정해놔서 Pod 죽일때 Graceful Shutdown할텐데?
5. Graceful Shutdown이 제대로 안됐나? 왜 안됐지?
6. 아 비동기...!&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;blockquote>
&lt;h4>Kubernetes HPA란&lt;span class="hx:absolute hx:-mt-20" id="kubernetes-hpa란">&lt;/span>
&lt;a href="#kubernetes-hpa%eb%9e%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>
&lt;/blockquote>
&lt;p>HPA(HorizontalPodAutoscaler)는 CPU, Memory 등 리소스가 정해둔 임계치를 초과할 경우 자동으로 스케일 아웃(Pod의 리소스를 증가 시키지 않고, Pod 개수 자체를 늘려줌) 해주는 기능을 갖추고 있습니다. HPA 컨트롤러가 리소스를 체크하며 정해둔 replicas 수에 맞춰 Pod를 줄이거나 늘려줍니다.
출처: &lt;a href="https://nirsa.tistory.com/187"target="_blank" rel="noopener">https://nirsa.tistory.com/187&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> [Nirsa:티스토리]&lt;/p>
&lt;blockquote>
&lt;h4>Graceful Shutdown이란&lt;span class="hx:absolute hx:-mt-20" id="graceful-shutdown이란">&lt;/span>
&lt;a href="#graceful-shutdown%ec%9d%b4%eb%9e%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h4>
&lt;/blockquote>
&lt;p>우아한 종료라고 직역하면 뭔가 어색하지만, 그 역의 경우를 생각해보면 제법 어울리는 표현이라는 생각이 듭니다. 우아한 종료는 프로그램이 종료될 때 최대한 side effect가 없도록 로직들을 잘 처리하고 종료하는 것을 말합니다.
출처: &lt;a href="https://csj000714.tistory.com/518"target="_blank" rel="noopener">https://csj000714.tistory.com/518&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p>
&lt;hr>
&lt;h3>원인 파악&lt;span class="hx:absolute hx:-mt-20" id="원인-파악">&lt;/span>
&lt;a href="#%ec%9b%90%ec%9d%b8-%ed%8c%8c%ec%95%85" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>Kubernetes HPA가 Pod가 더이상 필요하지 않다 생각해 Delete를 날리게 되면 Pod 를 삭제하기 전에 Pod 내의 컨테이너에 &lt;code>SIGTERM&lt;/code>시그널을 날리게 됩니다.&lt;/p>
&lt;p>시그널을 보내고, 일정 시간(기본적으로 30초) 동안 대기하다가 만약 일정 시간 내에 컨테이너가 종료되지 않으면 kubelet 은 &lt;code>SIGKILL&lt;/code> 시그널을 보내어 강제로 컨테이너를 종료시킵니다.&lt;/p>
&lt;p>스프링 부트 내장 WAS인 Tomcat은 Option을 설정할 경우 Graceful shutdown을 지원하는데
해당 서버는 잘 설정돼 있는 상태였기 때문에 &lt;code>SIGTERM&lt;/code>을 받는다면 Request를 받았던 요청들을 완료한 후 Rsponse를 반환하고 서버를 종료하게 됩니다.&lt;/p>
&lt;p>그래서 저는 해당하는 메소드가 비동기 로직을 Call해놓고는 Response를 반환했기 때문에 Tomcat 입장에서는 정상적으로 끝났다 생각하고 종료한 거 아닐까? 라는 생각이 들었습니다.&lt;/p>
&lt;p>바로 Pod가 죽는 시점쪽을 중점으로 로그를 까봤습니다.&lt;/p>
&lt;p>아니나 다를까 정답.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/5f58f935-b7e2-49a0-b8fc-9fbb7224c311/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>Response 이후에 바로 서버가 Shutdown 되기 시작하는 모습을 볼 수 있었습니다.&lt;/p>
&lt;p>스프링 애플리케이션이 비동기 async 로직을 다 수행하지 않았음에도 종료된 것이죠.&lt;/p>
&lt;p>그리고는 관련한 이슈를 찾아봤습니다 결과적으로 &lt;a href="https://kth990303.tistory.com/464"target="_blank" rel="noopener">비슷한 케이스&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>를 찾을 수 있었죠&lt;/p>
&lt;p>해결 방법 또한 찾을 수 있었습니다. 저또한 마찬가지로 다음과 같은 방법으로 해결했습니다. &lt;a href="https://velog.io/@byeongju/%EB%B9%84%EB%8F%99%EA%B8%B0-ThreadPool%EC%9D%98-Thread%EA%B0%80-%EC%8B%A4%ED%96%89%EC%A4%91%EC%9D%B8%EB%8D%B0-JVM%EC%9D%B4-%EC%A2%85%EB%A3%8C%EB%90%9C%EB%8B%A4%EB%A9%B4"target="_blank" rel="noopener">(관련 글)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p>
&lt;hr>
&lt;h3>정리&lt;span class="hx:absolute hx:-mt-20" id="정리">&lt;/span>
&lt;a href="#%ec%a0%95%eb%a6%ac" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>시퀀스 다이어그램으로 정리하자면 다음과 같았습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/84005938-77fd-4b15-8d42-6f7aa55fb626/image.jpg" alt="" loading="lazy" />&lt;/p>
&lt;p>글로 정리하자면 다음과 같았죠&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>- 12시 30분에 Request
- Request 직후 k8s pod delete
- 해당 pod request 더이상 안받음
- spring graceful 설정 돼 있기 때문에 response 줄때까지 shutdown 대기
- 로직 돌며 Async로직 만났을때 비동기 던지고 response 줌
- response 줬기때문에 shutdown
- Async 로직 안돔 ( 문제 상황 발생 )&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>재미있는 트러블슈팅이였습니다. Gracefult shutdown에 대해 한번 더 자세히 보게 된 계기가 됐고, Health Check나 비동기에 대해서도 한번 더 고심하게 되는 트러블 슈팅이였습니다.
최근들어 인프라쪽을 보게되는 일이 많았는데 K8s 파드가 오토스케일링 된다는 점을 생각하지 못했다면 디버깅하는데 좀더 시간이 걸렸을 수도 있겠다 싶었습니다.&lt;/p>
&lt;hr>
&lt;blockquote>
&lt;p>위 본문 내용중 정확하지 않은 내용이 포함돼 있을 수 있습니다.
저는 1년차 백엔드 개발자로 스스로 굉장히 부족한 사람이라는 점을 인지하고 있는지라
제가 적은 정보가 정확하지 않을까 걱정하고 있습니다.
혹여 제 정보가 잘못 됐을 수 있으니 단지 참고용으로만 봐주시고 관련된 내용을 한번 직접 알아보시는 걸 추천합니다.
혹여 잘못된 내용이 있거나 말씀해주시고 싶은 부분이 있으시다면 부담없이 적어주세요!
수용하고 개선하기 위해 노력하겠습니다!!!&lt;/p>
&lt;/blockquote>
&lt;h3>Reference&lt;span class="hx:absolute hx:-mt-20" id="reference">&lt;/span>
&lt;a href="#reference" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;a href="https://leehosu.github.io/kubernetes-delete-pod"target="_blank" rel="noopener">https://leehosu.github.io/kubernetes-delete-pod&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://hudi.blog/springboot-graceful-shutdown/"target="_blank" rel="noopener">https://hudi.blog/springboot-graceful-shutdown/&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://velog.io/@dongvelop/Springboot-Graceful-Shutdown"target="_blank" rel="noopener">https://velog.io/@dongvelop/Springboot-Graceful-Shutdown&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://findmypiece.tistory.com/321"target="_blank" rel="noopener">https://findmypiece.tistory.com/321&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://velog.io/@byeongju/%EB%B9%84%EB%8F%99%EA%B8%B0-ThreadPool%EC%9D%98-Thread%EA%B0%80-%EC%8B%A4%ED%96%89%EC%A4%91%EC%9D%B8%EB%8D%B0-JVM%EC%9D%B4-%EC%A2%85%EB%A3%8C%EB%90%9C%EB%8B%A4%EB%A9%B4"target="_blank" rel="noopener">https://velog.io/@byeongju/%EB%B9%84%EB%8F%99%EA%B8%B0-ThreadPool%EC%9D%98-Thread%EA%B0%80-%EC%8B%A4%ED%96%89%EC%A4%91%EC%9D%B8%EB%8D%B0-JVM%EC%9D%B4-%EC%A2%85%EB%A3%8C%EB%90%9C%EB%8B%A4%EB%A9%B4&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://peterica.tistory.com/184"target="_blank" rel="noopener">https://peterica.tistory.com/184&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://kth990303.tistory.com/464"target="_blank" rel="noopener">https://kth990303.tistory.com/464&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://saramin.github.io/2022-05-17-kubernetes-autoscaling/"target="_blank" rel="noopener">https://saramin.github.io/2022-05-17-kubernetes-autoscaling/&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p></description></item><item><title>JPA, MyBatis 동시 사용 시 발생할 수 있는 HikariCP Deadlock 해결 여정 (feat. OSIV)</title><link>https://jeongil.dev/ko/blog/backend/troubleshooting/hikaricp-deadlock-with-jpa-mybatis/</link><pubDate>Tue, 09 Jan 2024 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/backend/troubleshooting/hikaricp-deadlock-with-jpa-mybatis/</guid><description>
&lt;p>이번에 회사에서 직면했던 HikariCP Deadlock 문제에 대해 공유하고자 글을 남깁니다.&lt;/p>
&lt;hr>
&lt;h2>문제 발생&lt;span class="hx:absolute hx:-mt-20" id="문제-발생">&lt;/span>
&lt;a href="#%eb%ac%b8%ec%a0%9c-%eb%b0%9c%ec%83%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>오늘도 어김없이 문제는 Slack 메세지로부터 시작합니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/d41bbeea-f417-4cf1-be1c-5aaa7f04bbda/image.png" alt="" loading="lazy" />&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>Stack trace 중 일부 발췌&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>Caused by: java.sql.SQLTransientConnectionException:
HikariPool-1 - Connection is not available, request timed out after 30008ms.&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;/blockquote>
&lt;p>처음에 Slack으로 Stack trace를 얼핏 봤을때는 고개를 갸우뚱 하게 됐습니다.&lt;/p>
&lt;p>Hikari에 Connection을 받기 위해 30초나 대기 했는데 못받았다고&amp;hellip;?&lt;/p>
&lt;p>역시나 받자마자 어느 부분에서 발생한 건지 어떤 이유에서 발생한 건지 파악하기 위해 로그를 까보기 시작했습니다.&lt;/p>
&lt;p>우선 해당 예외가 발생한 서버의 &lt;code>maximum-pool-size&lt;/code>는 40으로 설정돼 있었습니다.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>서버 HikariPool Connection 관련 log&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>HikariPool-1 - Timeout failure stats (total=40, active=40, idle=0, waiting=46)&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;/blockquote>
&lt;p>예외가 발생한 당시 트래픽이 몰리는 시간 및 로직인걸 감안하더라도 30초를 대기했다가 Connection을 얻는 걸 실패했다는 건 도무지 이해할 수 없었습니다.&lt;/p>
&lt;p>좀 더 고개를 갸우뚱 하게 했던 점은, &lt;strong>해당 로직은 몇 개월 전 수정된 이후로 수정된 적이 없는 로직&lt;/strong>이였고, 몇 달간 문제없이 운영하다 이번에서야 이런 예외가 발생했다는 것이였습니다.&lt;/p>
&lt;p>머릿속에서 시뮬레이션을 해보다 관련 이슈가 존재하는지 찾아보게 됐습니다. 감사하게도 관련된 이슈를 어렵지 않게 찾을 수 있었습니다.&lt;/p>
&lt;p>&lt;a href="https://techblog.woowahan.com/2664/"target="_blank" rel="noopener">HikariCP Dead lock에서 벗어나기 (이론편) - 우아한형제들 기술블로그&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p>
&lt;p>Deadlock을 의심하지 않았던 것은 아니였습니다. 그러나 어플리케이션 레벨이 아닌 DB단에서의 Deadlock을 의심했지만 해당하는 문제는 없었고, DB단에서 Deadlock이 발생했다면 Deadlock에 관한 예외가 터져야 했기 때문에 그 부분을 의심하고 있진 않았습니다.&lt;/p>
&lt;blockquote>
&lt;p>그런데 이게 웬걸.. HikariCP에서도 Deadlock이 발생할 수 있던 거였구나&amp;hellip;?&lt;/p>
&lt;/blockquote>
&lt;p>생각해보지도 경험해보지도 못했기 때문에 의심할 수 없었습니다&amp;hellip;&lt;/p>
&lt;p>해당 글과 비슷한 증상들을 확인할 수 있었기 때문에 얼마 안 가 원인 파악할 수 있겠다 싶었습니다. 결론적으로 해당 글에서 HikariCP Deadlock이 발생했던 원인은 다음으로 꼽고 있습니다.&lt;/p>
&lt;blockquote>
&lt;p>부하 상황에서 Thread간 Connection을 차지하기 위한 Race Condition이 발생합니다.
메세지 1개를 저장하는데 &lt;strong>한 Transaction에서 동시에 Connection 2개를 사용&lt;/strong>하면서 HikariCP에 대한 Thread간 Deadlock이 발생하게 되었습니다.&lt;/p>
&lt;/blockquote>
&lt;hr>
&lt;h2>문제 해결..?&lt;span class="hx:absolute hx:-mt-20" id="문제-해결">&lt;/span>
&lt;a href="#%eb%ac%b8%ec%a0%9c-%ed%95%b4%ea%b2%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>자 원인 파악에 많이 다가선 거 같다 느끼고 금방이라도 해결할 수 있을 것만 같습니다.&lt;/p>
&lt;p>서버 코드를 바로 까보기 시작했죠.&lt;/p>
&lt;p>그런데 이게 웬걸&amp;hellip;? 예외가 발생했던 해당 로직은 &lt;strong>Select로만 이루어져 있으며, 심지어 Transaction도 걸려있지 않은데&amp;hellip;?&lt;/strong>&lt;/p>
&lt;p>다시금 갈피를 잃고 말았습니다.&lt;/p>
&lt;p>우선 다시금 갈피를 잡기 위해 이것저것 시도해보기 시작했고 힌트를 잡을 수 있었습니다.&lt;/p>
&lt;hr>
&lt;h2>왜 Connection을 반환을 안해??&lt;span class="hx:absolute hx:-mt-20" id="왜-connection을-반환을-안해">&lt;/span>
&lt;a href="#%ec%99%9c-connection%ec%9d%84-%eb%b0%98%ed%99%98%ec%9d%84-%ec%95%88%ed%95%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>Local 환경에서 &lt;code>maximum-pool-size&lt;/code>를 1로 설정하고 해당 로직을 테스트해봤습니다.&lt;/p>
&lt;p>결과적으로 같은 예외를 직면할 수 있었고 어느 라인에서 발생하는지도 파악할 수 있었습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">long&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">findBy&lt;/span>&lt;span class="o">~~~&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">factory&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">select&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">serviceNotice&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">count&lt;/span>&lt;span class="p">())&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">from&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">serviceNotice&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">where&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">serviceNotice&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">actType&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">eq&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;특정 조건&amp;#34;&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">serviceNotice&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">section&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">eq&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;특정 조건&amp;#34;&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">serviceNotice&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">actEnable&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">eq&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">serviceNotice&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">startDt&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">before&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">nowDate&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">serviceNotice&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">endDt&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">after&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">nowDate&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">fetchOne&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>정확하게는 해당 메소드가 끝난 후에도 Connection을 반환하지 않고 Active 상태로 하나 물고 있는 현상을 발견할 수 있었습니다.&lt;/p>
&lt;p>처음에는 &lt;code>Connection Leak&lt;/code>으로 인한 HikariCP Deadlock이라고 생각했습니다. 해당 로직을 실행할 때 기대했던 Connection 개수는 한 개였지만 해당 코드에서 Connection Leak이 발생하니 로직이 모두 마무리될 때까지 Connection이 동시에 최대 2개 필요한 로직이 되버린 것이라고요.&lt;/p>
&lt;p>&lt;strong>그런데 나중에 알고 보니 Connection Leak이 아니였습니다&amp;hellip;&lt;/strong>&lt;/p>
&lt;hr>
&lt;h2>진짜 문제 해결 중&lt;span class="hx:absolute hx:-mt-20" id="진짜-문제-해결-중">&lt;/span>
&lt;a href="#%ec%a7%84%ec%a7%9c-%eb%ac%b8%ec%a0%9c-%ed%95%b4%ea%b2%b0-%ec%a4%91" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>관련된 글을 찾을 수는 있었습니다.&lt;/p>
&lt;p>&lt;a href="https://colin-d.medium.com/querydsl-%EC%97%90%EC%84%9C-db-connection-leak-%EC%9D%B4%EC%8A%88-40d426fd4337"target="_blank" rel="noopener">Querydsl에서 transform 사용시에 DB connection leak 이슈&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p>
&lt;p>그러나 아쉽게도 저희는 해당 글의 이슈와 완전히 동일하지 않았습니다. &lt;code>transform&lt;/code>을 사용하고 있진 않았거든요.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/29a8df6a-c3a3-480f-8269-96503a346b21/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>위 name의 method가 아닐 경우에는 entityManager는 close되지 않는다고 합니다. 그런데 fetchOne의 내부 메소드 이름은 &lt;code>getSingleResult&lt;/code>이기 때문에 close 돼야 했는데&amp;hellip; 어째서 안됐는지 모를 뿐더러 Transaction 어노테이션을 달고 진행해봐도 close되지 않고 있습니다&amp;hellip;&lt;/p>
&lt;p>먼저 QueryDSL이 원인인지 파악해보고 싶어 JPQL로 코드를 변경해 테스트해봤지만 같은 예외 상황이 발생했습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/9d021d03-69e4-43e0-a27b-7a146171dd22/image.png" alt="" loading="lazy" />&lt;/p>
&lt;p>QueryDSL 자체의 문제는 아닐 가능성이 높다 판단하게 됐습니다.&lt;/p>
&lt;p>결국 Connection을 HikariCP에 제대로 반환하지 못했기 때문에 생긴 문제로 생각이 들어 그 부분을 집중적으로 보게 됐습니다.&lt;/p>
&lt;p>실제 Connection을 반환하게 되기까지의 코드를 따라가보려 Debug를 실시했고 &lt;code>DefaultJpaDialect&lt;/code> 클래스의 코드 몇 줄이 눈에 들어왔습니다.&lt;/p>
&lt;p>우선 &lt;code>releaseJdbcConnection()&lt;/code> 메소드 내부를 보면&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/93544a75-a4da-4d4e-8ff6-93c79e0997a6/image.png" alt="" loading="lazy" />&lt;/p>
&lt;blockquote>
&lt;p>This implementation does nothing, assuming that the Connection will implicitly be closed with the EntityManager.&lt;/p>
&lt;/blockquote>
&lt;p>주석을 보면 Connection 반환을 &lt;code>EntityManager&lt;/code>에 위임하고 있는 모습을 확인할 수 있었습니다.&lt;/p>
&lt;p>해당 로직과 EntityManager를 중점으로 생각하고 코드를 까봐야겠습니다.&lt;/p>
&lt;blockquote>
&lt;p>또 한 가지 의문인 점은 테스트 코드로 해당 로직을 호출했을 때는 Connection 1개로도 문제 없더라구요&amp;hellip; 참 알다가도 모르겠네요..&lt;/p>
&lt;/blockquote>
&lt;hr>
&lt;h2>원인 파악 완료&lt;span class="hx:absolute hx:-mt-20" id="원인-파악-완료">&lt;/span>
&lt;a href="#%ec%9b%90%ec%9d%b8-%ed%8c%8c%ec%95%85-%ec%99%84%eb%a3%8c" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>원인 파악했습니다.&lt;/p>
&lt;p>EntityManager가 close되는 시점에 대한 부분을 좀 더 파악해보다&lt;/p>
&lt;blockquote>
&lt;p>그러고 보니 영속성 컨텍스트가 Connection을 언제 놓아주지&amp;hellip;?&lt;/p>
&lt;/blockquote>
&lt;p>사실 저는 그전에는 Connection을 쿼리의 리턴을 받은 순간 혹은 Transaction이 걸려있다면 Transaction이 끝나는 순간 반환하겠지? 라는 생각을 하고 있었습니다. 해당하는 로직은 Transaction이 안 걸려있기 때문에 당연하게도 쿼리가 리턴받은 순간 Connection을 반환할 거다라고 생각하고 있었습니다. 그러나 의문을 가지게 된 순간부터 관련된 내용을 좀 더 찾아보게 됐습니다.&lt;/p>
&lt;p>그리고는 &lt;code>OSIV 옵션&lt;/code>에 대해 알게 됐습니다.&lt;/p>
&lt;h3>OSIV(Open Session In View)란?&lt;span class="hx:absolute hx:-mt-20" id="osivopen-session-in-view란">&lt;/span>
&lt;a href="#osivopen-session-in-view%eb%9e%80" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;a href="https://ykh6242.tistory.com/m/entry/JPA-OSIVOpen-Session-In-View%EC%99%80-%EC%84%B1%EB%8A%A5-%EC%B5%9C%EC%A0%81%ED%99%94"target="_blank" rel="noopener">관련 글&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p>
&lt;p>&lt;strong>OSIV ON일 때:&lt;/strong>&lt;/p>
&lt;p>&lt;img src="https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fbd835C%2FbtqTPzbjhqa%2FAPhn7gWwr4pRhzCL79N4q1%2Fimg.png" alt="" loading="lazy" />&lt;/p>
&lt;ul>
&lt;li>클라이언트의 요청이 들어오면 서블릿 필터나, 스프링 인터셉터에서 영속성 컨텍스트를 생성한다. 단 이 시점에서 트랜잭션은 시작하지 않는다.&lt;/li>
&lt;li>서비스 계층에서 @Transactional로 트랜잭션을 시작할 때 미리 생성해둔 영속성 컨텍스트를 찾아와서 트랜잭션을 시작한다.&lt;/li>
&lt;li>서비스 계층이 끝나면 트랜잭션을 커밋하고 영속성 컨텍스트를 플러시한다. &lt;strong>이 시점에 트랜잭션은 끝내지만 영속성 컨텍스트는 종료되지 않는다.&lt;/strong>&lt;/li>
&lt;li>컨트롤러와 뷰까지 영속성 컨텍스트가 유지되므로 조회한 엔티티는 영속 상태를 유지한다.&lt;/li>
&lt;li>서블릿 필터나, 스프링 인터셉터로 요청이 돌아오면 영속성 컨텍스트를 종료한다.&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>OSIV OFF일 때:&lt;/strong>&lt;/p>
&lt;p>&lt;img src="https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&amp;amp;fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FemsRZ9%2FbtqTLyKOQQ7%2F5cKM4Ma00A7LYKwhde77Zk%2Fimg.png" alt="" loading="lazy" />&lt;/p>
&lt;ul>
&lt;li>OSIV를 끄면 트랜잭션을 종료할 때 영속성 컨텍스트를 닫고, &lt;strong>데이터베이스 커넥션도 반환한다.&lt;/strong> 따라서 커넥션 리소스를 낭비하지 않는다.&lt;/li>
&lt;li>OSIV를 끄면 모든 지연로딩을 트랜잭션 안에서 처리해야 한다. 따라서 지금까지 작성한 많은 지연 로딩 코드를 트랜잭션 안으로 넣어야 하는 단점이 있다.&lt;/li>
&lt;/ul>
&lt;p>OSIV 또는 OEIV 패턴을 사용하기 위한 스프링 웹 인터셉터로 트랜잭션이 종료되더라도 EntityManager의 관리 상태를 유지하는 기능으로, &lt;strong>이 때문에 Connection이 유지됐던 것이였습니다.&lt;/strong>&lt;/p>
&lt;pre class="mermaid hx:mt-6">
sequenceDiagram
participant Client as 클라이언트
participant Filter as OSIV Filter
participant Service as Service
participant EM as EntityManager
participant DB as Database
Client-&amp;gt;&amp;gt;Filter: HTTP 요청
Filter-&amp;gt;&amp;gt;EM: 영속성 컨텍스트 생성
EM-&amp;gt;&amp;gt;DB: Connection 획득
Filter-&amp;gt;&amp;gt;Service: 비즈니스 로직 실행
Service-&amp;gt;&amp;gt;EM: JPA 쿼리 실행
EM-&amp;gt;&amp;gt;DB: SELECT
DB--&amp;gt;&amp;gt;EM: 결과 반환
Service--&amp;gt;&amp;gt;Filter: 로직 완료
Note over EM,DB: 트랜잭션 종료, 하지만 Connection 유지!
Filter--&amp;gt;&amp;gt;Client: HTTP 응답
Filter-&amp;gt;&amp;gt;EM: 영속성 컨텍스트 종료
EM-&amp;gt;&amp;gt;DB: Connection 반환
&lt;/pre>&lt;p>&lt;strong>Connection이 유지되는 것만으로는 HikariCP Deadlock이 발생할 조건을 만족시키지 않았지만&lt;/strong>, 문제는 QueryDSL 이후 코드에 발생 조건을 충족시키는 코드가 존재했다는 것이였습니다.&lt;/p>
&lt;p>QueryDSL 이후 코드에는 &lt;strong>MyBatis로 이루어진 코드가 존재했기 때문입니다&amp;hellip;&lt;/strong>&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>어째서 MyBatis랑 JPA랑 같이 있나요?&lt;/strong>&lt;/p>
&lt;p>기존 MyBatis로 이루어진 로직을 JPA로 변경하는 작업을 진행하던 서버였고, 단계별로 JPA로 변경하면서 일부 로직만 수정이 완료된 상태였던 것입니다.&lt;/p>
&lt;/blockquote>
&lt;p>&lt;strong>Connection이 유지된 상태에서 MyBatis를 사용하게 되고 Connection이 한 개 더 필요해지면서 Deadlock이 발생했던 것이였습니다.&lt;/strong>&lt;/p>
&lt;pre class="mermaid hx:mt-6">
flowchart TB
subgraph Request[&amp;#34;하나의 HTTP 요청에서 Connection 2개 필요&amp;#34;]
JPA[&amp;#34;1. JPA 쿼리 실행&amp;lt;br/&amp;gt;→ Connection #1 획득&amp;lt;br/&amp;gt;→ OSIV로 인해 유지&amp;#34;]
MyBatis[&amp;#34;2. MyBatis 쿼리 실행&amp;lt;br/&amp;gt;→ Connection #2 필요&amp;lt;br/&amp;gt;→ 💥 Pool이 가득 차면 Deadlock!&amp;#34;]
JPA --&amp;gt; MyBatis
end
&lt;/pre>&lt;p>이래서 테스트 코드로 Service 로직만 테스트했을 땐 문제가 발생하지 않았던 거죠. (OSIV는 웹 요청 컨텍스트에서만 동작)&lt;/p>
&lt;hr>
&lt;h2>결론: HikariCP Deadlock 발생 조건&lt;span class="hx:absolute hx:-mt-20" id="결론-hikaricp-deadlock-발생-조건">&lt;/span>
&lt;a href="#%ea%b2%b0%eb%a1%a0-hikaricp-deadlock-%eb%b0%9c%ec%83%9d-%ec%a1%b0%ea%b1%b4" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>&lt;strong>핵심은 OSIV가 아니라, 한 태스크에서 Connection을 2개 필요로 하면 Deadlock이 발생할 수 있다는 것입니다.&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>해당 예외 발현 조건
1. JPA, MyBatis 동시 사용
2. JPA, MyBatis가 동일한 Connection Pool 공유
3. OSIV 옵션 ON
(※ Off이더라도 한 Transaction 안에 영속성 컨텍스트가 로딩된 이후에 MyBatis 코드가 호출되면 결과 동일)
4. REST API로 요청 받음 (OSIV 옵션 On일 경우)
5. 한 Task 안에서 영속성 컨텍스트 로딩 → Connection 1개 잡고 있음
6. MyBatis 사용 → Connection 1개 더 필요 → Connection 2개가 필요한 Task가 됐음
7. 5번에서 6번으로 넘어가는 로직동안 Connection을 모두 점유한 상태라면 Deadlock 발생&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 위 조건 발생 코드 예시&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">deadLockMethod&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">mybatisSelectMethod&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// Connection Pool 1/1 (대기 큐: 0)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// Connection 반환 - Connection Pool 0/1 (대기 큐: 0)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">jpaSelectMethod&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// Connection Pool 1/1 (대기 큐: 0)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 영속성 컨텍스트 Close() 되지 않으므로 Connection 유지 - Connection Pool 1/1 (대기 큐: 0)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">mybatisSelectMethod&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// Connection Pool 1/1 (대기 큐: 1)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// → 30초간 대기 후 Exception: Deadlock 발생 시점!!&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;hr>
&lt;h2>해결 방법&lt;span class="hx:absolute hx:-mt-20" id="해결-방법">&lt;/span>
&lt;a href="#%ed%95%b4%ea%b2%b0-%eb%b0%a9%eb%b2%95" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>해당하는 문제는 OSIV 옵션을 조정하는 것은 어느 정도의 영향도를 줄지 파악하지 못한 상태이기 때문에 지양하게 됐고, &lt;strong>한 Task 안에 MyBatis와 JPA를 동시에 사용하지 않도록 코드 레벨에서 수정&lt;/strong>하도록 결론지어졌습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># OSIV 비활성화 (선택적)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">spring&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">jpa&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">open-in-view&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">false&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>단, OSIV를 끄더라도 &lt;strong>한 Transaction 안에서 JPA와 MyBatis를 혼용하면 여전히 Deadlock이 발생할 수 있습니다.&lt;/strong> 근본적인 해결책은 혼용을 제거하는 것입니다.&lt;/p>
&lt;hr>
&lt;h2>그 전에는 발생하지 않았던 이유&lt;span class="hx:absolute hx:-mt-20" id="그-전에는-발생하지-않았던-이유">&lt;/span>
&lt;a href="#%ea%b7%b8-%ec%a0%84%ec%97%90%eb%8a%94-%eb%b0%9c%ec%83%9d%ed%95%98%ec%a7%80-%ec%95%8a%ec%95%98%eb%8d%98-%ec%9d%b4%ec%9c%a0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>해당 예외가 그전에는 발생하지 않았던 이유는 생각보다 단순하다면 단순했습니다.&lt;/p>
&lt;p>저희 회사는 쿠버네티스를 사용 중에 있습니다. 저희는 트래픽이 몰릴 시간대에 미리 최소 파드 개수를 늘려놓습니다만, 최근에 &lt;strong>서버 운용 비용을 절감하기 위해 늘리는 파드 개수를 기존 5개에서 2개로 줄였습니다.&lt;/strong>&lt;/p>
&lt;p>기존에는 트래픽이 여러 파드로 나눠지면서 Connection을 모두 점유할 일이 없었지만, 파드 수가 줄어들며 한 파드에 트래픽이 두 배로 늘어나면서 동시에 요청이 꽂히게 되면 Connection을 모두 점유하게 되면서 해당 예외가 발생했던 겁니다.&lt;/p>
&lt;blockquote>
&lt;p>이 문제를 모두 해결하기 전까지는 파드 수를 다시 늘려 트래픽을 분산시켜서 임시방편 조치를 했습니다.. ㅜ&lt;/p>
&lt;/blockquote>
&lt;hr>
&lt;h2>느낀점&lt;span class="hx:absolute hx:-mt-20" id="느낀점">&lt;/span>
&lt;a href="#%eb%8a%90%eb%82%80%ec%a0%90" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>JPA에 대한 지식이 조금만 더 있었어도 보자마자 알아차렸을 텐데&amp;hellip;&lt;/p>
&lt;p>JPA, DBCP, MyBatis, JDBC에 대한 공부를 더 해야겠다는 다짐을 할 수 있었고, JPA의 코드를 까보며 Debug하는 것도 되게 좋은 경험이였던 것 같습니다. 생각보다 되게 흥미로운 경험이였습니다.&lt;/p>
&lt;hr>
&lt;h3>Reference&lt;span class="hx:absolute hx:-mt-20" id="reference">&lt;/span>
&lt;a href="#reference" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;ul>
&lt;li>&lt;a href="https://techblog.woowahan.com/2664/"target="_blank" rel="noopener">https://techblog.woowahan.com/2664/&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> - HikariCP Deadlock에서 벗어나기 (이론편)&lt;/li>
&lt;li>&lt;a href="https://techblog.woowahan.com/2663/"target="_blank" rel="noopener">https://techblog.woowahan.com/2663/&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> - HikariCP Deadlock에서 벗어나기 (실전편)&lt;/li>
&lt;li>&lt;a href="https://colin-d.medium.com/querydsl"target="_blank" rel="noopener">https://colin-d.medium.com/querydsl&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에서-db-connection-leak-이슈&lt;/li>
&lt;li>&lt;a href="https://ykh6242.tistory.com/m/entry/JPA-OSIVOpen-Session-In-View"target="_blank" rel="noopener">https://ykh6242.tistory.com/m/entry/JPA-OSIVOpen-Session-In-View&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>와-성능-최적화&lt;/li>
&lt;li>&lt;a href="https://github.com/brettwooldridge/HikariCP"target="_blank" rel="noopener">https://github.com/brettwooldridge/HikariCP&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>Spring batch job 동시 등록 Deadlock 문제 직면 ( Deadlock accessing creating a job on sqlserver when multiple jobs start at once )</title><link>https://jeongil.dev/ko/blog/backend/troubleshooting/spring-batch-job-deadlock/</link><pubDate>Mon, 20 Nov 2023 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/backend/troubleshooting/spring-batch-job-deadlock/</guid><description>
&lt;p>이번에 제가 회사에서 직면했던 Spring batch 관련 문제에 대해 공유하고자 글을 남깁니다.&lt;/p>
&lt;hr>
&lt;h2>문제 발생&lt;span class="hx:absolute hx:-mt-20" id="문제-발생">&lt;/span>
&lt;a href="#%eb%ac%b8%ec%a0%9c-%eb%b0%9c%ec%83%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>해당 문제는 에러 Slack 메세지로부터 시작됩니다.
회사 Batch 서버에서 Deadlock이 발생했다는 Stack trace였습니다.&lt;/p>
&lt;p>당연하게도 Deadlock은 서비스에 심각한 영향을 줄 수 있었기 때문에 지체없이
문제를 파악하기 시작했고 로그를 까보게 됐습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/20624ee0-53a1-4021-b7c4-38d1dd59cec5/image.png" alt="" loading="lazy" />&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>해당 Stack trace 중 일부&lt;/strong>
com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction&lt;/p>
&lt;/blockquote>
&lt;p>Deadlock이 발생한 시점에 실행된 Job은 총 3개 였습니다.&lt;/p>
&lt;p>실행되지 않은 Job은 하나였고, 다른 2개의 Job은 문제없이 실행됐음을 확인할 수 있었습니다.&lt;/p>
&lt;p>게다가 더 다행이였던 점은 실행되지 않은 Job은 운영 환경에서의 테스트를 충분히 거치기 위해 서비스에 영향이 가지 않는 선에서 실 데이터로 테스트를 하던 Job이 였기에 데이터나 서비스에 영향이 없었다는 점이였습니다.&lt;/p>
&lt;p>서비스에 영향이 없다는 것을 파악하며 한시름 놓고 이제는 원인을 파악하기 시작했습니다.&lt;/p>
&lt;hr>
&lt;h2>원인 분석&lt;span class="hx:absolute hx:-mt-20" id="원인-분석">&lt;/span>
&lt;a href="#%ec%9b%90%ec%9d%b8-%eb%b6%84%ec%84%9d" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>해당 Deadlock이 발생한 테이블은 &lt;strong>BATCH_JOB_INSTANCE&lt;/strong>라는 테이블로 해당 테이블에 대해 이해하려면 Spring batch에 대한 지식이 조금 필요합니다.&lt;/p>
&lt;p>저희 회사의 Batch 서버는 Spring batch로 개발돼 있습니다.&lt;/p>
&lt;blockquote>
&lt;p>( 기존 PHP와 Crontab으로 이루어져 있던 batch기능들을 Spring batch로 옮기며 추가적인 개발을 하는 중 입니다. )&lt;/p>
&lt;/blockquote>
&lt;p>&lt;code>Spring&lt;/code>에서는 &lt;code>Spring batch framework&lt;/code>를 통해 배치작업을 위한 다양한 기능들을 간편하게 사용 할 수 있도록 제공 해 주고 있습니다.&lt;/p>
&lt;p>그 중, Spring batch가 제공하는 가장 기본적인 기능으로 배치 작업 하는동안 사용되는 모든 메타정보들 (작업 시간, 파라미터, 정상수행 여부 …)을 기록하여 작업 중에 사용하거나 모니터링 용도로 사용 할 수 있게 해줍니다.&lt;/p>
&lt;p>&lt;img src="https://t1.daumcdn.net/cfile/tistory/99E033405B66D86909" alt="" loading="lazy" />&lt;/p>
&lt;p>이러한 테이블들을 &lt;code>Metadata tables&lt;/code>라고 하는데 &lt;strong>BATCH_JOB_INSTANCE&lt;/strong>는 이러한 메타 테이블 중 하나입니다.&lt;/p>
&lt;p>이게 Deadlock이 걸릴 정도로 트래픽이 많은 테이블도 아니였기 때문에 이상하다는 생각이 들었습니다.&lt;/p>
&lt;p>이대로 둘 수는 없었기 때문에 당연하게도 관련 레퍼런스를 찾게됐습니다만,
아쉽게도 한글로 돼있는 관련된 글은 찾지 못했습니다.&lt;/p>
&lt;blockquote>
&lt;p>( 물론 존재하지만 제가 못찾은 걸 수 있습니다 )&lt;/p>
&lt;/blockquote>
&lt;p>이는 제게는 너무 슬픈 사실이였습니다.
제 부족한 영어실력때문인지 한글을 찾게 되는 본능이 항상 남아있었기에
영어로 돼있는 글들을 읽어야한다는게 슬프게 다가왔습니다&amp;hellip;.&lt;/p>
&lt;p>그러나 문제는 해결해야하기때문에 관련 사항을 찾아보다 같은 문제를 직면한 이슈를 찾게 됐습니다.&lt;/p>
&lt;p>&lt;a href="https://github.com/spring-projects/spring-batch/issues/1448"target="_blank" rel="noopener">https://github.com/spring-projects/spring-batch/issues/1448&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p>
&lt;p>본 이슈 내용은 대략 제 상황과 비슷했습니다.&lt;/p>
&lt;p>해당 이슈는 2013년 11월 22일 처음 발행됐습니다.
비슷한 내용의 글이 &lt;a href="https://stackoverflow.com/questions/70563630/spring-batch-deadlock-could-not-increment-identity-nested-exception-is-com-mi"target="_blank" rel="noopener">stack overflow&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에도 올라와 있었죠.&lt;/p>
&lt;p>해당 이슈에서 말하는 원인은 다음과 같았습니다.&lt;/p>
&lt;blockquote>
&lt;p>In the SimpleJobRepository when creating a job it first SELECTs for the first job, then if it doesn&amp;rsquo;t find one, INSERTs a new one. Unfortunately that first select (even at serializable) just takes out shared locks. So two concurrent processes both get shared (reader) locks, then both try to acquire exclusive (writer) locks &amp;ndash; leading to a deadlock.&lt;/p>
&lt;/blockquote>
&lt;h5>번역&lt;span class="hx:absolute hx:-mt-20" id="번역">&lt;/span>
&lt;a href="#%eb%b2%88%ec%97%ad" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h5>&lt;p>SimpleJobRepository에서 작업을 만들 때 먼저 첫 번째 작업을 선택한 다음, 작업을 찾지 못하면 새로운 작업을 삽입합니다. 불행히도 첫 번째 SELECT 문은 공유 락(리더 락)만 획득하게 됩니다. 그래서 두 개의 동시 프로세스가 모두 공유(리더) 락을 획득한 다음, 모두 배타적(라이터) 락을 획득하려고 하면 데드락이 발생합니다&lt;/p>
&lt;hr>
&lt;h2>문제 해결&lt;span class="hx:absolute hx:-mt-20" id="문제-해결">&lt;/span>
&lt;a href="#%eb%ac%b8%ec%a0%9c-%ed%95%b4%ea%b2%b0" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h2>&lt;p>먼저 가장 간단한 해결방법은 이랬습니다.&lt;/p>
&lt;p>&lt;strong>1. 여러개의 Job을 동시에 실행시키지 않는다&lt;/strong>&lt;/p>
&lt;p>그러나 이는 절대 좋은 방법이 아니라는 생각이 들었습니다.
읽는과 동시에 거부감이 든 해결방법이였습니다. 이유는 많겠지만 이렇게 해결했을 때
문제는 해결되지 않은 상태이기때문에 여러 스케줄들 중 겹치는게 많아지는 시점이 존재해진다면
문제는 다시 발생하게 될 것 입니다.&lt;/p>
&lt;p>그리고 이는 문제를 해결하는 것이 아닌 회피하는 방법이라는 생각이 제 개인적인 견해입니다.&lt;/p>
&lt;p>이슈에서 첫번째로 제안한 해결방법은 다음과 같았습니다.&lt;/p>
&lt;p>&lt;strong>2. Batch 관련 설정 정보 Bean 등록&lt;/strong>&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;span class="lnt">45
&lt;/span>&lt;span class="lnt">46
&lt;/span>&lt;span class="lnt">47
&lt;/span>&lt;span class="lnt">48
&lt;/span>&lt;span class="lnt">49
&lt;/span>&lt;span class="lnt">50
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@Configuration&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@EnableBatchProcessing&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">BatchConfiguration&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">static&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">final&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ISOLATION_REPEATABLE_READ&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;ISOLATION_REPEATABLE_READ&amp;#34;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nd">@Autowired&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">DataSource&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dataSource&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nd">@Autowired&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">PlatformTransactionManager&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">platformTransactionManager&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nd">@Bean&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">JobRepository&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">jobRepository&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">throws&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Exception&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">JobRepositoryFactoryBean&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">factory&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">JobRepositoryFactoryBean&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">factory&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setDataSource&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">dataSource&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">factory&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setTransactionManager&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">platformTransactionManager&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">factory&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setValidateTransactionState&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">factory&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setIsolationLevelForCreate&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">ISOLATION_REPEATABLE_READ&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">factory&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setIncrementerFactory&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">customIncrementerFactory&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">factory&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">afterPropertiesSet&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">factory&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getObject&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nd">@Bean&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">SimpleJobLauncher&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">jobLauncher&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">JobRepository&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobRepository&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">SimpleJobLauncher&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">simpleJobLauncher&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">SimpleJobLauncher&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">simpleJobLauncher&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setJobRepository&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">jobRepository&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">simpleJobLauncher&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">DataFieldMaxValueIncrementerFactory&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">customIncrementerFactory&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">CustomDataFieldMaxValueIncrementerFactory&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">dataSource&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">CustomDataFieldMaxValueIncrementerFactory&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">extends&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">DefaultDataFieldMaxValueIncrementerFactory&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">CustomDataFieldMaxValueIncrementerFactory&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">DataSource&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dataSource&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">super&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">dataSource&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nd">@Override&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">DataFieldMaxValueIncrementer&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">getIncrementer&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">incrementerType&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">incrementerName&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">DataFieldMaxValueIncrementer&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">incrementer&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">super&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getIncrementer&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">incrementerType&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">incrementerName&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">incrementer&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">instanceof&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">SqlServerMaxValueIncrementer&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">((&lt;/span>&lt;span class="n">SqlServerMaxValueIncrementer&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">incrementer&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="na">setCacheSize&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">20&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">incrementer&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>job repository의 Isolation level을 별도로 설정해주고 직접 Bean으로 등록하여 해결하는 방법이였습니다.&lt;/p>
&lt;blockquote>
&lt;p>해당 이슈에서는 REPEATABLE_READ단계로 설정해주어 &lt;code>could not increment identity&lt;/code>
문제를 직면했기 때문에 Isolation level을 &lt;code>READ_COMMITTED&lt;/code>로 변경했다고 합니다.&lt;/p>
&lt;/blockquote>
&lt;h5>본문&lt;span class="hx:absolute hx:-mt-20" id="본문">&lt;/span>
&lt;a href="#%eb%b3%b8%eb%ac%b8" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h5>&lt;p>Different jobs were now trying to insert into the DB at the same time, causing a deadlock. We now set IsolationLevel to &amp;ldquo;ISOLATION_READ_COMMITTED&amp;rdquo;. To prevent executing the same job in parallel on a cluster we&amp;rsquo;ve been using Hazelcast-locks all along.&lt;/p>
&lt;blockquote>
&lt;p>한가지 참고하셔야할 사항은
Spring boot 2.1 부터는 bean definition overriding이 기본이 false이기때문에 bean을 수동으로 등록하여 overriding 하기 위해서는 &lt;code>application.yml&lt;/code>에 &lt;code>spring.main.allow-bean-definition-overriding: true&lt;/code>옵션을 추가하셔야합니다.&lt;/p>
&lt;/blockquote>
&lt;p>상당히 괜찮은 방법으로 보입니다.
그래도 다른 방법이 존재하는지 찾아봅시다.&lt;/p>
&lt;p>&lt;strong>3. 관련 Class Override&lt;/strong>
다른 방법으로는 관련 클래스들을 override하는 방법입니다.
이하 본문과 같습니다.&lt;/p>
&lt;p>Make the following fields of type IDENTITY:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>BATCH_JOB_INSTANCE.JOB_INSTANCE_ID
BATCH_JOB_EXECUTION.JOB_EXECUTION_ID
BATCH_STEP_EXECUTION.STEP_EXECUTION_ID&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>Change or copy JdbcJobInstanceDao (SqlServerJdbcJobInstanceDao) and change the CREATE_JOB_INSTANCE sql constant and createJobInstance method to:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">static&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">final&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">CREATE_JOB_INSTANCE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;INSERT into %PREFIX%JOB_INSTANCE(JOB_NAME, JOB_KEY, VERSION)&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">+&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34; values (?, ?, ?)&amp;#34;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Override&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">JobInstance&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">createJobInstance&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobName&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">JobParameters&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobParameters&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">Assert&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">notNull&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">jobName&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;Job name must not be null.&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">Assert&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">notNull&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">jobParameters&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;JobParameters must not be null.&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">Assert&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">state&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">getJobInstance&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">jobName&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobParameters&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">==&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;JobInstance must not already exist&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">JobInstance&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobInstance&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">JobInstance&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobName&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">jobInstance&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">incrementVersion&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">KeyHolder&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">generatedKeyHolder&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">GeneratedKeyHolder&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">getJdbcTemplate&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">update&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">connection&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">-&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">final&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">PreparedStatement&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">connection&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">prepareStatement&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">getQuery&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">CREATE_JOB_INSTANCE&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Statement&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">RETURN_GENERATED_KEYS&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setString&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobName&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setString&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">2&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobKeyGenerator&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">generateKey&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">jobParameters&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setInt&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">3&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobInstance&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getVersion&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">},&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">generatedKeyHolder&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">jobInstance&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setId&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">generatedKeyHolder&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getKey&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">longValue&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobInstance&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>Change or copy JdbcJobExecutionDao (SqlServerJdbcJobExecutionDao) and change SAVE_JOB_EXECUTION sql constant and saveJobExecution method:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">static&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">final&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">SAVE_JOB_EXECUTION&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;INSERT into %PREFIX%JOB_EXECUTION(JOB_INSTANCE_ID, START_TIME, &amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">+&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;END_TIME, STATUS, EXIT_CODE, EXIT_MESSAGE, VERSION, CREATE_TIME, LAST_UPDATED, JOB_CONFIGURATION_LOCATION) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)&amp;#34;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Override&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">saveJobExecution&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">JobExecution&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">validateJobExecution&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">incrementVersion&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">KeyHolder&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">generatedKeyHolder&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">GeneratedKeyHolder&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">getJdbcTemplate&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">update&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">connection&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">-&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">PreparedStatement&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">connection&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">prepareStatement&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">getQuery&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">SAVE_JOB_EXECUTION&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Statement&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">RETURN_GENERATED_KEYS&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setLong&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getJobId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setDate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">2&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getStartTime&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">!=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">java&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">sql&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">Date&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getStartTime&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">getTime&lt;/span>&lt;span class="p">())&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setDate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">3&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getEndTime&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">!=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">java&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">sql&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">Date&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getEndTime&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">getTime&lt;/span>&lt;span class="p">())&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setString&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">4&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getStatus&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">toString&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setString&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">5&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getExitStatus&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">getExitCode&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setString&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">6&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getExitStatus&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">getExitDescription&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setInt&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">7&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getVersion&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setDate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">8&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getCreateTime&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">!=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">java&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">sql&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">Date&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getCreateTime&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">getTime&lt;/span>&lt;span class="p">())&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setDate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">9&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getLastUpdated&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">!=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">java&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">sql&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">Date&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getLastUpdated&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">getTime&lt;/span>&lt;span class="p">())&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setString&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">10&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getJobConfigurationName&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">},&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">generatedKeyHolder&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setId&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">generatedKeyHolder&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getKey&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">longValue&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">insertJobParameters&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getId&lt;/span>&lt;span class="p">(),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">jobExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getJobParameters&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>Change or copy JdbcStepExecutionDao (SqlServerJdbcStepExecutionDao) and change the SAVE_STEP_EXECUTION sql constant and saveStepExecution/saveStepExecutions methods:&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt"> 10
&lt;/span>&lt;span class="lnt"> 11
&lt;/span>&lt;span class="lnt"> 12
&lt;/span>&lt;span class="lnt"> 13
&lt;/span>&lt;span class="lnt"> 14
&lt;/span>&lt;span class="lnt"> 15
&lt;/span>&lt;span class="lnt"> 16
&lt;/span>&lt;span class="lnt"> 17
&lt;/span>&lt;span class="lnt"> 18
&lt;/span>&lt;span class="lnt"> 19
&lt;/span>&lt;span class="lnt"> 20
&lt;/span>&lt;span class="lnt"> 21
&lt;/span>&lt;span class="lnt"> 22
&lt;/span>&lt;span class="lnt"> 23
&lt;/span>&lt;span class="lnt"> 24
&lt;/span>&lt;span class="lnt"> 25
&lt;/span>&lt;span class="lnt"> 26
&lt;/span>&lt;span class="lnt"> 27
&lt;/span>&lt;span class="lnt"> 28
&lt;/span>&lt;span class="lnt"> 29
&lt;/span>&lt;span class="lnt"> 30
&lt;/span>&lt;span class="lnt"> 31
&lt;/span>&lt;span class="lnt"> 32
&lt;/span>&lt;span class="lnt"> 33
&lt;/span>&lt;span class="lnt"> 34
&lt;/span>&lt;span class="lnt"> 35
&lt;/span>&lt;span class="lnt"> 36
&lt;/span>&lt;span class="lnt"> 37
&lt;/span>&lt;span class="lnt"> 38
&lt;/span>&lt;span class="lnt"> 39
&lt;/span>&lt;span class="lnt"> 40
&lt;/span>&lt;span class="lnt"> 41
&lt;/span>&lt;span class="lnt"> 42
&lt;/span>&lt;span class="lnt"> 43
&lt;/span>&lt;span class="lnt"> 44
&lt;/span>&lt;span class="lnt"> 45
&lt;/span>&lt;span class="lnt"> 46
&lt;/span>&lt;span class="lnt"> 47
&lt;/span>&lt;span class="lnt"> 48
&lt;/span>&lt;span class="lnt"> 49
&lt;/span>&lt;span class="lnt"> 50
&lt;/span>&lt;span class="lnt"> 51
&lt;/span>&lt;span class="lnt"> 52
&lt;/span>&lt;span class="lnt"> 53
&lt;/span>&lt;span class="lnt"> 54
&lt;/span>&lt;span class="lnt"> 55
&lt;/span>&lt;span class="lnt"> 56
&lt;/span>&lt;span class="lnt"> 57
&lt;/span>&lt;span class="lnt"> 58
&lt;/span>&lt;span class="lnt"> 59
&lt;/span>&lt;span class="lnt"> 60
&lt;/span>&lt;span class="lnt"> 61
&lt;/span>&lt;span class="lnt"> 62
&lt;/span>&lt;span class="lnt"> 63
&lt;/span>&lt;span class="lnt"> 64
&lt;/span>&lt;span class="lnt"> 65
&lt;/span>&lt;span class="lnt"> 66
&lt;/span>&lt;span class="lnt"> 67
&lt;/span>&lt;span class="lnt"> 68
&lt;/span>&lt;span class="lnt"> 69
&lt;/span>&lt;span class="lnt"> 70
&lt;/span>&lt;span class="lnt"> 71
&lt;/span>&lt;span class="lnt"> 72
&lt;/span>&lt;span class="lnt"> 73
&lt;/span>&lt;span class="lnt"> 74
&lt;/span>&lt;span class="lnt"> 75
&lt;/span>&lt;span class="lnt"> 76
&lt;/span>&lt;span class="lnt"> 77
&lt;/span>&lt;span class="lnt"> 78
&lt;/span>&lt;span class="lnt"> 79
&lt;/span>&lt;span class="lnt"> 80
&lt;/span>&lt;span class="lnt"> 81
&lt;/span>&lt;span class="lnt"> 82
&lt;/span>&lt;span class="lnt"> 83
&lt;/span>&lt;span class="lnt"> 84
&lt;/span>&lt;span class="lnt"> 85
&lt;/span>&lt;span class="lnt"> 86
&lt;/span>&lt;span class="lnt"> 87
&lt;/span>&lt;span class="lnt"> 88
&lt;/span>&lt;span class="lnt"> 89
&lt;/span>&lt;span class="lnt"> 90
&lt;/span>&lt;span class="lnt"> 91
&lt;/span>&lt;span class="lnt"> 92
&lt;/span>&lt;span class="lnt"> 93
&lt;/span>&lt;span class="lnt"> 94
&lt;/span>&lt;span class="lnt"> 95
&lt;/span>&lt;span class="lnt"> 96
&lt;/span>&lt;span class="lnt"> 97
&lt;/span>&lt;span class="lnt"> 98
&lt;/span>&lt;span class="lnt"> 99
&lt;/span>&lt;span class="lnt">100
&lt;/span>&lt;span class="lnt">101
&lt;/span>&lt;span class="lnt">102
&lt;/span>&lt;span class="lnt">103
&lt;/span>&lt;span class="lnt">104
&lt;/span>&lt;span class="lnt">105
&lt;/span>&lt;span class="lnt">106
&lt;/span>&lt;span class="lnt">107
&lt;/span>&lt;span class="lnt">108
&lt;/span>&lt;span class="lnt">109
&lt;/span>&lt;span class="lnt">110
&lt;/span>&lt;span class="lnt">111
&lt;/span>&lt;span class="lnt">112
&lt;/span>&lt;span class="lnt">113
&lt;/span>&lt;span class="lnt">114
&lt;/span>&lt;span class="lnt">115
&lt;/span>&lt;span class="lnt">116
&lt;/span>&lt;span class="lnt">117
&lt;/span>&lt;span class="lnt">118
&lt;/span>&lt;span class="lnt">119
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">static&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">final&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">SAVE_STEP_EXECUTION&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;INSERT into %PREFIX%STEP_EXECUTION(VERSION, STEP_NAME, JOB_EXECUTION_ID, START_TIME, &amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">+&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;END_TIME, STATUS, COMMIT_COUNT, READ_COUNT, FILTER_COUNT, WRITE_COUNT, EXIT_CODE, EXIT_MESSAGE, READ_SKIP_COUNT, WRITE_SKIP_COUNT, PROCESS_SKIP_COUNT, ROLLBACK_COUNT, LAST_UPDATED) &amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">+&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)&amp;#34;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Override&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">saveStepExecution&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">StepExecution&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">incrementVersion&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">final&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">KeyHolder&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">generatedKeyHolder&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">GeneratedKeyHolder&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">getJdbcTemplate&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">update&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">connection&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">-&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">PreparedStatement&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">connection&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">prepareStatement&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">getQuery&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">SAVE_STEP_EXECUTION&lt;/span>&lt;span class="p">),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Statement&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">RETURN_GENERATED_KEYS&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setInt&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getVersion&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setString&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">2&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getStepName&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setLong&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">3&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getJobExecutionId&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setDate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">4&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getStartTime&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">!=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Date&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getStartTime&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">getTime&lt;/span>&lt;span class="p">())&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setDate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">5&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getEndTime&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">!=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Date&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getEndTime&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">getTime&lt;/span>&lt;span class="p">())&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setString&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">6&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getStatus&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">toString&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setInt&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">7&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getCommitCount&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setInt&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">8&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getReadCount&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setInt&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">9&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getFilterCount&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setInt&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">10&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getWriteCount&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setString&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">11&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getExitStatus&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">getExitCode&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setString&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">12&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">truncateExitDescription&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getExitStatus&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">getExitDescription&lt;/span>&lt;span class="p">()));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setInt&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">13&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getReadSkipCount&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setInt&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">14&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getWriteSkipCount&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setInt&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">15&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getProcessSkipCount&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setInt&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">16&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getRollbackCount&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setDate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">17&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getLastUpdated&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">!=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Date&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getLastUpdated&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">getTime&lt;/span>&lt;span class="p">())&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ps&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">},&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">generatedKeyHolder&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setId&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">generatedKeyHolder&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getKey&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="na">longValue&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Override&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">saveStepExecutions&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="kd">final&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Collection&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">StepExecution&lt;/span>&lt;span class="o">&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecutions&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">Assert&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">notNull&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">stepExecutions&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;Attempt to save a null collection of step executions&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">StepExecution&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">stepExecutions&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">saveStepExecution&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">stepExecution&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">Change&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">or&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">create&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">copy&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">of&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">JobRepositoryFactoryBean&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">SqlServerJobRepositoryFactoryBean&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">with&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">following&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">changes&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Override&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">protected&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">JobInstanceDao&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">createJobInstanceDao&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">throws&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Exception&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">SqlServerJdbcJobInstanceDao&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">SqlServerJdbcJobInstanceDao&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setJdbcTemplate&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">jdbcOperations&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setJobIncrementer&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">incrementerFactory&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getIncrementer&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">databaseType&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">tablePrefix&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">+&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;JOB_SEQ&amp;#34;&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setTablePrefix&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">tablePrefix&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">afterPropertiesSet&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Override&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">protected&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">JobExecutionDao&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">createJobExecutionDao&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">throws&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Exception&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">SqlServerJdbcJobExecutionDao&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">SqlServerJdbcJobExecutionDao&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setJdbcTemplate&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">jdbcOperations&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setJobExecutionIncrementer&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">incrementerFactory&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getIncrementer&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">databaseType&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">tablePrefix&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">+&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;JOB_EXECUTION_SEQ&amp;#34;&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setTablePrefix&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">tablePrefix&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setClobTypeToUse&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">determineClobTypeToUse&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">this&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">databaseType&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setExitMessageLength&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">maxVarCharLength&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">afterPropertiesSet&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Override&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">protected&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">StepExecutionDao&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">createStepExecutionDao&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">throws&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Exception&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">SqlServerJdbcStepExecutionDao&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">SqlServerJdbcStepExecutionDao&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setJdbcTemplate&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">jdbcOperations&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setStepExecutionIncrementer&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">incrementerFactory&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getIncrementer&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">databaseType&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">tablePrefix&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">+&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;STEP_EXECUTION_SEQ&amp;#34;&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setTablePrefix&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">tablePrefix&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setClobTypeToUse&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">determineClobTypeToUse&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">this&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">databaseType&lt;/span>&lt;span class="p">));&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setExitMessageLength&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">maxVarCharLength&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">afterPropertiesSet&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dao&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">Create&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">batch&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">configuration&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">to&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">use&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">SqlServerBatchConfigurer&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">that&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">uses&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">SqlServerJobRepositoryFactoryBean&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nd">@Configuration&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">BatchConfiguration&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nd">@Bean&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">SqlServerBatchConfigurer&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">basicBatchConfigurer&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">BatchProperties&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">properties&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">DataSource&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dataSource&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">SqlServerBatchConfigurer&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">properties&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dataSource&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">SqlServerBatchConfigurer&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">extends&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">BasicBatchConfigurer&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">final&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">DataSource&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dataSource&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">final&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">BatchProperties&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">properties&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">SqlServerBatchConfigurer&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="kd">final&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">BatchProperties&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">properties&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">final&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">DataSource&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dataSource&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">super&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">properties&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dataSource&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">this&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">properties&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">properties&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">this&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">dataSource&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dataSource&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nd">@Override&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">protected&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">JobRepository&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">createJobRepository&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">throws&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Exception&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">SqlServerJobRepositoryFactoryBean&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">factory&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">SqlServerJobRepositoryFactoryBean&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// this is required to avoid deadlocks&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">factory&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setIsolationLevelForCreate&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;ISOLATION_REPEATABLE_READ&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">factory&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setDataSource&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">this&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">dataSource&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">tablePrefix&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">this&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">properties&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getTablePrefix&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">StringUtils&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">hasText&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">tablePrefix&lt;/span>&lt;span class="p">))&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">factory&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setTablePrefix&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">tablePrefix&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">factory&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setTransactionManager&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">getTransactionManager&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">factory&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">afterPropertiesSet&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">factory&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getObject&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>조금 번거로워 보입니다.
유지보수에도 용이할 것 같진 않았습니다.&lt;/p>
&lt;p>&lt;strong>4. Version Up&lt;/strong>&lt;/p>
&lt;p>해당문제는 &lt;code>spring-batch 4.x&lt;/code> 버전에서 발생한다고 &lt;a href="https://stackoverflow.com/questions/70563630/spring-batch-deadlock-could-not-increment-identity-nested-exception-is-com-mi"target="_blank" rel="noopener">StackOverflow&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>에서는 설명하고 있습니다.
Github에서도 Batch 버전이 v5.0.0이 돼서야 해당 이슈에 대한 Bug fix가 이루어 진 모습을 확인 할 수 있죠.
&lt;a href="https://github.com/spring-projects/spring-batch/releases/tag/v5.0.0"target="_blank" rel="noopener">(해당 버전 Release note)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a> -&amp;gt; 이슈 번호 #1448를 보시면 됩니다.&lt;/p>
&lt;p>물론 장단점이 있겠지만 Version up도 좋은 방법이 될 듯 합니다.
하지만 Version up을 고민하실때 &lt;strong>고려하셔야만 하는 사항&lt;/strong>이 존재합니다.&lt;/p>
&lt;blockquote>
&lt;p>&lt;code>Spring Batch5&lt;/code>는 &lt;code>Spring framework 6 (Spring boot를 사용중이라면 Spring boot 3)&lt;/code>을 의존하고 있습니다.
또한 &lt;code>Spring framework 6 ( Spring boot 3 )&lt;/code>는 최소 &lt;code>Java 17&lt;/code>을 사용해야만 합니다.
한줄로 정리하자면 &lt;code>Spring Batch5&lt;/code>는 최소 &lt;code>Spring framework 6 ( Srping boot 3 )&lt;/code>와 최소 &lt;code>Java 17&lt;/code>이 필요합니다.&lt;/p>
&lt;/blockquote>
&lt;p>그렇기 때문에 해당 문제만을 해결하기 위해 &lt;code>Spring&lt;/code>, &lt;code>Java&lt;/code>, &lt;code>Spring Batch&lt;/code>
위 3가지 모두의 버전업을 해야 하는 것인지 충분한 고민과 논의가 거쳐진 후에
결정하셔야 한다고 생각합니다.
아시다시피 위 3가지 모두 각각 따로 버전업을 하는 이슈가 생긴다고 해도 신경써야할 게 굉장히 많으실겁니다.
3가지 모두를 한번에 버전업을 하시게 된다면&amp;hellip; &lt;strong>( 야근하실지도&amp;hellip;? )&lt;/strong>&lt;/p>
&lt;p>물론 3가지중 하나만 버전업 하셔도 된다면 좀 더 낫긴 하겠습니다만..&lt;/p>
&lt;blockquote>
&lt;p>문제 직면시 저희 회사 서버의 기술 스택은 이러했습니다.
Spring boot : 2.7.3
해당 Boot의 spring batch dependency 버전은 4.3.6입니다 &lt;a href="https://docs.spring.io/spring-boot/docs/2.7.3/reference/html/dependency-versions.html#appendix.dependency-versions"target="_blank" rel="noopener">( 참고 )&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
JDK : 11&lt;/p>
&lt;/blockquote>
&lt;p>그래서 결국 저는(회사 Batch Server는) 어떻게 해결했냐
버전업을 택한다면 보시다시피 저희 회사의 기술 스택이 위 3가지 버전을 모두 업해야하기때문에
굉장히 신경쓸게 많아지는 케이스인지라 버전업으로 해결하기를 결정하진 않았습니다.&lt;/p>
&lt;p>3번도 썩 제 마음에 들지는 않았구요.&lt;/p>
&lt;p>결국 &lt;strong>2번 Batch 관련 설정 정보 Bean 등록&lt;/strong>을 선택했습니다.
적용후에 해당 사항과 관련된 이슈가 나온다면 다시금 업데이트 하도록 하겠습니다.&lt;/p>
&lt;p>긴 글 읽어주셔서 감사합니다.
마지막으로 이 글이 누군가에게 도움이 되길 바라며 이만 마치겠습니다&lt;/p>
&lt;blockquote>
&lt;p>위 본문 내용중 정확하지 않은 내용이 포함돼 있을 수 있습니다.
저는 1년차 백엔드 개발자로 스스로 굉장히 부족한 사람이라는 점을 인지하고 있는지라
제가 적은 정보가 정확하지 않을까 걱정하고 있습니다.
혹여 제 정보가 잘못 됐을 수 있으니 단지 참고용으로만 봐주시고 관련된 내용을 한번 직접 알아보시는 걸 추천합니다.
혹여 잘못된 내용이 있거나 말씀해주시고 싶은 부분이 있으시다면 부담없이 적어주세요!
수용하고 개선하기 위해 노력하겠습니다!!!&lt;/p>
&lt;/blockquote>
&lt;h3>Reference&lt;span class="hx:absolute hx:-mt-20" id="reference">&lt;/span>
&lt;a href="#reference" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;a href="https://github.com/spring-projects/spring-batch/issues/1448"target="_blank" rel="noopener">https://github.com/spring-projects/spring-batch/issues/1448&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://stackoverflow.com/questions/29493484/primary-key-violation-in-spring-batchs-batch-job-instance-table-while-running-j?noredirect=1#comment47186282_29493484"target="_blank" rel="noopener">https://stackoverflow.com/questions/29493484/primary-key-violation-in-spring-batchs-batch-job-instance-table-while-running-j?noredirect=1#comment47186282_29493484&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://github.com/spring-projects/spring-batch/releases/tag/v5.0.0"target="_blank" rel="noopener">https://github.com/spring-projects/spring-batch/releases/tag/v5.0.0&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://stackoverflow.com/questions/70563630/spring-batch-deadlock-could-not-increment-identity-nested-exception-is-com-mi"target="_blank" rel="noopener">https://stackoverflow.com/questions/70563630/spring-batch-deadlock-could-not-increment-identity-nested-exception-is-com-mi&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://jojoldu.tistory.com/326"target="_blank" rel="noopener">https://jojoldu.tistory.com/326&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://taes-k.github.io/2021/03/01/spring-batch-table/"target="_blank" rel="noopener">https://taes-k.github.io/2021/03/01/spring-batch-table/&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://docs.spring.io/spring-batch/docs/current/reference/html/schema-appendix.html"target="_blank" rel="noopener">https://docs.spring.io/spring-batch/docs/current/reference/html/schema-appendix.html&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p></description></item><item><title>자바 POI를 이용한 엑셀다운로드 공용 Util 클래스 만들기</title><link>https://jeongil.dev/ko/blog/backend/performance/java-poi-excel-utils/</link><pubDate>Sun, 19 Nov 2023 00:00:00 +0000</pubDate><guid>https://jeongil.dev/ko/blog/backend/performance/java-poi-excel-utils/</guid><description>
&lt;p>거창한 내용은 아니지만 몇달전 회사에서 경험했던 것을 공유하고자 합니다.&lt;/p>
&lt;p>시작은 사내 관리자들이 사용하는 백오피스에서의 end user, 즉 회사 동료분들에게서의
문의사항에서 시작됐습니다.&lt;/p>
&lt;p>문의사항은 다음과 같았습니다.&lt;/p>
&lt;blockquote>
&lt;p>특정 Row수가 넘어가면 Excel 다운로드가 안되거나 이상하게 돼요&amp;hellip;!&lt;/p>
&lt;/blockquote>
&lt;p>현재 우리 회사에서는 제가 입사하기 이전부터 기존 PHP로 이루어져있던 여러 서버들을 Java로 변경하는 작업을 진행중에 있었습니다.&lt;/p>
&lt;p>그 중에는 백오피스 서버도 존재했습니다.&lt;/p>
&lt;p>해당 백오피스에서는 게시판구현의 편의성과 용이함을 위해 datatables 라이브러리를
선택해 사용해오고 있었습니다.&lt;/p>
&lt;p>해당 게시판들의 내용을 엑셀로 다운로드 받을 수 있는 기능 또한 해당 라이브러리에서 제공해주는
엑셀 다운로드 기능을 사용해왔는데요.&lt;/p>
&lt;p>해당 기능에서 발생한 문제였습니다.
문제는 다음과 같았습니다.&lt;/p>
&lt;blockquote>
&lt;p>엑셀 다운로드 기능이 Row수가 특정 행 미만이라면 문제가 없음
Row가 많아지면 문제가 둘중 하나로 실현됨&lt;/p>
&lt;/blockquote>
&lt;ol>
&lt;li>첫 페이지의 내용만 엑셀에 담긴다.&lt;/li>
&lt;li>다운로드 자체가 이루어지지 않는다.&lt;/li>
&lt;/ol>
&lt;p>얼핏봐도 문제가 좀 있어보였습니다.&lt;/p>
&lt;p>해당 문제에 관한 비슷한 글이 존재했습니다. -&amp;gt; &lt;a href="https://datatables.net/forums/discussion/56948/excel-export-of-huge-number-of-rows"target="_blank" rel="noopener">( 해당 글 )&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p>
&lt;p>해결방법은 chunk 방법으로 해결할 수 있다고 하는데 이 방법으로 해결할까 했지만,
몇 가지 문제가 더 존재했습니다.
다음은 end user의 또 한가지 문의사항이였습니다.&lt;/p>
&lt;blockquote>
&lt;p>엑셀 다운로드도 좀 느린거같아요&amp;hellip;!&lt;/p>
&lt;/blockquote>
&lt;p>관련된 사항도 찾아봤지만 사실 라이브러리에서 제공해주는 통합 기능같은 경우는 직접 컨트롤 하기
어려운 부분들이 존재했습니다.&lt;/p>
&lt;p>그렇기에 직접 자바에서 구현하는 방법으로 진행하기로 했죠.&lt;/p>
&lt;p>다행이 POI라는 Apache에서 만든 라이브러리가 존재했기때문에 비교적 쉽게 만들 수 있도록 되어 있었습니다.&lt;/p>
&lt;p>참고할 점&lt;/p>
&lt;blockquote>
&lt;ol>
&lt;li>HSSF : EXCEL 2007 이전 버전(.xls)에서 사용하는 방식
2) XSSF : EXCEL 2007 이후 버전(2007포함 .xlsx)에서 사용하는 방식
3) SXSSF : XSSF의 Streaming Version으로 메모리를 적게 사용하여 대용량 엑셀 다운로드에 주로 사용되는 방식
[출처] &lt;a href="https://blog.naver.com/tmondev/221388780914"target="_blank" rel="noopener">Java 대용량 엑셀 다운로드 기능 구현|작성자 티몬개발&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/li>
&lt;/ol>
&lt;/blockquote>
&lt;p>저는 SXSSF방식으로 진행했습니다.&lt;/p>
&lt;p>이왕 만드는 거 공용으로 사용할 수 있도록 만들고 싶었습니다.
그래서 공용 Util 클래스로 만들어서 수많은 게시판에서도 간단하게 사용할 수 있도록 하고싶었습니다. 물론 지금 볼땐 많이 부족해보이긴 합니다 ㅎ&amp;hellip;&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;span class="lnt">45
&lt;/span>&lt;span class="lnt">46
&lt;/span>&lt;span class="lnt">47
&lt;/span>&lt;span class="lnt">48
&lt;/span>&lt;span class="lnt">49
&lt;/span>&lt;span class="lnt">50
&lt;/span>&lt;span class="lnt">51
&lt;/span>&lt;span class="lnt">52
&lt;/span>&lt;span class="lnt">53
&lt;/span>&lt;span class="lnt">54
&lt;/span>&lt;span class="lnt">55
&lt;/span>&lt;span class="lnt">56
&lt;/span>&lt;span class="lnt">57
&lt;/span>&lt;span class="lnt">58
&lt;/span>&lt;span class="lnt">59
&lt;/span>&lt;span class="lnt">60
&lt;/span>&lt;span class="lnt">61
&lt;/span>&lt;span class="lnt">62
&lt;/span>&lt;span class="lnt">63
&lt;/span>&lt;span class="lnt">64
&lt;/span>&lt;span class="lnt">65
&lt;/span>&lt;span class="lnt">66
&lt;/span>&lt;span class="lnt">67
&lt;/span>&lt;span class="lnt">68
&lt;/span>&lt;span class="lnt">69
&lt;/span>&lt;span class="lnt">70
&lt;/span>&lt;span class="lnt">71
&lt;/span>&lt;span class="lnt">72
&lt;/span>&lt;span class="lnt">73
&lt;/span>&lt;span class="lnt">74
&lt;/span>&lt;span class="lnt">75
&lt;/span>&lt;span class="lnt">76
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">ExcelUtils&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">static&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">SXSSFWorkbook&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">defaultStyleExcel&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">sheetName&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="o">[]&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">columnNames&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">List&lt;/span>&lt;span class="o">&amp;lt;?&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dataList&lt;/span>&lt;span class="p">){&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">SXSSFWorkbook&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">excel&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">SXSSFWorkbook&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// Cell style - 컬럼&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">CellStyle&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">columnHeaderStyle&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ExcelStyle&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getColumnHeaderStyle&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">excel&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">CellStyle&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">defaultStyle&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ExcelStyle&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getDefaultStyle&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">excel&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">CellStyle&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">defaultNumberStyle&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ExcelStyle&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getDefaultNumberStyle&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">excel&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">CellStyle&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">defaultDecimalStyle&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ExcelStyle&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getDefaultDecimalStyle&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">excel&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kt">int&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">rowNo&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">0&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 행 번호&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">Sheet&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">columnSheet&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">excel&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">createSheet&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">sheetName&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">Row&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">columnRow&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">columnSheet&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">createRow&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">rowNo&lt;/span>&lt;span class="o">++&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kt">int&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">columnCellNum&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">0&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">columnName&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">columnNames&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ExcelCellUtils&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">createCellWithStyle&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">columnRow&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">columnCellNum&lt;/span>&lt;span class="o">++&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">columnName&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">columnHeaderStyle&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ExcelCellUtils&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">resizeCell&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">columnSheet&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">columnCellNum&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">Class&lt;/span>&lt;span class="o">&amp;lt;?&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dataClass&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dataList&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">get&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">0&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="na">getClass&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">Field&lt;/span>&lt;span class="o">[]&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">fields&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dataClass&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getDeclaredFields&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kt">int&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">rowCellNum&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">0&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Object&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">data&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">dataList&lt;/span>&lt;span class="p">){&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">Row&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">row&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">columnSheet&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">createRow&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">rowNo&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">rowCellNum&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">0&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Field&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">field&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">fields&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">field&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setAccessible&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 필드에 접근하기 위해 접근성을 변경&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">Object&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">fieldValue&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">try&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">fieldValue&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">field&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">get&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">data&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">catch&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">IllegalAccessException&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">throw&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">BadRequestException&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;Excel 생성을 위해 항목의 Field 값을 가져오던 도중 문제가 발생했습니다.&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">field&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getType&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">==&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Integer&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">class&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">||&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">field&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getType&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">==&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">BigInteger&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">class&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">||&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">field&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getType&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">==&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Long&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">class&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kt">long&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">value&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">fieldValue&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">==&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">0&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Long&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">parseLong&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">fieldValue&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">toString&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ExcelCellUtils&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">createCellWithStyle&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">row&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">rowCellNum&lt;/span>&lt;span class="o">++&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">value&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">defaultNumberStyle&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">else&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">field&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getType&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">==&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">BigDecimal&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">class&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">||&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">field&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getType&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">==&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Double&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">class&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kt">double&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">value&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">fieldValue&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">==&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">0&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Double&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">parseDouble&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">fieldValue&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">toString&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ExcelCellUtils&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">createCellWithStyle&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">row&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">rowCellNum&lt;/span>&lt;span class="o">++&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">value&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">defaultDecimalStyle&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">else&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ExcelCellUtils&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">createCellWithStyle&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">row&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">rowCellNum&lt;/span>&lt;span class="o">++&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">fieldValue&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">==&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">GlobalStatus&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">EMPTY_STRING&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">fieldValue&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">toString&lt;/span>&lt;span class="p">(),&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">defaultStyle&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">rowNo&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">%&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">10000&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">==&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">0&lt;/span>&lt;span class="p">){&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 10000만행 마다 주기적인 flush 진행&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">try&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">((&lt;/span>&lt;span class="n">SXSSFSheet&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">columnSheet&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="na">flushRows&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">rowNo&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="n">1&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">catch&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">IOException&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">throw&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">BadRequestException&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getMessage&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">rowNo&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">++&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// cell 사이즈 맞추기&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="kt">int&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">0&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">rowCellNum&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">1&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="o">++&lt;/span>&lt;span class="p">){&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ExcelCellUtils&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">resizeCell&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">columnSheet&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">i&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">excel&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">ExcelCellUtils&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">static&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Cell&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">createCellWithStyle&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Row&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">row&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">int&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">cellNum&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Double&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">value&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">CellStyle&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">style&lt;/span>&lt;span class="p">){&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">Cell&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">cell&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">row&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">createCell&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">cellNum&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">if&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">value&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">==&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">null&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">value&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">0D&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">cell&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setCellValue&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">value&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">cell&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setCellStyle&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">style&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">cell&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">static&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">resizeCell&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Sheet&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">sheet&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">int&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">cellNum&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">((&lt;/span>&lt;span class="n">SXSSFSheet&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="n">sheet&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="na">trackColumnForAutoSizing&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">cellNum&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">sheet&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">autoSizeColumn&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">cellNum&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">sheet&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">setColumnWidth&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">cellNum&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">sheet&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getColumnWidth&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">cellNum&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">+&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">1024&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>해당 유틸에는 현재 다른 코드들도 많지만 주요한 부분만 가져오자면 다음과 같습니다.&lt;/p>
&lt;p>데이터가 자연수인지 실수인지에 문자열인지에 따라 해당 형식을 달리하고
1만행마다 Flush를 진행해 Out of memory도 방지해 줬습니다.&lt;/p>
&lt;p>여기서 Flush란 뭘까요?&lt;/p>
&lt;blockquote>
&lt;p>메모리에 있는 데이터를 디스크(임시파일)로 옮기고 메모리를 비워내는 것입니다.&lt;/p>
&lt;/blockquote>
&lt;p>참고하실 점 엑셀이 다운로드든 뭐든 기능을 다 하고 나면 임시 파일을 지워줘야 합니다!!&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// 예시&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">try&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">excel&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">write&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">response&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">getOutputStream&lt;/span>&lt;span class="p">());&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">excel&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">close&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">catch&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">Exception&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">){&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">logger&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">debug&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;파일 Output중 실패했습니다.&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">finally&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="c1">// 임시 파일 삭제&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">excel&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">dispose&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>처음에는 뭣도 모르고 만들었다가 테스트과정에서 자꾸 Out of memory이 발생했었습니다.. ㅎ ;;&lt;/p>
&lt;p>&lt;a href="https://techblog.woowahan.com/2698/"target="_blank" rel="noopener">아 엑셀다운로드 개발,,, 쉽고 빠르게 하고 싶다 (feat. 엑셀 다운로드 모듈 개발기)&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p>
&lt;p>물론 위와같은 방식을 참조해 만들까도 했지만 저희 백오피스 서버에서는 형식이 어느정도 일정했고, 회사가 스타트업인지라 위 기능구현에 충분한 시간을 할애하기 어려웠기 때문에 이정도로 하기로 결정지었습니다.&lt;/p>
&lt;p>해당 기능으로 변경이후 퍼포먼스 변화는 다음과 같았습니다.&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>4~5분(브라우저 다운 case 존재, 첫 페이지만 다운로드 되는 케이스 존재) -&amp;gt; 1분 미만 및 해당 케이스들 사라짐&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>서버 리소스 또한 문제가 없었습니다.
약 4만 5천행의 데이터를 대상으로 기능을 실행했을때, CPU 자원을 좀 잡아먹긴하는 것 같습니다만
메모리 자원은 잘 관리하는 모습을 확인 할 수 있었습니다.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/2ce1baf4-86f2-42fc-aa27-6e739bd2c893/image.jpg" alt="" loading="lazy" />&lt;/p>
&lt;p>결과적으로 기한내에 문제를 해결할 수 있었죠.&lt;/p>
&lt;p>&lt;img src="https://velog.velcdn.com/images/12onetwo12/post/a46e40f0-3b97-4513-954f-8fd414414d05/image.jpg" alt="" loading="lazy" />&lt;/p>
&lt;div class="hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code">
&lt;div>&lt;pre>&lt;code>해당 4만 5천행의 데이터&lt;/code>&lt;/pre>&lt;/div>&lt;div class="hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0">
&lt;button
class="hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title="Copy code"
>
&lt;div class="hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;div class="hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4">&lt;/div>
&lt;/button>
&lt;/div>
&lt;/div>
&lt;p>물론 아직은 여러모로 부족한 점이 많은 기능이라고 생각합니다.&lt;/p>
&lt;p>위 엑셀 다운로드 모듈 개발기처럼 공용화도 더 해야할 부분들이 보이고
리플렉션을 사용했기때문에 컴파일 시점에 문제를 잡을 수 없다는 것도 문제죠.
성능또한 리플렉션에서 좀 걸리는것 같기도 하구요.
스타일도 다양하게 먹일 수 있도록 하기도 해야하는 부분들이 존재해서
아직은 부족한 점이 많은 공용 Util 클래스 만들기였었던 것 같습니다.&lt;/p>
&lt;p>어디까지나 주니어 개발자의 몸부림이라 귀엽게 봐주시면 감사할 것 같습니다.&lt;/p>
&lt;p>오늘도 역시 이 글이 누군가의 도움이 되길 바라며 이만 마치겠습니다. 감사합니다!&lt;/p>
&lt;h3>Reference&lt;span class="hx:absolute hx:-mt-20" id="reference">&lt;/span>
&lt;a href="#reference" class="subheading-anchor" aria-label="Permalink for this section">&lt;/a>&lt;/h3>&lt;p>&lt;a href="https://datatables.net/"target="_blank" rel="noopener">https://datatables.net/&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://poi.apache.org/"target="_blank" rel="noopener">https://poi.apache.org/&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://techblog.woowahan.com/2698/"target="_blank" rel="noopener">https://techblog.woowahan.com/2698/&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://datatables.net/forums/discussion/56948/excel-export-of-huge-number-of-rows"target="_blank" rel="noopener">https://datatables.net/forums/discussion/56948/excel-export-of-huge-number-of-rows&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>
&lt;a href="https://blog.naver.com/tmondev/221388780914"target="_blank" rel="noopener">https://blog.naver.com/tmondev/221388780914&lt;svg class="hx:inline hx:rtl:rotate-270 hx:align-baseline" height="1em" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
&lt;path d="m9.1716 7.7574h7.0711m0 0v7.0711m0-7.0711-8.4853 8.4853" stroke-linecap="round" stroke-linejoin="round"/>
&lt;/svg>&lt;/a>&lt;/p></description></item></channel></rss>