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

はてなリモートインターン2021 マイクロサービス 講義資料

49f49940f0831a426745c028684bcdad?s=47 hatena
October 08, 2021

はてなリモートインターン2021 マイクロサービス 講義資料

49f49940f0831a426745c028684bcdad?s=128

hatena

October 08, 2021
Tweet

Transcript

  1. ϚΠΫϩαʔϏε microservice #hatenaintern2021

  2. 泘㗧 • microservice • Ͳ͜Ͱ microservice Λ㒻㕴͢Δ͔? • microservice chassis

    • Մ᧺ଌੑ (observability) • service 㕽㙳৴ • 㒻ࢄ data ؅ཧ • micro frontend • microservice ͷ release
  3. NJDSPTFSWJDF .

  4. NJDSPTFSWJDF micro + service

  5. NJDSPTFSWJDF micro + service micro- : খ͞ͳ

  6. NJDSPTFSWJDF micro + service micro- : খ͞ͳ service :

  7. NJDSPTFSWJDF micro + service micro- : খ͞ͳ service : a

    system that provides something that the public needs, organized by the government or a private company (Oxford)
  8. NJDSPTFSWJDF micro + service micro- : খ͞ͳ service : a

    system that provides something that the public needs, organized by the government or a private company (Oxford)
  9. NJDSPTFSWJDF micro + service micro- : খ͞ͳ service : a

    system that provides something that the public needs, organized by the government or a private company (Oxford) [user needs] <-(provides something)- [system (= service)]
  10. NJDSPTFSWJDF micro + service micro- : খ͞ͳ service : a

    system that provides something that the public needs, organized by the government or a private company (Oxford) [user ͷٻΊ] <-(෺ࣄΛఏڙ͢Δ)- [࢓૊Έ (= service)]
  11. TFSWJDF ྫ :

  12. TFSWJDF ྫ : ͸ͯͳϦϞʔτΠϯλʔϯγοϓ 2021 [Πϯλʔϯੜͷօ͞Μ] <-(contents)- [͸ͯͳϦϞʔτΠϯλʔϯγοϓ 2021]

  13. TFSWJDF ྫ : ͸ͯͳϒϩά [user] <-(ϒϩάͷ㕑ᅎ)- [͸ͯͳϒϩά]

  14. TFSWJDF user ʹ෺ࣄΛఏڙ͢Δ࢓૊Έ (service)

  15. TFSWJDF খ͞ͳ࢓૊Έ (service) Λ૊Έ߹͸ͤͯେ͖ͳ࢓૊Έ (service) Λ࡞Δ

  16. TFSWJDF service ͷதͰ͸ᒬʑͳ process (OS process, goroutine, OOP class instance,

    etc.) ͕ಈ͍ͯΙΔ .
  17. TFSWJDF service ͷதͰ͸ᒬʑͳ process (OS process, goroutine, OOP class instance,

    etc.) ͕ಈ͍ͯΙΔ [ଞͷ process ͔Βͷೖྗ] <-(ܭࢉ΍ख᠃͖)- [process = (service)]
  18. TFSWJDF OOP class instance Λ "service" ͱݺͿྫ cf. PoEAA p.133,

    p.139 "Service Layer"
  19. TFSWJDF service ͷதͰ͸ᒬʑͳ process (OS process, goroutine, OOP class instance,

    etc.) ͕ಈ͍ͯΙΔ [ଞͷ process ͔Βͷೖྗ] <-(ܭࢉ΍ख᠃͖)- [process = (service)]
  20. TFSWJDF service ͷೖΕࢠ͕㒁ʹ᠃͘৔߹΋͋Δ

  21. TFSWJDF service ͷதʹ service ͕͋ͬͯɺதͷ service ͕ deploy ͢ΔᄸҐͰ΋͋Δ৔߹ɺதͷ service

    Λ microservice ͱݺͿ
  22. TFSWJDF Q. ͜Ε͸ service Ͱ͔͢?

  23. TFSWJDF [user ͷٻΊ] <-(෺ࣄΛఏڙ͢Δ)- [࢓૊Έ (= service)]

  24. TFSWJDF [user ͷٻΊ] <-(෺ࣄΛఏڙ͢Δ)- [࢓૊Έ (= service)] user ͱ࢓૊Έ͸نଇ (protocol)

    ʹኺͬͯ΍ΓऔΓ͢Δ
  25. TFSWJDF [user ͷٻΊ] <-(෺ࣄΛఏڙ͢Δ)- [࢓૊Έ (= service)] user ͱ࢓૊Έ͸نଇ (protocol)

    ʹኺͬͯ΍ΓऔΓ͢Δ ྫ : • menu ʹԊͬͯḼ亣͠୅ۚΛ፫; <- 㘆඼Λ㗵͚౉͢ • HTTP request <- HTTP response
  26. TFSWJDF microservice ͷ㑔ޠ : SOA (service oriented architecture)

  27. TFSWJDF microservice ͷ㑔ޠ : SOA (service oriented architecture) Amazon @

    2002 1)͜ͷ࣌఺ΑΓɺશͯͷνʔϜ͸αʔϏεΠϯλʔϑΣʔεΛ௨ͯ͡શͯͷσʔλͱػೳΛެ։͢Δ͜ͱɻ 2)֤νʔϜ͸֤ʑͦͷΠϯλʔϑΣʔεΛ௨ͯ͡௨৴͠ͳ͚Ε͹ͳΒͳ͍ɻ 3)ͦͷଞͷશͯͷϓϩηεؒ௨৴͸ڐՄ͞Εͳ͍ɻμΠϨΫτϦϯΫɺଞͷνʔϜͷσʔλιʔε͔Β௚઀ σʔλΛಡΉ͜ͱɺϝϞϦڞ༗ϞσϧɺόοΫυΞɺશͯΛې͡ΔɻωοτϫʔΫӽ͠ͷαʔϏεΠϯλʔ ϑΣʔεΛܦ༝ͨ͠௨৴͚͕ͩڐՄ͞ΕΔɻ 4)࢖༻͢Δٕज़͸໰Θͳ͍ɻ HTTP ɺ Corba ɺ Pubsub ɺ ΧελϜϓϩτίϧɺԿͰ΋ྑ͍ɻ Bezos ͸ؾʹ ͠ͳ͍ɻ 5)શͯͷαʔϏεΠϯλʔϑΣʔε͸ɺྫ֎ͳ͘ɺ֎෦ʹެ։ՄೳͳΑ͏ʹθϩ͔Βઃܭ͞Εͳ͚Ε͹ͳΒͳ ͍ɻ͢ͳΘͪɺνʔϜ͸શੈքͷσϕϩούʹ޲͚ͯΠϯλʔϑΣʔεΛެ։͢Δ͜ͱ͕Ͱ͖ΔΑ͏ɺઃܭ ͠ɺܭը͠ͳ͚Ε͹ͳΒͳ͍ɻྫ֎͸ແ͍ɻ Steve Yegge ͷ Google ͱϓϥοτϑΥʔϜʹؔ͢ΔͿͬͪΌ͚࿩Λ༁ͨ͠ʢલฤʣ
  28. TFSWJDF microservice ͷ㑔ޠ : SOA (service oriented architecture) Amazon @

    2002 1)͜ͷ࣌఺ΑΓɺશͯͷνʔϜ͸ αʔϏεΠϯλʔϑΣʔεΛ௨ͯ͡શͯͷσʔλͱػೳΛެ։͢Δ ͜ͱɻ 2)֤νʔϜ͸֤ʑ ͦͷΠϯλʔϑΣʔεΛ௨ͯ͡௨৴͠ͳ͚Ε͹ͳΒͳ͍ ɻ 3)ͦͷଞͷશͯͷϓϩηεؒ௨৴͸ڐՄ͞Εͳ͍ɻμΠϨΫτϦϯΫɺଞͷνʔϜͷσʔλιʔε͔Β௚઀ σʔλΛಡΉ͜ͱɺϝϞϦڞ༗ϞσϧɺόοΫυΞɺશͯΛې͡ΔɻωοτϫʔΫӽ͠ͷαʔϏεΠϯλʔ ϑΣʔεΛܦ༝ͨ͠௨৴͚͕ͩڐՄ͞ΕΔɻ 4)࢖༻͢Δٕज़͸໰Θͳ͍ɻ HTTP ɺ Corba ɺ Pubsub ɺ ΧελϜϓϩτίϧɺԿͰ΋ྑ͍ɻ Bezos ͸ؾʹ ͠ͳ͍ɻ 5)શͯͷαʔϏεΠϯλʔϑΣʔε͸ɺྫ֎ͳ͘ɺ֎෦ʹެ։ՄೳͳΑ͏ʹθϩ͔Βઃܭ͞Εͳ͚Ε͹ͳΒͳ ͍ɻ͢ͳΘͪɺνʔϜ͸શੈքͷσϕϩούʹ޲͚ͯΠϯλʔϑΣʔεΛެ։͢Δ͜ͱ͕Ͱ͖ΔΑ͏ɺઃܭ ͠ɺܭը͠ͳ͚Ε͹ͳΒͳ͍ɻྫ֎͸ແ͍ɻ Steve Yegge ͷ Google ͱϓϥοτϑΥʔϜʹؔ͢ΔͿͬͪΌ͚࿩Λ༁ͨ͠ʢલฤʣ
  29. TFSWJDF Q. ͜Ε͸ service Ͱ͔͢? .

  30. TFSWJDF Q. ͜Ε͸ service Ͱ͔͢? A. ͍͍͑ɻ͜Ε͸ service Ͱ͸͋Γ·ͤΜɻuser ͱ࢓૊Έ͸نଇ

    (protocol) ʹኺͬͯ΍ΓऔΓͯ͠Ι·ͤΜ
  31. TFSWJDF user ͱ࢓૊Έͷ㕽ʹ͸௨৴࿏͕͋Δ

  32. TFSWJDF 㙳৴͕نଇ (protocol) ʹኺͬͯΙΕ͹ɺ㙳৴࿏͸ந৅Ͱ͖Δ

  33. NPOPMJUI microservice ͷሣٛޠ͸ monolith monolith : Ұຕؠ

  34. NPOPMJUI microservice ʹ͓͍ͯɺservice ͷ user ͸ଞͷ service [user service] <-(෺ࣄΛఏڙ͢Δ)-

    [provider service]
  35. NPOPMJUI service 㚎ͷ process ΍ OOP class instance ͕ɺଞͷ process

    ΍ OOP class instance Λ user ͱͯ͠෺ࣄΛఏڙ ͯ͠ΙΕ͹ɺ͜ΕΒ΋ service ͱݟ၏ͤΔ [user class] <-(෺ࣄΛఏڙ͢Δ)- [provider class]
  36. NPOPMJUI service 㚎ͷ process ΍ OOP class instance ͕ɺଞͷ process

    ΍ OOP class instance Λ user ͱͯ͠෺ࣄΛఏڙ ͯ͠ΙΕ͹ɺ͜ΕΒ΋ service ͱݟ၏ͤΔ Ͱ͸ process ͸ microservice Ͱͤ͏͔?
  37. NPOPMJUI microservice ʹԙ͚Δݸʑͷ service ͸ deploy ᄸҐ • ᘐཱʹ deploy

    ͢ΔͷͳΒ microservice • వΊͯ deploy ͢ΔͳΒ monolith ઃܭʹ͸ microservice ͱ monolith Ͱಉ͡ख๏͕㒊΁ΔɻಘΒΕΔᏈՌ΋ࣅΔ ྫ : refactoring (㘟㕡㙹 architecture)
  38. ל׆ךNJDSPTFSWJDF؅㒻׌׾־ .

  39. ל׆ךNJDSPTFSWJDF؅㒻׌׾־ • "-ility" ͷڥ

  40. ל׆ךNJDSPTFSWJDF؅㒻׌׾־ • "-ility" ͷڥ • business capability ͷڥ • scalability

    ͷڥ • security ͷڥ
  41. CVTJOFTTDBQBCJMJUZס㗞 ྫ : • 㚒ᨽ • 㘆඼දࣔɾᒾࡧ • ՝ۚ •

    ग़ՙ
  42. CVTJOFTTDBQBCJMJUZס㗞 [user ͷٻΊ] <-(෺ࣄΛఏڙ͢Δ)- [࢓૊Έ (= service)] business capability ͷڥ

    = user ͷٻΊΔ෺ࣄͷڥ • user ͕ҟͳΔ • user ͸ಉ͕ͩ͡ٻΊΔ෺ࣄ͕ҟͳΔ
  43. CVTJOFTTDBQBCJMJUZס㗞 ʮservice Λ㒻͚ΔͳΒ team Λ㒻͚Δʯ͔?

  44. CVTJOFTTDBQBCJMJUZס㗞 Conway ͷ๏ଇ : service ͷ㗇㙉͸૊৫ͷ㗇㙉ʹኺ; cf. Melvin E. Conway

    "How Do Committees Invent?" 1968
  45. CVTJOFTTDBQBCJMJUZס㗞 Conway ͷ๏ଇ : service ͷ㗇㙉͸૊৫ͷ㗇㙉ʹኺ; ૊৫͕㗇㙉 X Λ࣋ͭ =>

    service ͷ㗇㙉͕ X ʹ㖢ෟ͘
  46. CVTJOFTTDBQBCJMJUZס㗞 Conway ͷ๏ଇ : service ͷ㗇㙉͸૊৫ͷ㗇㙉ʹኺ; ૊৫͕㗇㙉 X Λ࣋ͭ =>

    service ͷ㗇㙉͕ X ʹ㖢ෟ͘ service ͷ㗇㙉Λ X ʹ͢Δ <= ૊৫ͷ㗇㙉Λ X ʹ͢Δ
  47. CVTJOFTTDBQBCJMJUZס㗞 Conway ͷ๏ଇ : service ͷ㗇㙉͸૊৫ͷ㗇㙉ʹኺ; ཧ༝ : 1. team

    㕽ͷ communication ͸ team 㚎ͷ communication ΑΓࠔ㐾Ͱ͋Δ 2. ։ᚙ (dev) ͱ㕑༻ (ops) ͷᴥᴪ 3. ։ᚙ process ͷதʹᯅΕͨ cost
  48. CVTJOFTTDBQBCJMJUZס㗞 Conway ͷ๏ଇ : service ͷ㗇㙉͸૊৫ͷ㗇㙉ʹኺ; ཧ༝ : 1. team

    ⇭ͷ communication ͸ team ⤨Ƒ communication ΑΓࠔ㐾Ͱ͋Δ 2. ։ᚙ (dev) ͱ㕑༻ (ops) ͷᴥᴪ 3. ։ᚙ process ͷதʹᯅΕͨ cost ʮservice Λ㒻͚ΔͳΒ team Λ㒻͚Δʯ͸ཧ༝ 1 ʹண໨ͯ͠ΙΔ
  49. CVTJOFTTDBQBCJMJUZס㗞 1. team ⇭ͷ communication ͸ team ⤨Ƒ communication ΑΓࠔ㐾Ͱ͋Δ

    service ͷᏓ㒁ʹ͍ͭͯɺ • team Λ㒻͚Δͱ team 㚎 communication ͷ cost ͕ݮΔ (path ͕ݮΔ) • team Λ㒻͚Δͱ team 㕽 communication ͷ cost ͕⃧͑Δ (亣຺ (context) ͕ڞ༗͞ΕͯΙͳ͍)
  50. CVTJOFTTDBQBCJMJUZס㗞 1. team ⇭ͷ communication ͸ team ⤨Ƒ communication ΑΓࠔ㐾Ͱ͋Δ

    service ΛᏓ㒁͢Δࡍͷ team 㕽 communication ʹ͸ɺ • service ͷڞ༗ (Ꮣ㒁͕ࣗݾ׬݁͠ͳ͍) • ਓͷڞ༗ (݉຿)
  51. CVTJOFTTDBQBCJMJUZס㗞 ʮservice Λ㒻͚ΔͳΒ team Λ㒻͚Δʯ͸ɺҎ্ͷ cost ⃧ݮʹ᮫ͯ͠亯㙺ͳͱ͜ΖΛݟෟ͚ͯߦ;

  52. CVTJOFTTDBQBCJMJUZס㗞 ʮservice Λ㒻͚ΔͳΒ team Λ㒻͚Δʯ͸ɺҎ্ͷ cost ⃧ݮʹ᮫ͯ͠亯㙺ͳͱ͜ΖΛݟෟ͚ͯߦ; Q. 亯㙺?

  53. CVTJOFTTDBQBCJMJUZס㗞 ʮservice Λ㒻͚ΔͳΒ team Λ㒻͚Δʯ͸ɺҎ্ͷ cost ⃧ݮʹ᮫ͯ͠亯㙺ͳͱ͜ΖΛݟෟ͚ͯߦ; Q. 亯㙺? A.

    service શᱪΛΑ͘ɺૉૣ͘Ꮣ㒁͠᠃͚ΔࣄΛ໨ࢦ͢
  54. CVTJOFTTDBQBCJMJUZס㗞 ʮservice Λ㒻͚ΔͳΒ team Λ㒻͚Δʯ͸ɺҎ্ͷ cost ⃧ݮʹ᮫ͯ͠亯㙺ͳͱ͜ΖΛݟෟ͚ͯߦ; Q. 亯㙺? A.

    service શᱪΛΑ͘ɺૉૣ͘Ꮣ㒁͠᠃͚ΔࣄΛ໨ࢦ͢ ཧ༝ 2 ͷղܾࡦ (SRE (site reliability engneering)) ɺཧ༝ 3 ͷղܾࡦ (CD (៺᠃㙹 delivery / deploy)) ΋ಉᒬʹɺ cost ⃧ݮʹ᮫ͯ͠亯㙺ͳͱ͜ΖΛݟෟ͚ͯߦ;
  55. TDBMBCJMJUZס㗞 scaling • scale up : ߴ͍ੑೳͷ server Λ㒊; <->

    scale down • scale out : server ͷᢕᏐΛ⃧΍͢ <-> scale in
  56. TDBMBCJMJUZס㗞 Kubernetes ͷ pod ͩͱɺ • scale up : VPA

    (vertical pod autoscaler) • scale out : HPA (horizontal pod autoscaler)
  57. TDBMBCJMJUZס㗞 The scale cube : service Λ scale out ͢Δࡾख๏

    • x ࣠ : ಉ͡ service Λ ಉ͡໾㕴Ͱ deploy ͢Δ (scale out) • y ࣠ : 㖇ೳ㑌ʹ service Λ㒻㕴͢Δ (microservice) • z ࣠ : ಉ͡ service Λ deploy ͢Δ͕ɺdeploy ͢Δ server 㑌ʹҟͳΔ໾㕴Λ፦͸ͤΔ
  58. TDBMBCJMJUZס㗞 x ࣠ : ಉ͡ service Λ ಉ͡໾㕴Ͱ deploy ͢Δ

    (scale out)
  59. TDBMBCJMJUZס㗞 y ࣠ : 㖇ೳ㑌ʹ service Λ㒻㕴͢Δ (microservice)

  60. TDBMBCJMJUZס㗞 z ࣠ : ಉ͡ service Λ deploy ͢Δ͕ɺdeploy ͢Δ

    server 㑌ʹҟͳΔ໾㕴Λ፦͸ͤΔ ྫ : • batch ႔ཧ༻ server Λผ㙾 deploy ͢Δ • gateway Ͱछ㑔㑌ʹ request Λ㒻͚Δ • DB Λਨ㙮㒻㕴͢Δ (ਫ㚻㒻㕴͸ x ࣠) • DB ͷ read replica Λ㗇㙡͢Δ
  61. TDBMBCJMJUZס㗞 z ࣠ : ಉ͡ service Λ deploy ͢Δ͕ɺdeploy ͢Δ

    server 㑌ʹҟͳΔ໾㕴Λ፦͸ͤΔ
  62. TFDVSJUZס㗞 㘒ใ security ͷࡾ㛿ૉ • C : 㖇ີੑ (confidentiality) •

    I : ׬㙂ੑ (integrity) • A : Մ༻ੑ (availability)
  63. TFDVSJUZ㖇㳡䓪 DPOEFOUJBMJUZ ס㗞 access ੍ޚ • AWS IAM • Kubernetes

    ͷ ServiceRoleɺClusterRole • OPA (open policy agent)
  64. TFDVSJUZ㱭㙂䓪 JOUFHSJUZ ס㗞 • DB ͷ㒻཭ • service 㕽㙳৴ͷ㕆ᥒ㕡

  65. TFDVSJUZ⺎榫䓪 BWBJMBCJMJUZ ס㗞 ো᛻Λ೾㖎ͤ͞ͳ͍ • fault tolerance • API rate

    limit • circuit braker ো᛻͔Β伭෮͢Δ • auto healing • back pressure
  66. NJDSPTFSWJDFDIBTTJT .

  67. NJDSPTFSWJDFDIBTTJT chassis : γϟʔγɻ࿮૊Έ ͲΜͳ microservice ʹ΋㛿ΔɺԣᏗ㙹ͳ᮫৺ࣄ (cross cutting concern)

    Λመ᧋͢Δ a.k.a. framework
  68. NJDSPTFSWJDFDIBTTJT ͲΜͳ microservice ʹ΋㛿ΔɺԣᏗ㙹ͳ᮫৺ࣄ (cross cutting concern) Λመ᧋͢Δ ྫ :

    • ઃఆͷ㙦ೖ • Մ᧺ଌੑ (observability) • health check • graceful shutdown • error handling • debug • service discovery • service 㕽㚒ᨽɾ㚒Մ
  69. NJDSPTFSWJDFDIBTTJT ͲΜͳ microservice ʹ΋㛿ΔɺԣᏗ㙹ͳ᮫৺ࣄ (cross cutting concern) Λመ᧋͢Δ መ᧋ྫ :

    • Sprint Boot + Spring Cloud • nytimes/gizmo
  70. ⺎鈴峮䓪 PCTFSWBCJMJUZ .

  71. ⺎鈴峮䓪 PCTFSWBCJMJUZ service ͷᕝ͍ͨͨ͠ੑ࣭ : • Մ᧺ଌੑ (observability) : ᧺ଌ͔Β

    service ͷ㐫ଶΛਪଌͰ͖Δ • Մ੍ޚੑ (controllability) : service Λ㛕Ή㐫ଶʹᏓ㒁Ͱ͖Δ • ҆ఆੑ (stability) : service ͷ㐫ଶ͸Ұఆͷൣᅴʹཹ·Δ
  72. ⺎鈴峮䓪 PCTFSWBCJMJUZ Մ᧺ଌੑͷࡾ㚋㖥 : • metric (ྫ : Prometheusɺ Mackerel

    :-)) • tracing (APM (application performance monitoring)ɺ㒻ࢄ tracing) • logging (㗇㙉㕡 logɺहूɺ㒻ੳ)
  73. TFSWJDF㕽㙳⟓ .

  74. TFSWJDF㕽㙳⟓ service ͸ service ͱ㙳৴͢Δ

  75. TFSWJDF㕽㙳⟓ 㙳৴͕نଇ (protocol) ʹኺͬͯΙΕ͹ɺ㙳৴࿏͸ந৅Ͱ͖Δ

  76. TFSWJDF㕽㙳⟓ 㙳৴͕نଇ (protocol) ʹኺͬͯΙΕ͹ɺ㙳৴࿏͸ந৅Ͱ͖Δ ઌʹنଇ (protocol) ΛܾΊΔͱɺ㙳৴ઌͷ service Λᔅʹͤͣ։ᚙͰ͖Δ

  77. TFSWJDF㕽㙳⟓ ઌʹنଇ (protocol) ΛܾΊΔͱɺ㙳৴ઌͷ service Λᔅʹͤͣ։ᚙͰ͖Δ 㙳৴ํࣜنଇͷྫ : • HTTP

    • message broker (Amazon SQSɺAmazon SNSɺGoogle Cloud Pub/SubɺKafkaɺNATSɺAMQP) • GraphQL • gRPC
  78. TFSWJDF㕽㙳⟓ ઌʹنଇ (protocol) ΛܾΊΔͱɺ㙳৴ઌͷ service Λᔅʹͤͣ։ᚙͰ͖Δ 㙳৴㚎༰نଇͷྫ : • OpenAPI

    • GraphQL • gRPC
  79. TFSWJDF㕽㙳⟓ ઌʹنଇ (protocol) ΛܾΊΔͱɺ㙳৴ઌͷ service Λᔅʹͤͣ։ᚙͰ͖Δ => schema first 㙳৴㚎༰نଇͷྫ

    : • OpenAPI • GraphQL • gRPC
  80. TFSWJDF㕽㙳⟓ ઌʹنଇ (protocol) ΛܾΊΔͱɺ㙳৴ઌͷ service Λᔅʹͤͣ։ᚙͰ͖Δ => schema first schema

    first ʹ͢Δͱɺ • ։ᚙ㐥㕽ͷ communication cost ͕Լ͕Δ • schema Λ㒊ͬͯ test Ͱ͖Δ schema ͸㛿ٻ service ͱఏڙ service ͷڞ༗ࢿݯ (ཧ༝ 3 : ڞ༗ࢿݯͳͷͰ CD (៺᠃㙹 delivery) ͢Δͷ͕㛕·͍͠)
  81. TFSWJDF㕽㙳⟓ 㙳৴͕نଇ (protocol) ʹኺͬͯΙΕ͹ɺ㙳৴࿏͸ந৅Ͱ͖Δ

  82. TFSWJDF㕽㙳⟓ 㙳৴͕نଇ (protocol) ʹኺͬͯΙΕ͹ɺ㙳৴࿏͸ந৅Ͱ͖Δ container (ྫ : containerd) ͱ orchestrator

    (ྫ : Kubernetes) ͸ɺ႔ཧ㕹ڥ (service 㕹ڥ : ops) ͔Β႔ཧ㚎༰ (service 㚎 ༰ : dev) Λந৅ͨ͠ ͔͠͠㙳৴㕹ڥ (service 㕽㕹ڥ) ͔Β㙳৴㚎༰ (service 㕽㚎༰) ͷந৅ (ྫ : Kubernetes' sevice) ͸ෆॆ㒻
  83. TFSWJDF㕽㙳⟓ 㙳৴͕نଇ (protocol) ʹኺͬͯΙΕ͹ɺ㙳৴࿏͸ந৅Ͱ͖Δ container (ྫ : containerd) ͱ orchestrator

    (ྫ : Kubernetes) ͸ɺ႔ཧ㕹ڥ (service 㕹ڥ : ops) ͔Β႔ཧ㚎༰ (service 㚎 ༰ : dev) Λந৅ͨ͠ ͔͠͠㙳৴㕹ڥ (service 㕽㕹ڥ) ͔Β㙳৴㚎༰ (service 㕽㚎༰) ͷந৅ (ྫ : Kubernetes' sevice) ͸ෆॆ㒻 => service mesh
  84. TFSWJDFNFTI service ͸ଞͷ service ͱ㙮઀㙳৴͠ͳ͍ɻ㕽ʹ proxy ͕ೖΓɺproxy ͕㙳৴Λ᧺ଌɾ੍ޚ͢Δ 㖇ೳͷྫ :

    • ၊૝ service • load balancing • timeoutɺretry • health checkɺcircuit braker • fault injection • 㕆ᥒ㕡ɺ㚒ᨽ • deploy ؅ཧ (A/B testingɺcanary releaseɺrollout (linearɺB/G (Blue/Green))) •
  85. TFSWJDFNFTI service ͸ଞͷ service ͱ㙮઀㙳৴͠ͳ͍ɻ㕽ʹ proxy ͕ೖΓɺproxy ͕㙳৴Λ᧺ଌɾ੍ޚ͢Δ • data

    plane : proxy ͷಇ͖ • control plane : proxy Λ᧺ଌɾ੍ޚ͢Δ
  86. TFSWJDFNFTI service ͸ଞͷ service ͱ㙮઀㙳৴͠ͳ͍ɻ㕽ʹ proxy ͕ೖΓɺproxy ͕㙳৴Λ᧺ଌɾ੍ޚ͢Δ Q. proxy

    ࣗᱪ͸ container Ͱಈ͘ඞ㛿͕͋Γ·͔͢?
  87. TFSWJDFNFTI service ͸ଞͷ service ͱ㙮઀㙳৴͠ͳ͍ɻ㕽ʹ proxy ͕ೖΓɺproxy ͕㙳৴Λ᧺ଌɾ੍ޚ͢Δ Q. proxy

    ࣗᱪ͸ container Ͱಈ͘ඞ㛿͕͋Γ·͔͢? A. ͍͍͑ɻመࡍͷ network 㖇ೳ΍ topology Λந৅͠౷Ұ㙹ʹ᧺ଌɾ੍ޚͰ͖Ε͹ཧ࿦্͸ɺΑΓ native ͳ software ΍ kernel ΍ bare metal Ͱመ᧋͢Δࣄ΋ՄೳͰ͢ɻSDN (software defined networking) ͸ͦͷࢼΈͱ΋ ݴ΁·͢
  88. TFSWJDFNFTI መ᧋ྫ : • Istio • Consul Connect (on Nomad)

    • Linkerd
  89. TFSWJDFNFTI መ᧋ྫ : • Istio <- ࠓၼ㒊;ͷ͸͜Ε • Consul Connect

    • Linkerd
  90. *TUJP • data plane : Envoy proxy • control plane

    : istiod
  91. *TUJP control plane ͷಇ͖ • data plane Λ㗇㙡͢Δ : sidecar

    injection • data plane Λઃఆ͢Δ : Envoy ͷઃఆΛ࡞Γɺઃఆ͢Δ • data plane ͔Βͷ໰ͻ߹͸ͤʹ౴΁Δ : ઃఆʹදͤͳ͍ Envoy ͷ੍ޚ • data plane Λ᧺ଌ͢Δ : Մ᧺ଌੑ (observability)
  92. *TUJP • data plane Λ㗇㙡͢Δ : sidecar injection

  93. *TUJP • data plane Λઃఆ͢Δ : Envoy ͷઃఆΛ࡞Γɺઃఆ͢Δ • data

    plane ͔Βͷ໰ͻ߹͸ͤʹ౴΁Δ : ઃఆʹදͤͳ͍ Envoy ͷ੍ޚ
  94. *TUJP • data plane Λ᧺ଌ͢Δ : Մ᧺ଌੑ (observability)

  95. 㒻丆EBUB畘杼 .

  96. 㒻丆EBUB畘杼 microservice ͸ଞͷ microservice ʹґଘ͢Δ [microservice] <-(෺ࣄΛఏڙ͢Δ)- [microservice]

  97. 㒻丆EBUB畘杼 software = data + ႔ཧ data ͷ㕅ͻ͸ read ͱ

    write ʹ㒻͚ΒΕΔ (cf. CQRS (command query ੹຿㒻཭)) • read : [microservice] <-(data ΛᩇΈग़͢)- [microservice] • write : [microservice] <-(data Λอଘͤ͞Δ)- [microservice]
  98. 㒻丆EBUB畘杼SFBE read : [microservice] <-(data ΛᩇΈग़͢)- [microservice] • API composition

    • materialized view • ڞ༗ DB
  99. 㒻丆EBUB畘杼SFBE API composition ଞͷ service ͔ΒɺAPI Λ㙳ͯ͠ data Λऔಘ͠ɺ૊Έ߹͸ͤͯ㒊; ΄ͱΜͲͷ৔߹ʹ㙺͢Δ

  100. 㒻丆EBUB畘杼SFBE API composition ࣅͨख๏ : • API gateway : API

    composition Λߦ;ሢ༻ͷ microservice • BFF (backend for frontend) : ಛఆͷ frontend ޲͚ͷ API gateway
  101. 㒻丆EBUB畘杼SFBE materialized view ᩇΈऔΓሢ༻ͷ view Λ࡞Δ ʮmicroserviceʯಉ࢜͸ີ݁߹ɻಉ͡ team ͕ᩇΈ /

    㘃͖ၷํͷ microservice Λ㘂༗͢ΔͳΒ㓂ར
  102. 㒻丆EBUB畘杼SFBE ڞ༗ DB data ͕อଘ͞ΕͯΙΔ DB ʹ㙮઀ᩇΈग़͠ʹΏ͘ DB ͸㚎ᢒɻ㚎ᢒ͔Β㙮઀㘗ࣄΛᢛ΁Δ΍͏ͳ΋ͷɻ͋ΒΏΔࠔ㐾Λ᧷ޛͯ͠㗘༻͠Α͏

  103. 㒻丆EBUB畘杼XSJUF write : [microservice] <-(data Λอଘͤ͞Δ)- [microservice] • event sourcing

    • TCC (try-confirm / cancel) • saga • ڞ༗ DB
  104. 㒻丆EBUB畘杼XSJUF event sourcing 㐫ଶΛᏓ㒁 event ͷूੵͱͯ͠ද͸͢ɻmessage broker ͷՄ༻ੑ͕ߴ͚Ε͹ɺ֤ service ͷো᛻ʹӨ伖͞Εʹ

    ͍͘
  105. 㒻丆EBUB畘杼XSJUF TCC (try-confirm / cancel) ΍ͬͯΈͯɺΈΜͳΑ͚Ε͹อଘɺ୭͔ବ໨ͳΒ cancel a.k.a. ೋ૬ commit

    Ұൠ㙹ʹ͸ DBMS (database management system) ʹෟሱ͢Δ transaction 㖇ೳΛ㒊;͕ɺͦΕʹݶΒͳ͍ Մ༻ੑʹ㐾͋Γ
  106. 㒻丆EBUB畘杼XSJUF TCC (try-confirm / cancel) ΍ͬͯΈͯɺΈΜͳΑ͚Ε͹อଘɺ୭͔ବ໨ͳΒ cancel

  107. 㒻丆EBUB畘杼XSJUF TCC (try-confirm / cancel) ΍ͬͯΈͯɺΈΜͳΑ͚Ε͹อଘɺ୭͔ବ໨ͳΒ cancel

  108. 㒻丆EBUB畘杼XSJUF TCC (try-confirm / cancel) ΍ͬͯΈͯɺΈΜͳΑ͚Ε͹อଘɺ୭͔ବ໨ͳΒ cancel

  109. 㒻丆EBUB畘杼XSJUF TCC (try-confirm / cancel) ΍ͬͯΈͯɺΈΜͳΑ͚Ε͹อଘɺ୭͔ବ໨ͳΒ cancel

  110. 㒻丆EBUB畘杼XSJUF TCC (try-confirm / cancel) ΍ͬͯΈͯɺΈΜͳΑ͚Ε͹อଘɺ୭͔ବ໨ͳΒ cancel

  111. 㒻丆EBUB畘杼XSJUF TCC (try-confirm / cancel) ΍ͬͯΈͯɺΈΜͳΑ͚Ε͹อଘɺ୭͔ବ໨ͳΒ cancel

  112. 㒻丆EBUB畘杼XSJUF TCC (try-confirm / cancel) ΍ͬͯΈͯɺΈΜͳΑ͚Ε͹อଘɺ୭͔ବ໨ͳΒ cancel

  113. 㒻丆EBUB畘杼XSJUF TCC (try-confirm / cancel) ΍ͬͯΈͯɺΈΜͳΑ͚Ε͹อଘɺ୭͔ବ໨ͳΒ cancel

  114. 㒻丆EBUB畘杼XSJUF saga ׬݁ͨ͠ transaction Λ૊Έ߹͸ͤͯෳᏐͷ DB ΛᏓ㒁͢Δ transaction ͕ࣦഊͨ͠Βɺ㖅ʹመߦͨ͠ transaction

    Λଧͪ㘌͢ิঈ transaction Λመߦͯ͠ rollback ͢Δɻิ ঈ transaction ͸֬መʹመߦͰ͖Δᗣɺႈ౳ʹ͠ retry ՄೳͰͳ͚Ε͹ͳΒͳ͍
  115. 㒻丆EBUB畘杼XSJUF saga ׬݁ͨ͠ transaction Λ૊Έ߹͸ͤͯෳᏐͷ DB ΛᏓ㒁͢Δ • choreography based

    saga • orchestration based saga
  116. 㒻丆EBUB畘杼XSJUF choreography based saga ֤ service ͕ࣗ཯㙹ʹ message Λ΍ΓऔΓͯ͠ɺ݁Ռ㙹ʹ㙂ᱪͷ㒁৽͕ඇಉ㖆ʹߦ͸ΕΔ

  117. 㒻丆EBUB畘杼XSJUF choreography based saga ࣦഊͨ͠Βิঈ transaction Λٯၚ೻͢Δ

  118. 㒻丆EBUB畘杼XSJUF choreography based saga ࣦഊͨ͠Βิঈ transaction Λٯၚ೻͢Δ

  119. 㒻丆EBUB畘杼XSJUF orchestration based saga saga ͷ㙂㕥㙸Λ҃Δ service ͕ಉ㖆㙹ʹ؂ಜ͢Δ TCC ͱ΄΅ಉ͡

  120. 㒻丆EBUB畘杼XSJUF orchestration based saga ࣦഊͨ͠Βิঈ transaction Λመߦ͢Δ

  121. 㒻丆EBUB畘杼XSJUF orchestration based saga ࣦഊͨ͠Βิঈ transaction Λመߦ͢Δ

  122. 㒻丆EBUB畘杼XSJUF ڞ༗ DB ಉ͡ DB ΛᩇΈ㘃͖͢Δ DB ͸㚎ᢒɻ㚎ᢒΛڞ༗͢Δ΍͏ͳ΋ͷɻ᧷ޛ͸͍͍͔?

  123. 㒻丆EBUB畘杼 CAP ఆཧ : ҎԼͷࡾᑍ݅Λಉ࣌ʹ׬શʹ㙘㘫Ͱ͖ͳ͍ • Ұ؏ੑ (consistency) • Մ༻ੑ

    (availability) • network 㒻Ꮧ଱ੑ (partition tolerance)
  124. 㒻丆EBUB畘杼 CAP ఆཧ : ҎԼͷࡾᑍ݅Λಉ࣌ʹ׬શʹ㙘㘫Ͱ͖ͳ͍ • Ұ؏ੑ (consistency) • Մ༻ੑ

    (availability) • network 㒻Ꮧ଱ੑ (partition tolerance) BASE : ෦෼తʹͰ͋Ε͹ CAP ͸ಉ࣌ʹ㙘㘫Ͱ͖Δ (<-> ACID (ݪࢠੑ (atomicity)ɺҰ؏ੑ (consistemcy)ɺᘐཱੑ (isolation)ɺӬ᠃ ੑ (durability))) • Basically Available • Soft-state • ݁Ռ੔߹ੑ (Eventually consistent)
  125. NJDSPGSPOUFOE .

  126. NJDSPGSPOUFOE microservice Λ։ᚙ͢Δ team ͕ɺ֘ᙛ͢Δ frontend ΋։ᚙ͢Δ ͍҃͸ business capability

    ʹԊͬͯ frontend ͚ͩ㒻㕴ͯ͠͠·; < microservice Ͱߦͬͨͷͱಉٞ͡࿦
  127. NJDSPGSPOUFOE 㒻㕴ख๏ : • page 㙂ᱪΛఏڙ͢Δ (route-based code splitting) •

    component Λఏڙ͢Δ (ྫ : React componentɺCSS in JSɺCSS Module) • error ͸ด͡㗓ΊΔ
  128. NJDSPGSPOUFOE㕽㙳⟓ • frontend ಉ࢜͸㙳৴ͤͣɺbackend Λհ͢Δ • URL ͷ query string

    Λհ͢Δɻpage ͕㒻͔ΕͯΙΔͳΒ༗༻ • property Λհͯ͠౉͢ (ྫ : React propertyɺDOM attribute) • event emitter • 㐫ଶΛڞ༗͢Δ (ڞ༗ DB ͱಉ͡ࠔ㐾Λ᧷ޛ͢Δ) (ྫ : Redux Λڞ༗)
  129. NJDSPGSPOUFOE 㒻㕴ͨ͠΋ͷΛ഑৴͢Δख๏ : • 㙂͘ҟͳΔ Web site ͱͯ͠㗇㙡͢Δ • bundling

    (ྫ : Webpack) • backend Ͱ૊Έ߹͸ͤΔ (ྫ : SSI (server-side includes)ɺESI (edge-side includes)) • lazy load (ྫ : loadable-componentsɺdynamic import)
  130. NJDSPGSPOUFOE backend ։ᚙͱ frontend ։ᚙͰҟͳΔ㒻㕴Λߦ;ͳΒɺ => BFF (backend for frontend)

    : ಛఆͷ frontend ޲͚ͷ API gateway
  131. NJDSPTFSWJDFסSFMFBTF .

  132. NJDSPTFSWJDFסSFMFBTF release Λࡾͭʹ㒻͚Δ : build + deploy + release

  133. NJDSPTFSWJDFסSFMFBTF release Λࡾͭʹ㒻͚Δ : build + deploy + release •

    canary release • B/G (Blue/Green) deloyment • feature toggle
  134. NJDSPTFSWJDFסSFMFBTF canary release Ұ෦ͷ user ʹઌߦͯ͠ release ͢Δ

  135. NJDSPTFSWJDFסSFMFBTF B/G (Blue/Green) deployment ৽ᢜၷํΛڞʹ deploy ͔ͯ͠Β release Λ੾Γସ΁Δ

  136. NJDSPTFSWJDFסSFMFBTF feature toggle deploy ͢ΕͲ΋ release ͤͣ

  137. NJDSPTFSWJDFסSFMFBTF 㒻ࢄ system Ͱ͸೗ԿͳΔ release खॱͰ΋ɺ2 version ͕ᝀཱ͠͏Δ

  138. NJDSPTFSWJDFסSFMFBTF 㒻ࢄ system Ͱ͸೗ԿͳΔ release खॱͰ΋ɺ2 version ͕ᝀཱ͠͏Δ ሣࡦ :

    • ޙํޓ׵ੑΛอͭ • API versioning ʹͯ৽ API Λᢜ client ͔Β੾Γ཭͢ • error budget ΛఆΊɺerror Λڐ༰͢Δ • fronend ౳ cache ͷڧ੍ purge Λመ᧋͢Δ
  139. ׷זיײ׷ֹסؤ٭ػ٭մ㡎״ױ׌ נ٭

  140. ׷זיײ׷ֹ*TUJP㚊⪌ • istioctl Λ install ͠·ͤ͏ • istioctl install !"set

    profile=demo !"context hatena-intern-2021 • kubectl label namespace hatena-intern-2021 istio-injection=enabled • kubectl get namespace hatena-intern-2021 -o yaml Ͱ istio-injection ͕ enabled ʹ ͳͬͯΙΔ͜ͱΛ֬㚒͠·͢
  141. ׷זיײ׷ֹ*TUJP㚊⪌ • kubectl apply -f https:!"raw.githubusercontent.com/istio/istio/release-1.7/ samples/addons/kiali.yaml Ͱ Kiali Λ㚊ೖ͠·͢

    • kubectl apply -f https:!"raw.githubusercontent.com/istio/istio/release-1.7/ samples/addons/prometheus.yaml Ͱ Prometheus Λ㚊ೖ͠·͢ • application Λ九㖈ಈ͠·ͤ͏ • istioctl dashboard kiali Ͱ㐫ଶΛ֬㚒͠·ͤ͏ • sign in ͸ admin:admin
  142. ,JBMJ

  143. ׷זיײ׷ֹGBVMUJOKFDUJPO ಛఆͷ㖇ೳʹ㕇ᅷ㙹ʹނোΛᚙੜͤͯ͞Ө伖ൣᅴΛ㙭΂·͢ • Injecting an HTTP abort fault Λࢀ㒅ʹɺrenderer service

    Λམͱͯ͠Έ·ͤ͏ (503 Service Temporarily Unavailable)ɻهࣄΛӾཡɾ࡞㘫ɾ㒁৽Ͱ͖Δ͔֬㚒͠·ͤ͏ɻfault %age ΛԼ͛ͨͱ͖ͷᎮಈΛ֬㚒͠· ͤ͏ • Kiali Ͱ application ͷ㐫ଶΛ֬㚒͠·ͤ͏ • blog service ͷ error message Λ֬㚒͠·ͤ͏ɻ·ͨ istio-proxy ͷ log ͔Β "authority": "renderer-go:50051" Λ୳͠ɺresponse_flags ͷ㙟Λ֬㚒͠·ͤ͏
  144. ׷זיײ׷ֹGBVMUJOKFDUJPO • renderer service Λɺਖ਼ৗʹಈ࡞͢Δ͕ɺresponse ͕ 5 ඵᬌΕΔ㐫ଶʹ͍ͯͩ͘͠͞ • Kiali

    Ͱ application ͷ㐫ଶΛ֬㚒͠·ͤ͏ • istio-proxy ͷ log ͷ response_flags Λ֬㚒͠·ͤ͏ • kubectl delete virtualservices.networking.istio.io [໊㙁] Ͱ fault injection Λղআ͠· ͤ͏
  145. 㒁מ㱃שמע CloudNative • CNCF Cloud Native Interactive Landscape • The

    Amazon Builders' Library microservice • microservice - .ŇoO(ͬͪ͞ΌΜͰ͢Αʌ(ʏl _ l)ůƄ ˑ) • Sam NewmanʮϚΠΫϩαʔϏεΞʔΩςΫνϟʯ2016 • Susan J. FowlerʮϓϩμΫγϣϯϨσΟϚΠΫϩαʔϏεԽʯ2017 • Neal Ford, Rebecca Parsons, Patrick KuaʮਐԽతΞʔΩςΫνϟʯ2018 • Sam NewmanʮϞϊϦε͔ΒϚΠΫϩαʔϏε΁ʯ2020