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

Kotlin製のGraphQLサーバーをNode.jsでモジュラモノリス化している話

 Kotlin製のGraphQLサーバーをNode.jsでモジュラモノリス化している話

Kazuhito Hokamura

November 19, 2023
Tweet

More Decks by Kazuhito Hokamura

Other Decks in Technology

Transcript

  1. Kotlin੡ͷGraphQLαʔόʔΛNode.jsͰϞδϡϥϞϊϦεԽ͍ͯ͠Δ࿩
    JSConf JP 2023
    @hokaccha

    View full-size slide

  2. 2
    About Me
    Kazuhito Hokamura
    software engineer
    @hokaccha
    @hokaccha

    View full-size slide

  3. @Ubie,Inc. 3
    1. ϢϏʔͷϓϩμΫτʹ͍ͭͯ
    2. ϢϏʔͷγεςϜͷݱঢ়ͱ՝୊
    3. ՝୊ʹରͯ͠औΓ૊ΜͰ͍Δ͜ͱ
    Table of Contents

    View full-size slide

  4. @Ubie,Inc. 4
    ࣗ෼ͷ঱ঢ়Λ౴͑Δ͚ͩͰɺ
    ࢀߟප໊΍ۙ͘ͷҩྍػؔ౳
    ʮड਍ͷख͕͔Γʯ͕ௐ΂ΒΕΔ
    ҩྍݱ৔Ͱ࣮ࡍʹ࢖ΘΕ஁͑ΒΕͨAIΛɺੜ׆ऀ͕ద੾ͳ
    ҩྍʹ͔͔Δ໨҆ͱͯ͠։์͍ͯ͠·͢ (2020೥य़ʙ)
    ແྉͰ ୭Ͱ΋
    ͍ͭͰ΋ ΄΅શͯͷ঱ঢ়Ͱˎ
    ˎ99% (1.3ສ௒)ͷ঱ঢ়ʹରԠ

    View full-size slide

  5. @Ubie,Inc. 5
    ໰਍ۀ຿ޮ཰Խ΍ೝ஌޲্ͳͲɺ
    ױऀ͞ΜͱͷίϛϡχέʔγϣϯઃܭΛ௨͡ɺ
    ਍࡯ͷ࣭޲্Λࢧԉ͢Δҩྍػؔ޲͚αʔϏε
    පӃɾΫϦχοΫͦΕͧΕͷχʔζʹ߹ΘͤͨҎԼͷΑ͏ͳ
    ػೳΛఏڙɾ։ൃ͍ͯ͠·͢
    ϢϏʔAI໰਍ ϢϏʔϦϯΫ
    ϗʔϜϖʔδAI૬ஊ૭ޱ etc…

    View full-size slide

  6. @Ubie,Inc. 6
    2. ϢϏʔͷγεςϜͷݱঢ়ͱ՝୊
    3. ՝୊ʹରͯ͠औΓ૊ΜͰ͍Δ͜ͱ
    Table of Contents
    1. ϢϏʔͷϓϩμΫτʹ͍ͭͯ

    View full-size slide

  7. 7
    γεςϜΞʔΩςΫνϟ

    View full-size slide

  8. 8
    ● ෳ਺ͷݴޠɾϑϨʔϜϫʔΫ͕ཚཱ͍ͯ͠Δ
    ○ Kotlin/Spring Boot, Rails, Node.js/NestJS, Go, Python
    ○ API ΋ GraphQL, gRPC, REST ͕ࠞࡏ
    ● ίʔυϕʔε͕େ͖͘ͳ͖ͬͯͯػೳͷڥք͕ᐆດʹͳΓɺΦʔφʔγοϓ͕ෆ໌ྎʹͳ͍ͬͯΔ
    ○ ಛʹϓϩμΫτଆͷαʔϏε͕ංେԽ͍ͯ͠Δ
    ● ݹ͔͘Β͋ΔϨΨγʔͳγεςϜ΍σʔλ͕ΞʔΩςΫνϟతͳ࿪Λ࢈ΜͰ͍Δ
    ○ ೝ஌ෛՙͷ্ঢɺอकίετͷ૿ՃͳͲʹΑΓੜ࢈ੑ͕௿Լ͍ͯ͠Δ
    γεςϜ্ͷ՝୊

    View full-size slide

  9. 9
    ҰݴͰ͍͏ͱ
    ٕज़తෛ࠴͕
    ੵΈ্͕͖ͬͯͨʂʂ

    View full-size slide

  10. @Ubie,Inc. 10
    3. ՝୊ʹରͯ͠औΓ૊ΜͰ͍Δ͜ͱ
    2. ϢϏʔͷγεςϜͷݱঢ়ͱ՝୊
    Table of Contents
    1. ϢϏʔͷϓϩμΫτʹ͍ͭͯ

    View full-size slide

  11. 11
    औΓ૊ΜͰ͍Δ͜ͱ
    ● ϦΞʔΩςΫςΟϯάʹΑΔٕज़తෛ࠴ͷղফ
    ○ ٕज़ελοΫͷ౷Ұ
    ○ ϞδϡϥϞϊϦεԽ
    ● ٕज़తෛ࠴Λίϯτϩʔϧ͢ΔͨΊͷऔΓ૊Έ
    ○ ٕज़ઓུɾํ਑ͷݴޠԽɾυΩϡϝϯςʔγϣϯ
    ○ Design DocʹΑΔઃܭϨϏϡʔͷϓϩηε੔උ
    ● ੜ࢈ੑࢦඪͷՄࢹԽͱ໨ඪͷઃఆ
    ○ Four KeysʹΑΔՄࢹԽ
    ○ ੜ࢈ੑվળͷͨΊͷઓུࡦఆ
    ← ࠓ೔͸͜͜ͷ࿩͠

    View full-size slide

  12. 12
    ٕज़ελοΫͷ౷Ұ

    View full-size slide

  13. 13
    γεςϜΞʔΩςΫνϟ To-Be

    View full-size slide

  14. 14
    ٕज़ελοΫͷ౷Ұ
    ● όοΫΤϯυ͸ݴޠΛNode.js/Goʹ౷Ұ
    ○ ϓϩμΫτଆͷαʔϏε͸Node.jsɺϓϥοτϑΥʔϜଆ͸Goʹ͢Δ
    ○ Node.jsͷਪ঑ߏ੒͸ NestJS, Prisma ͋ͨΓ͕༗ྗ
    ● ϑϩϯτΤϯυ͸Next.jsʹ౷Ұ
    ○ ݱঢ়ͱ͋·Γဃ཭͸ͳ͍ͷͰٕज़ελοΫ͸େ෯ͳมߋ༧ఆ͸ͳ͠
    ● API͸GraphQLʹ౷Ұ
    ○ gRPCͷซ༻Λߟ͍͕͑ͯͨGraphQLʹ౷Ұ͢Δํ޲Ͱݕ౼த

    View full-size slide

  15. 15
    ϞδϡϥϞϊϦε
    ʢAI͕ߟ͑ΔϞδϡϥϞϊϦεͷਤʣ

    View full-size slide

  16. 16
    ϞδϡϥϞϊϦε #ͱ͸
    ϞϊϦεͳΞϓϦέʔγϣϯͷ಺෦Λػೳ୯ҐͰϞδϡʔϧʹ෼ׂͨ͠ΞʔΩςΫνϟ

    View full-size slide

  17. 17
    Φʔφʔγοϓ͕େࣄ
    ʢAI͕ߟ͑ΔΦʔφʔγοϓʣ

    View full-size slide

  18. 18
    Why ϞδϡϥϞϊϦε

    View full-size slide

  19. 19
    v.s. ϚΠΫϩαʔϏε

    View full-size slide

  20. 20
    v.s. ϚΠΫϩαʔϏε
    ● ωοτϫʔΫ௨৴͕ൃੜ͠ͳ͍ͨΊɺ৴པੑ΍ύϑΥʔϚϯεͳͲͷ఺Ͱ༗ར
    ● ಉҰίʔυϕʔεͳͷͰ։ൃ؀ڥͷߏங΍ΠϯςάϨʔγϣϯςετ͕༰қ
    ● ΤϥʔτϥοΩϯά΍؂ࢹɺτϥϒϧγϡʔςΟϯά͕γϯϓϧʹͳΔ
    ● ϞδϡʔϧͷڥքͷมߋʹରԠ͠΍͍͢
    ϞδϡϥϞϊϦεͷϝϦοτ

    View full-size slide

  21. 21
    v.s. ϚΠΫϩαʔϏε
    ● ػೳ୯ҐͰσϓϩΠ΍εέʔϦϯά͕Ͱ͖ͳ͍
    ● ϓϩμΫτͷεέʔϧʹ൐ͬͯσϓϩΠύΠϓϥΠϯ΍CI͕ංେԽɺෳࡶԽ͢Δ
    ● ϞδϡʔϧͷڥքΛҡ࣋͢ΔͨΊͷίετ͕͔͔Δ
    ϞδϡϥϞϊϦεͷσϝϦοτ

    View full-size slide

  22. 22
    ϢϏʔʹ͓͚ΔϞδϡϥϞϊϦε

    View full-size slide

  23. 23
    ٕज़બఆ
    ● NestJS Ͱ GraphQL αʔόʔΛߏங͢Δ
    ● ORM ͸ Prisma
    ● ϑϨʔϜϫʔΫ΍ϥΠϒϥϦ͸͍ͨͬͯී௨ͷߏ੒

    View full-size slide

  24. 24
    ύοέʔδ؅ཧ
    ● package.json ͕ϧʔτʹ͋Δ͚ͩͷී௨ͷ Node.js ϓϩδΣΫτ
    ● npm workspace ͱ Turborepo Λ࢖ͬͨ multi packages ߏ੒΋ݕ౼
    ○ શͯͷϞδϡʔϧͰಉ͡ϥΠϒϥϦ΍ઃఆΛ࢖͏ͷͰ

    ϝϦοτ͕গͳ͍
    ○ ෳࡶੑͷ૿ՃͳͲͷσϝϦοτ্͕ճΔͱ൑அͯ͠΍Ίͨ

    View full-size slide

  25. 25
    Database, ORM
    ● DB͸ϞδϡʔϧؒͰڞ༗͢Δ
    ○ Ϟδϡʔϧ͝ͱʹDBͷεΩʔϚΛ෼͚Δʢ༧ఆʣ
    ● ςʔϒϧɾܕͷఆٛ͸Ϟδϡʔϧ͝ͱʹఆٛ͢Δ
    ● prisma-import Λ࢖ͬͯ݁߹͢Δ
    ○ github.com/ajmnz/prisma-import
    ● ϞδϡʔϧΛލ͍ͩjoin͸ڐՄ͠ͳ͍
    ● ϞδϡʔϧΛލ͍ͩτϥϯβΫγϣϯ͸ݕ౼த

    View full-size slide

  26. 26
    GraphQL
    ● GraphQLͷεΩʔϚ΋ؚΊ֤ͯϞδϡʔϧ͕؅ཧ͢Δ
    ● ΤϯτϦϙΠϯτͰεΩʔϚͱresolverΛ݁߹͢Δ

    View full-size slide

  27. 27
    Ϟδϡʔϧؒ௨৴
    ● exportͨؔ͠਺Λݺͼग़͚ͩ͢
    ○ TypeScriptͷܕ͕͋ΔͷͰഁյతͳมߋʹΑͬͯյΕΔͱ͍͏͜ͱ͸ൃੜ͠ʹ͍͘͸ͣ
    ● ֎෦ͷϞδϡʔϧʹެ։͍ͯ͠Δػೳ͔Ͳ͏͔Λ໌ࣔͰ͖ΔΑ͏ʹ͢Δ
    ○ modules/module-name ௚Լͷ index.ts Ͱ export ͨ͠΋ͷҎ֎͸֎෦͔Β͸ར༻͠ͳ͍
    ○ eslint ͷ import/no-internal-modules Λ࢖੍ͬͯݶ͢Δ

    View full-size slide

  28. 28
    ςετ
    ● NestJSͷDIΛ࢖ͬͯࣗ਎ͷϞδϡʔϧҎ֎Λmock͢Δ
    ● ଞͷϞδϡʔϧͷมߋʹΑͬͯςετ͕յΕͳ͍

    View full-size slide

  29. 29
    ·ͱΊ
    ● ϢϏʔ͸ϓϩμΫτ΍૊৫͕εέʔϧ͖ٕͯͯ͠ज़తෛ࠴Λฦ͍ͯ͠ΔϑΣʔζ
    ● औΓ૊Έͱٕͯ͠ज़ελοΫͷ౷Ұ΍ϞδϡϥϞϊϦεԽΛਐΊ͍ͯΔ
    ● ָ͍࣌͠ظͳͷͰڵຯΛ࣋ͬͯ͘Εͨํ͸੠͔͚͍ͯͩ͘͞ʂ

    View full-size slide

  30. 30
    Ұॹʹ΍ͬͯ͘ΕΔํ
    ੵۃืूதʂ

    View full-size slide

  31. 31
    UbieͰ͸ੵۃతʹ࠾༻Λߦ͍ͬͯ·͢ɻ͋ͳͨͷԠืΛ͓଴
    ͍ͪͯ͠·͢ɻ
    ΧδϡΞϧ໘ஊԠืϑΥʔϜ
    We Are Hiring!

    View full-size slide