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

モジュラモノリスで表現する複雑なドメイン領域と境界 / Expressing complex ...

showmant
October 17, 2020

モジュラモノリスで表現する複雑なドメイン領域と境界 / Expressing complex domain regions and boundaries with 'modular monoliths

showmant

October 17, 2020
Tweet

More Decks by showmant

Other Decks in Programming

Transcript

  1. "CPVU"MQ *OD 'PVOEFEJO w FNQMPZFFTJODMVEJOHFOHJOFFST w %FMJWFSJOH4VCTDSJQUJPONBOBHFNFOUTPGUXBSF 4DBMFCBTF 4BB4 

    w 6TF%%% 4DBMB $MFBO"SDIJUFDUVSF 5ZQF4DSJQU 3FBDU Ξϧϓגࣜձࣾ͸໊ͷΤϯδχΞ͕ࡏ੶͠ɺαϒεΫϦϓγϣϯ؅ཧͷ4BB4Λఏڙ %%%ɺ4DBMBΛ࠾༻͠ϑϩϯτΤϯυ͸3FBDUɺ5ZQF4DSJQUͰ࣮૷
  2. 5PEBZT5PQJD w 8IJDIEPNBJOBSFBTEPFT4DBMFCBTFIBOEMF  w 8IBUXFSFTPNFQSPCMFNTXF`WFFODPVOUFSFEXIJMFEFWFMPQJOH 4DBMFCBTF  w 8IZEJEXFBEPQUNPEVMBSNPOPMJUIT

     w )PXEJEXFEFTJHOUIFNPEVMBSNPOPMJUIT  w )PXBSFUIFNPEVMBSNPOPMJUITXPSLJOHTPGBS  w 8IBUJTUIFOFYUTUFQ ຊ೔ͷΞδΣϯμ͸ΞʔΩςΫνϟͷ࿩ͳͷͰɺ૊৫΍υϝΠϯྖҬʹ͍ͭͯઆ໌͠ͳ͕Β ϞδϡϥϞϊϦεʹ͍͓ͭͯ࿩͍ͤͯͨͩ͘͞ɻ
  3. 4DBMFCBTF 8IBUJT4DBMFCBTF w 4VCTDSJQUJPO#VTJOFTT&⒏DJFODZ3FWFOVF0QUJNJ[BUJPO1MBUGPSN w $FOUSBMJ[FENBOBHFNFOUPGDPNQMFYQSPEVDUEFTJHO DPOUSBDUT  CJMMJOH JOWPJDF

    FUDJO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DBUJPO JOUPNPEVMFT TVDIBTBEPNBJO NPEFM FUD ϞδϡϥϞϊϦε͸୯ҰσϓϩΠΛҡ࣋ͭͭ͠υϝΠϯϞσϧͳͲΛ୯Ґͱͯ͠Ϟδϡʔϧ෼ׂ͢Δ͜ͱͰ Ϟδϡʔϧੑͷ޲্Λૂ͏ΞʔΩςΫνϟ $POUFYU" $POUFYU#
  8. )PX%JE8F%FTJHO*U 4DBMFCBTFTBQQMJDBUJPOMBZFST ґଘੑٯసͷݪଇΛద༻্ͯ͠ҐϨΠϠʔ͔ΒԼҐϨΠϠʔ΁ͷࢀরͷΈՄೳ Secondary Adapter UseCase Domain Primary Adapter Shared

    Primary Adapter Shared SecondaryAdapter Shared Library Shared Domain Only the code from the top to the bottom layer can be referenced
  9. 1SJNBSZBOE4FDPOEBSZ"EBQUFS w 1SJNBSZ"EBQUFS w UIFBDUPSUIBUESJWFTUIFBQQMJDBUJPO w &BTJMZDIBOHFBDUPSTBOESVOCVTJOFTTMPHJD w 4FDPOEBSZ"EBQUFS w

    ESJWFOCZUIFBQQMJDBUJPO w FJUIFSHFUUIFTPMVUJPOPSTJNQMZJOGPSNJU ϓϥΠϚϦΞμϓλ͸)UUQ΍$POTVNFSͳͲͷΠϯλʔϑΣʔεΛ࣮૷ ηΧϯμϦ͸%#ΞΫηε΍֎෦αʔϏεͱͷ࿈ܞΛ୲͍ͬͯΔ )PX%JE8F%FTJHO*U
  10. 1SFQBSFBOTCUQSPKFDUGPSFBDIDPOUFYU TCUϓϩδΣΫτΛίϯςΩετ͝ͱʹ༻ҙ Secondary Adapter UseCase Domain Primary Adapter Shared Primary

    Adapter Shared Secondary Adapter Shared Library Shared Domain AuthN Ctx AuthZ Ctx Subscription Ctx Invoice Ctx )PX%JE8F%FTJHO*U
  11. 1SFQBSF.POPMJUI"EBQUFSMBZFSTGPSTZTUFNFOUSZQPJOUT ༻ҙͨ͠ϓϩδΣΫτΛϞϊϦεΞμϓλʹґଘͤ͞Δ MonolithAdapter Secondary Adapter UseCase Domain Primary Adapter Shared

    Primary Adapter Shared Secondary Adapter Shared Library Shared Domain AuthN Ctx AuthZ Ctx Subscription Ctx Invoice Ctx )PX%JE8F%FTJHO*U
  12. 8IZEPFTUIF.POPMJUI"EBQUFSSFGFSFODFBMMUIFPUIFSBEBQUFST ϞϊϦεΞμϓλ͸σϓϩΠ୯Ґͷू໿ͱɺίϯςΩετؒ௨৴Λ࣮ݱ͢ΔͨΊʹ͋Δ MonolithAdapter AuthN Ctx AuthZ Ctx Subscription Ctx Invoice

    Ctx Secondary Adapter UseCase Domain Primary Adapter Shared Primary Adapter Shared Secondary Adapter Shared Library Shared Domain w 5PHSPVQUIFNUPHFUIFSBTBVOJUPG EFQMPZNFOU w 5PJNQMFNFOUJOUFSDPOUFYU DPNNVOJDBUJPO )PX%JE8F%FTJHO*U
  13. %FpOFUIFJOUFSGBDFPGJOUFSTFSWJDFDPNNVOJDBUJPOCZQSPUPCVG *%- ίϯςΩετؒ௨৴ʹ੍໿Λ΋͍ͨͤͯͳ͍ͷͰɺڞ௨4FDPOEBSZ"EBQUFSʹQSPUPͷఆٛΛ഑ஔ͢Δ͜ͱͰ શίϯςΩετ͔ΒࢀরՄೳͳঢ়ଶʹ͢Δ There are currently no restrictions on

    inter-service communication. The protocol buffer's definition is placed in a shared SecondaryAdapter so that it can be referenced from all contexts. Secondary Adapter UseCase Domain Primary Adapter Shared Primary Adapter Shared SecondaryAdapter Shared Library Shared Domain )PX%JE8F%FTJHO*U
  14. ࣮૷͸H31$ͷϓϥΠϚϦΞμϓλʹߦ͏ɻଞͷϨΠϠʔ΍ಉҰϨΠϠʔͷଞͷΤϯτϦʔϙΠϯτ͔Β ࢀর͢Δ͜ͱ͸Ͱ͖ͳ͍ RemoteFunction is implemented here. Because an implementation called

    via gRPC implementation is here, reference from other layers is not allowed. MonolithAdapter AuthNCtx AuthZCtx SubscriptionCtx InvoiceCtx Secondary Adapter UseCase Domain Http Adapter Shared Primary Adapter Shared Secondary Adapter Shared Library Shared Domain Batch Adapter Kinesis Adapter gRPC Adapter 8IFSFEJEXFJNQMFNFOUUIF3FNPUFGVODUJPO )PX%JE8F%FTJHO*U
  15. 4UVC DMJFOU ͸ࣗಈͰੜ੒͞ΕΔ͕ɺϞδϡϥϞϊϦεͰ͸H31$Λ࣮ࡍʹ࢖͏͜ͱ͸ͳ͍ͷͰ 3FNPUF'VODUJPOʹPWFSSJEFͯࠩ͠͠ସ͑Δ w 5IF4UVC BVUPNBUJDBMMZ HFOFSBUFE DPOUBJOTBO JNQMFNFOUBUJPOPGH31$

    DPNNVOJDBUJPO w 3FQMBDJOHUIFJNQMFNFOUBUJPO PGBH31$DBMMXJUIBTJNQMF GVODUJPODBMMCZPWFSSJEJOHJU "MUIPVHINFUIPETBSFPWFSSJEEFOUPTJNQMJGZUIFFYQMBOBUJPO  UIFSFJTBXBZXFEPOUIBWFUPPWFSSJEFFWFSZUJNF SFNPUF'VODUJPOJTBEEFE *OKFDUSFNPUFGVODUJPOUPTUVC )PX%JE8F%FTJHO*U
  16. 3FQMBDFUIF4UVCJNQMFNFOUBUJPOJONPOPMJUI$UY ϞϊϦείϯςΩετͷΈ͕͢΂ͯͷڥքΛ·͙ͨ͜ͱ͕Ͱ͖ΔͷͰɺ ڞ௨ηΧϯμϦΞμϓλʹ͋ΔΠϯλʔϑΣʔεʹରͯ͠ɺ֤ίϯςΩετͷH31$Ξμϓλʹઃஔ͞Ε࣮ͨ૷Λ%*͢Δ Monolith context is able to cross the

    boundaries of each context. the Implementation is injected in the gRPC adapter for each context into an auto-generated RemoteFunction in the Shared SecondaryAdapter. Secondary Adapter UseCase Domain Http Shared Http Shared Secondary Adapter Shared Library Shared Domain Batch SharedBatch Kinesis Shared Kinesis gRPC Shared gRPC Monolith Adapter )PX%JE8F%FTJHO*U
  17. )PXJUXPSLTGPSVT 1PTJUJWFT w 4UBSUXJUIBTNBMMTDBMF MPXJNQBDUBSFB w 5SJBMBOEFSSPSJOEFpOJOHCPVOEBSJFTCBTFEPOUIFEJTDVTTJPO w %PNBJONPEFMJOHXJUISFTQFDUUPDPOUFYUCPVOEBSJFT w

    "0QQPSUVOJUZGPS$PSSFDU%PNBJO%FTJHOBOE$POUFYU#PVOEBSJFT Өڹൣғͷগͳ͍ͱ͜Ζ͔Βখ͘͞τϥΠͰ͖Δɻ΍Γͳ͕ΒɺυϝΠϯڥքͷ࠶ఆٛ΋ߦΘΕ͍ͯΔɻ ίϯςΩετڥքΛҙࣝͨ͠υϝΠϯઃܭ΋Ͱ͖ΔΑ͏ʹͳͬͨɻ
  18. $PODMVTJPOBOEPVSOFYUTUFQ w .PEVMBS.POPMJUIJTPOFPGUIFHPPETPMVUJPOTUIBUDBOCFEFWFMPQFEXIJMF DPOTJEFSJOHUIFDPOUFYUCPVOEBSJFT w $PNQBSFEUP.JDSPTFSWJDF ZPVDBOTUBSUXJUIBTNBMMUSZ w TCUBOE4DBMB1#BSFXPOEFSGVM BOEXJUIUIFNJUTFBTZUPBDIJFWF

    w 4DBMFCBTFJTTUJMMHPJOHUPCFBUSJBMBOEFSSPSQSPDFTTPGEPNBJOEFTJHO w *OTPNFDBTFT XFNBZSFWFSUCBDLUP.POPMJUIBHBJO w 8FXBOUUPDBSWFPVUUIFTFSWJDFTUIBUIBWFBTJHOJpDBOUCFOFpUPG NJDSPTFSWJDJOH υϝΠϯઃܭͷࢼߦࡨޡΛ܁Γฦ͢͜ͱʹ͓͍ͯඇৗʹ༗ޮͳखஈͰ͋Δ͕ɺ৔߹ʹΑͬͯ͸ϞϊϦεʹ໭͢͜ͱ΋ ߟ͑ΒΕΔɻ͏·͘ਐΊΒΕɺ૊৫΋੒௕͍͚ͯ͠͹ɺϚΠΫϩαʔϏεԽʹ΋ൺֱత༰қʹਐΊΒΕΔͷͰ͸ͳ͍͔ɻ