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. ৘ড߂ঌܿ 6TFS ా҅ ੿࢑ ੋૐ SE1BSUZ ஶబஎઁ੘ ݫఋ੿ࠁҙܻ ౸ݒ ࢚ಿҙܻࢲ࠺झ

    6 6 'SPOU6* ੿࢑ా҅ઑഥ 6 6 6 6 6 6 6 6 6 % % % % % % % % % % $POUFYU.BQ %
  2. public class Product { ... private ProductSalesInfo productSalesInfo; private ProductMetaInfo

    productMetaInfo; private Content content; ... /** * ౸ݒ द੘ * @param startSaleDt */ public void startSale(LocalDateTime startSaleDt) { validateProduct(); productSalesInfo = ProductSalesInfo.startSale(startSaleDt); } }
  3. 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); }
  4. 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); } }
  5. 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
  6. class ProductMapper { Product mapToDomainEntity(...) { return Product.withId( new Product.ProductId(productJpaEntity.getId()),

    ProductSalesInfo... ProductMetaInfo... Content...); } ProductJpaEntity mapToJpaEntity(Product product) { return ProductJpaEntity... .build(); } }
  7. 2"

  8. ଵҊޙ೴  %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बബࢼ৉ ਤః࠘झ