๊ฐœ์š”


ํŠธ๋žœ์žญ์…˜ ๋ฒ”์œ„๋ฅผ ํšจ์œจ์ ์œผ๋กœ ๊ด€๋ฆฌํ•˜๊ณ , ์„œ๋น„์Šค ํ™•์žฅ ์‹œ ๊ณ ๋ คํ•ด์•ผ ํ•  ์„œ๋น„์Šค ๋ถ„๋ฆฌ ์ „๋žต ๋ฐ ํŠธ๋žœ์žญ์…˜ ๊ด€๋ฆฌ ์ „๋žต์„ ๋ถ„์„ํ•ฉ๋‹ˆ๋‹ค.
์ด๋ฅผ ํ†ตํ•ด ํ™•์žฅ์„ฑ๊ณผ ์œ ์ง€๋ณด์ˆ˜์„ฑ์„ ํ–ฅ์ƒ์‹œํ‚ค๋Š” ํ•ด๊ฒฐ ๋ฐฉ์•ˆ์„ ์กฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

์ฃผ์š” ๋‚ด์šฉ

  • ์„œ๋น„์Šค ๊ฐ„ ๊ฒฐํ•ฉ๋„ ์™„ํ™”: ์„œ๋น„์Šค์˜ ๋…๋ฆฝ์„ฑ์„ ๋†’์—ฌ ํ™•์žฅ์„ฑ๊ณผ ์œ ์ง€๋ณด์ˆ˜์„ฑ์„ ๊ฐœ์„ ํ•ฉ๋‹ˆ๋‹ค.
  • ํŠธ๋žœ์žญ์…˜ ๊ด€๋ฆฌ ์ „๋žต: ๋ถ„์‚ฐ ์‹œ์Šคํ…œ์—์„œ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” ํŠธ๋žœ์žญ์…˜ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•œ ๋ฐฉ๋ฒ•์„ ์กฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง๊ณผ ํŠธ๋žœ์žญ์…˜์˜ ๋ฒ”์œ„

๋ฌด๋ถ„๋ณ„ํ•œ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง๊ณผ ํŠธ๋žœ์žญ์…˜์˜ ๊ทœ๋ชจ ๋˜ํ•œ ์šฐ๋ฆฌ๊ฐ€ ์˜ˆ์ธกํ•˜์ง€ ๋ชปํ•œ ๋ฌธ์ œ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฌธ์ œ์ 

  • ํŠธ๋žœ์žญ์…˜ ๋ฒ”์œ„๊ฐ€ ๊ณผ๋„ํ•˜๊ฒŒ ๋„“์€ ๊ฒฝ์šฐ
    • ๋‹จ์ผ ํŠธ๋žœ์žญ์…˜์—์„œ ๋„ˆ๋ฌด ๋งŽ์€ ์ž‘์—…์„ ์ฒ˜๋ฆฌํ•˜๋ฉด ๋ฐ๋“œ๋ฝ ๋ฐ ์„ฑ๋Šฅ ์ €ํ•˜ ๋ฐœ์ƒ ๊ฐ€๋Šฅ์„ฑ์ด ๋†’์•„์ง‘๋‹ˆ๋‹ค.
    • ๋กค๋ฐฑ ์‹œ, ๋ถˆํ•„์š”ํ•˜๊ฒŒ ๋งŽ์€ ๋ฆฌ์†Œ์Šค๊ฐ€ ์˜ํ–ฅ์„ ๋ฐ›์Šต๋‹ˆ๋‹ค.
  • ํŠธ๋žœ์žญ์…˜ ๋‚ด DB์™€ ๋ฌด๊ด€ํ•œ ์ž‘์—… ์ˆ˜ํ–‰
    • ํŒŒ์ผ ์ž…์ถœ๋ ฅ, ์™ธ๋ถ€ API ํ˜ธ์ถœ ๋“ฑ ํŠธ๋žœ์žญ์…˜ ์™ธ๋ถ€์—์„œ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•  ์ž‘์—…์ด ํฌํ•จ๋  ๊ฒฝ์šฐ ์„ฑ๋Šฅ ์ €ํ•˜์™€ ๋กค๋ฐฑ ๋ถˆ๊ฐ€ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

ํ•ด๊ฒฐ ๋ฐฉ์•ˆ

  • ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง๊ณผ ํŠธ๋žœ์žญ์…˜ ๋ฒ”์œ„ ๋ถ„๋ฆฌ: ํŠธ๋žœ์žญ์…˜ ๋‚ด์—์„œ ์ตœ์†Œํ•œ์˜ ์ž‘์—…๋งŒ ์ฒ˜๋ฆฌํ•˜๊ณ , ๋‚˜๋จธ์ง€ ์ž‘์—…์€ ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ ๋˜๋Š” ์ด๋ฒคํŠธ ๊ธฐ๋ฐ˜ ์ฒ˜๋ฆฌ๋กœ ๋ถ„๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ด๋ฒคํŠธ๋ฅผ ํ†ตํ•œ ๊ด€์‹ฌ์‚ฌ ๋ถ„๋ฆฌ

