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

#mixi #DeLT スタートアップでマイクロサービスアーキテクチャやってみた / Micr...

riita10069
January 26, 2021

#mixi #DeLT スタートアップでマイクロサービスアーキテクチャやってみた / Microservice Architecture at a Startup

riita10069

January 26, 2021
Tweet

More Decks by riita10069

Other Decks in Technology

Transcript

  1. 2 About me Ryota Yamada Tokyo Institute of Technology Department

    of Information and Communications Engineerin g Berrar DataScience Laborator y Former Tech Design Inc. CT O Journey Inc. Lead Enginee r Volare an engineering organizatio n Twitter: @riita10069 aboutme: https://riita10069.m e Interest: Go, Cloud Native, SRE, DevOps, AI, MLOps, DataOps, FPGA
  2. גࣜձࣾTech Design ࠷ߴٕज़੹೚ऀ(CTO) • ϏδωεϞσϧͷߏஙɺαʔϏεઆ໌ࢿྉͷ࡞੒ • ૝ఆಋೖاۀͱͦͷϢʔβʔετʔϦʔͷ࡞੒ • ػೳཁ݅ɺඇػೳཁ݅ͷઃఆ •

    ΞϓϦέʔγϣϯίʔυɺΫϥ΢υΞʔΩςΫτͷ࣮૷ • ٕज़બఆɺϞμϯͳٕज़΁ͷΩϟονΞοϓ • ϝϯόʔͷ࠾༻ • ΤϯδχΞϦϯάϚωʔδϟʔɺεΫϥϜϚελʔ ϓϩμΫτͱϝϯόʔͱϏδωεʹؔ͢Δ͜ͱͷશͯΛ͔̌Β࡞ͬͨɻ
  3. Tree Service Authentication Service Web BFF API BFF App BFF

    API Gateway ※؆ུԽ͞Ε͍ͯ·͢ɻ Account Service News Service User Service BFF Layer GW Layer SVC Layer Scraper Service NLP Service Company Service Payment Service Partner Service Recommend Service
  4. 28 Schema ۦಈ։ൃΛ࠾༻ • SchemaΛ؅ཧ͢ΔrepositoryΛҰͭ࡞੒ • .protoΛ͜ͷrepositoryͰ؅ཧ͍ͯ͠Δɻ • ΤϯυϙΠϯτΛ௥Ճߋ৽͢Δ৔߹͸PRΛ͜͜΁ૹΔ •

    ഁյతมߋͷݕ஌ (https://github.com/uber/prototool break check) • ໋໊نଇͷపఈ (https://github.com/yoheimuta/protolint) • APIυΩϡϝϯτͷࣗಈ࡞੒ • pb.goΛࣗಈੜ੒͠ɺࣗಈͰPull RequestΛద੾ͳrepositoryʹૹ৴ • ͜ΕΒ͕શͯCIͰߦΘΕΔ
  5. 30 Queryෳࡶ͗͢໰୊ • TreeͷҰཡϖʔδʹඞཁͳαʔϏε͸ • Partner, Company, User, Tree, Authorization…

    • ෆՄೳͰ͸ͳ͍͚ΕͲAPI Composition͸͠ΜͲ͍ • ΫΤϦͷύϑΥʔϚϯε໰୊ͱ޲͖߹ͬͯΒΕͳ͍ • API GW͸ඞཁͳΧϥϜ͕Ͳ͜ʹ͋Δ͔஌Δඞཁ(ૄ݁߹ੑ) Query͚ͩMonolith΁
  6. 32 Query vs Command • QueryΛ࢖͏৔߹ • ݪଇෳ਺ͷϦϨʔγϣϯ͕བྷΉҰཡϖʔδͷऔಘ࣌ͷΈ • ͭ·Γɺ/resources/:id΍/users/:id͸commandͰڞ༗

    • CommandΛ࢖͏৔߹ • σʔλͷ࡞੒ɺߋ৽ɺϏδωεϩδοΫ͸શͯͪ͜Β • ิঈτϥϯβΫγϣϯʹ͍ͭͯ͸݁Ռ੔߹ੑͷΈΛٻΊΔ
  7. 34 CAPͷఆཧ • C: (Strong)Consistency • A: Availability • P:

    (Tolerance to Network)Partition • ͜ͷ̏ͭͷཁૉ͕τϨʔυΦϑͷؔ܎ [Eric Brewer] • ैདྷͷRDBͰ͸ɺڧ͍Ұ؏ੑΛٻΊ͍ͯͨɻ • ϚΠΫϩαʔϏεͰ͸ɺͲ͜Λଥڠ͍͔ͯ͘͠ɻ
  8. 37 τϥϯβΫγϣϯ 5SFF 4FSWJDF $PNQBOZ 4FSWJDF ۓٸঢ়گ 
 ͷ೾ٴ 6TFS

    4FSWJDF 2VFSZ 4FSWJDF $MPVE 1VC4VC &NFSHFODZ &NFSHFODZ &NFSHFODZ ᶃ ᶄ
  9. 38 τϥϯβΫγϣϯ 5SFF 4FSWJDF $PNQBOZ 4FSWJDF ۓٸঢ়گ 
 ͷ೾ٴ 6TFS

    4FSWJDF 2VFSZ 4FSWJDF $MPVE 1VC4VC 4VDDFTT 4VDDFTT 4VDDFTT ᶅ ᶆ ͭ0,ͳΒ 
 Ϩεϙϯε ᶇ 5SZJOH 5SZJOH 5SZJOH
  10. 39 τϥϯβΫγϣϯ 5SFF 4FSWJDF $PNQBOZ 4FSWJDF ۓٸঢ়گ 
 ͷ೾ٴ 6TFS

    4FSWJDF 2VFSZ 4FSWJDF $MPVE 1VC4VC $PO fi SN $PO fi SN $PO fi SN ᶉ ᶈ ͭ0,ͳΒ 
 Ϩεϙϯε ᶇ $PO fi SNFE $PO fi SNFE $PO fi SNFE
  11. 40 τϥϯβΫγϣϯ 5SFF 4FSWJDF $PNQBOZ 4FSWJDF 6TFS 4FSWJDF 2VFSZ 4FSWJDF

    $MPVE 1VC4VC 4VDDFTT 4VDDFTT 5JNFPVU ᶅ ᶆ • ੔߹ੑͷͨΊͷϦτϥΠ • Pub/SubͷϦτϥΠ • ॏཁͳͷ͕ႈ౳ੑ • ϦΫΤετIDΛॴ࣋ • ॏେͳγεςϜো֐ରԠ IUUQTHJUIVCDPNNFSDBSJHPDJSDVJUCSFBLFS 5SZJOH 5SZJOH
  12. 41 τϥϯβΫγϣϯ 5SFF 4FSWJDF $PNQBOZ 4FSWJDF 6TFS 4FSWJDF 2VFSZ 4FSWJDF

    $MPVE 1VC4VC $BODFM $BODFM 'BVMU ᶉ ᶈ ͭ0,ἧΘͳ͍ 
 Ϩεϙϯε ᶇ • ิঈτϥϯβΫγϣϯ • Ұ͕ࣦͭഊͨ͠ΒRollback • Tree͸ΠϕϯτΛॲཧ͢Δ 
 ଞͷαʔϏεΛ஌͍ͬͯΔ • ૄ݁߹ͱ͸͍͚ͳ͍͚ΕͲ… $BODFM $BODFM
  13. 43 Event Sourcing • Pub/Subʹ্͛ΒΕͨEventΛશͯKVSʹه࿥͢Δ • EventΛ࠶ੜ͢Δ͚ͩͰ݁Ռ੔߹ੑͷอͨΕͨσʔλʹ • ࠶ੜʹ΍ͨΒ͔͔࣌ؒΔͷͰఆظతʹεφοϓγϣοτ •

    APIόʔδϣϯʹΑͬͯڍಈ͕มΘΔͷͰɺ 
 σϓϩΠͷࡍʹ΋εφοϓγϣοτΛ࡞੒͢Δ • KVSʹ͸datastoreΛ࢖༻ͨ͠ IUUQTHJUIVCDPNNFSDBSJEBUBTUPSF
  14. 45 Ϣχοτςετ • Ϣχοτςετ͸CIͰ͋Δఔ౓ճͤΔ͕ɺ 
 ݁߹ςετͱDBͷѻ͍͕՝୊ʹͳͬͯ͘ • ࣗ࡞OSS Cynthia(https://github.com/riita10069/cynthia) 


    ʹΑͬͯMockΛ࢖ͬͨɺRepositoryͷςετΛඞਢͱͨ͠ • ·ͨRepositoryͷςετ͸sqlmockΛ࢖༻ͨ͠ 
 https://github.com/DATA-DOG/go-sqlmock
  15. 48 αʔϏεͷݸ਺෼Πϯϑϥ؀ڥΛߏங͢Δ • ҰͭͷϚΠΫϩαʔϏε͕࡞Δ΂͖k8s Resource • Deploy, Service, PDB, HPA,

    DestinationRule 
 Virtual Service, CI, CD, Duplicator(CRD), Terraform • ͜ΕΛTest, Dev, Prod؀ڥʹରͯࠩ͠෼ͳ͘࡞੒ • 1300ߦఔ౓ͷyamlΛ20Ҏ্΋ن཯Λ΋ͬͯ࡞੒͸ແཧ • K8sͷখ͞ͳϛε͕Πϯγσϯτʹͭͳ͕Γɺֶशίετେ • Ϧιʔεͷ໋໊نଇ΍σΟϨΫτϦߏ੒΋่յ
  16. 49 SKUF (Spectacular Kubernetes Unified Framework) • ڧ͘ந৅Խ͞ΕͨKubernetes Manifest FrameworkΛ಺੡

    • AppʹඞཁͳCueͱtfϑΝΠϧΛίϚϯυͰࣗಈੜ੒ • CueݴޠʹΑ੍ͬͯݶ͕ڧ͘ಇ໋໊͖ͳͲͷن཯Λอͭ • kustomizeΛ༻͍ͨdev, test, staging؀ڥ΋ࣗಈੜ੒ • cloudbuild.ymlͱArgoCDͷઃఆ΋ద੾ʹࣗಈੜ੒͞ΕΔ • ࠷௿ݶͷઃఆΦϓγϣϯ • Size, Scale, Network, Secret, ConfigMap
  17. 50 SKUF (Spectacular Kubernetes Unified Framework) ͨͬͨ͜Ε͚ͩͰ %FQMPZNFOU 4FSWJDF /BNFTQBDF

    3#"$ 1%# )1" %FTUJOBUJPO3VMF 7JSUVBM4FSWJDF ͜ΕΛࣗಈੜ੒
  18. 51 Kptͷ׆༻ • ResilireͰ͸ɺ5ͭఔ౓ͷCustom ControllerΛӡ༻ • ֤ϚΠΫϩαʔϏενʔϜ͸͜ΕΛ׆༻͢Δ͜ͱ͕ਪ঑ • ͦͷͨΊʹɺCustom ResourceͷManifestΛ࡞੒͸େม

    • Manifestͷ഑෍ʹkptΛ࢓༷ • https://github.com/GoogleContainerTools/kpt • NamespaceͳͲɺϚΠΫϩαʔϏενʔϜʹݻ༗ͳ΋ͷΛ 
 KptfileΛ༻͍ͯ؅ཧ͢Δ͜ͱͰCRͷσϓϩΠΛ༻ҙʹͨ͠
  19. 52 Code Generation Tool • ελʔτΞοϓͷ։ൃͷ΄ͱΜͲ͕CRUDͷ։ൃ • Go͔ͭClean ArchitectureͷCRUDΛࣗಈੜ੒͢Δ 


    ίʔυδΣωϨʔλʔͷ։ൃΛ࢖༻ͯ͠։ൃ଎౓Λ୲อ • ϚΠΫϩαʔϏεͱClean ArchitectureʹΑͬͯ 
 0 → 1։ൃͷεϐʔυײΛٯʹߴΊΔ͜ͱ͕Ͱ͖Δ • .protoͷΈΛهड़ͯ͠ɺCRUD΍migration͕ࣗಈੜ੒