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

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

kakao
December 09, 2022

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

#MSA #DDD

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

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

kakao

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

    View full-size slide

  2. %PNBJO%SJWFO%FTJHO


    8IZ%%%


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


    "SDIJUFDUVSF


    5IFSFJT/P4JMWFS#VMMFU


    View full-size slide

  3. ౵౟ցࢎ੉౟

    View full-size slide

  4. .POPMJUIJD


    ӝࣿࠗ଻


    ਬ૑ࠁࣻ੄য۰਑


    ӝמ੄Ҋ଱ച
    -FHBDZ4FSWFS

    View full-size slide

  5. %PNBJO%SJWFO%FTJHO

    View full-size slide

  6. %PNBJO%SJWFO%FTJHO
    بݫੋ੄ݽ؛җ۽૒ী૘઺


    6CJRVJUPVT-BOHVBHF ࠁಞ੸঱যࢎਊ


    4PGUXBSF&OUJUZ৬%PNBJOрѐ֛੄ੌ஖

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  9. $POUFYU

    .BQ
    #PVOEFE

    $POUFYU
    "HHSFHBUF

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  12. ৘ড߂ঌܿ 6TFS
    ా҅
    ੿࢑
    ੋૐ
    SE1BSUZ
    ஶబஎઁ੘ ݫఋ੿ࠁҙܻ
    ౸ݒ
    ࢚ಿҙܻࢲ࠺झ
    6 6
    'SPOU6*
    ੿࢑ా҅ઑഥ
    6
    6
    6
    6
    6
    6
    6
    6
    6
    %
    %
    %
    %
    % % %
    %
    % %
    $POUFYU.BQ
    %

    View full-size slide

  13. ࢚ಿҙܻࢲ࠺झ
    "HHSFHBUF $POU

    ੘ಿ"HHSFHBUF
    3PPU&OUJUZ
    7BMVF0CKFDU
    &OUJUZ
    7JEFP1SPEVDU
    1SPEVDU4BMFT*OGP
    1SPEVDU.FUB*OGP
    *NBHF1SPEVD
    1SPEVDU4BMFT*OGP
    1SPEVDU.FUB*OGP

    View full-size slide

  14. "SDIJUFDUVSF

    View full-size slide

  15. -BZFSFE $MFBO )FYBHPOBM

    View full-size slide

  16. ↟ 6TFS*OUFSGBDF


    ↟ "QQMJDBUJPO


    ↟ %PNBJO


    ↟ *OGSBTUSVDUVSF
    -BZFSFE"SDIJUFDUVSF
    6*
    "QQMJDBUJPO
    %PNBJO
    *OGSBTUSVDUVSF

    View full-size slide

  17. ↟ &YUFSOBM*OUFSGBDF


    ↟ *OUFSGBDF"EBQUFS


    ↟ 6TF$BTF


    ↟ &OUJUZ
    $MFBO"SDIJUFDUVSF
    6TF$BTF
    &OUJUZ
    $POUSPMMFS
    8FC
    %# 6*
    %FWJDF
    (BUFXBZ

    View full-size slide

  18. )FYBHPOBM"SDIJUFDUVSF
    &OUJUZ
    6TF$BTF
    8FC
    %#
    .FTTBHF#SPLFS
    "EBQUFS
    "EBQUFS "EBQUFS
    1PSU
    1PSU
    "EBQUFS
    1PSU
    /PUJGJDBUJPO

    View full-size slide

  19. -BZFSFE $MFBO )FYBHPOBM

    View full-size slide

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

    View full-size slide

  21. public class Product {


    ...


    private ProductSalesInfo productSalesInfo;


    private ProductMetaInfo productMetaInfo;


    private Content content;


    ...


    /**


    * ౸ݒ द੘


    * @param startSaleDt


    */


    public void startSale(LocalDateTime startSaleDt) {


    validateProduct();


    productSalesInfo = ProductSalesInfo.startSale(startSaleDt);


    }


    }


    View full-size slide

  22. 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);


    }


    View full-size slide

  23. 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);


    }


    }


    View full-size slide

  24. 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

    View full-size slide

  25. class ProductMapper {


    Product mapToDomainEntity(...) {


    return Product.withId(


    new Product.ProductId(productJpaEntity.getId()),


    ProductSalesInfo...


    ProductMetaInfo...


    Content...);


    }


    ProductJpaEntity mapToJpaEntity(Product product) {


    return ProductJpaEntity...


    .build();


    }


    }


    View full-size slide

  26. 5IFSFJT/P4JMWFS#VMMFU

    View full-size slide

  27. $POT
    .4"ীࢲয়חױ੼਷߹ѐ۽j


    "SDIJUFDUVSFҳഅীࢲࢤࢿغחࢤпࠁ׮݆਷௏٘


    пبݫੋী؀ೠ֫਷੉೧بо೙ਃ

    View full-size slide

  28. 1SPT
    ࠁಞ੸ੋ঱যࢎਊীٮܲࡅܲழޭפா੉࣌


    بݫੋрҙ҅оࠂ੟ೠ҃਋௾ౣীࢲ੿ܻооמ


    بݫੋ੄ܻ࠙ীٮܲਬ૑ࠁࣻী؀ೠಞ੄ࢿ


    ࢜۽਍ӝמ߂ਃҳࢎ೦ী؀ೠਬোࢿ

    View full-size slide

  29. 1SPT $POU

    &ODBQTVMBUJPO


    -PPTFDPVQMJOH )JHIDPIFTJPO


    %PNBJO-PHJD੄ܻ࠙۽#VTJOFTT-PHJDী૘઺


    ௏٘оةࢿ

    View full-size slide

  30. %PNBJO%SJWFO%FTJHO

    View full-size slide

  31. ଵҊޙ೴

    %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बബࢼ৉ ਤః࠘झ

    View full-size slide