ApplicationEventPublisher์™€ EventListener

  • ApplicationEventPublisher: ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋‚ด ์ด๋ฒคํŠธ๋ฅผ ๋ฐœํ–‰ํ•˜์—ฌ ์„œ๋น„์Šค ๊ฐ„ ๊ฒฐํ•ฉ๋„๋ฅผ ๋‚ฎ์ถฅ๋‹ˆ๋‹ค.
  • EventListener / TransactionalEventListener: ํŠน์ • ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ๋น„๋™๊ธฐ ๋ฐฉ์‹ ๋˜๋Š” ํŠธ๋žœ์žญ์…˜ ๊ฒฝ๊ณ„ ๋‚ด์—์„œ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.
  • @TransactionalEventListener์™€ @Async๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ, ํŠธ๋žœ์žญ์…˜ ์ข…๋ฃŒ ํ›„ ๋น„๋™๊ธฐ๋กœ ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์–ด ์„ฑ๋Šฅ๊ณผ ์‘๋‹ต ์†๋„๋ฅผ ๊ฐœ์„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์„ค๊ณ„ ๋ฐฉํ–ฅ

  1. ์ด๋ฒคํŠธ ๋ฐœํ–‰: ApplicationEventPublisher๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์— ์ด๋ฒคํŠธ๋ฅผ ๋ฐœํ–‰ํ•ฉ๋‹ˆ๋‹ค.
  2. ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ ์„ค์ •: ์ด๋ฒคํŠธ๋ฅผ ๊ตฌ๋…ํ•˜์—ฌ ๋ถ€๊ฐ€ ๊ธฐ๋Šฅ์„ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.
  3. ์˜ค๋ฅ˜ ๋ฐ ์žฌ์‹œ๋„ ์ฒ˜๋ฆฌ: ๋น„๋™๊ธฐ ์ž‘์—…์—์„œ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•  ๊ฒฝ์šฐ ์ด๋ฅผ ๋กœ๊น…ํ•˜๊ฑฐ๋‚˜, ์žฌ์‹œ๋„ ๋กœ์ง์„ ์ถ”๊ฐ€ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

๋ถ„์‚ฐ ํŠธ๋žœ์žญ์…˜ ๊ด€๋ฆฌ ํŒจํ„ด์„ ํ†ตํ•œ ๊ด€์‹ฌ์‚ฌ ๋ถ„๋ฆฌ

Saga ํŒจํ„ด

  • ๋ถ„์‚ฐ ํŠธ๋žœ์žญ์…˜ ํ™˜๊ฒฝ์—์„œ ํŠธ๋žœ์žญ์…˜์˜ ์ผ๊ด€์„ฑ์„ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•œ ํŒจํ„ด.
  • ๊ฐ ์„œ๋น„์Šค๊ฐ€ ๋กœ์ปฌ ํŠธ๋žœ์žญ์…˜์„ ์ฒ˜๋ฆฌํ•œ ํ›„ ์ด๋ฒคํŠธ๋ฅผ ๋ฐœํ–‰ํ•˜์—ฌ ๋‹ค์Œ ์ž‘์—…์„ ์ด์–ด๋‚˜๊ฐ‘๋‹ˆ๋‹ค.

Choreography(ํฌ๋ ˆ์˜ค๊ทธ๋ž˜ํ”ผ) ํŒจํ„ด

  • ์ด๋ฒคํŠธ ๊ธฐ๋ฐ˜์œผ๋กœ ํŠธ๋žœ์žญ์…˜ ํ๋ฆ„์„ ์กฐ์œจ. ๊ฐ ์„œ๋น„์Šค๊ฐ€ ์ž์ฒด ์ด๋ฒคํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜์—ฌ ํŠธ๋žœ์žญ์…˜ ์‹คํ–‰.
    • ๊ฐ ์„œ๋น„์Šค๋Š” ์ž์‹ ์˜ ๋กœ์ปฌ ํŠธ๋žœ์žญ์…˜์„ ์‹คํ–‰ํ•˜๊ณ , ์ž‘์—… ์™„๋ฃŒ ํ›„ ์ด๋ฒคํŠธ๋ฅผ ๋ฐœํ–‰.
    • ๋‹ค๋ฅธ ์„œ๋น„์Šค๋Š” ํ•ด๋‹น ์ด๋ฒคํŠธ๋ฅผ ๊ตฌ๋…ํ•˜์—ฌ ์ž์‹ ์˜ ์ž‘์—…์„ ์‹คํ–‰.

