Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ㄷㄷㄷ: Domain Driven Design과 적용 사례 공유

kakao
PRO
December 09, 2022

ㄷㄷㄷ: Domain Driven Design과 적용 사례 공유

#MSA #DDD

Legacy Server의 포팅을 위해 Domain Driven Design을 적용하여 MSA 화 한 사례를 공유합니다.

발표자 : sherlock.hs
카카오 엔터테인먼트에서 백엔드 개발자로 일하고 있는 셜록입니다. git blame을 열면 혹시나 제가 짠 코드일까 두근두근하면서, 레거시 서버로 고통받았던 나날과 함께 backlog를 열심히 청소하는 중입니다.

kakao
PRO

December 09, 2022
Tweet

More Decks by kakao

Other Decks in Programming

Transcript

  1. %PNBJO%SJWFO%FTJHOҗ੸ਊࢎ۹ҕਬ $PQZSJHIU,BLBP$PSQ"MMSJHIUTSFTFSWFE3FEJTUSJCVUJPOPSQVCMJDEJTQMBZJTOPUQFSNJUUFEXJUIPVUXSJUUFOQFSNJTTJPOGSPN,BLBP ŬŬŬ ੉ೠथTIFSMPDLIT ஠஠য়ূఠపੋݢ౟ JG LBLBP 

  2. %PNBJO%SJWFO%FTJHO 8IZ%%% %%%੸ਊী೙ਃ೮؍Ѫٜ "SDIJUFDUVSF 5IFSFJT/P4JMWFS#VMMFU

  3. ౵౟ցࢎ੉౟

  4.  .POPMJUIJD  ӝࣿࠗ଻  ਬ૑ࠁࣻ੄য۰਑  ӝמ੄Ҋ଱ച -FHBDZ4FSWFS

  5. %PNBJO%SJWFO%FTJHO

  6. %PNBJO%SJWFO%FTJHO  بݫੋ੄ݽ؛җ۽૒ী૘઺  6CJRVJUPVT-BOHVBHF ࠁಞ੸঱যࢎਊ  4PGUXBSF&OUJUZ৬%PNBJOрѐ֛੄ੌ஖

  7. 8IZ%%%

  8. %%% #%% 5%% #VTJOFTT৬੄ഈস઺द పझ౟੗زച ߈ࠂ੸ੋࢸ҅ࣻ੿

  9. %%%੸ਊী೙ਃ೮؍Ѫٜ

  10. $POUFYU 
 .BQ #PVOEFE 
 $POUFYU "HHSFHBUF

  11. #PVOEFE$POUFYU ৘ড߂ঌܿ ా҅ 6TFS ੿࢑ ஶబஎઁ੘ ݫఋ੿ࠁҙܻ ౸ݒ ੋૐ SE1BSUZ

  12. ৘ড߂ঌܿ ా҅ 6TFS ੿࢑ ஶబஎઁ੘ ݫఋ੿ࠁҙܻ ౸ݒ ੋૐ SE1BSUZ #PVOEFE$POUFYU

    $POU
  13. ৘ড߂ঌܿ 6TFS ా҅ ੿࢑ ੋૐ SE1BSUZ ஶబஎઁ੘ ݫఋ੿ࠁҙܻ ౸ݒ ࢚ಿҙܻࢲ࠺झ

    6 6 'SPOU6* ੿࢑ా҅ઑഥ 6 6 6 6 6 6 6 6 6 % % % % % % % % % % $POUFYU.BQ %
  14. "HHSFHBUF

  15. ࢚ಿҙܻࢲ࠺झ "HHSFHBUF $POU ੘ಿ"HHSFHBUF 3PPU&OUJUZ 7BMVF0CKFDU &OUJUZ 7JEFP1SPEVDU 1SPEVDU4BMFT*OGP 1SPEVDU.FUB*OGP

    *NBHF1SPEVD 1SPEVDU4BMFT*OGP 1SPEVDU.FUB*OGP
  16. "SDIJUFDUVSF

  17. -BZFSFE $MFBO )FYBHPOBM

  18. ↟ 6TFS*OUFSGBDF ↟ "QQMJDBUJPO ↟ %PNBJO ↟ *OGSBTUSVDUVSF -BZFSFE"SDIJUFDUVSF 6*

    "QQMJDBUJPO %PNBJO *OGSBTUSVDUVSF
  19. ↟ &YUFSOBM*OUFSGBDF ↟ *OUFSGBDF"EBQUFS ↟ 6TF$BTF ↟ &OUJUZ $MFBO"SDIJUFDUVSF 6TF$BTF

    &OUJUZ $POUSPMMFS 8FC %# 6* %FWJDF (BUFXBZ
  20. )FYBHPOBM"SDIJUFDUVSF &OUJUZ 6TF$BTF 8FC %# .FTTBHF#SPLFS "EBQUFS "EBQUFS "EBQUFS 1PSU

    1PSU "EBQUFS 1PSU /PUJGJDBUJPO
  21. -BZFSFE $MFBO )FYBHPOBM

  22. ੘ಿ౸ݒ 8FC %# .FTTBHF#SPLFS %"0 $POUSPMMFS $POTVNFS 3FQPTJUPSZ 4FSWJDF /PUJGJDBUJPO

    1SPEVDFS 4FSWJDF
  23. public class Product { ... private ProductSalesInfo productSalesInfo; private ProductMetaInfo

    productMetaInfo; private Content content; ... /** * ౸ݒ द੘ * @param startSaleDt */ public void startSale(LocalDateTime startSaleDt) { validateProduct(); productSalesInfo = ProductSalesInfo.startSale(startSaleDt); } }
  24. 8FC $POUSPMMFS 4FSWJDF @PostMapping(path = "/product/{productId}") public void saleProduct(@PathVariable("productId") Long

    productId) { productUseCase.saleProduct(ProductSaleCommand .builder() .productId(new ProductId(productId)) .build()); } public interface ProductUseCase { void saleProduct(ProductSaleCommand command); }
  25. public class SaleService implements ProductUseCase { private final LoadProductPort loadProductPort;

    private final SaveProductPort saveProductPort; private final EventPublishPort eventPublishPort; @Override public void saleProduct(ProductSaleCommand cmd) { Product product = loadProductPort.loadProduct(cmd.getProductId()); product.startSale(LocalDateTime.now()); saveProductPort.saveProduct(product); eventPublishPort.publisherEvent(product); } }
  26. class ProductPersistenceAdapter implements LoadProductPort, SaveProductPort { ... @Override public Product

    loadProduct(ProductId productId) { ProductJpaEntity productJpaEntity = productRepository .findById(productId.getValue())...; ContentJpaEntity contentJpaEntity = contentRepository .findByProductId(productId.getValue())...; return mapper.mapToDomainEntity(...); } @Override public void saveProduct(Product product) { productRepository.save( mapper.mapToJpaEntity(product)); } } %# %"0 3FQPTJUPSZ
  27. class ProductMapper { Product mapToDomainEntity(...) { return Product.withId( new Product.ProductId(productJpaEntity.getId()),

    ProductSalesInfo... ProductMetaInfo... Content...); } ProductJpaEntity mapToJpaEntity(Product product) { return ProductJpaEntity... .build(); } }
  28. 5IFSFJT/P4JMWFS#VMMFU

  29. $POT  .4"ীࢲয়חױ੼਷߹ѐ۽j  "SDIJUFDUVSFҳഅীࢲࢤࢿغחࢤпࠁ׮݆਷௏٘  пبݫੋী؀ೠ֫਷੉೧بо೙ਃ

  30. 1SPT  ࠁಞ੸ੋ঱যࢎਊীٮܲࡅܲழޭפா੉࣌  بݫੋрҙ҅оࠂ੟ೠ҃਋௾ౣীࢲ੿ܻооמ  بݫੋ੄ܻ࠙ীٮܲਬ૑ࠁࣻী؀ೠಞ੄ࢿ  ࢜۽਍ӝמ߂ਃҳࢎ೦ী؀ೠਬোࢿ

  31. 1SPT $POU  &ODBQTVMBUJPO  -PPTFDPVQMJOH )JHIDPIFTJPO  %PNBJO-PHJD੄ܻ࠙۽#VTJOFTT-PHJDী૘઺ 

    ௏٘оةࢿ
  32. %%%

  33. %PNBJO%SJWFO%FTJHO

  34. 2"

  35. ଵҊޙ೴  %BSTIBO4BUZBOEt")ZCSJE1SBDUJDFuBDDFTTFE"VHVTU IUUQT XXXNPCJMFMJWFDBCMPHWBMVF - PG - UEE -

    CEE - EEE  &SJD&WBOT %PNBJO%SJWFO%FTJHO USBOT੉؀৐৤ӣ ਤః࠘झ   3PCFSU$.BSUJO 5IF$MFBO"SDIJUFDUVSF ࣠ળ੉৤ӣ بࢲ୹౸ੋࢎ੉౟   5PN)PNCFSHT (FU:PVS)BOET%JSUZ0O$MFBO"SDIJUFDUVSF 1BDLU1VCMJTIJOH   աܖࣁ݃ࢎ֢ࠗ بݫੋ઱بࢸ୍҅੷ੑޙ USBOTबബࢼ৉ ਤః࠘झ