From e80364cd255bf0044d0d858aa01eef0d05093b7f Mon Sep 17 00:00:00 2001 From: JiWoo Date: Mon, 8 Jan 2024 22:32:09 +0900 Subject: [PATCH] =?UTF-8?q?docs(README):=20=EB=A6=AC=EB=93=9C=EB=AF=B8=20C?= =?UTF-8?q?D=20flow=20=EC=82=AC=EC=A7=84=20=EB=B3=80=EA=B2=BD=20(#107)=20(?= =?UTF-8?q?#108)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 439 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 438 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d1b60fb..e59f0b21 100644 --- a/README.md +++ b/README.md @@ -38,10 +38,447 @@ |:-:|:-:| |shine|ngwoon| |[zbqmgldjfh](https://github.com/zbqmgldjfh)|[ngwoon](https://github.com/ngwoon)| +
+ +## ๐Ÿง Pain Point +
+ ๋ณธ๋ฌธ ํ™•์ธ (๐Ÿ‘ˆ Click) +
+ +๊ธฐ์กด์˜ ํ•™๊ต ๊ณต์ง€๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์•ฑ์ด ์•„๋‹Œ ํ™ˆํŽ˜์ด์ง€๋กœ ์ ‘๊ทผ โ†’ ํ•ด๋‹น ํ•™๊ณผ๋กœ ์ด๋™ โ†’ ํ•™๊ณผ ๋‚ด์˜ ๊ณต์ง€ํ•จ ์ ‘์† +๊ณผ๊ฐ™์ด ๋ถˆํ•„์š”ํ•œ step์„ ์ง„ํ–‰ํ•ด์•ผ๋งŒ ๊ณต์ง€๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ์œผ๋ฉฐ, ๋…ธํŠธ๋ถ์ด ์—†๋‹ค๋ฉด ๊ณต์ง€๋ฅผ ํ™•์ธํ•˜๊ธฐ๊ฐ€ ๋งค์šฐ ๋ถˆํŽธ ํ–ˆ์Šต๋‹ˆ๋‹ค. + +์ด๋Ÿฌํ•œ ๋ถˆํŽธํ•จ์„ ์—†์• ๊ณ , ๋ชจ๋“  ๊ฑด๊ตญ๋Œ€ ํ•™์ƒ๋“ค์—๊ฒŒ ํŽธ๋ฆฌํ•œ ๊ณต์ง€๋ฅผ ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•ด ๋งŒ๋“  ์„œ๋น„์Šค์ž…๋‹ˆ๋‹ค. +๋น„๋ก ์•„์ง๋„ ๋งŽ์ด ๋ถ€์กฑํ•˜์ง€๋งŒ, ์ž˜ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค๋Š” ํ”ผ๋“œ๋ฐฑ์„ ๋ฐ›์„๋•Œ์˜ ๋ฟŒ๋“ฏํ•จ์„ ์›๋™๋ ฅ์œผ๋กœ ๊ฐœ์„ ํ•ด๋‚˜๊ฐ€๋Š” ์ค‘ ์ž…๋‹ˆ๋‹ค. + +
+ +## ๐Ÿ“‘ EventStorming +
+ ๋ณธ๋ฌธ ํ™•์ธ (๐Ÿ‘ˆ Click) +
+๋„๋ฉ”์ธ ๋ชจ๋ธ ๋ถ„๋ฆฌ๋ฅผ ์œ„ํ•œ Event Storming (4์ผ ์†Œ์š”)
+์ด๋ฒคํŠธ ์Šคํ† ๋ฐ ๋„์ค‘ ์ถ”๊ฐ€๋˜๋Š” ์ด๋ฒคํŠธ๋„ ์ถฉ๋ถ„ํ•˜๊ฒŒ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ง€๊ธˆ์˜ ์„ ํƒ์ด 100% ๋ชจ๋‘๊ฐ€ ๋™์˜ ๊ฐ€๋Šฅํ•œ ๋ชจ๋ธ ๋ถ„๋ฆฌ๋Š” ์•„๋‹ ์ˆ˜ ์žˆ๋‹ค. + +### 2-2-1) ****Event (Orange Sticker)**** +![์ด๋ฒคํŠธ](https://github.com/ku-ring/ku-ring-backend-web/assets/60593969/80eb6138-a98b-415e-83e2-3eb0dcc709e4) +์šฐ์„  ์‹œ๊ฐ„์˜ ํ๋ฆ„์— ๋”ฐ๋ผ ๋น„์ง€๋‹ˆ์Šค์˜ ์ƒํƒœ ๋ณ€๊ฒฝ์„ ์˜๋ฏธํ•˜๋Š” ๋„๋ฉ”์ธ ์ด๋ฒคํŠธ๋ฅผ ๋„์ถœํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค. + +ํŒ€์›๋“ค๊ณผ ํ•จ๊ป˜ ์˜ค๋ Œ์ง€์ƒ‰ ํฌ์ŠคํŠธ์ž‡์— ์ด๋ฒคํŠธ ๋ช…์„ ์ž‘์„ฑํ•˜์˜€๋Š”๋ฐ, ์ด๋–„ **์ด๋ฒคํŠธ ๋ช…์€ ๊ณผ๊ฑฐ๋ช…์œผ๋กœ ์ž‘์„ฑํ•œ๋‹ค.** ๋ผ๋Š” ๋‚ด์šฉ์„ ์ค€์ˆ˜ํ•˜๋ ค ๋…ธ๋ ฅํ•˜์˜€์Šต๋‹ˆ๋‹ค. + +์ด๋ฒคํŠธ๊ฐ„์˜ ๊ณต๊ฐ„์„ ๋‘๋˜ ์ด๋ฒคํŠธ๊ฐ€ ์—ฐ์‡„์ ์œผ๋กœ ๋ฐœํ–‰ํ•˜๋Š” ๊ฒฝ์šฐ ๋ฐ”๋กœ ์˜†์— ๋ถ™์ธ๋‹ค. ๊ฐ™์€ ์‹œ์ ์— ๋น„์ง€๋‹ˆ์Šค ์กฐ๊ฑด์— ๋”ฐ๋ผ ๋Œ€์ฒด์ ์œผ๋กœ ๋ฐœ์ƒ๋  ์ˆ˜ ์žˆ๋Š” ์ด๋ฒคํŠธ๋Š” ์•„๋ž˜์— ๊ฐ™์€ ๋ผ์ธ์„ ์ƒ์œผ๋กœ ๋ถ™์ธ๋‹ค. + +๋„๋ฉ”์ธ ์ด๋ฒคํŠธ๋Š” ๋น„์ง€๋‹ˆ์Šค์˜ ์–ด๋–ค ์ƒํƒœ๋ฅผ ์ƒ์„ฑ,๋ณ€๊ฒฝ,์‚ญ์ œํ•˜๋Š” ์š”์†Œ๋ผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์‹œ์Šคํ…œ์˜ ํ™”๋ฉด์„ ์—ฐ์ƒํ•˜์ง€ ๋ง๊ณ  ๋น„์ง€๋‹ˆ์Šค๊ฐ€ ํ˜๋Ÿฌ๊ฐ์— ๋”ฐ๋ผ ๋น„์ง€๋‹ˆ์Šค๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ์š”์†Œ๋“ค์˜ ์ƒํƒœ๊ฐ€ ์–ด๋–ป๊ฒŒ ๋ณ€๊ฒฝ๋˜๋Š”์ง€๋ฅผ ์ƒ๊ฐํ•˜๋„๋ก ํ•˜์˜€์Šต๋‹ˆ๋‹ค. + +์šฐ๋ฆฌ ํŒ€์€ ์‹œ์Šคํ…œ์„ ์‚ฌ์šฉํ•˜๋Š” ์—ญํ• (์‚ฌ์šฉ์ž, ๋””์ž์ด๋„ˆ, ๊ฐœ๋ฐœ์ž)๋กœ ๋‚˜๋ˆ„์–ด์„œ ์‚ฌ๋žŒ๋“ค์„ ๋ฐฐ์ •ํ•˜์—ฌ ์—…๋ฌด๋ณ„๋กœ ๋…ผ์˜๊ฐ€ ๊ฐ€๋Šฅํ•œ ์ˆ˜์ค€์ธ ์ ์ ˆํ•œ ์ธ์›์ด(4๋ช…) ์ฐธ์—ฌํ•˜์˜€์Šต๋‹ˆ๋‹ค. + + +### 2-2-2) ****Command (Blue Sticker)**** +![์ปค๋ฉ˜๋“œ](https://github.com/ku-ring/ku-ring-backend-web/assets/60593969/722eff4b-b082-4935-a2ca-5c0e7621f0a7) +์ด๋ฒคํŠธ๋ฅผ ํŠธ๋ฆฌ๊ฑฐํ•˜๋Š”(๋ฐœ์ƒ์‹œํ‚ค๋Š”) ์ปค๋งจ๋“œ๋ฅผ ๋„์ถœํ•˜์˜€์œผ๋ฉฐ ์œ„ ์‚ฌ์ง„๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. + +์ปค๋งจ๋“œ์˜ ๊ฒฝ์šฐ ํŒŒ๋ž€์ƒ‰ ํฌ์ŠคํŠธ์ž‡์— ์ž‘์„ฑํ•˜์—ฌ ๋ถ™์˜€์œผ๋ฉฐ, ์ปค๋งจ๋“œ๋Š” ์ด๋ฒคํŠธ๋ฅผ ๋ณด๋ฉด ์‰ฝ๊ฒŒ ์œ ์ถ”ํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐ๋ฉ๋‹ˆ๋‹ค. +**ํ•˜๋‚˜์˜ ์ปค๋งจ๋“œ์— ์˜ํ•ด ์—ฌ๋Ÿฌ๊ฐœ์˜ ์ด๋ฒคํŠธ๊ฐ€ ์—ฐ์† ๋ฐœ์ƒ๋  ์ˆ˜ ์žˆ์œผ๋ฉฐ ์ปค๋งจ๋“œ ํ•˜๋‚˜์— ์กฐ๊ฑด์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Œ์„ ์œ ์˜ํ•˜์ž!** + +> *[์ด๋ฒคํŠธ] ํ•  ๋•Œ๋Š” ํ•ญ์ƒ [์ปค๋งจ๋“œ] ํ•œ๋‹ค* + +### 2-2-3) ****Actor (Yellow Sticker)**** +![์—‘ํ„ฐ](https://github.com/ku-ring/ku-ring-backend-web/assets/60593969/b764d079-0be7-48f2-abfb-811cb9c75827) +์—‘ํ„ฐ๋Š” ์‚ฌ๋žŒ์ด๋‚˜ ์กฐ์ง์ด ๋  ์ˆ˜ ์žˆ๋Š”๋ฐ ์—ญํ•  ๊ด€์ ์œผ๋กœ ๋„์ถœํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค. ์—‘ํ„ฐ๋Š” ์ถ”์ƒ์ ์œผ๋กœ ์‹๋ณ„ํ•˜์ง€ ๋ง๊ณ  **๋น„์ง€๋‹ˆ์Šค๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ๊ตฌ์ฒด์ ์ธ ์—ญํ• ๋กœ ๊ณ ๋ คํ•˜์—ฌ ๋„์ถœํ•œ๋‹ค.** + +์ฆ‰ ๊ทธ๋ƒฅ ๋ชจ๋“  ์—…๋ฌด์—์„œ ๋ณดํŽธ์ ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ํšŒ์›, ๊ด€๋ฆฌ์ž๋กœ ๋ฝ‘์ง€ ๋ง๊ณ  ํŠน์ • ๋น„์ง€๋‹ˆ์Šค๋ฅผ ์‹ค์ œ์ ์œผ๋กœ ์ˆ˜ํ–‰ํ•˜๋Š” ์—ญํ• ์ž๋ฅผ ๋„์ถœํ•˜๋ ค๊ณ  ๋…ธ๋ ฅํ•˜์˜€์œผ, ์•กํ„ฐ๊ฐ€ ๊ตฌ์ฒดํ™” ๋  ์ˆ˜๋ก ์‹๋ณ„ํ•˜์ง€ ๋ชปํ•œ ์ปค๋งจ๋“œ์™€ ์ด๋ฒคํŠธ๊ฐ€ ์ถ”๊ฐ€์ ์œผ๋กœ ๋„์ถœ ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +์šฐ๋ฆฌ์˜ ์„œ๋น„์Šค๋Š” ์—‘ํ„ฐ๋Š” ํ•™๊ต์— ๋‹ค๋‹ˆ๋Š” ํ•™์ƒ, ๊ต์ง์› (๊ณต์ง€์•ฑ ์‚ฌ์šฉ์ž) ์ •๋„๋กœ ์ƒ๊ฐํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์—‘ํ„ฐ๋ฅผ ๋„์ถœํ•˜๊ณ  ๋ณด๋‹ˆ, ์—ฌ์ง€๊ป ๊ต์ง์›์„ ์œ„ํ•œ ๊ธฐ๋Šฅ์€ ์—†์—ˆ์Œ์„ ํ•œ๋ฒˆ ์ƒ๊ธฐํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. + +### 2-2-4) ****Aggregate (Yellow Sticker)**** +![์–ด๊ทธ๋ฆฌ๊ฒŒ์ดํŠธ](https://github.com/ku-ring/ku-ring-backend-web/assets/60593969/f1bb7fc4-a216-4aba-a5f5-c580b751f826) +์–ด๊ทธ๋ฆฌ๊ฒŒ์ดํŠธ๋Š” โ€˜๊ฒฐํ•ฉ๋ฌผโ€™์„ ์˜๋ฏธํ•˜๋Š”๋ฐ ์–ด๋– ํ•œ ๋„๋ฉ”์ธ ๊ฐ์ฒด๋ฅผ ์ค‘์‹ฌ์œผ๋กœ ์ƒ๊ฐํ•˜์˜€์œผ๋ฉฐ, +ํ•˜๋‚˜์˜ ACIDํ•œ ํŠธ๋žœ์žญ์…˜์— ๋ฌถ์—ฌ ๋ณ€ํ™”๋˜์–ด์•ผ ํ•  ๊ฐ์ฒด์˜ ๋ฌถ์Œ์„ ๋„์ถœํ•˜๊ณ , ๊ทธ๊ฒƒ๋“ค์„ ์ปค๋งจ๋“œ, ์ด๋ฒคํŠธ์™€ ํ•จ๊ป˜ ๋ฌถ์–ด๋ณด์•˜์Šต๋‹ˆ๋‹ค. + +### 2-2-5) ****๋ฐ”์šด๋””๋“œ ์ปจํ…์ŠคํŠธ๋กœ ๋ฌถ๊ธฐ**** +![๋ฐ”์šด๋””๋“œ์ปจํ…์ŠคํŠธ](https://github.com/ku-ring/ku-ring-backend-web/assets/60593969/e00f53cf-643b-49d5-bf86-22c1f1e606e6) +Bounded Context(BC)๋Š” ๋™์ผํ•œ ๋ฌธ๋งฅ์œผ๋กœ ํšจ์œจ์ ์œผ๋กœ ์—…๋ฌด ์šฉ์–ด(๋„๋ฉ”์ธ ํด๋ž˜์Šค)๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ์ฒด ๋ฒ”์œ„๋ฅผ ๋œปํ•œ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. +ํ•˜๋‚˜์˜ BC๋Š” ํ•˜๋‚˜ ์ด์ƒ์˜ ์–ด๊ทธ๋ฆฌ๊ฒŒ์ดํŠธ๋ฅผ ์›์†Œ๋กœ ๊ตฌ์„ฑ๋  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ด BC๋ฅผ ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค ๊ตฌ์„ฑ ๋‹จ์œ„๋กœ ์ •ํ•˜๊ฒŒ ๋˜๋ฉด ์ด๋ฅผ ๋‹ด๋‹นํ•˜๋Š” ํŒ€ ๋‚ด์˜ ์ปค๋ฎค๋‹ˆ์ผ€์ด์…˜์ด ํšจ์œจํ™” ๋ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค? + +์ถ”ํ›„ MSAํ™”๋ฅผ ๊ณ ๋ ค์ค‘์ด๊ธฐ์— ํ•จ๊ป˜ ๊ณ ๋ คํ•ด๋ณธ ๋Œ€์ƒ์ž…๋‹ˆ๋‹ค. + +### 2-2-6) ์™ธ๋ถ€ ์‹œ์Šคํ…œ ์ถ”๊ฐ€ +![์™ธ๋ถ€](https://github.com/ku-ring/ku-ring-backend-web/assets/60593969/03580d1f-6ef6-40fa-9326-fc7d080000be) +์ปค๋งจ๋“œ & ์ด๋ฒคํŠธ ๋ฐœ์ƒ ์‹œ ํ˜ธ์ถœ๋˜๊ฑฐ๋‚˜ ๊ด€๋ จ๋˜๋Š” ๋ ˆ๊ฑฐ์‹œ ์‹œ์Šคํ…œ์ด๋‚˜ ์™ธ๋ถ€ ์‹œ์Šคํ…œ ๋˜๋Š” ์žฅ๋น„๋ฅผ ๋„์ถœํ•˜์—ฌ ํ•‘ํฌ์ƒ‰ ํฌ์ŠคํŠธ์ž‡์— ์ž‘์„ฑํ•˜์—ฌ ์ด๋ฒคํŠธ์˜ ์˜ค๋ฅธ์ชฝ ์ƒ๋‹จ์— ์ถ”๊ฐ€! + +๋ณธ ์‹œ์Šคํ…œ์˜ ๊ตฌํ˜„ ๋Œ€์ƒ์ด ์•„๋‹ˆ์ง€๋งŒ ์‹œ์Šคํ…œ์˜ ๊ธฐ๋Šฅ ๊ตฌํ˜„์„ ์œ„ํ•ด ์—ฐ๊ณ„๊ฐ€ ํ•„์š”ํ•œ ์‹œ์Šคํ…œ๋“ค์„ ๋ชจ๋‘ ๋„์ถœํ•ด๋ณธ ๊ฒฐ๊ณผ, FCM์˜ ์•Œ๋ฆผ ๊ธฐ๋Šฅ ์ •๋„๊ฐ€ ์™ธ๋ถ€ ์˜์กด์œผ๋กœ ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค. + +### 2-2-7) ****Policy (Lilac Sticker)**** ๋„์ถœ +![์ •์ฑ…](https://github.com/ku-ring/ku-ring-backend-web/assets/60593969/219a2245-d4a9-444a-b8b1-7bf0f2d435a2) +ํด๋ฆฌ์‹œ(Policy)๋Š” ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•œ ํ›„ ์—ฐ์ด์–ด ๋ฐœ์ƒํ•˜๋Š” ๋ฐ˜์‘ํ˜• ์•ก์…˜์œผ๋กœ, **ํ•œ ์„œ๋น„์Šค ์ด๋ฒคํŠธ์— ๋Œ€ํ•ด ์ˆ˜ํ–‰๋˜์–ด์•ผ ํ•  ํƒ€ ์„œ๋น„์Šค์˜ ์•ก์…˜๋“ค๋กœ**, ๋จผ์ € ์ •์˜๋œ ์ด๋ฒคํŠธ ์•„๋ž˜์— ์ถ”๊ฐ€ํ•˜์˜€์Šต๋‹ˆ๋‹ค. +ํ•˜๋‚˜์˜ ์ด๋ฒคํŠธ์— ๋ฐ˜์‘ํ•˜์—ฌ ์ˆ˜ํ–‰๋˜์–ด์•ผ ํ•  ํด๋ฆฌ์‹œ๋Š” ์—ฌ๋Ÿฌ ํŒ€์—์„œ ๋„์ถœ๋œ ๋ฉ€ํ‹ฐ ์•ก์…˜์ด ์กด์žฌํ•  ์ˆ˜ ์žˆ๋‹ค. + +### 2-2-8) **ํด๋ฆฌ์‹œ์˜ ์ด๋™๊ณผ ์ปจํ…์ŠคํŠธ ๋งคํ•‘ (์ ์„ ์€ Pub/Sub, ์‹ค์„ ์€ Req/Resp)** +![์ตœ์ข…](https://github.com/ku-ring/ku-ring-backend-web/assets/60593969/d3e28458-f726-40bc-9a1e-01ca8329a295) +์œ„์™€ ๊ฐ™์ด ์ตœ์ข…์ ์œผ๋กœ ๋„๋ฉ”์ธ ๋ชจ๋ธ์„ ๋ถ„๋ฆฌํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!! + +
+ + +# ๐Ÿš€ ๋ฆฌํŒฉํ† ๋ง & ์„ฑ๋Šฅ ๊ฐœ์„  +
+ ๋ณธ๋ฌธ ํ™•์ธ (๐Ÿ‘ˆ Click) + +--- + +## 1. ์˜๋ฏธ์žˆ๋Š” ์ด๋ฆ„๊ณผ ํ•จ์ˆ˜ + +์ฝ”๋“œ๋ฅผ ๋‹ค์‹œ ๋˜๋Œ์•„๋ณด์•˜์„ ๋•Œ, ๋‹น์‹œ์—๋Š” ์ดํ•ดํ•  ์ˆ˜ ์žˆ์„ ์ •๋„์˜ ์ด๋ฆ„์œผ๋กœ ์ง€์—ˆ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์œผ๋‚˜ ๋ช…ํ™•ํ•˜๊ฒŒ ์™€๋‹ฟ์ง€ ์•Š๋Š” ๋„ค์ด๋ฐ๋“ค์ด ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. +๋”ฐ๋ผ์„œ ์ฃผ์„์ด ํ•„์š” ์—†์„ ์ •๋„๋กœ ๋ช…ํ™•ํ•˜๊ฒŒ ๋ณ€์ˆ˜๋ช…๊ณผ ํ•จ์ˆ˜๋ช…์„ ์ˆ˜์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค. +ํ•จ์ˆ˜์— ๋Œ€ํ•ด์„œ๋Š” Clean Code์—์„œ 5์ค„ ์ด๋‚ด๋ฅผ ๊ถŒ์žฅํ•˜๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. ์ฝ”๋“œ๋ฅผ ๋˜๋Œ์•„๋ณธ ๊ฒฐ๊ณผ ์ƒ๊ฐ๋ณด๋‹ค ํ•จ์ˆ˜๊ฐ€ ๊ธด ๊ฒƒ๋“ค์ด ์กด์žฌํ–ˆ๊ณ  ์ถฉ๋ถ„ํžˆ ์ค„์ผ ์ˆ˜ ์žˆ๋Š” ์ˆ˜์ค€์˜ ๋‚ด์šฉ๋“ค์ด์—ˆ๊ธฐ์— ํ•  ์ˆ˜ ์žˆ๋Š” ํ•œ์—์„œ 5์ค„ ๋‚ด์™ธ๋ฅผ ์ง€ํ‚ค๋„๋ก ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค. + +--- + +## 2. ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ์˜ ์–‘๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ๋‹จ๋ฐฉํ–ฅ์œผ๋กœ! +JPA์— ๋Œ€ํ•ด์„œ๋Š” ์„œ๋กœ ์–ด๋Š ์ •๋„ ์ดํ•ดํ•˜๊ณ  ์žˆ์–ด, ์ ์ ˆํ•œ fetch join์„ ์‚ฌ์šฉํ•˜์—ฌ ์ฝ”๋”ฉํ–ˆ์—ˆ๊ธฐ์— N+1 ๋ฌธ์ œ๋Š” ๋ฐœ์ƒํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. +ํ•˜์ง€๋งŒ ์—ฐ๊ด€๊ด€๊ณ„์— ๋Œ€ํ•ด์„œ ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. +๊ฐ€์žฅ ์ข‹์€ ์—ฐ๊ด€๊ด€๊ณ„ ์„ค๊ณ„๋Š” ๋‹จ๋ฐฉํ–ฅ์„ ๊ธฐ์ดˆ๋กœ ํ•˜๋˜ ํ•„์š”ํ•˜๋ฉด ์–‘๋ฐฉํ–ฅ ์„ค๊ณ„๋ฅผ ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. + +JPA ํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ ์ €์ž, ๊น€์˜ํ•œ ์„ ์ƒ๋‹˜์˜ ์˜๊ฒฌ์„ ๋นŒ๋ฆฌ์ž๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. +> ์–‘๋ฐฉํ–ฅ์œผ๋กœ ํ•˜๋ฉด ๋ณต์žก๋„๊ฐ€ ๋†’์•„์ง€๋Š” ๋‹จ์ ์ด ์žˆ์ง€๋งŒ ์„ฑ๋Šฅ์ƒ ์ด์ ์„ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. +์ •๋ง ์„ฑ๋Šฅ์ด ๋„ˆ๋ฌด ์ค‘์š”ํ•ด์„œ ์ฟผ๋ฆฌ ํ•˜๋‚˜๋ฅผ ์ค„์ด๋Š”๊ฒŒ ๊ผญ ํ•„์š”ํ•œ ์ƒํ™ฉ์ด๋ผ๋ฉด ๋ณต์žกํ•ด์ง€๋”๋ผ๋„ ์ตœ์ ํ™”๋ฅผ ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. +๋ฐ˜๋ฉด์— ์ฟผ๋ฆฌ๊ฐ€ ํ•˜๋‚˜ ๋” ๋‚˜๊ฐ€๋”๋ผ๋„ ์‹œ์Šคํ…œ ์ž์›์ด ์ถฉ๋ถ„ํ•ด์„œ ์„ฑ๋Šฅ์— ์˜ํ–ฅ์„ ๋ฏธ์น˜๋Š” ๊ฒƒ์ด ๋ฏธ๋ฏธํ•˜๋‹ค๋ฉด ์ฝ”๋“œ ๋ณต์žก๋„๋ฅผ ๋‚ฎ๊ฒŒ ์œ ์ง€ํ•˜๋Š” ๊ฒƒ์ด ๋” ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค. + +
+ kanban + kanban +
+ +๋‘˜๊ฐ„์— ์–‘๋ฐฉํ–ฅ์œผ๋กœ ์—ฐ๊ด€๊ด€๊ณ„๋ฅผ ๊ฐ–๊ณ  ์žˆ๋‹ค. +๊ทธ๋Ÿผ UserCategory์— ์ถ”๊ฐ€ํ•ด์ค„๋•Œ, User์ชฝ์˜ `private List userCategories = new ArrayList<>();` ์—๋„ UserCategory๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ , UserCategory ์ชฝ์—์„œ๋„ User๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผ ํ•œ๋‹ค!! +์ด๋Š” ์–‘๋ฐฉํ–ฅ์œผ๋กœ ๋งคํ•‘์ค‘์ด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. + +๋‹น์—ฐํžˆ ์—ฐ๊ด€๊ด€๊ณ„ ์ฃผ์ธ์ด UserCategory ์ด๊ธฐ ๋•Œ๋ฌธ์— UserCategory์— ์ถ”๊ฐ€ํ•˜๋Š”์ ์€ ์ ํ•ฉํ•˜๋‹ค. +ํ•˜์ง€๋งŒ ๋‹ค์Œ ์ฝ”๋“œ๋Š” UserCategory์ชฝ์—๋งŒ ์ถ”๊ฐ€์ค‘์ด๋‹ค. ํ”ํžˆ ๋งํ•˜๋Š” JPA ํŽธ์˜ ๋ฉ”์„œ๋“œ๋ฅผ ์ž‘์„ฑํ–ˆ์–ด์•ผ ํ—€๋Š”๋ฐ, ๋‹ค์Œ ์ฝ”๋“œ๋Š” ํŽธ์˜ ๋ฉ”์„œ๋“œ๊ฐ€ ์—†๋‹ค. +Untitled (3) + +๋”ฐ๋ผ์„œ UserCategory์—๋Š” ์‹ ๊ทœ UserCategory๊ฐ€ ์ถ”๊ฐ€ ๋˜์ง€๋งŒ, User๊ฐ€ ๋“ค๊ณ  ์žˆ๋Š” List๋Š” ๋น„์–ด ์žˆ๊ฒŒ ๋œ๋‹คโ€ฆ + +๋‹ค์Œ ๊ธ€์˜ 3๋ฒˆ โ€œ์–‘๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„ ์ฃผ์˜์ โ€์„ ๋ณด๋ฉด ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋‹ค. +https://blogshine.tistory.com/345 + +์•„์˜ˆ User์—์„œ UserCategory๋ฅผ ์‚ญ์ œํ•˜๋Š” ํŽธ์ด ๋” ์ข‹์„๊ฒƒ ๊ฐ™๋‹ค. ์–‘๋ฐฉํ–ฅ ์—ฐ๊ด€๊ด€๊ณ„๊ฐ€ ํ•„์ˆ˜์ ์ธ ํฌ์ธํŠธ๊ฐ€ ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค! โ†’ **User์—์„œ ์ œ๊ฑฐ!** +image +ํ…Œ์ด๋ธ” ๊ตฌ์กฐ์— ๋ณ€ํ™”๋Š” ์—†๊ธฐ์— ์ ์šฉ๊ฐ€๋Šฅ +--- + +## 3. ๊ณต์ง€ Scrap์ž‘์—… multi-threading ์ฒ˜๋ฆฌ๋กœ ์‹œ๊ฐ„ ๊ฐœ์„ ํ•˜๊ธฐ + +**๋ฌธ์ œ ์ƒํ™ฉ** + +- ๊ธฐ์กด์˜ 60๊ฐœ์˜ ํ•™๊ณผ๋ฅผ ์ „๋ถ€ Scrapํ•˜๋Š”๋ฐ ๋‹จ์ผ thread๋กœ๋Š” ๋„ˆ๋ฌด ์˜ค๋ž˜ ๊ฑธ๋ฆฌ๋Š” ๋ฌธ์ œ ๋ฐœ์ƒ + +**๋ฌธ์ œ ํ•ด๊ฒฐ** + +- 60๊ฐœ ํ•™๊ณผ์˜ ๊ณต์ง€๋ฅผ scrapํ•˜๋Š” ๊ณผ์ •์„ ๋ณ‘๋ ฌ์ฒ˜๋ฆฌ ํ•˜๋ฉด์„œ **Crawling ์„ฑ๋Šฅ๊ฐœ์„ ** + - ๋‹จ์ผ ๊ณต์ง€ ํŽ˜์ด์ง€ ๊ธฐ์ค€, core 6๊ฐœ : 3๋ถ„50์ดˆ โ†’ 49์ดˆ๋กœ ์„ฑ๋Šฅ์„ **4.39**๋ฐฐ ๊ฐœ์„  + - ์ „์ฒด ๊ณต์ง€ ํŽ˜์ด์ง€ ๊ธฐ์ค€, core 6๊ฐœ : 1์‹œ๊ฐ„ 12๋ถ„ 11์ดˆ โ†’ 15๋ถ„ 35์ดˆ๋กœ ์„ฑ๋Šฅ์„ **4.70**๋ฐฐ ๊ฐœ์„  + +**์ƒ์„ธ ๋‚ด์šฉ ๋งํฌ : ([๊ธ€ ๋งํฌ](https://blogshine.tistory.com/660))** + +--- +## 4. Full-Text-Index๋„์ž…์„ ํ†ตํ•œ **๊ฒ€์ƒ‰ ์„ฑ๋Šฅ๊ฐœ์„ ** + +**๋ฌธ์ œ ์ƒํ™ฉ** + +- ๊ธฐ์กด ๊ฒ€์ƒ‰์€ like ์ ˆ์„ ํ™œ์šฉํ•œ ๋‹จ์ˆœ full-scan๋ฐฉ์‹์˜ ๊ฒ€์ƒ‰์ด๋ผ๋Š” ๋‹จ์  + +**๋ฌธ์ œ ํ•ด๊ฒฐ** + +- ๊ณต์ง€ ๊ฒ€์ƒ‰ ์ฟผ๋ฆฌ ๋ณ€๊ฒฝ, ์ค‘์ง€๋‹จ์–ด, Full-Text-Index๋„์ž…์„ ํ†ตํ•œ **๊ฒ€์ƒ‰ ์„ฑ๋Šฅ๊ฐœ์„ ** + - ๊ฐœ์„  **์ „** : ๊ฒ€์ƒ‰์€ full Scan์„ ํ†ตํ•ด ์‹คํ–‰๊ณ„ํš์ด ์ˆ˜๋ฆฝ โ†’ 11s 59ms + - ๊ฐœ์„  **ํ›„** : Full Text index๊ณผ stop word ๋„์ž… โ†’ 591ms + - ๊ณต์ง€ 500๋งŒ๊ฑด ๊ธฐ์ค€ ๊ฒ€์ƒ‰ ์†๋„ **18.71๋ฐฐ ๊ฐœ์„ ** ํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค + +**์ƒ์„ธ ๋‚ด์šฉ ๋งํฌ : ([๊ธ€ ๋งํฌ](https://blogshine.tistory.com/664))** + +--- +## 5. ์ธ์ฆ, ์ธ๊ฐ€๋ฅผ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์œผ๋กœ๋ถ€ํ„ฐ ๋ถ„๋ฆฌํ•˜๊ธฐ + +**๋ฌธ์ œ ์ƒํ™ฉ** + +- ๋ถ€๊ฐ€์ ์ธ ์ธ์ฆ, ์ธ๊ฐ€ ๋กœ์ง์ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง๊ณผ ํ•จ๊ป˜ ํ˜ผ์žฌ๋˜์–ด ์žˆ๋Š” ์ƒํƒœ + +**๋ฌธ์ œ ํ•ด๊ฒฐ** + +image + +- ์ธ์ฆ, ์ธ๊ฐ€๋ฅผ ํ•ต์‹ฌ ๋น„์ฆˆ๋‹ˆ์Šค๋กœ์ง ์œผ๋กœ ๋ถ€ํ„ฐ ๋ถ„๋ฆฌํ•˜์—ฌ ๋ฆฌํŒฉํ† ๋ง ํ•˜๊ธฐ + - Spring Security์™€ ์œ ์‚ฌ ๊ตฌ์กฐ๋ฅผ ์ง์ ‘ ๊ตฌํ˜„ +- ์ง์ ‘ ๊ตฌํ˜„ํ•œ ์ „์ฒด ์ธ์ฆ ๋กœ์ง ํ๋ฆ„๋„ + +**์ƒ์„ธ ๋‚ด์šฉ ๋งํฌ : ([๊ธ€ ๋งํฌ](https://blogshine.tistory.com/678))** + +--- + +## 6. ํ”ํ•˜๋”” ํ”ํ•œ N+1 ์ฟผ๋ฆฌ ๊ฐœ์„ ๊ธฐ + +์›๋ž˜ ๋กœ์ง์—์„œ๋Š” ์‚ฌ์šฉ์ž์˜ Category ์ด๋ฆ„ ๋ชฉ๋ก์„ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•ด์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฒ˜๋ฆฌ๊ฐ€ ๋˜๊ณ  ์ž‡์—ˆ์Šต๋‹ˆ๋‹ค! + +![Untitled (2)](https://github.com/ku-ring/ku-ring-backend-web/assets/60593969/36dbdd3c-af5e-47ec-8e25-f2b0792f0486) + +getUserCategories ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๊ณ , + +```java +public List getUserCategories(String token) { + User user = userRepository.findByToken(token); + + // User์—์„œ ์ด๋ฏธ ์—ฐ๊ด€๊ด€๊ณ„๋กœ ๋“ค๊ณ  ์žˆ๋Š” ์ƒํ™ฉ์ด์—ˆ๋‹ค. + List userCategories = userCategoryRepository.findAllByUser(user); + + return userCategories.stream() + .map(UserCategory::getCategory) + .collect(Collectors.toList()); +} +``` + +์œ„์˜ ๊ธฐ์กด ์ฝ”๋“œ์—์„œ user๋ฅผ ์ฐพ์•„์˜ฌ๋•Œ ์‚ฌ์‹ค UserCategory๋ฅผ EAGER๋กœ ์ฐพ์•„์˜ค๊ณ  ์žˆ์—ˆ๋‹ค. +![Untitled (1)](https://github.com/ku-ring/ku-ring-backend-web/assets/60593969/ee224a35-a1e6-4d9f-9b6d-3ccfef43a24d) + +๋”ฐ๋ผ์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ณ€๊ฒฝ ํ–ˆ์–ด๋„ ๋ฌ์„๊ฒƒ ๊ฐ™๋‹ค! + +```java +List userCategories = user.getUserCategories(); // ์ด๋ฏธ User๋Š” UserCategory ์ •๋ณด๊ฐ€ ์žˆ์Œ +``` + +์ฆ‰, User๋ฅผ ์ฐพ์•„์˜ฌ๋•Œ ์ด๋ฏธ Category๋ฅผ ์ฐพ์•„์˜ค๋Š” ์ฟผ๋ฆฌ๊ฐ€ ๋‚˜๊ฐ”๋Š”๋ฐ, findAllByUser๋กœ ์ฐพ์•„์˜ฌ ํ•„์š”๊ฐ€ ์—†์—ˆ๋‹ค. + +(ps, ๋‹คํ–‰์ด 1์ฐจ ์บ์‹œ ๋•๋ถ„์— ์˜์†์„ฑ ์ปจํ…์ŠคํŠธ์—์„œ ์ฐพ์•„์˜ค๊ธฐ์— ๋™์ผํ•œ ์ฟผ๋ฆฌ๊ฐ€ 2๋ฒˆ ๋‚˜๊ฐ€์ง€๋Š” ์•Š๋Š”๋‹ค) + +getCategoryNamesFromCategories ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ตฌํ˜„๋˜์–ด ์žˆ์—ˆ๋‹ค! + +```java +public List getCategoryNamesFromCategories(List categories) { + return categories.stream() + .map(Category::getName) + .collect(Collectors.toList()); +} +``` + +์ด๋ ‡๊ฒŒ ์ฒ˜๋ฆฌ๋˜์–ด ์‚ฌ์šฉ์ž์˜ Category์ด๋ฆ„์„ ์ „๋ถ€ ๋ณด์—ฌ์ฃผ๊ณ  ์žˆ์—ˆ๋‹ค! + +์ฆ‰, User ํ•˜๋‚˜๋งŒ ์กฐํšŒํ•ด๋„ UserCategory๊นŒ์ง€ ํ•จ๊ป˜ ์กฐํšŒํ•˜๊ณ  ์žˆ์œผ๋‹ˆ~ + +1) token๊ฐ’์„ ๊ฐ–๋Š” User๋ฅผ ์ฐพ์•„์˜จ ํ›„ // ์ฟผ๋ฆฌ 1๋ฒˆ + +2) User์˜ UserCategory๋ฅผ ๋‹ค ์ฐพ์•„์˜จ๋‹ค. // UserCategory๋ฅผ ๋ฐ”๋กœ ์ฐพ์•„์˜ค๋Š” ์ฟผ๋ฆฌ N๊ฐœ (N+1๋ฌธ์ œ) + +3) ์ดํ›„ ์ฐพ์•„์˜จ UserCategory ๋ชฉ๋ก์„ ํ†ตํ•ด Category ๋ชฉ๋ก์„ ์ฐพ๋Š”๋‹ค. // Category N๊ฐœ๋งŒํผ ์ฟผ๋ฆฌ + +4) ์ฐพ์•„์˜จ Category ๋ชฉ๋ก์„ String ์ด๋ฆ„๋กœ ๋ฐ”๊พผ๋‹ค. + +์ฟผ๋ฆฌ๊ฐ€ ์ด 1 + 2N ๋งŒํผ ๋ฐœ์ƒ์ค‘์ด๋‹ค. + +### 6 - 1) ๋ณ€๊ฒฝ ์ „ ์ฟผ๋ฆฌ + +```bash +Hibernate: + select + user0_.id as id1_5_, + user0_.token as token2_5_ + from + user user0_ + where + user0_.token=? +2023-01-25 21:19:36.747 INFO 16011 --- [o-auto-1-exec-5] p6spy : #1674649176747 | took 1ms | statement | connection 22| url jdbc:mariadb://localhost:52131/test +select user0_.id as id1_5_, user0_.token as token2_5_ from user user0_ where user0_.token=? +select user0_.id as id1_5_, user0_.token as token2_5_ from user user0_ where user0_.token='test_fcm_token'; +Hibernate: + select + usercatego0_.user_token as user_tok3_6_0_, + usercatego0_.id as id1_6_0_, + usercatego0_.id as id1_6_1_, + usercatego0_.category_name as category2_6_1_, + usercatego0_.user_token as user_tok3_6_1_ + from + user_category usercatego0_ + where + usercatego0_.user_token=? +2023-01-25 21:19:36.749 INFO 16011 --- [o-auto-1-exec-5] p6spy : #1674649176749 | took 1ms | statement | connection 22| url jdbc:mariadb://localhost:52131/test +select usercatego0_.user_token as user_tok3_6_0_, usercatego0_.id as id1_6_0_, usercatego0_.id as id1_6_1_, usercatego0_.category_name as category2_6_1_, usercatego0_.user_token as user_tok3_6_1_ from user_category usercatego0_ where usercatego0_.user_token=? +select usercatego0_.user_token as user_tok3_6_0_, usercatego0_.id as id1_6_0_, usercatego0_.id as id1_6_1_, usercatego0_.category_name as category2_6_1_, usercatego0_.user_token as user_tok3_6_1_ from user_category usercatego0_ where usercatego0_.user_token='test_fcm_token'; +Hibernate: + select + user0_.id as id1_5_1_, + user0_.token as token2_5_1_, + usercatego1_.user_token as user_tok3_6_3_, + usercatego1_.id as id1_6_3_, + usercatego1_.id as id1_6_0_, + usercatego1_.category_name as category2_6_0_, + usercatego1_.user_token as user_tok3_6_0_ + from + user user0_ + left outer join + user_category usercatego1_ + on user0_.token=usercatego1_.user_token + where + user0_.token=? +2023-01-25 21:19:36.755 INFO 16011 --- [o-auto-1-exec-5] p6spy : #1674649176755 | took 1ms | statement | connection 22| url jdbc:mariadb://localhost:52131/test +select user0_.id as id1_5_1_, user0_.token as token2_5_1_, usercatego1_.user_token as user_tok3_6_3_, usercatego1_.id as id1_6_3_, usercatego1_.id as id1_6_0_, usercatego1_.category_name as category2_6_0_, usercatego1_.user_token as user_tok3_6_0_ from user user0_ left outer join user_category usercatego1_ on user0_.token=usercatego1_.user_token where user0_.token=? +select user0_.id as id1_5_1_, user0_.token as token2_5_1_, usercatego1_.user_token as user_tok3_6_3_, usercatego1_.id as id1_6_3_, usercatego1_.id as id1_6_0_, usercatego1_.category_name as category2_6_0_, usercatego1_.user_token as user_tok3_6_0_ from user user0_ left outer join user_category usercatego1_ on user0_.token=usercatego1_.user_token where user0_.token='test_fcm_token'; +HTTP/1.1 200 +Content-Type: application/json +Transfer-Encoding: chunked +Date: Wed, 25 Jan 2023 12:19:36 GMT +Keep-Alive: timeout=60 +Connection: keep-alive +``` + +N+1 ๋ฌธ์ œ๋กœ Userํ•œ๋ฒˆ ์กฐํšŒํ•˜๋Š”๋ฐ ์œ„์™€ ๊ฐ™์ด ์ฟผ๋ฆฌ๊ฐ€ 3๋ฒˆ ๋‚˜๊ฐ€๊ฒŒ ๋จ + +### 6 - 2) ๋ณ€๊ฒฝ ํ›„ + +๋ณ€๊ฒฝ ํ›„ ํ•œ๋ฐฉ ์ฟผ๋ฆฌ๋กœ ์กฐํšŒ ๋ +```java +public List getUserCategoryNamesByToken(String token) { + return queryFactory + .select(userCategory.category.name) + .from(userCategory) + .where(userCategory.user.token.eq(token)) + .fetch(); +} +``` + + + +___ + +## 7. Test Container๋ฅผ ํ†ตํ•œ ํ…Œ์ŠคํŠธ์˜ ๋ฉฑ๋“ฑ์„ฑ ๋ณด์žฅํ•˜๊ธฐ +ํ…Œ์ŠคํŠธ์™€, ์‹ค์ œ ์šด์˜ DB๋ฅผ ๋‘˜๋‹ค MariaDB ํ™˜๊ฒฝ์œผ๋กœ ์‚ฌ์šฉํ•˜์—ฌ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ผ์ด ์—†๋‹ค ์ƒ๊ฐํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค. +ํ•˜์ง€๋งŒ, utf8๊ณผ ๊ฐ™์€ ์ธ์ฝ”๋”ฉ ๋ฐฉ์‹์ด ๋กœ์ปฌ๊ณผ ํ”„๋กœ๋•์…˜์ด ๋‹ฌ๋ผ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์œผ๋ฉฐ, ์ด๋˜ํ•œ ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ์—์„œ ๊ฑธ๋Ÿฌ๋‚ด์ง€ ๋ชปํ•œ ๊ฒƒ์ด ๋ฌธ์ œ๋ผ ์ƒ๊ฐํ•˜์˜€์Šต๋‹ˆ๋‹ค. + +๋”ฐ๋ผ์„œ ์ดํ›„๋ถ€ํ„ฐ๋Š” ํ™˜๊ฒฝ ์ž์ฒด๋ฅผ ๋™์ผํ•˜๊ฒŒ ๋งŒ๋“  Test ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ”„๋กœ๋•์…˜ ํ™˜๊ฒฝ๊ณผ ๋™์ผํ™˜ ํ™˜๊ฒฝ๋ณ€์ˆ˜ ํ™˜๊ฒฝ์—์„œ ํ…Œ์ŠคํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋„๋ก ํ•˜์˜€์Šต๋‹ˆ๋‹ค. +ํ…Œ์ŠคํŠธ์—์„œ ์ˆ˜ํ–‰ ์‹œ๊ฐ„์ด ์กฐ๊ธˆ ๊ธธ์–ด์กŒ์ง€๋งŒ, ํ…Œ์ŠคํŠธ์˜ ๋ชฉ์ ์— ๋ถ€ํ•ฉํ•˜๋„๋ก ๋™์ž‘ํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. + +--- + +## 8. CI / ์ •์ ๋ถ„์„๊ธฐ(SonarCloud, jacoco)๋ฅผ ์‚ฌ์šฉํ•œ ์ฝ”๋“œ ์ปจ๋ฒค์…˜์— ๋Œ€ํ•œ ์ฝ”๋“œ๋ฆฌ๋ทฐ ์ž๋™ํ™” + +**๋ฌธ์ œ ์ƒํ™ฉ** + +- ์ •์  ๋ถ„์„ ๋„๊ตฌ๊ฐ€ ์—†์–ด ์ฝ”๋“œ์˜ ํ’ˆ์งˆ ๊ด€๋ฆฌ๋‚˜, ๋ฒ„๊ทธ ๋ฐœ๊ฒฌ๋“ฑ์ด ์–ด๋ ค์› ๋˜ ์ƒํ™ฉ + +**๋ฌธ์ œ ํ•ด๊ฒฐ** + +image + +- ์ •์  ๋ถ„์„ ๋„๊ตฌ๋ฅผ ํ†ตํ•œ ๋ถ„์„์„ ํ†ตํ•˜์—ฌ ์‚ฌ์ „์— ๋ฏธ๋ฆฌ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” ์ง€์ ๋“ค์„ ๋ณด์™„ํ•  ์ˆ˜ ์žˆ์Œ +- ํ…Œ์ŠคํŠธ ์ฝ”๋“œ์˜ ์ปค๋ฒ„๋ฆฌ์ง€์— ๋Œ€ํ•œ ๊ด€๋ฆฌ๊ฐ€ ํŽธ๋ฆฌํ•˜๋‹ค ์ƒ + +**์ƒ์„ธ ๋‚ด์šฉ ๋งํฌ : ([๊ธ€ ๋งํฌ](https://blogshine.tistory.com/658))** + +--- + +## 9. ์„œ๋ฒ„ ๋ชจ๋‹ˆํ„ฐ๋ง + +**๋ฌธ์ œ ์ƒํ™ฉ** + +- ์ด์ „์—๋Š” ๋ชจ๋‹ˆํ„ฐ๋ง ๋„๊ตฌ๊ฐ€ ์—†์–ด ์‹ค์‹œ๊ฐ„์œผ๋กœ ์„œ๋ฒ„์˜ ์ƒํƒœ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์—†์—ˆ๋‹ค. +- ์„œ๋ฒ„์˜ ์ƒํƒœ๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ์„œ๋ฒ„์— ์ ‘์†ํ•˜์—ฌ ๋กœ๊ทธ๋ฅผ ํ™•์ธํ•ด์•ผ ํ–ˆ๋‹ค. + +**๋ฌธ์ œ ํ•ด๊ฒฐ** + +image + +- ์„œ๋ฒ„์˜ ์ƒํƒœ๋ฅผ ์‹ค์‹œ๊ฐ„์œผ๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด ์„œ๋ฒ„์˜ ์ƒํƒœ๋ฅผ ๋น ๋ฅด๊ฒŒ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค. +- ์ผ์ • ๊ธฐ๊ฐ„๋™์•ˆ์˜ ์„œ๋ฒ„ ์ •๋ณด๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฌธ์ œ ๋ฐœ์ƒ์‹œ ์—ญ์ถ”์  ํ•ด๋ณผ ์ˆ˜ ์žˆ๋‹ค. +- ๋‹ค์Œ ๊ธ€ ๋งํฌ์—์„œ๋Š” ์ด๋ฅผ ํ†ตํ•˜์—ฌ ์„œ๋ฒ„๊ฐ€ ๋‹ค์šด๋˜๋Š” ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•œ ๊ธ€ ์ด๋‹ค! + +**์ƒ์„ธ ๋‚ด์šฉ ๋งํฌ : ([๊ธ€ ๋งํฌ](https://blogshine.tistory.com/669))** + +--- +
+
+ +# ๐Ÿ’Ž ์™œ ์ด ๊ธฐ์ˆ ์„ ์‚ฌ์šฉํ–ˆ๋Š”๊ฐ€? +
+ ๋ณธ๋ฌธ ํ™•์ธ (๐Ÿ‘ˆ Click) + +---- + +## 1. Querydsl + + +Spring Data JPA๊ฐ€ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ œ๊ณตํ•ด์ฃผ๋Š” CRUD ๋ฉ”์„œ๋“œ ๋ฐ ์ฟผ๋ฆฌ ๋ฉ”์„œ๋“œ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๋”๋ผ๋„, ์›ํ•˜๋Š” ์กฐ๊ฑด์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์ง‘ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ํ•„์—ฐ์ ์œผ๋กœ JPQL์„ ์ž‘์„ฑํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. +๊ฐ„๋‹จํ•œ ๋กœ์ง์„ ์ž‘์„ฑํ•˜๋Š”๋ฐ ํฐ ๋ฌธ์ œ๋Š” ์—†์œผ๋‚˜, ๋ณต์žกํ•œ ๋กœ์ง์˜ ๊ฒฝ์šฐ ๊ฐœํ–‰์ด ํฌํ•จ๋œ ์ฟผ๋ฆฌ ๋ฌธ์ž์—ด์ด ์ƒ๋‹นํžˆ ๊ธธ์–ด์ง‘๋‹ˆ๋‹ค. +JPQL ๋ฌธ์ž์—ด์— ์˜คํƒ€ ํ˜น์€ ๋ฌธ๋ฒ•์ ์ธ ์˜ค๋ฅ˜๊ฐ€ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ, ์ •์  ์ฟผ๋ฆฌ๋ผ๋ฉด ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋กœ๋”ฉ ์‹œ์ ์— ์ด๋ฅผ ๋ฐœ๊ฒฌํ•  ์ˆ˜ ์žˆ์œผ๋‚˜ ๊ทธ ์™ธ๋Š” ๋Ÿฐํƒ€์ž„ ์‹œ์ ์—์„œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. +์ด๋Ÿฌํ•œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•ด ์ฃผ๋Š” ๊ฒƒ์ด Querydsl์ด๊ธฐ์— Querydsl์„ ๋„์ž…ํ–ˆ์Šต๋‹ˆ๋‹ค. +Querydsl ๋„์ž…์œผ๋กœ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ด์ ์„ ์–ป์—ˆ์Šต๋‹ˆ๋‹ค. + +1. ๋ฌธ์ž๊ฐ€ ์•„๋‹Œ ์ฝ”๋“œ๋กœ ์ฟผ๋ฆฌ๋ฅผ ์ž‘์„ฑํ•จ์œผ๋กœ์จ, ์ปดํŒŒ์ผ ์‹œ์ ์— ๋ฌธ๋ฒ• ์˜ค๋ฅ˜๋ฅผ ์‰ฝ๊ฒŒ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. +2. ์ž๋™ ์™„์„ฑ ๋“ฑ IDE์˜ ๋„์›€์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค. +3. ๋™์ ์ธ ์ฟผ๋ฆฌ ์ž‘์„ฑ์ด ํŽธ๋ฆฌํ•˜๋‹ค. +4. ์ฟผ๋ฆฌ ์ž‘์„ฑ ์‹œ ์ œ์•ฝ ์กฐ๊ฑด ๋“ฑ์„ ๋ฉ”์„œ๋“œ ์ถ”์ถœ์„ ํ†ตํ•ด ์žฌ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. + +---- + +## 2. Flyway +dev, local ํ™˜๊ฒฝ์—์„œ๋Š” ๋‹จ์ˆœํžˆ ddl์„ create-drop ๋˜๋Š” update ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์—ˆ๊ธฐ์— DB์— ๋Œ€ํ•ด ๊ณ ๋ฏผํ•  ํ•„์š”๊ฐ€ ์—†์—ˆ์Šต๋‹ˆ๋‹ค. +ํ•˜์ง€๋งŒ ์šด์˜ํ™˜๊ฒฝ์—์„œ๋Š” ddl์„ validate ๋˜๋Š” none ์˜ต์…˜์„ ์‚ฌ์šฉํ•ด์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ดˆ๊ธฐ์—๋Š” DB script๋ฅผ ๋ฝ‘์•„์„œ ๋ณ„๋„๋กœ ๊ด€๋ฆฌ๋ฅผ ํ–ˆ์Šต๋‹ˆ๋‹ค. +์ดํ›„ ๊ธฐ๋Šฅ์ด ์ถ”๊ฐ€๋˜๋ฉด์„œ script๊ฐ€ ๋ณ€๊ฒฝ๋˜๋Š” ์ผ์ด ๋นˆ๋ฒˆํ•ด์กŒ๊ณ , ๋งค๋ฒˆ ์ผ์ผ์ด ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ์ด ๋ฒˆ๊ฑฐ๋กœ์šธ ๋ฟ ์•„๋‹ˆ๋ผ ์‹ค์ˆ˜ํ•˜๊ธฐ ๋”ฑ ์ข‹์€ ๋ถ€๋ถ„์ด๋ผ Flyway๋ฅผ ๋„์ž…ํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ˜•์ƒ๊ด€๋ฆฌ๋ฅผ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค. + +์ถ”๊ฐ€๋กœ ์ €์˜ ์ƒ๊ฐ์— ์ด์ ์€ +1. ํ˜‘์—…์‹œ ํŒ€์›์ด ddl์˜ ์ฝ”๋“œ๋ฆฌ๋ทฐ๋ฅผ ํ•˜๊ธฐ ๋งค์šฐ ํŽธํ•˜๋‹ค. +2. ๋‚ด๊ฐ€ ์ž‘์„ฑํ•œ ddl์ด ์ •์ƒ์ ์œผ๋กœ ์ถ”๊ฐ€๋œ๋‹ค, ์ฆ‰ ๋ณต๋ถ™์ด๋‚˜ ํƒ€์ดํ•‘ ํ•˜๋‹ค ๋‚˜๋Š” ํœด๋จผ์—๋Ÿฌ ๋“ฑ์„ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค. + +---- + +
+ + + +# โฐ ํ˜‘์—… ๋ฐฉ์‹ - Jira + +
+ ๋ณธ๋ฌธ ํ™•์ธ (๐Ÿ‘ˆ Click) +
+ +์ €ํฌ ์ฟ ๋งํŒ€์€ ํ˜‘์—… ๋ฐฉ์‹์œผ๋กœ Jira๋ฅผ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค. + +๊ตฌํ˜„ํ•ด์•ผํ•  ํฐ ๊ธฐ๋Šฅ๋“ค์„ ์—ํ”ฝ์œผ๋กœ ์ •์˜ํ•˜์—ฌ ์ผ์ •์„ ์„ค์ •ํ–ˆ๊ณ  ํ•˜๋‚˜์˜ ์—ํ”ฝ์— ํ•„์š”ํ•œ ๊ธฐ๋Šฅ๋“ค์ธ task๋ฅผ ์„ธ์„ธํ•˜๊ฒŒ ๋‚˜๋ˆ„์—ˆ์Šต๋‹ˆ๋‹ค. +์นธ๋ฐ˜๋ณด๋“œ๋ฅผ ํ†ตํ•ด task๋“ค์„ ๊ฐœ๋ฐœํ•ด์•ผํ•  ๋ชจ๋“  ๊ธฐ๋Šฅ๋“ค, ์ด๋ฒˆ์ฃผ์— ๊ฐœ๋ฐœํ•ด์•ผํ•  ๊ธฐ๋Šฅ, ๊ฐœ๋ฐœ ์ง„ํ–‰์ค‘, ๊ฐœ๋ฐœ ์™„๋ฃŒ๋œ ์นธ์œผ๋กœ ์˜ฎ๊ธฐ๋ฉด์„œ ํ•œ๋ˆˆ์— ๋ณผ ์ˆ˜ ์žˆ๋„๋ก ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค. + +์Šคํ”„๋ฆฐํŠธ๋Š” 1์ฃผ์ผ ๋‹จ์œ„๋กœ ์„ค์ •ํ•˜์—ฌ Jira ๋‚ด Confluence์—์„œ ์Šคํ”„๋ฆฐํŠธ ์ฃผ๊ธฐ๋™์•ˆ ์ง„ํ–‰ํ•ด์•ผํ•  ๊ธฐ๋Šฅ๋“ค์„ ์ •์˜ํ•˜๊ณ  ๋งˆ์Œ๊ฐ€์ง๊ณผ ์Šคํ”„๋ฆฐํŠธ๋ฅผ ๋งˆ์นœ ํ›„ ํšŒ๊ณ ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์Šคํ”„๋ฆฐํŠธ๋ฅผ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค. + +## ๋กœ๋“œ๋งต +
+ kanban +
+ +## ์นธ๋ฐ˜๋ณด๋“œ +
+ +
+ +
+ ## ๐Ÿ”Œ Infrastructures +
+ ๋ณธ๋ฌธ ํ™•์ธ (๐Ÿ‘ˆ Click) + ### CI Flow -แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-05-15 แ„‹แ…ฉแ„’แ…ฎ 5 08 22 +แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2023-05-15 แ„‹แ…ฉแ„’แ…ฎ 5 08 22 + +### CD Flow +image + +### CD Detail Flow (Test Server) +image + +๊ณผ์ • ์ •๋ฆฌ๊ธ€ +1) [Github Actions, CodeDeploy, Nginx ๋กœ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌํ•˜๊ธฐ - 1](https://blogshine.tistory.com/427) +2) [Github Actions, CodeDeploy, Nginx ๋กœ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌํ•˜๊ธฐ - 2](https://blogshine.tistory.com/428) +3) [Github Actions, CodeDeploy, Nginx ๋กœ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌํ•˜๊ธฐ - 3](https://blogshine.tistory.com/429) +4) [Github Actions, CodeDeploy, Nginx ๋กœ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌํ•˜๊ธฐ - 4](https://blogshine.tistory.com/430) + + [![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FKU-Stacks%2Fku-ring-backend-web&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com) +