์„ค๊ณ„ ๋ฐฉํ–ฅ

  1. ์„œ๋น„์Šค ๋ถ„๋ฆฌ ๋ฐ ์ด๋ฒคํŠธ ๋ฐœํ–‰
  2. ์ด๋ฒคํŠธ ํ๋ฆ„ ์ •์˜
    PaymentService๋Š” PaymentStartedEvent๋ฅผ ๋ฐœํ–‰ํ•ฉ๋‹ˆ๋‹ค.
    PointService๋Š” PaymentProcessedEvent๋ฅผ ๊ตฌ๋…ํ•˜์—ฌ ํฌ์ธํŠธ ์ฐจ๊ฐ ํ›„ PointsSubtractedEvent๋ฅผ ๋ฐœํ–‰ํ•ฉ๋‹ˆ๋‹ค.
    SeatService๋Š” PointsSubtractedEvent๋ฅผ ๊ตฌ๋…ํ•˜์—ฌ ์ขŒ์„ ์˜ˆ์•ฝ ํ›„ SeatsReservedEvent๋ฅผ ๋ฐœํ–‰ํ•ฉ๋‹ˆ๋‹ค.
    PaymentHistoryService๋Š” SeatsReservedEvent๋ฅผ ๊ตฌ๋…ํ•˜์—ฌ ๊ฒฐ์ œ ์ด๋ ฅ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
  3. ๋ณด์ƒ ํŠธ๋žœ์žญ์…˜: ์‹คํŒจํ•œ ๋‹จ๊ณ„๊ฐ€ ๋ฐœ์ƒํ•  ๊ฒฝ์šฐ ํ•ด๋‹น ๋‹จ๊ณ„์—์„œ ๋ณด์ƒ ํŠธ๋žœ์žญ์…˜์„ ๋ฐœํ–‰ํ•ฉ๋‹ˆ๋‹ค. ํฌ์ธํŠธ ์ฐจ๊ฐ์— ์‹คํŒจํ•˜๋ฉด ์ด์ „ ๋‹จ๊ณ„์˜ ์ž‘์—…์„ ๋ณด์ƒํ•˜๋Š” ์ด๋ฒคํŠธ๋ฅผ ๋ฐœํ–‰ํ•ฉ๋‹ˆ๋‹ค.

์žฅ์  ๋ฐ ๊ณ ๋ ค์‚ฌํ•ญ

  • ์žฅ์ : Orchestrator๊ฐ€ ์—†์–ด ์„œ๋น„์Šค ๊ฐ„ ๊ฒฐํ•ฉ๋„๊ฐ€ ๋‚ฎ์•„์ง€๊ณ , ๊ฐ ์„œ๋น„์Šค๋Š” ์ž์‹ ์˜ ์ฑ…์ž„๋งŒ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
  • ๊ณ ๋ ค์‚ฌํ•ญ: ์ด๋ฒคํŠธ ์ˆœ์„œ ๋ฐ ๋ณต๊ตฌ ๋กœ์ง์ด ์ž˜ ์„ค๊ณ„๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Orchestration(์˜ค์ผ€์ŠคํŠธ๋ ˆ์ด์…˜) ํŒจํ„ด

  • ์ค‘์•™ ์กฐ์ •์ž๊ฐ€ ํŠธ๋žœ์žญ์…˜ ํ๋ฆ„์„ ์ œ์–ดํ•˜์—ฌ ์‹คํ–‰ ์ˆœ์„œ๋ฅผ ๊ฒฐ์ •.
  • Saga ์˜ค์ผ€์ŠคํŠธ๋ ˆ์ดํ„ฐ๋Š” ๋‹จ๊ณ„๋ฅผ ์ธ์‹ํ•˜๊ณ  ํ•„์š”ํ•œ ์ˆœ์„œ๋Œ€๋กœ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. T3 ๋‹จ๊ณ„๊ฐ€ ์‹คํŒจํ•˜๋ฉด(๊ฒฐ์ œ ์‹คํŒจ) ์˜ค์ผ€์ŠคํŠธ๋ ˆ์ดํ„ฐ๋Š” ๋ณด์ • ํŠธ๋žœ์žญ์…˜ C1๊ณผ C2๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ดˆ๊ธฐ ์ƒํƒœ๋กœ ๋ณต์›ํ•ฉ๋‹ˆ๋‹ค.

์„ค๊ณ„ ๋ฐฉํ–ฅ

  1. Saga Orchestrator ์„ค๊ณ„: ๊ฐ ๋‹จ๊ณ„์˜ ์ด๋ฒคํŠธ๋ฅผ ์ˆ˜์‹ ํ•˜๊ณ  ์ ์ ˆํ•œ ์„œ๋น„์Šค ํ˜ธ์ถœ์„ ํ•˜์—ฌ ์ž‘์—…์„ ๊ด€๋ฆฌํ•˜๋Š” Orchestrator์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
  2. ๊ฐ ์„œ๋น„์Šค ๋ถ„๋ฆฌ ๋ฐ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋ง: ๋กœ์ปฌ ํŠธ๋žœ์žญ์…˜์„ ๊ฐœ๋ณ„ ์„œ๋น„์Šค์—์„œ ์ฒ˜๋ฆฌํ•˜๊ณ  ๊ฐ๊ฐ์˜ ์ž‘์—…์ด ๋๋‚œ ํ›„ ์„ฑ๊ณต/์‹คํŒจ ์ด๋ฒคํŠธ๋ฅผ ๋ฐœํ–‰ํ•ฉ๋‹ˆ๋‹ค.
  3. ์ด๋ฒคํŠธ ์ •์˜: ์ด๋ฒคํŠธ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
  4. ๋ณด์ƒ ํŠธ๋žœ์žญ์…˜ ์ •์˜: ์‹คํŒจ ์‹œ ๋ณด์ƒ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ํฌ์ธํŠธ ์ฐจ๊ฐ์— ์‹คํŒจํ•˜๋ฉด ์ด๋ฏธ ์ฐจ๊ฐ๋œ ํฌ์ธํŠธ๋ฅผ ๋ณต๊ตฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  5. ๋ฉ”์‹œ์ง€ ๋ธŒ๋กœ์ปค ๋˜๋Š” ์ด๋ฒคํŠธ ๋ฐœํ–‰: ๋ฉ”์‹œ์ง€ ๋ธŒ๋กœ์ปค๋ฅผ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ Spring์˜ ApplicationEventPublisher๋ฅผ ํ™œ์šฉํ•ฉ๋‹ˆ๋‹ค.

์žฅ์  ๋ฐ ๊ณ ๋ ค์‚ฌํ•ญ

  • ์žฅ์ 
    • Orchestrator๊ฐ€ ์ „์ฒด ํ”„๋กœ์„ธ์Šค๋ฅผ ์ค‘์•™์—์„œ ๊ด€๋ฆฌํ•˜๋ฏ€๋กœ ํ๋ฆ„์ด ๋ช…ํ™•ํ•ฉ๋‹ˆ๋‹ค.
    • ์„œ๋น„์Šค ๊ฐ„ ๊ฒฐํ•ฉ๋„๋ฅผ ์ค„์ด๊ณ  ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์˜ ๊ฐ€๋…์„ฑ์„ ํ–ฅ์ƒ์‹œํ‚ต๋‹ˆ๋‹ค.
  • ๊ณ ๋ ค์‚ฌํ•ญ
    • Orchestrator๊ฐ€ ๋‹จ์ผ ์žฅ์• ์ ์ด ๋  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์žฅ์•  ๋Œ€๋น„ ๋ฐ ๋ณต๊ตฌ ์ „๋žต์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
    • ๋ฉ”์‹œ์ง€ ์ง€์—ฐ์ด๋‚˜ ์‹คํŒจ์— ๋Œ€๋น„ํ•œ ์žฌ์‹œ๋„ ๋ฐ ๋ณด์ƒ ๋ฉ”์ปค๋‹ˆ์ฆ˜์„ ์ž˜ ์„ค๊ณ„ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

๋””์ž์ธ ํŒจํ„ด ๋น„๊ต

๋ถ„๋ฅ˜์žฅ์ ๋‹จ์ 
Orchestration- ์ค‘์•™์—์„œ ๋ชจ๋“  ํŠธ๋žœ์žญ์…˜ ์ œ์–ด ๊ฐ€๋Šฅ- ์ค‘์•™ ์กฐ์ •์ž๊ฐ€ ์‹œ์Šคํ…œ ๋ณ‘๋ชฉ์ด ๋  ์ˆ˜ ์žˆ์Œ
Choreography- ํŠธ๋žœ์žญ์…˜ ์ด๋ฒคํŠธ ๊ธฐ๋ฐ˜. ์„œ๋น„์Šค ๊ฐ„ ๋…๋ฆฝ์„ฑ ๋†’์Œ- ์‹คํŒจ ์‹œ ์ด๋ฒคํŠธ ๋ณต๊ตฌ๊ฐ€ ๋ณต์žกํ•จ

์ฐธ๊ณ 

profile
์–ด์ œ์˜ ๋‚˜๋ณด๋‹ค ์„ฑ์žฅํ•œ ์‚ฌ๋žŒ์ด ๋  ์ˆ˜ ์žˆ๋„๋ก ๋…ธ๋ ฅํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

0๊ฐœ์˜ ๋Œ“๊ธ€

๊ด€๋ จ ์ฑ„์šฉ ์ •๋ณด

Powered by GraphCDN, the GraphQL CDN